Ugly per Vertex/Fragment Lighting

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 :slight_smile: )

— 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

Sorry but this picture look perfectly fine, unless I miss something ?

Indeed, the picture looks perfectly fine. The effect is only visible upon zooming 10-15x on my CRT monitor. Of course, if you are using a cheap, 18bit TN monitor the artifact will be much more visible.

An amount of banding is normal. 24bit color means 8bits per component or 256 distinct shades per component. The eye can easily distinguish between them (you’d need at least 1024 shades for smooth gradients). Even worse, cheap monitors can only display 18bit colors (6bits per component or 64 shades) which makes the issue much more pronounced.

It’s not the end of the world, however. Just add some textures and the effect will all but disappear.

Well, maybe I was wrong, indeed the problem isn’t visible anymore when I use meshes instead of a large flat surface (I don’t want to use textures).
Sorry for having doubted of GLSL’s power :D, and thank you again.

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