Jump to content
  • Advertisement
Sign in to follow this  
My_Mind_Is_Going

OpenGL What's wrong with this picture? (shadow mapping problem)

This topic is 2957 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

I'm porting an existing (very basic) shadow map implementation from an XNA project over to one based on OpenGL and I'm getting the following, wrong result. Can anyone venture a guess as to what's going wrong? Something with the projected texture coordinates I suppose, but I can't figure out what.

There's supposed to be a single spotlight casting the shadow, located just in front of the camera and pointing in the view direction.

Share this post


Link to post
Share on other sites
Advertisement
Looks like your texture is up-side-down from what you expect ;)

OpenGL texture coordinates are up-side-down compared to DirectX coordinates. Assuming you're using shaders, a quick fix is to add "texCoord.y = 1.0-texCoord.y" right before you sample the projected shadow map.

Share this post


Link to post
Share on other sites
I tried that already actually, then I can't see any shadows at all. If I invert both x and y coordinates then I get the following result. The shadows are offset incorrectly in the x-direction now, and silhouettes are standing right next to the objects casting them. It looks like something is wrong with the light projection matrix or something, like the depths are inverted?



Share this post


Link to post
Share on other sites
It looks as if your light source is being projected from the same location as your shadows, in which case, the shadows are going to be behind hidden behind the objects casting them... which means that part of it is correct.

Is the light supposed to originate from somewhere else?

Share this post


Link to post
Share on other sites
I'm not sure I understand... the light is supposed to be right in front of the camera, facing in the look direction, sort of like a flashlight. If I remove that x-flip in the texture coordinates that I mentioned, then the shadows shown in the screen shot disappear because they're behind the objects, which is correct. But the question is why aren't any pixels farther back, such as on the wall, in the shadow?

I'm using deferred rendering for this (and the original XNA code was not) and drawing the lights as full screen quads, would that be introducing some complication I'm not aware of?

Share this post


Link to post
Share on other sites
You mentioned: shadows disappear (will be behind the casters), so I don't understand what the problem is.

Share this post


Link to post
Share on other sites
Hmmm... I put the light in a fixed position, so it doesn't move with the camera and it seems to be casting proper shadows now.

I just tried walking around, pointing a flashlight from eye-level and it is pretty difficult to get anything to cast a shadow... I guess you learn something new about the world every day :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!