0
\$\begingroup\$

How do you set a boolean for a shader? How do you write a conditional or assign a boolean in a shader?

So, it seems that shaders do not take booleans... so I tried assigning the float to 0 or 1 ren.material.SetFloat("_ZWriteVal", 1f);, but it doesn't seem to work...

 Shader "ZTestLess"
{

 Properties {
_Color ("Color", Color) = (0,0,0)
[Toggle(Z_WRITE_VAL)] 
_ZWriteVal("Z Write Val", Float) = 0
}

SubShader
 {
    Tags { "Queue" = "Background" }

    Pass
    {
        CGPROGRAM
        #pragma shader_feature Z_WRITE_VAL

         #ifdef Z_WRITE_VAL
            ZWrite On
         #else 
            ZWrite Off

           ZTest Less
            Color [_Color]
            Lighting Off 

         ENDCG
    }
}
}
\$\endgroup\$
3
  • \$\begingroup\$ Are you trying to change this toggle in script at runtime? That's not possible when using preprocessor directives. If that's not what you're trying to do, have you tried using an Int instead? \$\endgroup\$
    – DMGregory
    Commented Jun 14, 2020 at 9:45
  • \$\begingroup\$ I' trying to switch to/from Zwrite On to Zwrite Off at runtime to create a "dynamic material" \$\endgroup\$
    – ina
    Commented Jun 14, 2020 at 20:23
  • \$\begingroup\$ You can't do that, as explained at the link above. But you can swap between two different materials, one you've configured with ZWrite on, and the other with ZWrite off. \$\endgroup\$
    – DMGregory
    Commented Jun 14, 2020 at 20:24

0

You must log in to answer this question.

Browse other questions tagged .