Search Unity

Custom Shader Emits Realtime GI in Editor but not in Build

Discussion in 'Global Illumination' started by HUSHstudios, Aug 13, 2021.

  1. HUSHstudios

    HUSHstudios

    Joined:
    Sep 23, 2015
    Posts:
    11
    I have a custom surface shader which emits light using realtime global illumination in 2021.1 with the standard render pipeline. In the editor everything looks correct and the emitted light bounces on to nearby surfaces, however in my built scene there is no bounced light. I have another material using the standard shader which does properly emit light, so the Enlighten system is working in the scene, just not for my shader. Here is a simplified version of my shader with the logic removed for clarity.
    Code (CSharp):
    1. Shader "Custom/GlowShader"
    2. {
    3.     Properties
    4.     {
    5.         [HDR] _EmissionColor ("Emission Color", Color) = (1,1,1,1)
    6.         [MaterialToggle] _UseEmission ("Use Emission", float) = 1
    7.         [MainTexture] _EmissionMap ("Base (RGB) Trans (A)", 2D) = "white" {}
    8.         _AlphaMap ("Alpha Map", 2D) = "white" {}
    9.  
    10.         _LengthCutoff ("Length Cutoff", Range(0.0, 1.0)) = .97
    11.         _Smoothing ("Smoothing", Range(0.1, 15.0)) = 3
    12.         _Transparency ("Transparency", Range(0.0, 1.0)) = .2
    13.  
    14.         _NoiseTex ("Noise Texture", 2D) = "white" {}
    15.         _NoiseStrength ("Noise Strength", Range(0.0, 1.0)) = .1
    16.     }
    17.     SubShader
    18.     {
    19.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "ForceNoShadowCasting"="True"}
    20.         LOD 100
    21.  
    22.         ZWrite Off
    23.         Lighting Off
    24.         Blend SrcAlpha OneMinusSrcAlpha
    25.  
    26.         CGPROGRAM
    27.         // Physically based Standard lighting model, and enable shadows on all light types
    28.         #pragma surface surf Standard noshadow noambient alpha:fade
    29.  
    30.         // Use shader model 3.0 target, to get nicer looking lighting
    31.         #pragma target 3.0
    32.  
    33.         struct Input
    34.         {
    35.             float2 uv_MainTex : TEXCOORD0;
    36.             float2 uv2_AlphaMap : TEXCOORD1;
    37.         };
    38.  
    39.         sampler2D _EmissionMap;
    40.         sampler2D _NoiseTex;
    41.         sampler2D _AlphaMap;
    42.         float4 _EmissionColor;
    43.         float _NoiseStrength;
    44.        
    45.         float _LengthCutoff;
    46.         float _Smoothing;
    47.         float _Transparency;
    48.         float _UseEmission;
    49.  
    50.         // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    51.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    52.         // #pragma instancing_options assumeuniformscaling
    53.         UNITY_INSTANCING_BUFFER_START(Props)
    54.             // put more per-instance properties here
    55.         UNITY_INSTANCING_BUFFER_END(Props)
    56.  
    57.         void surf (Input IN, inout SurfaceOutputStandard o)
    58.         {
    59.             float4 col = tex2D (_EmissionMap, IN.uv_MainTex);
    60.             float alpha = 1.0;
    61.          
    62.             // logic to calculate alpha and emission based on input textures and values
    63.             // ...
    64.             // ...
    65.  
    66.             // set output
    67.             o.Alpha = alpha;
    68.             o.Emission = col.rgb * _EmissionColor * alpha * _UseEmission;
    69.             o.Albedo = col.rgb;
    70.             o.Metallic = 0.0;
    71.             o.Smoothness = 0.0;
    72.         }
    73.         ENDCG
    74.     }
    75.     FallBack "Unlit/Transparent"
    76. }
    Does anyone have any suggestions. Is there something about the way this shader is compiled that makes it work in editor but not in build? Thank you!
     
  2. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    1,080
  3. HUSHstudios

    HUSHstudios

    Joined:
    Sep 23, 2015
    Posts:
    11
    ok great thank for addressing this!