Skip to main content
gamedev.net
🔒 Locked

shadow mapping problem

Started by ppavel Aug 15, 2006 at 3:21 AM 6 replies 2k views
Original Post
ppavel
ppavel
Im learning how to make projected shadows. I'v already managed to save the depth texture and project it onto scene from the lights point of wiew. I works all great. This is the way how I inicialize the depth texture.

 glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 512, 512, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
     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_WRAP_S, GL_CLAMP);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
     glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

But than i want to add some compare_to_texture by adding

       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,GL_COMPARE_R_TO_TEXTURE);

I actualy dont know what should i expect to see after projecting such texture on scene but i would expect at least something ... but after using this all color and alpha information disappears. So what have i forgotten, or what to make diferent... ? thx
zedzeek
zedzeek
have a look at already existing working shadowmapping code, theres plenty of examples on the internet
try nvidia developer website
humus site
http://www.lighthouse3d.com/opengl/glsl/
http://www.gametutorials.com/Main.asp

good list of links here
http://www.realtimerendering.com/

etc
MARS_999
MARS_999
"but after using this all color and alpha information disappears."

What else would you expect? When you use glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB,GL_COMPARE_R_TO_TEXTURE); this will only return a true/false value for the depthmap e.g. is it or is it not in shadow... So if you want to see it as a texture you need to call it with IIRC GL_NONE for that texture unit its assigned to... As Zedzeek said check the net, BTW are you using shaders or FFP code path?
ppavel
ppavel
" this will only return a true/false value for the depthmap e.g. is it or is it not in shadow..."

This is clear, but i thought that it stores 0 or 1 information to texture so there is still something visible after projecting the texture on scene.

I use GLSL shader.

vertex:
varying vec4 shadowCoord;void main(){		vec4 vertpos=gl_Vertex;		shadowCoord=(gl_TextureMatrix[0]*gl_ModelViewMatrix)*vertpos;	gl_Position = ftransform();}


fragment:
uniform sampler2DShadow shadow;varying vec4 shadowCoord;void main(){	vec4 shad;	shad=shadow2DProj(shadow, shadowCoord);	gl_FragColor=shad;	}


I would expect this to show me black and white representation of what is shadowed and what is not. But the result is just white screen ...



[Edited by - ppavel on August 16, 2006 5:22:28 AM]
MARS_999
MARS_999
Try these

glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);//GL_NONE	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);//and you may want to change GL_CLAMP to CL_CLAMP_TO_EDGE IIRC FBO's need the //latter for some reason?


the GL_NONE is used when you want to shutdown the comparsions and use it as a normal texture
ppavel
ppavel
Still the same ...

Funny thing is that even sample codes from www.gametutorials.com doesnt work in my computer. My GK is Radeon X1600 so there should be no problem ...

Here is the whole code of my example:
http://rapidshare.de/files/29831579/code.txt.html

There might be some other stupid mistake I can not find. Could you please check it briefly (some comments are in czech, but I guess that generaly it's clear what is going on) ... thx

[Edited by - ppavel on August 18, 2006 4:25:03 AM]
ppavel
ppavel
I found out something, but i still dont understand where is the broblem.

I have set the window size to 512x512 to make setting the size of depth texture easyer (also to 512x512) than i set aspect ratio in gluPerspective to 1
gluPerspective(45,1,1,100)
so the shape deformes when I reshape the window. When window is set to 512x512 there is just white screen, but when i reshape it suddenly there appears some result of depth comparison, but not at the place where it should be ...

what em I doing wrong?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.