Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Zergling103 · Aug 08, 2013 at 12:12 AM · shaderztestzwritez fighting

Z Fighting Help - How to get bias for ZTest only, not ZWrite

Hi there,

I discovered that using Unity's Z Bias feature called "Offset" in shaderlab applies to both the ZTest and the ZWrite. Is there a way to apply the bias to one or the other only?

I figured that having a depth bias would help with Z fighting of polygons that occupy nearly the same space. The idea was that in the ZTest phase the pixel would only be drawn if it's depth, plus the bias, was less than what was already there. In which case, it'd draw the pixel and write to the ZBuffer as normal. The expectation was that it'd write the original Z value, without the bias, to the Z buffer:

 if ZCurrent + Bias < ZInDepthBuffer
    Draw the Pixel.
    ZInDepthBuffer = ZCurrent

However, unfortunately, when it wrote to the ZBuffer, it wrote the Z value with the bias added to it:

 if ZCurrent + Bias < ZInDepthBuffer
     Draw the pixel.
     ZInDepthBuffer = ZCurrent + Bias // <-- Problem!!!

Which basically means that the Offset feature is useless in combating Z fighting.

The only alternative is to have two passes, with the first pass writing to the Z buffer only, without any bias. The second pass would not write to the Z buffer, but would perform Z Testing with a bias, drawing the pixel normally if it passed the test.

Of course, the problem here is that this requires the same thing to be drawn twice - that is, twice the geometry is rendered. This is not acceptable in our case due to performance issues.

It also seems extremely ridiculous that we'd need another draw call as a work around for something as simple as how two numbers are added.

In conclusion, is there some magic cheat code keyword or syntax or whatever hack I need to use so that it does not ZWrite with a bias, and only uses the bias for performing the ZTest? If you can find it, you will be the honorary most awesome person of the century!

Thanks,

-Steve

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ZTest, and ZWrite Problem rendering a Cluster of Quads 2 Answers

How to have sorting order/layers used when Z depth is the same? 1 Answer

Can Unity Indie Use ZTest and ZWrite Shader Functions? 1 Answer

Z-priming alpha-per-vertex 0 Answers

Display complex object when it is behind the wall 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges