Search Unity

Conditionally disabling light on a shader

Discussion in 'Shaders' started by tertle, May 23, 2018.

  1. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    -edit2-
    While I've realized LightingStandardDefaultGI is the problem, I don't know how to conditionally make it not appear.

    -edit-

    Solved I think. Realized I didn't understand LightingStandardDefaultGI vs LightingStandardDefaultGI_GI. Need to fix up LightingStandardDefaultGI.

    -endit-


    Hi! Not that experienced with graphic programming and I've run into a problem. I'm trying to conditionally turn off lighting on a material and I thought doing this would work,

    Code (CSharp):
    1.  
    2.             inline void LightingStandardDefaultGI_GI(
    3.                 SurfaceOutputStandard s,
    4.                 UnityGIInput data,
    5.                 inout UnityGI gi)
    6.             {
    7.                 LightingStandard_GI(s, data, gi);
    8.  
    9.                 gi.light.color = half3(0, 0, 0);
    10. #ifdef DIRLIGHTMAP_SEPARATE
    11. #ifdef LIGHTMAP_ON
    12.                     gi.light2.color = half3(0, 0, 0);
    13. #endif
    14. #ifdef DYNAMICLIGHTMAP_ON
    15.                     gi.light3.color = half3(0, 0, 0);
    16. #endif
    17. #endif
    18.                     gi.indirect.diffuse = half3(0, 0, 0);
    19.                 gi.indirect.specular = half3(0, 0, 0);
    20.             }
    21.  
    but high intensity lights still show up. (The actual code takes the data.worldPos and turns off the lighting in certain areas but I've stripped it back for testing.)

    View attachment 279804

    What else do I need to do to the shader to ignore lighting.

    -edit-

    should add this is on a very basic surface shader

    Code (CSharp):
    1.  
    2.             void surf(Input IN, inout SurfaceOutputStandard o) {
    3.                 fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    4.                 fixed4 FoW = GetFoW(IN.worldPos);
    5.                 o.Albedo = c.rgb * FoW.rgb;
    6.                 o.Metallic = _Metallic;
    7.                 o.Smoothness = _Glossiness;
    8.                 o.Alpha = c.a;
    9.             }
    10.  
     
    Last edited: May 23, 2018