Disappearing Images

Started by
3 comments, last by sjmarsha 16 years, 6 months ago
Hi All I have noticed after I have draw my level to the screen that some parts go black if you are too far away. I am using DirectX, and C++ code. Is there a way to stop this from happening? regards Steven Marshall
Advertisement
Sounds like you've discovered the Z-Buffer. Nothing you can do about that. Increase the distance of the Z-Buffer, but this will also decrease the accuracy of it.
When creating a camera, you use a view frustum to dictate the perspective distortion that may occur. Anything outside of the frustum is not drawn. When displaying graphics on screen, you give 3d coordinates to display. If the distance is too far into the scene, it can go past the far plane of the view frustum, and will not be drawn. The same is true, when it gets too close. The reason why we need a near and far plane is to dictate use of the depth buffer.

Just like onscreen you use an RGBA Buffer to draw to, the depth buffer can consist of varying bit depths. If we were to have a distance say, that starts at 1 foot away (remember distance is completely arbitrarily defined in linear algebra), and ends 10 miles into the scene, unless the depth buffer has enough bits in it, it may not be able to differentiate drawing an object that is 10000 feet away, and one that is 10001 feet away. They would appear onscreen at the same distance, and would arbitrarily clip through each other. Picking a good near and far distance can be difficult depending on the precision you might want, as the distance that the depth buffer is able to differentiate gets larger at further distances depending on the field of view. So at one foot away, the buffer can differentiate an object drawn at z of 10 feet 1 inch and another at 10 feet 2 inches but as you get to 100 feet, there's a 4 inch gap.

Without an extremely large bit depth buffer, not currently supported for example, you would not be able to draw in the same scene a table one foot away with a piece of paper a quarter millimeter thick on it, and small branch detail on a tree that is a half a mile away, without getting clipping artifacting on one or the other.
You could also use a light fog so that objects sort of fade away in the distance before they disappear completely.
Quote:Original post by Dancin_Fool
Sounds like you've discovered the Z-Buffer. Nothing you can do about that. Increase the distance of the Z-Buffer, but this will also decrease the accuracy of it.


Hi There

Thanks for thisinfo. I have the following settings in my engine:

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = TRUE; //Z-Buffer
d3dpp.AutoDepthStencilFormat = D3DFMT_D16; //Z-Buffer

So what do I need to change to make the z-buffer bigger?

regards
Steve

This topic is closed to new replies.

Advertisement