I’m drawing several models, with the following code to set up render states:
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
Some models rendered not correctly. If I change one line of code:
GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
Now, others don’t work correctly. I used 2 codes with each code segment but it still doesn’t work.
How can i fix this rendering issue?
Screenshots:
I’m drawing the ground first, then the ‘road’ models.
Top: https://i.stack.imgur.com/xH8qp.png
When I change angle of the camera…: https://i.stack.imgur.com/Nbw3m.png
Your problem looks to be Z-Fighting, a problem that is caused by trying to render 2 or more polygons at the same distance from the camera.
When drawing the models you could disable the Z-buffer.
DepthStencilState.None