Search Unity

Resolved Different ZTest for each pass?

Discussion in 'Shader Graph' started by zhuchun, Aug 1, 2019.

  1. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    379
    Hi, It's great to see the ZTest option is available, but I'm wondering how to set them differently in shader graph, say I want to display one color for the LEqual part and another color for the Greater part of the object?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,000
    Shader Graph shaders are always only a single pass (for the main forward pass at least), and GPUs cannot change the ZTest mid-shader execution. If you want to have different ZTest settings, you'd need to have two separate shaders and materials applied to your object.
     
    iSinner and zhuchun like this.
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    1,864
    I'd like to understand what you mean by two separate materials. Let's say the mesh is just a single triangle. That single triangle can't have two materials, can it, rendered on different passes?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,000
    Yes, just add two materials to your object and it’ll render twice. Once with each material. It’ll also pop up a big warning on the renderer component about this that you can ignore.
     
  5. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    1,864
    Interesting. I didn't know that. However, I assume there's no way to fake a multi-pass shader using this approach, where the output of one shader gets passed into the second shader as input?