Jump to content
  • Advertisement
Sign in to follow this  
Say

why this rendering bug!

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

Looking at this image: i've create two swap chains it works fine if the second one is smaller the first, but if i size in width the second panel (second swap chain) the scene in this panel is rendered bad. Some face is transparent, empty without surface. I see the within of the mesh. Why? What do i wrong?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Do you have the z-buffer write and tests enabled?

sorry, i'm newbie about direct3d, can you indicate me better what do you mean?

Anyway i use this code:
i use this lines:
// on scene preparing
device.RenderState.ZBufferEnabled = true;

//on rendering
device.Clear(Clear.Target | Clear.ZBuffer, Color.Gray, 1.0f, 0);

other?

Share this post


Link to post
Share on other sites
What Kamikaze is talking about is that you must create a depth buffer when you first create the Direct3D device. When you call IDirect3D9::CreateDevice, make sure that the "EnableAutoDepthStencil" member of the PRESENT_PARAMETERS structure you pass in is set to TRUE.

This instructs the Direct3D object to create a device that has a depth buffer.

neneboricua

Share this post


Link to post
Share on other sites
Kamikaze15 is correct - you've got some depth buffering issues there [smile]

You're using MDX so I'm not sure the exact syntax, but the "Present Parameters" that you pass in to your CreateDevice call (new Device(...) in MDX?) should have an "AutoDepthStencilFormat" field - try setting this to D3DFMT_D16.

There is another possible cause... your projection matrix. With a value of 0 for the near plane you can end up with unstable/incorrect depth values - if the first suggestion doesn't work for you, post your code for creating a projection matrix.

hth
Jack

Share this post


Link to post
Share on other sites
i make all that you tell becouse i make this:
//for the first swap chain (directly to the device object)
presentParams[0].EnableAutoDepthStencil = true;
presentParams[0].AutoDepthStencilFormat = DepthFormat.D16;
...
device = new Device(..., presentParams[0]);

//for the second swap chain
presentParams[1].EnableAutoDepthStencil = true;
presentParams[1].AutoDepthStencilFormat = DepthFormat.D16;


Then this is my projection code:

float scale = 1.0f;
Vector3 pos = new Vector3();
Vector3 camPos = new Vector3();
Vector3 lookAt = new Vector3(0.0f, 0.0f, 5.0f);
Vector3 camUp = new Vector3(0.0f, 1.0f, 0.0f);

device.Transform.Project = Matrix.PerspectiveForLH((float)Math.PI / 4, 1.0f, 1.0f, 100.0f);
device.Transform.View = Matrix.LookAtLH(camPos, lookAt, camUp);
device.Transform.World = Matrix.Scaling(scale,scale,scale)*Matrix.Transform(0f, 0f, 0f)*Matrix.RotationY(Environment.TickCount/1000.0f);

Share this post


Link to post
Share on other sites
Maybe you have your camera too near from the object and a very large far clipping plane, which causes inaccuracies in the depth buffer.
Try to make your far clipping plane 10.0f in the projection matrix.

Share this post


Link to post
Share on other sites
Here's the modified version of your code

float scale = 1.0f;
Vector3 pos = new Vector3();
Vector3 camPos = new Vector3();
Vector3 lookAt = new Vector3(0.0f, 0.0f, 5.0f);
Vector3 camUp = new Vector3(0.0f, 1.0f, 0.0f);

device.Transform.Project = Matrix.PerspectiveForLH((float)Math.PI / 4, 1.0f, 1.0f, 10.0f); // <-- here is the change
device.Transform.View = Matrix.LookAtLH(camPos, lookAt, camUp);
device.Transform.World = Matrix.Scaling(scale,scale,scale)*Matrix.Transform(0f, 0f, 0f)*Matrix.RotationY(Environment.TickCount/1000.0f);



I don't know MDX, so I hope I modified it in the right place.

Share this post


Link to post
Share on other sites
I would be beneficial if you use a nicer Depth/Stencil buffer set. Usually a Depth buffer of 24 bits and Stencil buffer of 8. The setup would then look like this.


presentParams.AutoDepthStencilFormat = DepthFormat.D24S8;
presentParams.EnableAutoDepthStencil = true;

//Also when creating a Projection transformation matrix.
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.3f, 1.0f, 1000.0f);



This should push you in the right direction and get rid of your Depth issues. Make sure to clear the depth buffer, stencil buffer and target when rendering.


device.Clear(ClearFlags.Target | ClearFlags.ZBuffer | ClearFlags.Stencil, color, 1.0f, 0);



I hope this helps.
Take care.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!