Jump to content
  • Advertisement
Sign in to follow this  
j3di3

Software Engine: Shadow Z-Buffer problems

This topic is 4734 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 guys. I had to create a software engine for a project task for my school. With the engine - I've built a simple demo showing box made of springs jumping around. Now I would like to add some shadows so you could see the box'es shadows on the walls and floor. I read up and I found out that Shadow Z-Buffer technique could work very well for this task. However after adding it into my program shadows don't seem to work (correctly) at all. Please see the following screenshot: http://img294.echo.cx/img294/4376/weirdshadows9iv.png I'm sure the zbuffer is being filled correctly and I suspect the problem lies in the function that checks if a pixel is shadowed or not

//mCamera = camera matrix
//mLight = light matrix
inline bool bCmpShadowZBuffer(Vector p, float *iSBuffer) {
 
	bool res;
 
        // screen coordinates to read perspective coordinates
	p.x2d = p.x - SCREEN_W/2;
	p.y2d = SCREEN_H/2 - p.y;
 
	p.unperspective();
 
        // convert the point to light source coordinates
	p = p * mCamera.inverse() * mLight;
	p.perspective();
	p.x2d = SCREEN_W/2 + p.x2d;
	p.y2d = SCREEN_H/2 - p.y2d;
 
 
	int offset = p.y2d * SCREEN_W + p.x2d;
        res= (iSBuffer[offset] >= p.z);
	return res;
 
 
}
If anyone can find a problem I'll be very greatful. Also if anyone has a source code sample of shadow zbuffer that would be great too, I couldn't find any code snipplets. Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
This is commonly called shadow mapping.

You could test whether it works correctly by using a trivialized scene. For example a big wall with a small square in front of it and a light behind the square. Check the content of the shadow map and step through the code to see whether the calculations are correct.

Good luck!

Share this post


Link to post
Share on other sites
It only works correctly until I rotate the camera (in the beginning camera and light are in the same place), then the problems above start. :(
Does the function above seem correct to you?

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!