-
-
Save CouriersRyan/c4226b23e16c9c9eb1dc8a8374eb19d0 to your computer and use it in GitHub Desktop.
Works with stencil buffer and scripts to create graphic drop shadow on certain objects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Shader "Unlit/dropShadowShader" | |
| { | |
| Properties | |
| { | |
| _ShadowColor ("Shadow Color", Color) = (0, 0, 0, 1) | |
| _Range ("Range", Range(0, 1)) = 1 | |
| _DropOffset ("Offset", Vector) = (0.03, -0.01, -0.02) | |
| _AlphaCutoff ("Alpha Cutoff", 2D) = "white" {} | |
| //_stencilRef("stencil reference", Int) = 1 | |
| } | |
| SubShader | |
| { | |
| Tags { "RenderType"="Opaque" "Queue"="Geometry+1"} | |
| LOD 100 | |
| Pass | |
| { | |
| Cull Off | |
| AlphaToMask On | |
| //ZTest Off | |
| //ZWrite Off | |
| Offset 1, -1 | |
| Stencil | |
| { | |
| Ref 2 | |
| Comp notequal | |
| } | |
| CGPROGRAM | |
| #pragma vertex vert | |
| #pragma fragment frag | |
| // make fog work | |
| #pragma multi_compile_fog | |
| #include "UnityCG.cginc" | |
| struct appdata | |
| { | |
| float4 vertex : POSITION; | |
| float2 uv : TEXCOORD0; | |
| }; | |
| struct v2f | |
| { | |
| float4 vertex : SV_POSITION; | |
| float2 uv : TEXCOORD0; | |
| }; | |
| float4 _ShadowColor; | |
| float3 _DropOffset; | |
| float _Range; | |
| sampler2D _AlphaCutoff; | |
| v2f vert (appdata v) | |
| { | |
| v2f o; | |
| float3 viewSpacePos = UnityObjectToViewPos(v.vertex.xyz); | |
| o.vertex = mul(UNITY_MATRIX_P, float4(viewSpacePos + _Range * _DropOffset, 1.0f)); | |
| o.uv = v.uv; | |
| /*float4 worldSpacePos = mul(unity_ObjectToWorld, v.vertex); | |
| float3 viewDir = normalize(UnityWorldSpaceViewDir(worldSpacePos)); | |
| o.vertex = mul(UNITY_MATRIX_VP, worldSpacePos + (float4(viewDir, 0.0)));*/ | |
| return o; | |
| } | |
| fixed4 frag (v2f i) : SV_Target | |
| { | |
| // sample the texture | |
| float alpha = tex2D(_AlphaCutoff, i.uv).a; | |
| float4 color = _ShadowColor * (1, 1, 1, alpha); | |
| return color; | |
| } | |
| ENDCG | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment