Jump to content
  • Advertisement
Sign in to follow this  
Nichiyoobiko

OpenGL Shadowmapping onto a sphere

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

Hello! I programmed a little game. The level is a small sphere which I'd like to shadowmap. I tried to use the tutorial at: http://www.paulsprojects.net/tutorials/smt/smt.html where I render the scene three times. The problem I have now is, that the shadowmap is projected four times on my sphere and I don't know why. I'm a real noob on this subject. I am using OpenGL and no shaders (this is the next thing I want to learn ;) ) This is how it looks like: Free Image Hosting at www.ImageShack.us The textures of the objects aren't displayed correctly either. THX for your help in advance! [Edited by - Nichiyoobiko on July 27, 2007 1:40:58 AM]

Share this post


Link to post
Share on other sites
Advertisement
I'm surprised no one answered you yet. I had a suggestion but it was a hassle to renew my account (but now I just registered for another).

I think you're forgetting that you need to convert from the coordinates that you get from the projective texture matrix, which range from -1 to 1, to texture coordinates which range from 0 to 1. Look through that tutorial for the parts that mention biasMatrix. Paul wasn't that explicit with that step but it's important. Did you leave that out?

Share this post


Link to post
Share on other sites
If the texture is the "dark ball", the only thing that comes to mind is to check the texture addressing mode. The default is WRAP but for projective texturing CLAMP or CLAMP_TO_EDGE is more useful.
What's the addressing mode?

Share this post


Link to post
Share on other sites
thx for your replies. I set the adressing mode to CLAMP and I copied the bias matrix from Paul's tutorial but it didn't work at all. I got the results you can see on the screenshot. Now I changed the code and I am trying to use shader. Now I am confronted with a different error. I am casting the shadows only onto the sphere at the moment but I get a totally distorted image of the object. But I can see shadows. I downloaded cg tutorial and tried to use their codes.

Vertex shader:
void vp_shadowMapping(float4 position        : POSITION,
float3 normal : NORMAL,
out float4 oPosition : POSITION,
out float4 texCoordProj : TEXCOORD0,
out float4 diffuseLighting : TEXCOORD1,

uniform float4x4 modelViewProj,
uniform float3 lightPosition,
uniform float4x4 textureMatrix)
{
oPosition = mul(modelViewProj, position);
float3 lightDirection = normalize(lightPosition - position.xyz);
diffuseLighting = dot(lightDirection, normal);

texCoordProj = mul(textureMatrix, position);
}


Fragment shader:
void fp_shadowMapping(float4 texCoordProj    : TEXCOORD0,
float4 diffuseLighting : TEXCOORD1,
out float4 color : COLOR,

uniform sampler2D shadowMap)
{
float4 projColor = tex2Dproj(shadowMap,
texCoordProj);

color = projColor * diffuseLighting;
}


My problem with this code is, that I am not sure what exactly they are doing. They don't clamp the textureMatrix (I tried to clamp the matrix within the shader but the result didn't change.).
When do I have to pass the texture matrix to the shader? Does the viewing direction make a difference here? Or in other words does the "camera" at the light position have to be active or the "camera" at my viewpoint?

Again the resulting image:
Free Image Hosting at www.ImageShack.us

I'll explain to you, what you can see on the picture. The shadows look like a copy of the scene itself translated to the bottom left corner. The sphere is being distorted. It's too small and it's larger in width than it is in height. (It looks like a lying egg.) I think the problem lies in the used matrices but I'm not too sure about that. Oh yeah and please ignore the white spheres on the picture these are unused placeholders for lights.

[Edited by - Nichiyoobiko on July 30, 2007 4:02:26 AM]

Share this post


Link to post
Share on other sites
Can you post the code where you set up the texture matrix? I use GLSL for my shaders, but as far as I can tell your shaders look fine. They don't have to do all that much though, the important part is getting everything set up correctly ahead of time.

As far as some of your other questions go, you shouldn't need to clamp the texture in the shader because it should have already been biased from 0 to 1 when you set it up. The camera matrices are not involved in the texture matrix, so that shouldn't matter. Regardless of when you set it up, you'll simply take the light's view and projection matrices and the bias matrix and multiply them together (in the right order, of course). If the light doesn't move you only have to do this once (at least in GLSL - I assume Cg uniforms work the same way). The only thing you should have to worry about the camera matrices for is setting up the views for both passes (make sure you turn off the shadowing shader for the pass from the light's perspective).

I wasn't able to get Paul's original 3-pass method to work with textured objects. Maybe there's some way to do it with multi-texturing, but I didn't find it and the 2-pass shader method is better anyway so I didn't try very hard.

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!