﻿Shader "Video/EmissiveGamma" {
  Properties {
    _MainTex ("Emissive (RGB)", 2D) = "white" {}
    _EmissionScale ("Emission Scale", Float) = 1
    _EmissionLM ("Emission (Lightmapper)", Float) = 1
    [Toggle] _DynamicEmissionLM ("Dynamic Emission (Lightmapper)", Int) = 0
    [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  }
  SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200

      CGPROGRAM
      // Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows

      // Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
#pragma shader_feature _EMISSION
#pragma multi_compile APPLY_GAMMA_OFF APPLY_GAMMA

    fixed _EmissionScale;
    fixed _EmissionLM;
    int _DynamicEmissionLM;
    sampler2D _MainTex;

    struct Input {
      float2 uv_MainTex;
    };

    // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    // #pragma instancing_options assumeuniformscaling
    UNITY_INSTANCING_CBUFFER_START(Props)
      // put more per-instance properties here
      UNITY_INSTANCING_CBUFFER_END

      void surf (Input IN, inout SurfaceOutputStandard o) {
        // emissive comes from texture
        fixed4 e = tex2D (_MainTex, IN.uv_MainTex);
        o.Albedo = fixed4(0,0,0,0);
        o.Alpha = e.a;

#if APPLY_GAMMA
        e.rgb = pow(e.rgb,2.2);
#endif
        o.Emission = e * _EmissionScale;
        o.Metallic = 0;
        o.Smoothness = 0;
      }
    ENDCG
  }
  FallBack "Diffuse"
}
