I’m pretty sure my attenuations are well. Code is below. I use exactly the same lightings and material for both non-shaders and shaders tests.
Okay here they are. Here is the directory to access them:
http://dagecko.free.fr/images
// vertex shader:
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; // to clip-space
vec4 ev4_pos = gl_ModelViewMatrix * gl_Vertex;
ev_pos = vec3 (ev4_pos)/ev4_pos.w;
v_to_l = gl_LightSource[0].position.xyz - ev_pos;
dist = length (v_to_l);
normalize (v_to_l);
normal = gl_NormalMatrix * gl_Normal;
// normal = normalize (normal);
// fragment shader:
vec4 amb, dif, spe, amb_g;
float pf;
float dot_p = max (0., dot (normal,v_to_l));
// I assume we're in a local viewer lighting model
vec3 eye = -normalize (ev_pos);
vec3 hv = normalize (v_to_l + eye);
float dot_h = max (0., dot (normal,hv));
if (dot_p == 0.0)
pf = 0.0;
else
pf = pow (dot_h, gl_FrontMaterial.shininess);
float att = 1./ (gl_LightSource[0].constantAttenuation +
gl_LightSource[0].linearAttenuation * dist +
gl_LightSource[0].quadraticAttenuation * dist * dist);
amb = att * gl_LightSource[0].ambient * gl_FrontMaterial.ambient;
amb_g = gl_LightModel.ambient * gl_FrontMaterial.ambient;
dif = att * dot_p * gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse;
spe = att * pf * gl_LightSource[0].specular * gl_FrontMaterial.specular;
// C code:
ShaderMgr::UseShader (s_program);
s_program.GetUniform ("depth_sampler").Uniform ((GLint)1);
s_program.GetUniform ("tex_sampler").Uniform ((GLint)0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport (0,0,800,600);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPerspective (60, 4./3., 1.0, 100.);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
gluLookAt (4,4,4,0,0,0,0,1,0);
glGetFloatv (GL_MODELVIEW_MATRIX, &view_matrix[0][0]);
InvertMatrix (view_matrix, inv_view_matrix);
glLightfv (GL_LIGHT0, GL_POSITION, l_pos);
glLightfv (GL_LIGHT0, GL_AMBIENT, l_amb);
glLightfv (GL_LIGHT0, GL_DIFFUSE, l_dif);
glLightfv (GL_LIGHT0, GL_SPECULAR, white);
glActiveTexture (GL_TEXTURE1);
glBindTexture (GL_TEXTURE_2D, shadow_map_tex);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LESS);
glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
glMatrixMode (GL_TEXTURE);
glLoadIdentity();
glTranslatef (.5,.5,.5);
glScalef (.5,.5,.5);
glMultMatrixf (bias_matrix);
glMultMatrixf (light_projection_matrix);
glMultMatrixf (light_view_matrix);
glMultMatrixf (&inv_view_matrix[0][0]);
glMatrixMode (GL_MODELVIEW);
RenderScene();
glActiveTexture (GL_TEXTURE1);
glBindTexture (GL_TEXTURE_2D, 0);
ShaderMgr::UseFixedPipeline();