Hi,
Thanks for the quick answers :D
So the first thing I did was to setup two cull callbacks, the first one sets
the camera inverse view matrix to a uniform for the geometry pass like this
(camera->getRenderTargetCamera()->getInverseViewMatrix()) and is attached to
the g-buffer camera. The second one sets a vec4 uniform for the deferred pass
(the light position multiplied by the same camera inverse view matrix as
before) and is set to the quad geometry. here's the modified shaders:
gbuffer_vert.glsl
Code:
varying vec4 pos;
varying vec3 n;
uniform mat4 uViewMatrixInverse;
void main(void)
{
mat4 modelMatrix = uViewMatrixInverse * gl_ModelViewMatrix;
mat3 modelMatrix3x3 = mat3(modelMatrix);
// world space
pos = modelMatrix * gl_Vertex;
n = normalize(modelMatrix3x3 * gl_Normal);
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}
I'm not sure if it's normal but if I use something else than "gl_Position =
ftransform();" I get a black screen... The normal buffer is correct but the
position buffer now looks like this:
[Image: http://i41.tinypic.com/18ozn9.png ]
gbuffer_frag.glsl
Code:
varying vec4 pos;
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] = pos;
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;
uniform vec4 uLightPositionWorldSpace;
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 = uLightPositionWorldSpace.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;
}
Unfortunately, it did not work as I expected... even thought I transformed the
position, light position and the normal by the same modelMatrix, the light is
changing with my camera (maybe view space?). However this time, even though it
moves, the light seems to be doing the right effect (diff+spec).
[Image: http://i41.tinypic.com/ddfepd.png ]
Also the light is brighter if my camera points down but if I move up, it fades
out...
Thank you!
Cheers,
Micael
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=44300#44300
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org