OpenGL 4.0 Shading Language Cookbook

OpenGL 4.0 Shading Language Cookbook

David Wolff

Language: English

Pages: 340

ISBN: 1849514763

Format: PDF / Kindle (mobi) / ePub

OpenGL 4.0 Shading Language Cookbook

David Wolff

Language: English

Pages: 340

ISBN: 1849514763

Format: PDF / Kindle (mobi) / ePub


With over 60 recipes, this Cookbook will teach you both the elementary and finer points of the OpenGL Shading Language, and get you familiar with the specific features of GLSL 4.0. A totally practical, hands-on guide. Overview A full set of recipes demonstrating simple and advanced techniques for producing high-quality, real-time 3D graphics using GLSL 4.0 How to use the OpenGL Shading Language to implement lighting and shading techniques Use the new features of GLSL 4.0 including tessellation and geometry shaders How to use textures in GLSL as part of a wide variety of techniques from basic texture mapping to deferred shading Simple, easy-to-follow examples with GLSL source code, as well as a basic description of the theory behind each technique What you will learn from this book Compile, install, and communicate with shader programs Use new features of GLSL 4.0 such as subroutines and uniform blocks Implement basic lighting and shading techniques such as diffuse and specular shading, per-fragment shading, and spotlights Apply single or multiple textures Use textures as environment maps for simulating reflection or refraction Implement screen-space techniques such as gamma correction, blur filters, and deferred shading Implement geometry and tessellation shaders Learn shadowing techniques including shadow mapping and screen space ambient occlusion Use noise in shaders Use shaders for animation Approach This hands-on guide cuts short the preamble and gets straight to the point - actually creating graphics, instead of just theoretical learning. Each recipe is specifically tailored to satisfy your appetite for producing real-time 3-D graphics using GLSL 4.0. Who this book is written for If you are an OpenGL programmer looking to use the modern features of GLSL 4.0 to create real-time, three-dimensional graphics, then this book is for you. Familiarity with OpenGL programming, along with the typical 3D coordinate syste

Zend Framework 2.0 by Example: Beginner's Guide

Game and Graphics Programming for iOS and Android with OpenGL ES 2.0 (Wrox Programmer to Programmer)

Programming Chrome Apps

Xcode 4 iOS Development Beginner's Guide

Arduino Projects for Dummies

Professional C# 6 and .NET Core 1.0

 

 

 

 

 

 

 

 

 

 

order as viewed from the front side of the polygon.) By default when rendering, if the order of the vertices appear on the screen in a counter-clockwise order, it indicates a front facing polygon, however, we can change this by calling glFrontFace from the OpenGL program. There's more... In the vertex shader we determine the front side of the polygon by the direction of the normal vector, and in the fragment shader, the determination is based on the polygon's winding. For this to work properly,

shader from the recipe Using per-fragment shading for improved realism. Your OpenGL program must set the values for all uniform variables defined in that vertex shader as well as the fragment shader shown below. How to do it... To create a shader program that uses the ADS shading model with a spotlight, use the following code for the fragment shader. #version 400 in vec3 Position; in vec3 Normal; struct SpotLightInfo { vec4 position; // Position in eye coords. vec3 intensity; // Amb., Diff., and

carry out the following steps: 1. Use the following code within the vertex shader: #version 400 layout (location = 0) in vec3 VertexPosition; layout (location = 1) in vec3 VertexNormal; out vec3 ReflectDir; out vec3 RefractDir; // Reflected direction // Transmitted direction struct MaterialInfo { float Eta; // Ratio of indices of refraction float ReflectionFactor; // Percentage of reflected light }; uniform MaterialInfo Material; uniform bool DrawSkyBox; uniform uniform uniform uniform uniform

following fragment shader: #version 400 in vec3 ViewDir; in vec3 Normal; // View direction in world coordinates // Normal in world coordinates uniform samplerCube CubeMapTex; 136 // The env. map Chapter 4 uniform samplerCube DiffuseMap; uniform samplerCube SpecMap; // The diffuse env. map // The specular env. map uniform bool DrawSkyBox; struct MaterialInfo { vec3 BaseColor; float DiffuseFactor; float SpecFactor; }; uniform MaterialInfo Material; layout( location = 0 ) out vec4 FragColor;

following steps: 1. Deselect the FBO (revert to the default framebuffer), and clear the color/depth buffers. 2. Select the pass2 subroutine function. 3. Set the model, view, and projection matrices to the identity matrix. 4. Draw a single quad (or two triangles) that fills the screen (-1 to +1 in x and y), with texture coordinates that range from 0 to 1 in each dimension. How it works... The first pass renders all of the scene's geometry sending the output to a texture. We select the

Download sample

Download