Advertisement
Guest User

URP unlit shadow

a guest
Mar 19th, 2020
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Universal Render Pipeline/Custom/Unlit Shadow"
  2. {
  3.     Properties
  4.     {
  5.         _BaseMap ("Texture", 2D) = "white" {}
  6.         _BaseColor ("Light Color", Color) = (1,1,1,1)
  7.         _ShadowColor ("Shadow Color", Color) = (0.5,0.5,0.5,1)
  8.     }
  9.     SubShader
  10.     {
  11.         Tags{"LightMode" = "UniversalForward"}
  12.         LOD 100
  13.  
  14.         Pass
  15.         {
  16.             HLSLPROGRAM
  17.             #pragma vertex vert
  18.             #pragma fragment frag
  19.             #pragma multi_compile_fog
  20.            
  21.             #pragma prefer_hlslcc gles
  22.             #pragma exclude_renderers d3d11_9x
  23.            
  24.             #pragma target 3.0
  25.            
  26.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  27.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  28.            
  29.             #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  30.             #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  31.  
  32.             struct appdata
  33.             {
  34.                 float4 vertex : POSITION;
  35.                 float2 uv : TEXCOORD0;
  36.                 UNITY_VERTEX_INPUT_INSTANCE_ID
  37.             };
  38.  
  39.             struct v2f
  40.             {
  41.                 float2 uv : TEXCOORD0;
  42.                 float4 vertex : SV_POSITION;
  43.                 float4 positionWSAndFogFactor : TEXCOORD2; // xyz: positionWS, w: vertex fog factor
  44.                 float4 shadowCoord : TEXCOORD3;
  45.             };
  46.  
  47.             sampler2D _BaseMap;
  48.            
  49.             CBUFFER_START(UnityPerMaterial)
  50.             float4 _BaseMap_ST;
  51.             half4 _BaseColor;
  52.             half4 _ShadowColor;
  53.             CBUFFER_END
  54.  
  55.             v2f vert (appdata v)
  56.             {
  57.                 v2f o;
  58.                 VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  59.                 //VertexNormalInputs vertexNormalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  60.                 o.vertex = vertexInput.positionCS;
  61.                
  62.                 float fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  63.                 o.positionWSAndFogFactor = float4(vertexInput.positionWS, fogFactor);
  64.                
  65.                 o.shadowCoord = GetShadowCoord(vertexInput);
  66.                
  67.                 o.uv = TRANSFORM_TEX(v.uv, _BaseMap);
  68.                 return o;
  69.             }
  70.  
  71.             float4 frag (v2f i) : SV_Target
  72.             {
  73.                 // sample the texture
  74.                 float4 color = tex2D(_BaseMap, i.uv);
  75.                 float fogFactor = i.positionWSAndFogFactor.w;
  76.                
  77.                 #ifdef _MAIN_LIGHT_SHADOWS
  78.                 Light mainLight = GetMainLight(i.shadowCoord);
  79.                 #else
  80.                 Light mainLight = GetMainLight();
  81.                 #endif
  82.                
  83.                 color.rgb  = lerp(color * _ShadowColor, color * _BaseColor, mainLight.shadowAttenuation);
  84.                
  85.                 color.rgb = MixFog(color.rgb, fogFactor);
  86.                
  87.                 return color;
  88.             }
  89.             ENDHLSL
  90.         }
  91.         // Used for rendering shadowmaps
  92.         UsePass "Universal Render Pipeline/Lit/ShadowCaster"
  93.  
  94.         // Used for depth prepass
  95.         // If shadows cascade are enabled we need to perform a depth prepass.
  96.         // We also need to use a depth prepass in some cases camera require depth texture
  97.         // (e.g, MSAA is enabled and we can't resolve with Texture2DMS
  98.         UsePass "Universal Render Pipeline/Lit/DepthOnly"
  99.  
  100.         // Used for Baking GI. This pass is stripped from build.
  101.         UsePass "Universal Render Pipeline/Lit/Meta"
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement