Hi,
Having touched Glsl for the first time recently, I thought I could use it to make my lighting more realistic, so I tried to use a per vertex or a per fragment lighting shader, but in both cases, my lighting results in a really ugly ripple effect on the plane surface I use for testing.
Here is my fragment shader source, and an image of the result.
If anyone has an idea of the problem, Thank you for answering (and sorry for my poor english )
— Vertex shader —
varying vec3 Position;
varying vec3 Normal;
void main()
{
gl_Position = ftransform();
gl_FrontColor = gl_Color;
Position = vec3(gl_ModelViewMatrix * gl_Vertex);
Normal = normalize(gl_NormalMatrix * gl_Normal);
}
— Fragment shader —
varying vec3 Position;
varying vec3 Normal;
float Shininess = 10.0;
void main()
{
vec3 ToLightVector = normalize(gl_LightSource[0].position.xyz - Position);
vec3 ToEyeVector = normalize(- Position);
vec3 LightReflectVector = reflect(-ToLightVector, Normal);
vec3 Color = gl_Color.rgb;
vec3 AmbientColor = Color * gl_LightSource[0].ambient.rgb;
vec3 DiffuseColor = Color * gl_LightSource[0].diffuse.rgb * abs(dot(ToLightVector, Normal));
vec3 SpecularColor = Color * gl_LightSource[0].specular.rgb * pow(max(dot(LightReflectVector, ToEyeVector), 0.0), Shininess);
gl_FragColor.rgb = AmbientColor + DiffuseColor + SpecularColor;
gl_FragColor.a = gl_Color.a;
}
— Image —
Well, the quality is bad, and it’s a little hard to see, but in fullscreen mode, it hurts the eyes, really :sorrow:
Lighting.png