Jump to content
  • Advertisement
Sign in to follow this  
DoomAngel

Problem in Zbuffer with Shader

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

hi. i'v a problem as follows: when i use the fixed pipeline of DirectX to render models every thing is ok. but when i use the programable pipeline to render them ( even if i'm not trying to do any special effects on them ) some flickering appears in the model's polygons. which i assume that it's a ZBuffer problem. although that I do activate the Zenable parameters within the shader. thx.

Share this post


Link to post
Share on other sites
Advertisement
1) does enabling Z buffering and Z writes from the main code, but using the shader still flicker?

2) do you clear the Z buffer every frame in both cases? (you should)

3) Z fighting can be caused when the near clip plane of your projection matrix is too low (or worse 0) or the distance between near and far is too large for your world units.

4) Other problems with the way you handle projection in your shader can cause Z fighting - such as fiddling with the Z or W values of the final output of a vertex shader - or worse, [accidentally] setting W to 1 (e.g. float4 out(0,0,0,1); ... out.xyz = blah.xyz; ... return out;).

5) Have you done anything with DepthBias/ZBias render states? incorrect setting of those can cause Z fighting.

6) Is your depth buffer the same format in both tests? (i.e. could it be 16bit in the shader test and 24bit for the FFP version?)

7 Do you write depth values from your pixel shader?

Share this post


Link to post
Share on other sites
Thank you SICA because of your help.

the problem really was from the clip plane which was near.

but the big quistion is that every thing is OK when i render the objects by the fixed pipeline and the problem appear just when i use the programable one.

even i don't change the near clip plane distance???

Share this post


Link to post
Share on other sites
The output of the fixed function pipeline can be slightly different than the output of a shader.

However, it shouldn't be a big difference - but still enough that it would matter if you were doing multiple pass rendering with one pass using FFP and the other using shaders.

If the difference is quite big, then a difference in the transformation matrices used for each pipeline (particularly the projection matrix) or some other code in your vertex or pixel shader causing the transformed positions and rasterized pixels to be different.

Could you post the transformation code from your vertex shader? Also the part where you output to homogenous clip space too? (note: you shouldn't be doing the perspective/W divide yourself or adjusting the Z or W values being output from the shader).

Share this post


Link to post
Share on other sites
In the first pass of your effect technique (if you are using effects) you can set ZEnable = true and ZWriteEnable = true to ensure that the depth buffer is being used, in addition to what S1CA has said.

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!