logo资料库

OpenGL 4 Shading Language Cookbook-second edition.pdf

第1页 / 共394页
第2页 / 共394页
第3页 / 共394页
第4页 / 共394页
第5页 / 共394页
第6页 / 共394页
第7页 / 共394页
第8页 / 共394页
资料共394页,剩余部分请下载后查看
Cover
Table of Contents
Preface
Chapter 1: Getting Started With GLSL
Introduction
Using a function loader to access the latest OpenGL functionality
Using GLM for mathematics
Determining the GLSL and OpenGL version
Compiling a shader
Sending data to a shader using vertex attributes and vertex buffer objects
Getting a list of active vertex input attributes and locations
Sending data to a shader using uniform variables
Getting a list of active uniform variables
Using uniform blocks and uniform buffer objects
Getting debug messages
Building a C++ shader program class
Chapter 2: The Basics of GLSL Shaders
Introduction
Implementing diffuse, per-vertex shading with a single point light source
Implementing per-vertex ambient, diffuse, and specular (ADS) shading
Using functions in shaders
Implementing two-sided shading
Implementing flat shading
Using subroutines to select shader functionality
Discarding fragments to create a perforated look
Chapter 3: Lighting, Shading, and Optimization
Introduction
Shading with multiple positional lights
Shading with a directional light source
Using per-fragment shading for improved realism
Using the halfway vector for improved performance
Simulating a spotlight
Creating a cartoon shading effect
Simulating fog
Configuring the depth test
Chapter 4: Using Textures
Introduction
Applying a 2D texture
Applying multiple textures
Using alpha maps to discard pixels
Using normal maps
Simulating reflection with cube maps
Simulating refraction with cube maps
Applying a projected texture
Rendering to a texture
Using sampler objects
Chapter 5: Image Processing and Screen Space Techniques
Introduction
Applying an edge detection filter
Applying a Gaussian blur filter
Implementing HDR lighting with tone mapping
Creating a bloom effect
Using gamma correction to improve image quality
Using multisample anti-aliasing
Using deferred shading
Implementing order-independent transparency
Chapter 6: Using Geometry and Tessellation Shaders
Introduction
Point sprites with the geometry shader
Drawing a wireframe on top of a shaded mesh
Drawing silhouette lines using the geometry shader
Tessellating a curve
Tessellating a 2D quad
Tessellating a 3D surface
Tessellating based on depth
Chapter 7: Shadows
Introduction
Rendering shadows with shadow maps
Anti-aliasing shadow edges with PCF
Creating soft shadow edges with random sampling
Creating shadows using shadow volumes and the geometry shader
Chapter 8: Using Noise in Shaders
Introduction
Creating a noise texture using GLM
Creating a seamless noise texture
Creating a cloud-like effect
Creating a wood-grain effect
Creating a disintegration effect
Creating a paint-spatter effect
Creating a night-vision effect
Chapter 9: Particle Systems and Animation
Introduction
Animating a surface with vertex displacement
Creating a particle fountain
Creating a particle system using transform feedback
Creating a particle system using instanced particles
Simulating fire with particles
Simulating smoke with particles
Chapter 10: Using Compute Shaders
Introduction
Implementing a particle simulation with the compute shader
Using the compute shader for cloth simulation
Implementing an edge detection filter with the compute shader
Creating a fractal texture using the compute shader
Index
OpenGL 4 Shading Language Cookbook Second Edition Over 70 recipes demonstrating simple and advanced techniques for producing high-quality, real-time 3D graphics using OpenGL and GLSL 4.x David Wolff BIRMINGHAM - MUMBAI
OpenGL 4 Shading Language Cookbook Second Edition Copyright © 2013 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: July 2011 Second edition: December 2013 Production Reference: 1171213 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78216-702-0 www.packtpub.com Cover Image by Aniket Sawant (aniket_sawant_photography@hotmail.com)
Credits Project Coordinator Shiksha Chaturvedi Proofreaders Elinor Perry-Smith Chris Smith Indexer Mariammal Chettiyar Graphics Sheetal Aute Ronak Dhruv Production Coordinator Nilesh R. Mohite Cover Work Nilesh R. Mohite Author David Wolff Reviewers Bartłomiej Filipek Thomas Le Guerroué-Drévillon Muhammad Mobeen Movania Dario Scarpa Javed Rabbani Shah Acquisition Editors Gregory Wild Edward Gordon Usha Iyer Lead Technical Editor Neeshma Ramakrishnan Technical Editors Kunal Anil Gaikwad Jinesh Kampani Aman Preet Singh
About the Author David Wolff is an associate professor in the Computer Science and Computer Engineering Department at Pacific Lutheran University (PLU). He received a PhD in Physics and an MS in Computer Science from Oregon State University. He has been teaching computer graphics to undergraduates at PLU for over 10 years, using OpenGL.
About the Reviewers Bartłomiej Filipek is an experienced software developer with a passion for teaching. He has been leading OpenGL and graphics programming courses at Jagiellonian University in Cracow for around five years now. Additionally he gives lectures and workshops about modern C++ techniques at local universities. His professional experience focuses mostly on native application development including rendering systems, large-scale software development, game engines, multimedia applications, user interfaces, GPU computing, and even biofeedback. He shares his programming stories at his blog: http://www.bfilipek.com/. Thomas Le Guerroué-Drévillon is a freshly graduated software engineer. Having a profound interest in mathematics and drawing, it came easily to him to mix together these two passions in one field: computer graphics. Originally French, he used up all the opportunities given by his university to study and work all around the world. It allowed him to enjoy his first international experience in Estonia, the second in the prestigious KAIST in South Korea, and finally ending up now in Canada. Even though his university provided the mathematical background, he got his experience with OpenGL and GLSL on his own. He believes that the link between the well documented API and the shader samples is missing. Thus he naturally accepted to review this cookbook, which for him is the material he would have loved to get a hand on when he started developing interests in OpenGL/GLSL.
Dr. Muhammad Mobeen Movania received his PhD degree in Advance Computer Graphics and Visualization from Nanyang Technological University, Singapore. After finishing his PhD, he joined Institute for Infocomm Research, A-Star, Singapore to work on Augmented Reality based Virtual Tryon and Cloth Simulation systems using GPU and OpenGL. Before joining NTU, he was a junior graphics programmer at Data Communication and Control (DCC) Pvt. Ltd., Karachi, Pakistan. He worked on DirectX and OpenGL API for producing real-time interactive tactical simulators and dynamic integrated training simulators. His research interests include GPU-based volumetric rendering techniques, GPU technologies, real-time soft body physics, real-time dynamic shadows, real-time collision detection and response, and hierarchical geometric data structures. He is also the author of the OpenCloth project (http://code.google.com/p/opencloth), which implements various cloth simulation algorithms in OpenGL. His blog (http://mmmovania.blogspot.com) lists a lot of useful graphics tips and tricks. When not involved with computer graphics, he composes music and is an avid squash player. Dr. Mobeen has published several conference and journal papers on real-time computer graphics and visualization. Recently, he authored a book on OpenGL (OpenGL Development Cookbook by Packt Publishing, published in 2013) which details several applied recipes using modern OpenGL. He has also authored a book chapter in another book (OpenGL Insights by AK Peters/CRC Press, published in 2012). Dr. Mobeen is currently an Assistant Professor at DHA Suffa University, Karachi, Pakistan where he is busy nurturing young minds to become outstanding programmers and researchers of tomorrow. I would like to thank almighty ALLAH for bestowing his countless blessings on me and my family. After that, I would like to extend my gratitude towards my family, my parents (Mr. and Mrs. Abdul Aziz Movania), my wife (Tanveer Taji), my sisters (Mrs. Azra Saleem and Mrs. Sajida Shakir), my brothers (Mr. Khalid Movania and Mr. Abdul Majid Movania), all my nephews/nieces and my daughter (Muntaha Movania). Dario Scarpa has been coding for fun and profit for the last 15 years, and has no intention to stop. Jumping around among IT jobs as developer/sysadmin, amateur video game programming, and CS exams at the University of Salerno (Italy), he also managed to work with Adventure Productions in building Zodiac, a digital delivery platform focused on adventure games. At the time of reviewing this book, he's about to get his Master's degree, with a thesis on computer graphics that got him working intensively with—guess what—OpenGL.
Javed Rabbani Shah received his degree in Electrical Engineering from the University of Engineering and Technology, Lahore, Pakistan in 2004. He started his professional career by joining Delta Indus Systems (now Vision Master Inc.), where he worked with solder paste inspection systems for statistical process control involving technologies such as Image Processing, 3D Machine Vision, and FPGAs. He then joined the Embedded Systems Division of Mentor Graphics in 2007 and got the opportunity to work with the Nucleus+ real-time operating system, USB 2.0 middleware, WebKit, and OpenGL ES 2.0. He spearheaded the effort to integrate OpenGL ES 2.0 features in Mentor's cross-platform Inflexion 3D user interface engine. He is currently working at Saffron Digital in central London, where he is involved in work related to cross-platform secure video playback, DRM, and UltraViolet technologies. In his spare time, he likes to learn emerging technologies like OpenGL ES 3.0 and OpenCL.
分享到:
收藏