Hi, I recently have been trying to get a deferred rendering system to work using osg.
First of all in almost all the tutorials I've seen so far, the normal vector was multiplied by the normal matrix (gl_NormalMatrix), but when I did so in my geometry vertex shader, I had strange results (the normals where changing while I was moving in the scene) ... I later discovered that by leaving the gl_Normal untouched, I was getting the right result :| The real problem is at the "mixing" part in the deferred fragment shader, I can't seem to get the light vector right. After comparing my FBOs output with what I've seen online I concluded that the problem has to be with the way I computed the light vector... My first clue would be that since the position vector is multiplied with gl_ModelViewMatrix I guess the light vector should need to be transformed too but I can't find a way to get the valid ModelViewMatrix from osg, I tried to get it trough osg::State::getModelViewMatrix() but it didn't work... does it have something to do with the "osg_" uniforms because I can't get them to work either. Here's a screen of the FBOs [Image: http://i43.tinypic.com/2irssjm.png ] [Image: http://i42.tinypic.com/2eztsvd.png ] [Image: http://i39.tinypic.com/2hi6lj4.png ] Here's my shaders gbuffer_vert.glsl Code: varying vec3 pos; varying vec3 t; varying vec3 b; varying vec3 n; attribute vec4 aTangent; attribute vec4 aBitangent; void main(void) { gl_Position = ftransform(); gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; pos = gl_ModelViewMatrix * gl_Vertex; t = normalize(aTangent.xyz); b = normalize(aBitangent.xyz); n = normalize(gl_Normal); } gbuffer_frag.glsl Code: varying vec3 pos; varying vec3 t; varying vec3 b; varying vec3 n; uniform sampler2D sColorMap; uniform sampler2D sNormalMap; void main(void) { vec3 N = texture2D(sNormalMap, gl_TexCoord[0].xy).xyz; vec3 smoothOut = vec3(0.5,0.5,1.0); N = normalize((mix(smoothOut,N,1.0)*2.0)-1.0); gl_FragData[0] = vec4(pos, 1.0); gl_FragData[1] = vec4(normalize(n) * 0.5 + 0.5, 1.0); gl_FragData[2] = vec4(texture2D(sColorMap, gl_TexCoord[0].xy).xyz, 1.0); } light_pass_vert.glsl Code: void main(void) { gl_Position = ftransform(); gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; } light_pass_frag.glsl Code: uniform sampler2D uBuffer0; uniform sampler2D uBuffer1; uniform sampler2D uBuffer2; void main(void) { vec4 buffer0 = texture2D(uBuffer0,gl_TexCoord[0].st); vec4 buffer1 = texture2D(uBuffer1,gl_TexCoord[0].st); vec4 buffer2 = texture2D(uBuffer2,gl_TexCoord[0].st); vec3 P = buffer0.xyz; vec3 N = buffer1.xyz; vec3 C = buffer2.xyz; vec3 L = gl_LightSource[0].position.xyz - P; float dist = length(L); float att = 0.01 * dist; float NdotL = max(dot(N,L), 0.0); if(NdotL > 0.0) { gl_FragColor += att * (0.4 * NdotL); vec3 halfVector = normalize(L+P); float NdotHV = max(dot(N,halfVector),0.0); gl_FragColor += att * 1.0 * pow(NdotHV,24.0); } gl_FragColor *= buffer2; } Also I get a "result" if I set the light position at something like vec3(20,20,20) like this: [Image: http://i40.tinypic.com/amv6ut.png ] But if I try something like vec3(0,10,0) or negative value I get this: [Image: http://i42.tinypic.com/16c76n8.png ] Lighting was much simpler in forward rendering :) Cheers, Micael ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=44256#44256 _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

