rotfa

< xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /> < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />Hi
I have 2 different textured meshes that I want to place in a 3D-Room.

One, which is a rope, and the other is a poulley. I want to put the rope around the pulley. When I'm far away of the objects the rope is drawn before the pulley (which is wrong). When I'm, very near of the pulley, the rope is corrected displayed.

I got following settings in my code:

dev.RenderState.ZBufferEnable = true;
dev.RenderState.ZBufferWriteEnable =
true;
dev.RenderState.ZBufferFunction =
Compare.LessEqual;

I'm using Directx9 and visualc# express.

 

If you wanna look at what I mean (pictures say more than words) feel free to look at:

http://fabspage.blogspot.com/

 

Thanks!

 



Re: Game Technologies: Graphics Problems with depth-Buffer

BLANC Guillaume

Z values are not stored in the depth buffer with a linear function. I think it is a 1/Z like function. Anyway, it means that Z precision (the distance in meter between two Z values) is not the same near the camera or far from the camera. That is why you're experimenting that flickering. Also probably, if you move a bit more far, the rendering might flicker again.
A way to correct this is to modify near and far values. Indeed, Z precision depends on Zfar / Znear ratio (see projection matrix for more details). I'm usualy try to keep this ratio around 1000, but it really depends on your assets.





Re: Game Technologies: Graphics Problems with depth-Buffer

rotfa

Hello and thanks for the reply.

I had already played with the values with near-Plane and far-Plane to no avail. It still does display the rope in front of the pulley, when I'm far away from the objects.
I loked at the docs (for the 100th time :-|) at no avail.
I really don't know where to look further.
Here's my initilization of the transformation-pipeline.
_viewMatrix = Matrix.Identity;
_fov = (
float)Math.PI/4;
_screenWidth = frm.Width; //frm is the current Form
_screenHeight = frm.Height;
_aRatio = frm.Width / frm.Height;
_nPlane = 1f;
_fPlane = 10000f;
_cameraPosition =
new Vector3(0, 0, 0);
_cameraTarget =
new Vector3(0, 0, 1);
_cameraUpVector =
new Vector3(0, 1, 0);
_eyeOff =
new Vector3(0, 0, 0);
_perspectiveMatrix =
Matrix.PerspectiveFovLH (_fov, _aRatio, _nPlane, _fPlane);

_cameraPosition = new Vector3(_x, _y, _z) + _eyeOff; //x,y,z : Camera Position, yaq, pitch = camera angles.
_cameraTarget = _cameraPosition;
_cameraTarget.X += (
float)Math.Sin(_yaw);
_cameraTarget.Y += (
float)Math.Sin(_pitch);
_cameraTarget.Z += (
float)Math.Cos(_yaw);
_viewMatrix =
Matrix.LookAtLH(_cameraPosition, _cameraTarget, _cameraUpVector);


device.Transform.View = _viewMatrix;
device.Transform.Projection = _perspectiveMatrix;

For each Object I have a world-MAtrix calculated like that:

_world = Matrix.Identity;
_world *=
Matrix.Scaling(_scale.X, _scale.Y, _scale.Z);
_world *=
Matrix.RotationZ(_rotate.Z);
_world *=
Matrix.RotationY(_rotate.Y);
_world *=
Matrix.RotationX(_rotate.X);
_world *=
Matrix.Translation(_translate);

Thanks again for your help.





Re: Game Technologies: Graphics Problems with depth-Buffer

BLANC Guillaume

Your initialization seems good but far/near ratio is still too high. If reducing that ratio doesn't fix the issue (but it should at least for a very small ratio), then this is because some of your assets faces that are too near from each other (in z range scale).
Also, is your depth buffer a 32bit depth buffer Because the less bits it is, the more you'll have to reduce the far/near ratio.





Re: Game Technologies: Graphics Problems with depth-Buffer

rotfa

Hi Guillaume

You're the man! Thanks very very very ... much. You saved me this time. Hope I can revenge myself one day!
I have to use D16 for the depth-Buffer, because my GraphicCard doesn't support D32 (I know, have to change it one day, but this could happen to other persons which
will use my proggi. I By reducing the ratio (near=10, far=1000) everything look great!

Thanks again.