阴影Pass

作者:追风剑情 发布于:2016-11-8 15:18 分类:Shader

  1. // 投射阴影Pass
  2. Pass
  3. {
  4. Name "ShadowCaster"
  5. Tags { "LightMode" = "ShadowCaster" }
  6. Fog {Mode Off}
  7. ZWrite On ZTest LEqual Cull Off
  8. Offset 1, 1
  9.  
  10. CGPROGRAM
  11. #pragma vertex vert
  12. #pragma fragment frag
  13. #pragma multi_compile_shadowcaster
  14. #include "UnityCG.cginc"
  15.  
  16. struct v2f {
  17. V2F_SHADOW_CASTER;
  18. };
  19.  
  20. v2f vert( appdata_base v )
  21. {
  22. v2f o;
  23. TRANSFER_SHADOW_CASTER(o)
  24. return o;
  25. }
  26.  
  27. float4 frag( v2f i ) : SV_Target
  28. {
  29. SHADOW_CASTER_FRAGMENT(i)
  30. }
  31. ENDCG
  32. }
  33.  
  34. // 接受阴影Pass
  35. // note: editor needs this pass as it has a collector pass.
  36. Pass
  37. {
  38. Name "ShadowCollector"
  39. Tags { "LightMode" = "ShadowCollector" }
  40. Fog {Mode Off}
  41. ZWrite On ZTest LEqual
  42.  
  43. CGPROGRAM
  44. #pragma vertex vert
  45. #pragma fragment frag
  46. #pragma multi_compile_shadowcollector
  47.  
  48. //定义SHADOW_COLLECTOR_PASS宏,以开启阴影相关的辅助宏功能
  49. #define SHADOW_COLLECTOR_PASS
  50. #include "UnityCG.cginc"
  51.  
  52. struct appdata {
  53. float4 vertex : POSITION;
  54. };
  55.  
  56. struct v2f {
  57. V2F_SHADOW_COLLECTOR;
  58. };
  59.  
  60. v2f vert (appdata v)
  61. {
  62. v2f o;
  63. TRANSFER_SHADOW_COLLECTOR(o)
  64. return o;
  65. }
  66.  
  67. fixed4 frag (v2f i) : SV_Target
  68. {
  69. SHADOW_COLLECTOR_FRAGMENT(i)
  70. }
  71. ENDCG
  72. }

标签: Shader

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号