Guest User

Video-RealtimeEmissiveGamma-customemissionstrength.shader

a guest
Feb 18th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Shader "Video/RealtimeEmissiveGamma-MetaOnlyEmissionStrength" {
  3.   Properties {
  4.     _MainTex ("Emissive (RGB)", 2D) = "white" {}
  5.     _Emission ("Emission Scale", Float) = 1
  6.     [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  7.   }
  8.   SubShader {
  9.     Tags { "RenderType"="Opaque" }
  10.     LOD 100
  11.     Pass { Name "BASE" }
  12.    
  13.     CGPROGRAM  
  14.     #pragma surface surf Standard fullforwardshadows
  15.  
  16.     // Use shader model 3.0 target, to get nicer looking lighting
  17.     #pragma target 3.0
  18.     #pragma shader_feature _EMISSION
  19.     #pragma multi_compile APPLY_GAMMA_OFF APPLY_GAMMA
  20.  
  21.     fixed _Emission;
  22.     sampler2D _MainTex;
  23.  
  24.     struct Input {
  25.         float2 uv_MainTex;
  26.     };
  27.  
  28.     void surf (Input IN, inout SurfaceOutputStandard o) {
  29.         // emissive comes from texture
  30.         fixed4 e = tex2D (_MainTex, IN.uv_MainTex);
  31.         o.Albedo = fixed4(0,0,0,0);
  32.         o.Alpha = e.a;
  33.  
  34.         #if APPLY_GAMMA
  35.             e.rgb = pow(e.rgb,2.2);
  36.         #endif
  37.         o.Emission = e; // fix emission to "real" value, scaled in meta pass
  38.         o.Metallic = 0;
  39.         o.Smoothness = 0;
  40.     }
  41.     ENDCG
  42.  
  43.     Pass
  44.     {
  45.         Name "META"
  46.         Tags {"LightMode"="Meta"}
  47.         Cull Off
  48.         CGPROGRAM
  49.  
  50.         #include"UnityStandardMeta.cginc"
  51.  
  52.         fixed _Emission;
  53.            
  54.         float4 frag_meta2 (v2f_meta i): SV_Target
  55.         {
  56.             FragmentCommonData data = UNITY_SETUP_BRDF_INPUT (i.uv);
  57.             UnityMetaInput o;
  58.             UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);
  59.             fixed4 c = tex2D (_MainTex, i.uv);
  60.             o.Albedo = half3(0,0,0);
  61.             o.Emission = half3(c.rgb * _Emission); // multiplied by strength
  62.             return UnityMetaFragment(o);
  63.         }
  64.            
  65.         #pragma vertex vert_meta
  66.         #pragma fragment frag_meta2
  67.         #pragma shader_feature _EMISSION
  68.         #pragma shader_feature _METALLICGLOSSMAP
  69.         #pragma shader_feature ___ _DETAIL_MULX2
  70.         ENDCG
  71.     }
  72.   }
  73.  
  74.   FallBack "Diffuse"
  75.   CustomEditor "RealtimeEmissiveGammaGUI"
  76. }
Advertisement
Add Comment
Please, Sign In to add comment