Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Is it possible to create a shader property for cull, ztest?

Discussion in 'Shaders' started by jareds, Oct 6, 2008.

  1. jareds

    jareds

    Joined:
    May 8, 2008
    Posts:
    207
    Hey folks,

    Is there any way to create a shader property for cull or ztest? I have one shader I'd like to apply to all of my meshes, but there are a handful that I want to change the cull settings on.

    I looked at the ShaderLab documentation and I couldn't see any way to have "cull" or "ztest" be accessible as properties.

    http://unity3d.com/support/documentation/Components/SL-Properties.html

    I was thinking of creating a separate vector property _myCull and then somehow using this to say if the _myCull was (1, 0, 0, 0) then cull off, if it was (0, 0, 0, 0) then cull back. Is something like that possible in a shader? I've modified a few of the built-in shaders but I've never had to deal with conditionals in this way.

    Thanks,
    Jared
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    No, that's not possible.
     
  3. jareds

    jareds

    Joined:
    May 8, 2008
    Posts:
    207
    Thanks for letting me know.

    -Jared
     
  4. InappUser

    InappUser

    Joined:
    Oct 3, 2014
    Posts:
    1
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,238
    This was a question from 2008 (thus for Unity 2.0), and that link is from 2014 (and is the same Aras who originally responded to this thread) talking about a feature added in 2013 to Unity 4.3.

    But yes, you can do this now for pretty much every shader setting.
     
    Reahreic and eXonius like this.
  6. ian_unity431

    ian_unity431

    Joined:
    Oct 12, 2018
    Posts:
    10
    Try this:

    Property
    [Enum(Off,0,On,1)]_ZWrite ("ZWrite", Float) = 1.0
    [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("ZTest", Float) = 4 //"LessEqual"
    [Enum(UnityEngine.Rendering.CullMode)] _Culling ("Culling", Float) = 0

    Pass
    ZWrite [_ZWrite]
    ZTest [_ZTest]
    Cull [_Culling]
     
    Last edited: Oct 17, 2019
  7. JohnOknelorfDev

    JohnOknelorfDev

    Joined:
    Oct 2, 2017
    Posts:
    20
    Thank you very much, you are a genius! :)