Jump to content
  • Advertisement
Sign in to follow this  
sqwang

Back object can be seen in D3DX 9

This topic is 2545 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 am learning D3DX 9. I am building 3 cubes lined up along Z axis. One is at Z=-30, the second is at Z=0, the third is at Z=30. In the vertex buffer, the first one goes first, then the second and the last is the third.

The carmera eye is at (0,0,-80), looking at (0,0,0). When draw the buffer, I can see the cube at Z=30. It seems the render order is the order you created the cubes. I even use meshes and assign 3 cubes into different attributes, and use DrawSubset. It gives the same results.

What I should check? Any help is greatly appreciated!!!


I am migrating my WPF rendering to D3DX hoping the performance can be increased. But the learning curve is tough.



[font="Courier New"] [attachment=6497:multiple objects.txt][/font]

Share this post


Link to post
Share on other sites
Advertisement
To me this sounds suspiciously like depth writing and/or depth test are not enabled.
Here are some links for you:
  • General info on the depth buffer,
  • How to enable the depth test, (Make sure fragments are only passed to the output merger if they pass the depth test.)
  • How to modify depth writing flag. (Make sure fragments are allowed to write depth values.)Hope this helps!

Share this post


Link to post
Share on other sites
Sorry for duplication. This is my first time to use this forum.


Hi there,

I would like to thank you so much for quick reply on this.

Attached is a screen capture showing the render states I am using and what I got as resutls. The small rectangle should not be seen as it is farther from the big one.

Again, thanks a lot!!!



To me this sounds suspiciously like depth writing and/or depth test are not enabled.
Here are some links for you:
  • General info on the depth buffer,
  • How to enable the depth test, (Make sure fragments are only passed to the output merger if they pass the depth test.)
  • How to modify depth writing flag. (Make sure fragments are allowed to write depth values.)Hope this helps!

Share this post


Link to post
Share on other sites

Sorry for duplication. This is my first time to use this forum.

Don't mind, such things can happen. :)
There should be a "Delete Post" button in the bottom right corner of your own posts.


Attached is a screen capture showing the render states I am using and what I got as resutls.

That looks right. Have you created a depth buffer as well?

If this doesn't work I might need a closer look on your code. Would you post it here?

Share this post


Link to post
Share on other sites
Duplicate posts deleted.

In addition to what Tsus said, If you're using a perspective projection matrix (D3DXMatrixPerspectiveFovLH()), then you also need to make sure that the near and far clip planes are something sensible - in particular, the near clip plane should not be 0, and should be as far as possible (Try 0.1f), and the far clip should be something like 1000.0f for a 16-bit z-buffer, or up to something like 10000.0f for a 24-bit z-buffer.

Share this post


Link to post
Share on other sites
Please do not go with this one as the source codes are lengthy. Please check D3DTest, which is much much tiny and shows the problem very clear! If by an chance you did review this one, it has a typo in Add function. Thanks!

Hi there,

Thanks a lot for the help. I was preparing the codes for you to review. As this project is to link WPF rendering to D3DX. I developed 3 projects for this: 1) a CPP project handling any COM and D3DX calling, 2) a NET project handling the connectiong from D3DImage control, WPF 3D Visuals to the unmanaged dll (1), and 3) a test CS project, which contains 3 cubes. My goal of this upgrade or replacement is to include functions demonstrated in PICK and ShadowVolume (as the original WPF application allows user to hover the cursor to any object and display its properties, and camera rotation has to be enhanced to something like ShadowVolume, also shadow is a plus).

One critical function of D3D drives me to take whatever to do this migration: Vertex Color. Attaching color to each vertex and turn off the lights, it will produce interpolated color rendering. I am a structural engineer and this application is to display surface stresses of a structure. By using this function, we can simply designate a color to each vertex according to its stress level and D3D will do all others. WPF is no where close to being able to do this.


Let me be back to the 3 Cubes. Depth buffer seems not related to this issue. Effects, Vertex declaration and others may be related. But simply I do not know exactly. For easy to review, I do not send you the above three projects. A modified ShadowVolume, in which 3 cubes are added. The code scope thus becomes much small. These 3 cubes does not work along the dwarf (no depth). One however, I found in ShadowVolume is dwarf will be transparency if you do not render the AMBIENT (OnFrameRender, line 1451). Will this give some idea about why farther faces can be seen?

The transformations together with the effects, declarations may lead to this odds. Just for your reference, ShadowVolume maintains two cameras dealing with the geometries, viewer camera and model camera. A very nice feature that attracts me.

I came originally from OpenGL, then WPF and now trying to mix WPF and D3DX. Decisions made by WPF team is hard to be understood. Many critical functions from D3DX are not available in WPF, but they give an XNA, which sits in the middle between these two. I am wishing 3D rendering in WPF will be fundamentally changed in NET 5...

If you think, the original 3 projects are needed. Please let me know. I will try to trim it so to be easy read. Now it is extrmely ugly due to the testing.


Thank you so much and enjoy the holidays!

SW[attachment=6517:ShadowVolume.zip]

Share this post


Link to post
Share on other sites
Hi there,
The original source codes attached has a typo. Now this one is updated and it shows the problem clearly.

It contains a .NET project and a CPP project. The .NET hostes a control and the CPP project does all the work. InitializeScene is called to do the initialization, and RenderScene is called to do the rendering. The cubes are created by D3DXCreateMeshFVF. Vertex is defined as Position and Normal. When rendering, each cube shows well, but cubes sit farther can be seen through the near cubes.

SetMetrices will rotate the model so we can see the problem. It seems D3DX only do CULL check, no obscure check. But absoultely it is not right and some setting is not right. I desperately need help on understanding this. I need to use Mesh so I can assign different materials to each group of triangles.

The executables are built in 64bit. If you have that platform, you may be able to run it without build again.

Thank you so much!!!

[font="Courier New"][font="Courier New"][font="Courier New"]SW


[/font]
[/font]
[/font]

Share this post


Link to post
Share on other sites
Hi there,

This has been resolved! It turns out that [font="Courier New"]CreateDepthStencilSurface has to be called to create the depth buffer and then call [font="Courier New"]SetDepthStencilSurface to set the new buffer. http://msdn.microsoft.com/en-us/library/windows/desktop/bb204866%28v=vs.85%29.aspx says 'The depth buffer is automatically set as the render target of the device. When the device is reset, the depth buffer is automatically destroyed and re-created in the new size.' Seems it has to be re-created always after the device is created.

Hope the attached codes I am using helps any body who is struggling.

[attachment=6520:works.txt]
Thank you all very much!

SW


[/font]
[/font]


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!