UnlitCastShadow.shader 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. Shader "Imagine/UnlitCastShadows"
  2. {
  3. Properties
  4. {
  5. [HDR]_Color("Albedo", Color) = (1,1,1,1)
  6. _MainTex ("Texture", 2D) = "white" {}
  7. [Header(Stencil)]
  8. _Stencil ("Stencil ID [0;255]", Float) = 0
  9. _ReadMask ("ReadMask [0;255]", Int) = 255
  10. _WriteMask ("WriteMask [0;255]", Int) = 255
  11. [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Comparison", Int) = 0
  12. [Enum(UnityEngine.Rendering.StencilOp)] _StencilOp ("Stencil Operation", Int) = 0
  13. [Enum(UnityEngine.Rendering.StencilOp)] _StencilFail ("Stencil Fail", Int) = 0
  14. [Enum(UnityEngine.Rendering.StencilOp)] _StencilZFail ("Stencil ZFail", Int) = 0
  15. [Header(Rendering)]
  16. _Offset("Offset", float) = 0
  17. [Enum(UnityEngine.Rendering.CullMode)] _Culling ("Cull Mode", Int) = 2
  18. [Enum(Off,0,On,1)] _ZWrite("ZWrite", Int) = 1
  19. [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest ("ZTest", Int) = 4
  20. [Enum(None,0,Alpha,1,Red,8,Green,4,Blue,2,RGB,14,RGBA,15)] _ColorMask("Color Mask", Int) = 15
  21. }
  22. CGINCLUDE
  23. #include "UnityCG.cginc"
  24. half4 _Color;
  25. sampler2D _MainTex;
  26. float4 _MainTex_ST;
  27. struct appdata
  28. {
  29. float4 vertex : POSITION;
  30. float2 uv : TEXCOORD0;
  31. };
  32. struct v2f
  33. {
  34. float2 uv : TEXCOORD0;
  35. float4 vertex : SV_POSITION;
  36. };
  37. v2f vert (appdata v)
  38. {
  39. v2f o;
  40. o.vertex = UnityObjectToClipPos(v.vertex);
  41. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  42. return o;
  43. }
  44. half4 frag (v2f i) : SV_Target
  45. {
  46. return tex2D(_MainTex, i.uv) * _Color;
  47. }
  48. struct v2fShadow {
  49. V2F_SHADOW_CASTER;
  50. UNITY_VERTEX_OUTPUT_STEREO
  51. };
  52. v2fShadow vertShadow( appdata_base v )
  53. {
  54. v2fShadow o;
  55. UNITY_SETUP_INSTANCE_ID(v);
  56. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  57. TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
  58. return o;
  59. }
  60. float4 fragShadow( v2fShadow i ) : SV_Target
  61. {
  62. SHADOW_CASTER_FRAGMENT(i)
  63. }
  64. ENDCG
  65. SubShader
  66. {
  67. Stencil
  68. {
  69. Ref [_Stencil]
  70. ReadMask [_ReadMask]
  71. WriteMask [_WriteMask]
  72. Comp [_StencilComp]
  73. Pass [_StencilOp]
  74. Fail [_StencilFail]
  75. ZFail [_StencilZFail]
  76. }
  77. Pass
  78. {
  79. Tags { "RenderType"="Opaque" "Queue" = "Geometry" }
  80. LOD 100
  81. Cull [_Culling]
  82. Offset [_Offset], [_Offset]
  83. ZWrite [_ZWrite]
  84. ZTest [_ZTest]
  85. ColorMask [_ColorMask]
  86. CGPROGRAM
  87. #pragma target 3.0
  88. #pragma vertex vert
  89. #pragma fragment frag
  90. ENDCG
  91. }
  92. // Pass to render object as a shadow caster
  93. Pass
  94. {
  95. Name "ShadowCaster"
  96. Tags { "LightMode" = "ShadowCaster" }
  97. LOD 80
  98. Cull [_Culling]
  99. Offset [_Offset], [_Offset]
  100. ZWrite [_ZWrite]
  101. ZTest [_ZTest]
  102. CGPROGRAM
  103. #pragma vertex vertShadow
  104. #pragma fragment fragShadow
  105. #pragma target 2.0
  106. #pragma multi_compile_shadowcaster
  107. ENDCG
  108. }
  109. }
  110. }