glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10, 10, -10, 10, 0.1, 10.0);
FloatBuffer lpm = FloatBuffer.allocate(16);
glGetFloatv(GL_PROJECTION_MATRIX, lpm);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
new GLU().gluLookAt(2f, 6, 0,
0, 0, 0,
0, 1, 0); // light view matrix
FloatBuffer 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, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
camera.setOrbit(l, 0.01f, rAngle_roty, rAngle_rotx);
camera.update(null);
glViewport(0,0,width,height);
glColor4f(0.6f,0.6f,0.6f,1f);
renderScene(gl);
/**
* 3. Pass from camera point of view with light
*/
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 texgen
Matrix4f 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);
glEnable(GL_TEXTURE_2D);
//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 texture
glBindTexture(GL_TEXTURE_2D, sm_id.get(0));
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//Enable shadow comparison
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
//Shadow comparison should be true (ie not in shadow) if r<=texture
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
//Shadow comparison should generate an INTENSITY result
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
renderScene(gl);
//Disable textures and texgen
glActiveTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);
Shadowmapping: wrong shadow-color
hello, there is problem with my shadowmap implementation.
the areas that are shadowed do not have the correct shadow-color. it seems as if the shadow-color is modulated with the shadow-map itself, since i use multitexturing
i have regular textures in GL_TEXTURE0 and the shadow-map in GL_TEXTURE1.
and since i must have booth textures active in the 3rd and last pass, it seems that the color of the shadow-map at a certain point is modulated into the normal color.
what can i do about this?
here is the renderloop
[Edited by - ehmdjii on March 2, 2008 5:39:14 AM]
Sorry I did send you a reply, meh doesn't look like it saved.
Since your problem is with modulation, try fiddling about with glTexEnvf and changing the Colour modes to GL_REPLACE or GL_COMBINE and see what you get. The weird artefact across the screen usually equates to the projection matrix not being accurate so I would check that.]
I've started to give up and move to shaders with my current implementation, it works well but I hate things that can't change colour except per vertex.
Neutrinohunter
Since your problem is with modulation, try fiddling about with glTexEnvf and changing the Colour modes to GL_REPLACE or GL_COMBINE and see what you get. The weird artefact across the screen usually equates to the projection matrix not being accurate so I would check that.]
I've started to give up and move to shaders with my current implementation, it works well but I hate things that can't change colour except per vertex.
Neutrinohunter
thanks for your reply neutrinohunter.
however, when i change the env_mode to gl_replace everything goes white and changing it to gl_combine gives still the same result as with gl_modulate.
however, when i change the env_mode to gl_replace everything goes white and changing it to gl_combine gives still the same result as with gl_modulate.
//Bind & enable shadow map texture
glBindTexture(GL_TEXTURE_2D, sm_id.get(0));
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //This looks like the problem, not sure though.
Try using GLSL, its a lot easier and faster since you don't have to draw the scene 3 times.
Seriously though, you posted this 3 times.......download the source code from paulsprojects that you are using, or figure it out.
http://www.gamedev.net/community/forums/topic.asp?topic_id=483991
http://www.gamedev.net/community/forums/topic.asp?topic_id=484075
http://www.gamedev.net/community/forums/topic.asp?topic_id=484910
glBindTexture(GL_TEXTURE_2D, sm_id.get(0));
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //This looks like the problem, not sure though.
Try using GLSL, its a lot easier and faster since you don't have to draw the scene 3 times.
Seriously though, you posted this 3 times.......download the source code from paulsprojects that you are using, or figure it out.
http://www.gamedev.net/community/forums/topic.asp?topic_id=483991
http://www.gamedev.net/community/forums/topic.asp?topic_id=484075
http://www.gamedev.net/community/forums/topic.asp?topic_id=484910
sorry for posting this problem multiple times. it is just that is not exactly the same problem. ;-) my shadowmapping implementation evolved and the topic slightly changed, so i opened a new thread.
i already read through paul's code several times, but since he is not using texturing, he does not seem to have this problem.
yes, GLSL would be a lot easier, but i am targeting very low end hardware so i cannot rely on shaders. besides, i just wanna know how it works without shaders. :-)
i already read through paul's code several times, but since he is not using texturing, he does not seem to have this problem.
yes, GLSL would be a lot easier, but i am targeting very low end hardware so i cannot rely on shaders. besides, i just wanna know how it works without shaders. :-)
btw i finally got it working. i forgot to disable the shadowmap after the first pass.
thanks everybody!
thanks everybody!
Ooh you have nice seethrough shadows, you care to share your source/ideas?
I'm trying to get that effect for multiple lights and possibly ambient occlusion but haven't been able to get that lovely effect.
You using GL_ARB_shadow_ambient? In either case I would like to talk to you about how I can get some sweet looking shadows :)
Neutrinohunter
I'm trying to get that effect for multiple lights and possibly ambient occlusion but haven't been able to get that lovely effect.
You using GL_ARB_shadow_ambient? In either case I would like to talk to you about how I can get some sweet looking shadows :)
Neutrinohunter
hi
no i am not using shadow_ambient only GL_ARB_shadow, GL_ARB_depth_texture, and GL_ARB_multitexture
the only difference from my implementation and the one at pauls projects is, that it uses texturing and alphatest also in the shadow-pass.
the source is already posted in the first post. it only misses one glDisable(GL_TEXTURE_2D) after the first pass in order to disable the shadowmap.
no i am not using shadow_ambient only GL_ARB_shadow, GL_ARB_depth_texture, and GL_ARB_multitexture
the only difference from my implementation and the one at pauls projects is, that it uses texturing and alphatest also in the shadow-pass.
the source is already posted in the first post. it only misses one glDisable(GL_TEXTURE_2D) after the first pass in order to disable the shadowmap.
Mmmm so are you doing multi texturing like.
glMultiTex...0(ShadowMap Coords...)
glMutliTex...1(Floor Coords...)
or vice versa.
or are you drawing the floor with glTexCoord then using the texture matrix and glTexGen to transform the coordinates?
And congratulations on getting this working :)
Neutrinohunter
NVM, I looked at the source again and saw all of it was there :p So what is your next plan? Multiple Lights? TSM? PSM? Shaders?
glMultiTex...0(ShadowMap Coords...)
glMutliTex...1(Floor Coords...)
or vice versa.
or are you drawing the floor with glTexCoord then using the texture matrix and glTexGen to transform the coordinates?
And congratulations on getting this working :)
Neutrinohunter
NVM, I looked at the source again and saw all of it was there :p So what is your next plan? Multiple Lights? TSM? PSM? Shaders?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement