Sign in to follow this  
bushman_IL

Shadow Mapping Lighting GLSL

Recommended Posts

Hello, I am implementing shadow mapping using GLSL. My application draws a room (6 quads to form walls, ceiling and floor) and inside tha room I have a sphere in the center of the room. My biggest problem is that when I position my light directly in the center of the room above the sphere and the view is directly in the center of the room on the floor (so I would expect my light to just point from the ceiling to the floor) When I do this, I do not see any shadows... so I'll adjust the view of the light to point towards the right edge of the room, and now I see a shadow casted by my sphere... however the shadow looks cutoff from the center of the room to the left. So this brings up two questions... Why am I not able to see a shadow when my light points straight down to the floor? and why is my shadow cutoff? I wish I could post screenshots as this would make my point very clear! It almost seems as though my light is a very narrow point light... how would I be able to set it so it lights the entire room? I'm still new to 3D but I'm guessing that the shadows are casted depending on what my glulookat specifies for the light source. Is there a way to cover the entire room. I understand I am asking for help on a very specific question and have not posted any code... but I'm not sure where to start... hopefully this question can be answered by theory, but tell me what to post and I'll psot it. Thanks for your help!!

Share this post


Link to post
Share on other sites
Hi,

Judging from your explanation, I would guess that you're using gluLookAt() to orient the camera. The up vector must not be collinear with the line formed by the center and the eye, but if the up vector points straight up and the camera is pointed directly down, this will be the case. Try changing your up vector to something like (0,0,1) depending on how you want your shadowmap oriented.

-G

Share this post


Link to post
Share on other sites
This can be a lot of things... you should debug drawing your depth map to see what is being rendered on it. My guess is that your zNear and zFar may be wrong.

Share this post


Link to post
Share on other sites
Thank you both for your reply...

Geometrian, you are correct... I am using gluLookAt for the light orientation. I tried changing my upVector to what you suggested but didn't seem to make a difference. I am not sure what else to try (not exactly sure how it works). My near and far clip planes look correct as well.... here is a code snippet that will hopefully help...


// Let's push on a new matrix so we don't change the rest of the world
Gl.glPushMatrix();

// Push on a new matrix to keep our view changes isolated
Gl.glPushMatrix();

// Reset the current modelview matrix
Gl.glLoadIdentity();

// This is where we set the light's position and view.
Glu.gluLookAt(ceilingCenter.x, 5, ceilingCenter.z,
ceilingCetner.x + 4, 0, ceilingCenter.z, 0, 0, 1);

// Now that we have the light's view, let's save the current modelview matrix.
Gl.glGetFloatv(Gl.GL_MODELVIEW_MATRIX, g_mModelView);

// Now pop off the current light view's matrix
Gl.glPopMatrix();

// Reset the current matrix
Gl.glLoadIdentity();

// Set our FOV, aspect ratio, then near and far planes for the light's view
Glu.gluPerspective(60.0f, 1.0f, 0.1f, 1000.0f);

// Grab the current matrix that will be used for the light's projection matrix
Gl.glGetFloatv(Gl.GL_MODELVIEW_MATRIX, g_mProjection);

// Go back to the original matrix
Gl.glPopMatrix();



I've also posted a screenshot, notice that the bottom left, it's cut off.. the shadow is not the shape of the cylinder. So it almost appears that my camera view is a straight line cutting off the rest of my shadow since it's not in the view (if that makes sense).

"Screen Shot"

biraneto, I wanted to use your suggestion to see what is being rendered to my depth map.. is there a program you know of that will allow me to visually see what is being drawn while each call is made. Any guidance would really be appreciated

Share this post


Link to post
Share on other sites
There is no secret... its just a texture so you only need to bind it to some polygons to see it.

You may add somethin like this to the end of the render code. vis should be something like 256...

gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0.0D, vis, 0.0D, vis, -1D, 1.0D);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glViewport(0, 0, vis, vis);
gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glEnable(GL.GL_TEXTURE_2D);
// shadow texture is your depth map
gl.glBindTexture(GL.GL_TEXTURE_2D, shadowTexture);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0.0F, 0.0F);
gl.glVertex3f(0.0F, 0.0F, 0.0F);
gl.glTexCoord2f(1.0F, 0.0F);
gl.glVertex3f(vis, 0.0F, 0.0F);
gl.glTexCoord2f(1.0F, 1.0F);
gl.glVertex3f(vis, vis, 0.0F);
gl.glTexCoord2f(0.0F, 1.0F);
gl.glVertex3f(0.0F, vis, 0.0F);
gl.glEnd();



From your screen looks like you are too close to the object. Not really too close... but you aren't beeing able to see it entirely.

Share this post


Link to post
Share on other sites
Thank you for the reply... I ended up (somewhat) getting it. I removed the ceiling and raised the light 10 units and now the eye of the light/camera covers the entire room... not sure if there is a way around that by keeping the light at ceiling level??

I posted a screen shot, that shows what the shadows look like with furniture. You can see a little shadow underneathe the table. I had one more question regarding this... it seems that my light is coming straight down so I only see a shadow underneathe the table. Is there a way to make my light illuminate the room, so that I can see a shadow from the table underneathe as well as on the wall behind it? Not sure if that would involve using multiple lights, a different type of light or just an entirely different method?? Any help would be great!!

screen shot - screen_shot_link

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this