The best tutorial out there(deferred shading)

What do you recommend? Some sample code would be very nice.

I’d recommend the “Orange Book” and at the same time have the GLSL spec in front of you… choose your GL version though!

The OP specifically wanted a tutorial on “deferred shading”, and the Orange Book does not talk about it, AFAIK.

Do you have anything that does? :slight_smile:

This one is a really good one here. They use classes from their own engine but they at least show the code for the most important functions. It’s opengl 2 but can easily be converted to opengl 3/4 (I use opengl 3.3). The best one I like so far. The orange book does have something on deffered rendering but I can only remember it being strictly for shadow volumes.

try this (opengl 2.0)

Another example I got a little help out of was hlsl example of deffered rendering from ati rendermonkey and if your still not satisfied look at this list of info.

here

Thanks!

The OP specifically wanted a tutorial on “deferred shading”, and the Orange Book does not talk about it, AFAIK.

My epic bad: I managed to somehow read it as “The best tutorial out there”, dropping the deferred shading and seeing just “GLSL”.

My sincere apologies.

accepted :slight_smile:

Ok I am currently using a shader that I found for computing the light at each pixel using the G-Buffer. I think this shader uses the properties of the material. I don’t wont that. How can the light be computed in the simplest possible way? I am using textures and the wont no material properties what so ever. This source below also don’t work very well when i disable color material. The colors then are right but big pieces of the models are totally black.

  1 uniform sampler2D Positions, Normals, Colors;
  2 
  3 void main(void)
  4 {
  5     vec4 colorMap, ambientGlobal, ambient, diffuse;
  6     vec3 ecPos, n, aux, lightDir, halfVector;
  7     float NdotL, NdotHV, dist, att;
  8 
  9     ecPos = texture2D(Positions, gl_TexCoord[0].st).xyz;
 10     n = texture2D(Normals, gl_TexCoord[1].st).xyz;
 11     colorMap = texture2D(Colors, gl_TexCoord[2].st);
 12 
 13     ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
 14 
 15     aux = gl_LightSource[0].position.xyz - ecPos;
 16     dist = length(aux);
 17     lightDir = normalize(aux);
 18 
 19     att = 1.0 / (gl_LightSource[0].constantAttenuation +
 20                 gl_LightSource[0].linearAttenuation * dist +
 21                 gl_LightSource[0].quadraticAttenuation * dist * dist);
 22 
 23     ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
 24 
 25     gl_FragColor = ambientGlobal + ambient * att;
 26 
 27     diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
 28     NdotL = max(dot(n, lightDir), 0.0);
 29 
 30     if (NdotL > 0.0) {
 31         gl_FragColor += att * (diffuse * NdotL);
 32         halfVector = normalize(lightDir + normalize(ecPos));
 33         NdotHV = max(dot(n, halfVector), 0.0);
 34         gl_FragColor += att * gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(NdotHV, gl_FrontMaterial.shininess);
 35     }
 36 
 37     gl_FragColor *= colorMap;
 38 }
~        

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.