Advertisement
Guest User

UNLIT with Shadows

a guest
May 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/UNLITwithShadows" {
  2. Properties {
  3.         _Color ("Main Color", Color) = (1,1,1,1)
  4.         _MainTex ("Base (RGB)", 2D) = "white" {}
  5.     }
  6.     SubShader {
  7.         Tags {"Queue" = "Geometry" "RenderType" = "Opaque"}
  8.  
  9.         Pass {
  10.             Tags {"LightMode" = "ForwardBase"}
  11.             CGPROGRAM
  12.                 #pragma vertex vert
  13.                 #pragma fragment frag
  14.                 #pragma multi_compile_fwdbase
  15.                 #pragma fragmentoption ARB_fog_exp2
  16.                 #pragma fragmentoption ARB_precision_hint_fastest
  17.                
  18.                 #include "UnityCG.cginc"
  19.                 #include "AutoLight.cginc"
  20.                
  21.                 struct v2f
  22.                 {
  23.                     float4  pos         : SV_POSITION;
  24.                     float2  uv          : TEXCOORD0;
  25.                     LIGHTING_COORDS(1,2)
  26.                 };
  27.  
  28.                 v2f vert (appdata_tan v)
  29.                 {
  30.                     v2f o;
  31.                    
  32.                     o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
  33.                     o.uv = v.texcoord.xy;
  34.                     TRANSFER_VERTEX_TO_FRAGMENT(o);
  35.                     return o;
  36.                 }
  37.  
  38.                 sampler2D _MainTex;
  39.  
  40.                 fixed4 frag(v2f i) : COLOR
  41.                 {
  42.                     fixed atten = LIGHT_ATTENUATION(i); // Light attenuation + shadows.
  43.                     //fixed atten = SHADOW_ATTENUATION(i); // Shadows ONLY.
  44.                     return tex2D(_MainTex, i.uv) * atten;
  45.                 }
  46.             ENDCG
  47.         }
  48.  
  49.         Pass {
  50.             Tags {"LightMode" = "ForwardAdd"}
  51.             Blend One One
  52.             CGPROGRAM
  53.                 #pragma vertex vert
  54.                 #pragma fragment frag
  55.                 #pragma multi_compile_fwdadd_fullshadows
  56.                 #pragma fragmentoption ARB_fog_exp2
  57.                 #pragma fragmentoption ARB_precision_hint_fastest
  58.                
  59.                 #include "UnityCG.cginc"
  60.                 #include "AutoLight.cginc"
  61.                
  62.                 struct v2f
  63.                 {
  64.                     float4  pos         : SV_POSITION;
  65.                     float2  uv          : TEXCOORD0;
  66.                     LIGHTING_COORDS(1,2)
  67.                 };
  68.  
  69.                 v2f vert (appdata_tan v)
  70.                 {
  71.                     v2f o;
  72.                    
  73.                     o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
  74.                     o.uv = v.texcoord.xy;
  75.                     TRANSFER_VERTEX_TO_FRAGMENT(o);
  76.                     return o;
  77.                 }
  78.  
  79.                 sampler2D _MainTex;
  80.  
  81.                 fixed4 frag(v2f i) : COLOR
  82.                 {
  83.                     fixed atten = LIGHT_ATTENUATION(i); // Light attenuation + shadows.
  84.                     //fixed atten = SHADOW_ATTENUATION(i); // Shadows ONLY.
  85.                     return tex2D(_MainTex, i.uv) * atten * SHADOW_ATTENUATION(i);
  86.                 }
  87.             ENDCG
  88.         }
  89.     }
  90.     FallBack "VertexLit"
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement