Hi,
I'm doing tests with shader for the lighting and the following problem happens
to me ...
With the camera close enough, all goes well, but if they turn away, do not seem
to take into account the position of the light.
Two images: the first up close, and the other from a distance and back lighting.
[Image: http://img227.imageshack.us/img227/3906/lighting1.jpg ][Image:
http://img266.imageshack.us/img266/7084/lighting2.jpg ]
vertex shader:
Code:
uniform vec3 eyePosition;
varying vec2 Texcoord;
varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;
varying vec4 color;
varying vec3 position;
void main( void )
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
Texcoord = gl_MultiTexCoord0.xy;
position = gl_Vertex.xyz;
vec4 fvObjectPosition = gl_ModelViewMatrix * gl_Vertex;
ViewDirection = normalize(eyePosition - fvObjectPosition.xyz);
LightDirection = normalize(gl_LightSource[0].position.xyz -
fvObjectPosition.xyz);
Normal = gl_NormalMatrix * gl_Normal;
float NdotL = max(dot(Normal, LightDirection), 0.0);
vec4 diffuse = NdotL * gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
vec4 ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
vec4 globalAmbient = gl_LightModel.ambient * gl_FrontMaterial.ambient;
vec3 fvReflection = normalize( ( ( 2.0 * Normal ) * NdotL ) -
LightDirection );
float fRDotV = max( 0.0, dot( fvReflection, ViewDirection ) );
vec4 specular = gl_FrontMaterial.specular * gl_LightSource[0].specular *
pow(fRDotV,200.0);
gl_FrontColor = diffuse + globalAmbient + ambient + specular;
}
Any idea what can be the problem?
Thank you!
Cheers,
Aitor
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=32224#32224
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org