Created
January 15, 2017 11:48
-
-
Save Fscibe/37d71499737e309d00eb837094ac64d0 to your computer and use it in GitHub Desktop.
[Unity Shader] Projector Blob Shadow
This file contains 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
// | |
// Based on Unity's "ProjectorMultiply" shader: | |
// Slightly modified to apply effect only when the surface is pointing up. | |
// | |
// Upgrade NOTE: replaced '_Projector' with 'unity_Projector' | |
// Upgrade NOTE: replaced '_ProjectorClip' with 'unity_ProjectorClip' | |
Shader "Projector/BlobShadow" { | |
Properties { | |
_ShadowTex ("Cookie", 2D) = "gray" {} | |
_FalloffTex ("FallOff", 2D) = "white" {} | |
} | |
Subshader { | |
Tags {"Queue"="Transparent"} | |
Pass { | |
ZWrite Off | |
ColorMask RGB | |
Blend DstColor Zero | |
Offset -1, -1 | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile_fog | |
#include "UnityCG.cginc" | |
struct vertex_out { | |
float4 uvShadow : TEXCOORD0; | |
float4 uvFalloff : TEXCOORD1; | |
UNITY_FOG_COORDS(2) // TEXCOORD2 | |
float4 pos : SV_POSITION; | |
float intensity : TEXCOORD3; // additional intensity, based on normal orientation | |
}; | |
float4x4 unity_Projector; | |
float4x4 unity_ProjectorClip; | |
vertex_out vert (float4 vertex : POSITION, float3 normal : NORMAL) | |
{ | |
vertex_out o; | |
o.intensity = sign(dot(float3(0.0, 1.0, 0.0), UnityObjectToWorldNormal(normal))); // 1.0 if pointing UP | |
o.pos = mul (UNITY_MATRIX_MVP, vertex); | |
o.uvShadow = mul (unity_Projector, vertex); | |
o.uvFalloff = mul (unity_ProjectorClip, vertex); | |
UNITY_TRANSFER_FOG(o,o.pos); | |
return o; | |
} | |
sampler2D _ShadowTex; | |
sampler2D _FalloffTex; | |
fixed4 frag (vertex_out i) : SV_Target | |
{ | |
fixed4 texS = tex2Dproj (_ShadowTex, UNITY_PROJ_COORD(i.uvShadow)); | |
texS.a = 1.0-texS.a; | |
fixed4 texF = tex2Dproj (_FalloffTex, UNITY_PROJ_COORD(i.uvFalloff)); | |
fixed4 res = lerp(fixed4(1,1,1,0), texS, texF.a * i.intensity); | |
UNITY_APPLY_FOG_COLOR(i.fogCoord, res, fixed4(1,1,1,1)); | |
return res; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment