Jump to content
  • Advertisement
Sign in to follow this  
kmart216

Mesh rendering is messed up looking

This topic is 4778 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

I'm working on a 3D DirectX game for a senior project. We are currently having trouble rendering meshes correctly. For some reason when the meshes are rendered, some faces are in front of others that shouldn't be. Loading the mesh with Mesh Viewer works fine, it renders it with no problem. It's as if the z-buffer isn't working correctly as things that shouldn't rendered are (like a building behind another is partially visible). Does anyone have any ideas? I'm using Managed DirectX 9.0c (Feburary 2005 update), but has been happening since the original DirectX 9.0c. Here's the line of code where I create the device. // Set up the structure used to create the D3DDevice. Since we are now // using more complex geometry, we will create a device with a zbuffer. m_PresentParams.Windowed = true; m_PresentParams.SwapEffect = Direct3D.SwapEffect.Discard; m_PresentParams.EnableAutoDepthStencil = true; m_PresentParams.AutoDepthStencilFormat = Direct3D.DepthFormat.D16; m_PresentParams.BackBufferFormat = Direct3D.Format.Unknown; // Create the D3DDevice device = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, Direct3D.CreateFlags.SoftwareVertexProcessing, m_PresentParams); // Turn on the zbuffer device.RenderState.ZBufferEnable = true; Let me know if you need more info (I'm not sure what would be informative). You can go to http://www.friendsofmetro.com/simuc/ site to get the setup file for the current game. It will be slow, but you want at least the game installation. Then, once you start you want to run as a server. Thanks

Share this post


Link to post
Share on other sites
Advertisement
1) What values do you have for the far and near clip planes set in your projection matrix ?

a. near should never be 0

b. the value of near should be as high as is bearable for your scene.

c. the distance between near and far should be sensible. For example a near plane of 1.0 and a far plane of 1000001.0 when your world units are in metres isn't too sensible.

d. for a 16 bit Z buffer you only have 65536 discrete Z buffer positions available; a range of 1000000 metres means you get around 15 metres per Z buffer position - so in the Z buffer there would be no difference between a building one metre away from the camera and a building 10 metres away.


2) If you need all of the range specified by your clip planes, you could always use a D32 or a D24 Z buffer to get extra range.


3) Try setting the D3DRS_ZENABLE and D3DRS_ZWRITEENABLE render states to TRUE

Share this post


Link to post
Share on other sites
>>1) What values do you have for the far and near clip planes set in your >>projection matrix ?

far = 3500.0
near = 1.0

...

>>3) Try setting the D3DRS_ZENABLE and D3DRS_ZWRITEENABLE render states to TRUE

I tried this (Z enable was already set to true).

Also, when I rotate the camera in place, the rendering is different. A face (part of it) will suddenly be in front of another.

If I change the value of the far plane at runtime from 3500 down to 500 the rendering looks really different each frame, but it never looks any better.

You can go to the senior project website to look at the screenshots to see what I'm talking about, http://www.friendsofmetro.com/simuc. The images are the last 2 links on the page.

Share this post


Link to post
Share on other sites
Make sure you are clearing the Z buffer when you call IDirect3DDevice9::Clear (i.e. specify D3DCLEAR_ZBUFFER as well as D3DCLEAR_TARGET).

It's difficult to tell from the screenshot provided though, but those artifacts could be caused by the Z buffer from the previous frame being tested against and written to for the current frame (and so on), as would happen if you didn't clear the Z buffer.

Share this post


Link to post
Share on other sites
I am clearing the z-buffer, here's the piece of code that gets called at the beginning of the render function.

App.GraphicDevice.Clear(Direct3D.ClearFlags.Target | Direct3D.ClearFlags.ZBuffer, System.Drawing.Color.Blue, 1.0f, 0);

where App.GraphicDevice is the Direct3D rendering device.

If you want to look at the source code, you can go to the project website (http://www.friendsofmetro.com/simuc/). From there you can click on 'Source Jammer' to go to the source control server web interface. Then enter the archive name of 'SimUC' (case-sensitive). From there the current source is in the 'working_app\src\' directory.

Is there any other info I could give 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!