   Shadow Mapping: shadow color determined by depth
  hello, i finally got shadow mapping almost working. there is one last problem:as you can see in this screenshot, the color of the shadowed-areas is actually determined by the depth of the objects in the shadow map.this is obviously not what i want. i want the shadow to have the same darkness everywhere.i originally intended to get the darkness by rendering the scene with a modulated color of glColor4f(0.5,0.5,0.5,1); // makes everything darkand in the shadow-comparison pass i render withglColor4f(1,1,1,1); // makes everything brightthanks!   
  Mmmm, how are you rendering it?GL_LUMINANCE or GL_INTENSITY?Colour Texture or Depth Texture?NeutrinohunterP.S Whatever you are doing, I've been trying to think of algorithm to do this to take into account that objects which are nearer to the receiver tend to be less blurred than those from afar. So when you figure it out, let me know! :)   ;  hello,i am using GL_INTENSITY and a depth texture. thanks!   ;  What about to use GL_RGB instead of intesity and render objects with colors, that you select, not intensity (which is calculated)? That should work better (and as side product you'd be able to use colored shadows ;)).Neutrinohunter - well, this is quite complicated, cause there doesn't exist any good solution, which is NOT using N-passes of rendering and easy to code. You have to hand code everything. Anyway there is solution how to make plausible soft shadows (or can be reffered also as shadows casted form area -> area shadows). For the solutions - one of them is hierarchical min-max shadow maps (which is using mipmapping to generate plausible shadows), another is percetage-closer soft shadows (PCSS) you need to sort your geometry (blockers) in right order - If you'd not do that, you'll see light bleeding. Another solution is F.e. my PCML shadow maps - which are using realtime raytracing to compute plausible soft shadows (can be depth map based too instead of raytracing, but there'd be worse quality). There are surely more solutions to solve plausible shadows.   ;  thanks, but GL_RGB seems to be an invalid enumerant for GL_DEPTH_TEXTURE_MODE_ARB.i was wondering, how exactly does it happen, that the shadow-darkness is coming from the depth of the shadowmap? i thought the shadow comparison is a true or false comparions but it seems to be some float.   ;  If you're using GL_ARB_shadow or GL_SGIX_shadow, then there are just values true or false - no other value can be returned, so issues are somewhere else.   ;  yeah, but where? :-)maybe it's because i am using multitexturing?however here is the relevant code:glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-5, 5, -5, 5, 0.0, 10.0);//.gluPerspective(90, 1, 1, 16.0); //light projection matrixFloatBuffer lpm = FloatBuffer.allocate(16);glGetFloatv(GL_PROJECTION_MATRIX, lpm);glMatrixMode(GL_MODELVIEW);glLoadIdentity();new GLU().gluLookAt(1, 8, 0, 0, 0, 0, 0, 1, 0); // light view matrixFloatBuffer lvm = FloatBuffer.allocate(16);glGetFloatv(GL_MODELVIEW_MATRIX, lvm);glViewport(0, 0, sm_size, sm_size);glEnable(GL_POLYGON_OFFSET_FILL);glPolygonOffset(1.1f, 4.0f);glColorMask(false, false, false, false);renderScene(gl);glDisable(GL_POLYGON_OFFSET_FILL);glActiveTexture(GL_TEXTURE1);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, sm_id.get(0));glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sm_size, sm_size);glColorMask(true, true, true, true);/** * 2. pass from camera point of view, without light */glClear(GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_PROJECTION);glLoadIdentity();new GLU().gluPerspective(45, 1, 0.1, 100.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();new GLU().gluLookAt(10, 6, 8, 0, 0, 0, 0, 1, 0);glViewport(0,0,width,height);glColor4f(0.6f,0.6f,0.6f,1f);renderScene(gl);/** * 3. Pass from camera point of view with light *///glLightfv(GL_LIGHT1, GL_DIFFUSE, white);//glLightfv(GL_LIGHT1, GL_SPECULAR, white);glColor4f(1,1,1,1);//Calculate texture matrix for projection//This matrix takes us from eye space to the light's clip space//It is postmultiplied by the inverse of the current view matrix when specifying texgenMatrix4f biasMatrix = new Matrix4f(0.5f, 0.0f, 0.0f, 0.0f,0.0f, 0.5f, 0.0f, 0.0f,0.0f, 0.0f, 0.5f, 0.0f,0.5f, 0.5f, 0.5f, 1.0f);//bias from [-1, 1] to [0, 1]Matrix4f lightprojectionMatrix = Matrix4f.fromFloatBuffer(lpm);Matrix4f lightviewMatrix = Matrix4f.fromFloatBuffer(lvm);Matrix4f textureMatrix = biasMatrix.mult(lightprojectionMatrix).mult(lightviewMatrix);glActiveTexture(GL_TEXTURE1);//Set up texture coordinate generation.glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.getRow(0));glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.getRow(1));glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.getRow(2));glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.getRow(3));glEnable(GL_TEXTURE_GEN_S);glEnable(GL_TEXTURE_GEN_T);glEnable(GL_TEXTURE_GEN_R);glEnable(GL_TEXTURE_GEN_Q);//Bind & enable shadow map textureglBindTexture(GL_TEXTURE_2D, sm_id.get(0));//Enable shadow comparisonglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);//Shadow comparison should be true (ie not in shadow) if r<=textureglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);//Shadow comparison should generate an INTENSITY resultglTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);renderScene(gl);//Disable textures and texgenglDisable(GL_TEXTURE_GEN_S);glDisable(GL_TEXTURE_GEN_T);glDisable(GL_TEXTURE_GEN_R);glDisable(GL_TEXTURE_GEN_Q);;  glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);Now this is very strange line! I can't see any difference in my old GL_ARB_shadow program - if I use this or if I don't. Try removing this line (well, then your shadows would look black) else it's issue in multitexturing.Anyway good step to play more with shadow maps would be shaders (cause you can't do that kind of tricks with ffp).   ;  Just out of interest what happens if you change the texture generation to://This matrix takes us from eye space to the light's clip space//It is postmultiplied by the inverse of the current view matrix when specifying texgenMatrix4f biasMatrix = new Matrix4f(0.5f, 0.0f, 0.0f, 0.0f,0.0f, 0.5f, 0.0f, 0.0f,0.0f, 0.0f, 0.5f, 0.0f,0.5f, 0.5f, 0.5f, 1.0f);//bias from [-1, 1] to [0, 1]Matrix4f lightprojectionMatrix = Matrix4f.fromFloatBuffer(lpm);Matrix4f lightviewMatrix = Matrix4f.fromFloatBuffer(lvm);Matrix4f textureMatrix = biasMatrix.mult(lightprojectionMatrix).mult(lightviewMatrix);glActiveTexture(GL_TEXTURE1);//Set up texture coordinate generation.GLfloat sPlane[4] = {1.0f, 0.0f, 0.0f, 0.0f};   GLfloat tPlane[4] = {0.0f, 1.0f, 0.0f, 0.0f};   GLfloat rPlane[4] = {0.0f, 0.0f, 1.0f, 0.0f};   GLfloat qPlane[4] = {0.0f, 0.0f, 0.0f, 1.0f};   glTexGenfv(GL_S, GL_EYE_PLANE, sPlane);   glTexGenfv(GL_T, GL_EYE_PLANE, tPlane);   glTexGenfv(GL_R, GL_EYE_PLANE, rPlane);   glTexGenfv(GL_Q, GL_EYE_PLANE, qPlane);   glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );   glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );   glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );   glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );   glEnable(GL_TEXTURE_GEN_S);   glEnable(GL_TEXTURE_GEN_T);   glEnable(GL_TEXTURE_GEN_R);   glEnable(GL_TEXTURE_GEN_Q);  glMatrixMode(GL_TEXTURE);glLoadMatrixf(textureMatrix);;  thanks!Villem: if i remove this line then it defaults to LUMINANCE and gives pitchblack shadows, which is not what i want.Neutrinohunter:if i change the planes, then i get a light from another position, but still the shadow does not have the same darkness everywhere.   