Search Unity

Question Z Fighting with object when intersecting another object, how to fix?

Discussion in 'Shader Graph' started by JacketPotatoeFan, Aug 22, 2019.

  1. JacketPotatoeFan

    JacketPotatoeFan

    Joined:
    Nov 23, 2016
    Posts:
    34
    Hello,

    Not sure if this can be done with Shader Graph, but is there a way to force an object to render in front of another object when they are intersecting?

    The player can place down objects in the world. The object being moved around will turn red (with some transparency) to let them know it can't be placed there. When it's inside an object z fighting happens.

    I don't know much about shaders, but reading up on older solutions it looks like adding "offset -1, -1" to the shader could fix it. I tried editing the shader code to see if this would work, but it didn't.

    Any ideas of how to solve this issue without scaling the object?
     
  2. whoisj

    whoisj

    Joined:
    Jan 4, 2018
    Posts:
    26
    Does adjusting the Render Queue value on the material help at all?
     
  3. JacketPotatoeFan

    JacketPotatoeFan

    Joined:
    Nov 23, 2016
    Posts:
    34
    Hey. I tried that but I didn't see any difference unfortunately.

    I think I might have to go with scaling the object for now. Thanks.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Render queue won’t help. Offset can help in specific situations, and this certainly sounds like one of them, but it’s possible you didn’t add Offset to the correct place in the shader, or that it wasn’t enough to help in this particular case.

    The other option would be to use a vertex position offset that simulates the Offset parameter. I posted an example here:
    https://forum.unity.com/threads/sha...-property-in-shader-code.663550/#post-4459513