ProjectorAdditive.shader 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Upgrade NOTE: replaced '_Projector' with 'unity_Projector'
  2. // Upgrade NOTE: replaced '_ProjectorClip' with 'unity_ProjectorClip'
  3. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  4. Shader "Projector/AdditiveTint" {
  5. Properties {
  6. _Color ("Tint Color", Color) = (1,1,1,1)
  7. _Attenuation ("Falloff", Range(0.0, 1.0)) = 1.0
  8. _MainTex ("Cookie", 2D) = "gray" {}
  9. }
  10. Subshader {
  11. Tags {"Queue"="Transparent"}
  12. Pass {
  13. ZWrite Off
  14. ColorMask RGB
  15. Blend SrcAlpha One // Additive blending
  16. Offset -1, -1
  17. CGPROGRAM
  18. #pragma vertex vert
  19. #pragma fragment frag
  20. #include "UnityCG.cginc"
  21. struct v2f {
  22. float4 uvShadow : TEXCOORD0;
  23. float4 pos : SV_POSITION;
  24. };
  25. float4x4 unity_Projector;
  26. float4x4 unity_ProjectorClip;
  27. v2f vert (float4 vertex : POSITION)
  28. {
  29. v2f o;
  30. o.pos = UnityObjectToClipPos (vertex);
  31. o.uvShadow = mul (unity_Projector, vertex);
  32. return o;
  33. }
  34. sampler2D _MainTex;
  35. fixed4 _Color;
  36. float _Attenuation;
  37. fixed4 frag (v2f i) : SV_Target
  38. {
  39. // Apply alpha mask
  40. fixed4 texCookie = tex2Dproj (_MainTex, UNITY_PROJ_COORD(i.uvShadow));
  41. fixed4 outColor = saturate(_Color * texCookie * 1);
  42. // Attenuation
  43. float depth = i.uvShadow.z; // [-1 (near), 1 (far)]
  44. return outColor * clamp(1.0 - abs(depth) + _Attenuation, 0.0, 1.0);
  45. }
  46. ENDCG
  47. }
  48. }
  49. }