Software Engine: Shadow Z-Buffer problems

Started by
1 comment, last by j3di3 18 years, 10 months ago
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!
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!
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?

This topic is closed to new replies.

Advertisement