Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Proper culling with Standard shader

Discussion in 'Shaders' started by dandepeched, Feb 23, 2019.

  1. dandepeched

    dandepeched

    Joined:
    Feb 22, 2016
    Posts:
    31
    Hi,

    I've done a simple ball model with both transparent and opaque parts.
    I'm using Standard shader to render it, but it gives inconsistent result under certain angles.
    As you can see on image below, sometimes opaque part is rendered over upper part:


    Any suggestions how it can be fixed?
     
    Last edited: Feb 23, 2019
  2. drcrck

    drcrck

    Joined:
    May 23, 2017
    Posts:
    312
    can you attach a picture that is bigger than 100x100?
     
  3. dandepeched

    dandepeched

    Joined:
    Feb 22, 2016
    Posts:
    31
    Sorry, attached a new one :)
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,611
    This is because you're using a single material with a mix of "opaque" and transparency within a single transparent material. Effecient and correct real time sorting of transparent objects is an unsolved problem:
    https://forum.unity3d.com/threads/render-mode-transparent-doesnt-work-see-video.357853/#post-2315934

    Generally speaking opaque objects should use an opaque material, and transparent objects should use a transparent material. So in this case you may want to use two materials.

    However, for this particular model, a custom shader with a depth prepass would likely work for your needs.
    See:
    Transparent shader with depth writes
    https://docs.unity3d.com/Manual/SL-CullAndDepth.html
     
    dandepeched likes this.
  5. dandepeched

    dandepeched

    Joined:
    Feb 22, 2016
    Posts:
    31
    Thanks for your answer. I used 2 materials, but they were both set to Transparent mode. Setting one of them to Opaque fixed incorrect rendering :)
     
    bgolus likes this.
unityunity