Jump to content
  • Advertisement
Sign in to follow this  
glmisscelan

Shadow mapping problems

This topic is 4147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I got shadow mapping without textures working with GLSL, but now im in problems again, im trying to do it with textures... Im using GL_TEXTURE_ARB0 for the normal texures and GL_TEXTURE_ARB1 for the shadow map textures. Here the vertex and frag shaders. Vertex: varying vec4 ProjShadow; void main(void) { ProjShadow = gl_TextureMatrix[1] * gl_Vertex; gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = ftransform(); } Frag: uniform sampler2DShadow ShadowMap; varying vec4 ProjShadow; uniform sampler2D texture0; uniform sampler2D texture1; void main (void) { //vec3 color = vec3(1.0, 1.0, 1.0); //color *= shadow2DProj(ShadowMap, ProjShadow).r; //gl_FragColor = vec4(color, 0.0); gl_FragColor = texture2D(texture2, gl_TexCoord[0].xy) * shadow2DProj(ShadowMap, ProjShadow).r; } Im setting texture0 an 1 with glGetUniformLocationARB with their correponding textures. At the i end i see the escene with normal textures and no shadow map, if i comment the normal textures and uncoment the lines from the frag shader it works ( with some artifacts but works :-) ). And there some extrange things, if let the normal textures uncomment and use and activate this frag shader for all the execution time vec3 color = vec3(1.0, 1.0, 1.0); color *= shadow2DProj(ShadowMap, ProjShadow).r; gl_FragColor = vec4(color, 0.0); i can see the escene with one normal texture doing extrange things. Maybe i have an error with glActiveTextures but all im doing is activate it, binding it and deactivate it before it corresponding glBegin/glEnd, same for shadow mapping texture. Any ideas? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Here is code for generating the shadow map:

int gl_sl_generate_shadow_map()
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixf(mLightProj.m);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadMatrixf(mLightView.m);

glViewport(0, 0, TEXTURE_SHADOW_SIZE, TEXTURE_SHADOW_SIZE);

glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glDisable(GL_LIGHTING);
glShadeModel(GL_FLAT);

glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
float lightpos[4] = {30, 0, 80, 1};


draw_cube2();
draw_cube3();
//bsp_render();

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, text_shadow);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TEXTURE_SHADOW_SIZE, TEXTURE_SHADOW_SIZE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
//glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glCullFace(GL_BACK);
glDisable(GL_CULL_FACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glViewport(0, 0, conf_get_scr(SCR_WD), conf_get_scr(SCR_HG));

}

and here is code for second pass:

int gl_sl_render_from_CPOV()
{
GLint randomtexture1_loc = glGetUniformLocationARB(glsl_get_program(), "texture1");
glActiveTextureARB(GL_TEXTURE1_ARB);
glUniform1iARB(randomtexture1_loc, 1);

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, text_shadow);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
//glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMultMatrixf(mBias.m);
//glScalef(0.5, 0.5, 0.5);
glMultMatrixf(mLightProj.m);
glMultMatrixf(mLightView.m);


glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

glMatrixMode(GL_MODELVIEW);

GLint randomtexture0_loc = glGetUniformLocationARB(glsl_get_program(), "texture0");
glActiveTextureARB(GL_TEXTURE0_ARB);
glUniform1iARB(randomtexture0_loc, 0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, text_normal);

glsl_put(); //enable shader

draw_cube2(); //draw un cube in a room with textures
draw_cube3();

glsl_quit(); //disable shader

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);

}

Thanks

Share this post


Link to post
Share on other sites
Do you know how to draw a single quad with the shadowmap only? Try that first and see if you can see anything. Remember you will have to shutdown the comparison with GL_NONE to see it.

Share this post


Link to post
Share on other sites
I think there are some inconsistencies between GLSL and C code.
Have you copied and pasted exactly the code you use?

1) GLSL : you are reading a sampler called texture2 which isn't declared anywhere.
2) C : you are binding the shadowmap to texture1 sampler (which btw isn't a shadow sampler) and you are reading the ShadowMap sampler instead.

Are those two mistakes really mistakes or just typos you did while writing the posts?

HellRaiZer

Share this post


Link to post
Share on other sites
Hi,

To HellRaiZer:

You are rigth, there were two mistakes (at least). I have made a lot of test and my code is full of garbage. Thanks. I correct them but im getting the same error.

To MARS_999:

I think than the shadow map generation isnt my problem. Thanks anyway.



I updloaded some pics for better explanation.

Here is my normal scene render from the light point of view. A rooom with a cube inside:

http://img253.imageshack.us/my.php?image=normalscenelpovej9.jpg

Here is a pic from the shadow map:

http://img104.imageshack.us/img104/6128/shadowmapqm9.jpg

Here is the scener render w/o textures from the Light point of view and changing the shaders to this:
//fragment shader
void main (void)
{
vec3 color = vec3(1.0, 1.0, 1.0);
color *= shadow2DProj(ShadowMap, ProjShadow).r;
gl_FragColor = vec4(color, 0.0);
//gl_FragColor = texture2D(texture0, gl_TexCoord[0].xy) * shadow2DProj(ShadowMap, ProjShadow).r;
}
//vertex shader
varying vec4 ProjShadow;

void main(void)
{
ProjShadow = gl_TextureMatrix[0] * gl_Vertex;
//gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}

http://img104.imageshack.us/img104/239/scenelpovee5.jpg

I can see the light shadowing the walls and yes some artifacts :-).

As i commented on previous post i left this shader activate por all the application, activating the textures unit i see the scene render normaly, with textures ?¿?¿, and my frag shadow should convert all to black and white. I dont understand ?¿?¿

And final the scene with textues and the shader i copied in the other post:

http://img67.imageshack.us/img67/9418/finalscenelpovof7.jpg

Thanks in advance.





Share this post


Link to post
Share on other sites
Well if your Texture unit 0 is what you want to use for your shadowmap texture coordinates make sure you call Unit 0 before you upload all the bias and matrices. And then make sure you call the next unit Texture unit 1 and upload the correct texture coordinates for the base textures....

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!