Unlit.shader 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. Shader "SupGames/PlanarReflection/Unlit"
  2. {
  3. Properties{
  4. _Color("Color", Color) = (1,1,1,1)
  5. _MainTex("Main Texture", 2D) = "white" {}
  6. _MaskTex("Mask Texture", 2D) = "white" {}
  7. _BlurAmount("Blur Amount", Range(0,7)) = 1
  8. }
  9. SubShader{
  10. Tags {"RenderType" = "Opaque"}
  11. LOD 100
  12. Pass {
  13. CGPROGRAM
  14. #pragma vertex vert
  15. #pragma fragment frag
  16. #pragma fragmentoption ARB_precision_hint_fastest
  17. #pragma shader_feature_local BLUR
  18. #pragma shader_feature_local VRon
  19. #pragma multi_compile_instancing
  20. #pragma multi_compile_fog
  21. #include "UnityCG.cginc"
  22. UNITY_DECLARE_SCREENSPACE_TEXTURE(_ReflectionTex);
  23. #ifdef VRon
  24. UNITY_DECLARE_SCREENSPACE_TEXTURE(_ReflectionTexRight);
  25. #endif
  26. UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
  27. UNITY_DECLARE_SCREENSPACE_TEXTURE(_MaskTex);
  28. fixed4 _LightColor0;
  29. fixed _RefAlpha;
  30. fixed4 _MainTex_ST;
  31. fixed4 _Color;
  32. fixed _BlurAmount;
  33. fixed4 _ReflectionTex_TexelSize;
  34. struct appdata
  35. {
  36. fixed4 vertex : POSITION;
  37. fixed2 uv : TEXCOORD0;
  38. UNITY_VERTEX_INPUT_INSTANCE_ID
  39. };
  40. struct v2f
  41. {
  42. fixed4 pos : SV_POSITION;
  43. fixed4 uv : TEXCOORD0;
  44. fixed2 fogCoord : TEXCOORD1;
  45. #if defined(BLUR)
  46. fixed4 offset : TEXCOORD2;
  47. #endif
  48. UNITY_VERTEX_INPUT_INSTANCE_ID
  49. UNITY_VERTEX_OUTPUT_STEREO
  50. };
  51. v2f vert(appdata v)
  52. {
  53. v2f o;
  54. UNITY_SETUP_INSTANCE_ID(v);
  55. UNITY_INITIALIZE_OUTPUT(v2f, o);
  56. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  57. o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
  58. o.pos = UnityObjectToClipPos(v.vertex);
  59. fixed4 scrPos = ComputeNonStereoScreenPos(o.pos);
  60. o.uv.zw = scrPos.xy;
  61. o.fogCoord.y = scrPos.w;
  62. #if defined(BLUR)
  63. fixed2 offset = _ReflectionTex_TexelSize.xy * _BlurAmount;
  64. o.offset = fixed4(-offset, offset);
  65. #endif
  66. UNITY_TRANSFER_FOG(o, o.pos);
  67. return o;
  68. }
  69. fixed4 frag(v2f i) : SV_Target
  70. {
  71. UNITY_SETUP_INSTANCE_ID(i);
  72. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
  73. fixed4 color = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, i.uv.xy);
  74. fixed4 mask = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MaskTex, i.uv.xy);
  75. i.uv.zw /= i.fogCoord.y;
  76. fixed4 reflection = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTex, i.uv.zw);
  77. #if defined(BLUR)
  78. i.offset /= i.fogCoord.y;
  79. i.offset = fixed4(i.uv.zz + i.offset.xz, i.uv.ww + i.offset.yw);
  80. reflection += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTex, i.offset.xz);
  81. reflection += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTex, i.offset.xw);
  82. reflection += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTex, i.offset.yz);
  83. reflection += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTex, i.offset.yw);
  84. reflection *= 0.2h;
  85. #endif
  86. #ifdef VRon
  87. fixed4 reflectionr = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTexRight, i.uv.zw);
  88. #ifdef BLUR
  89. reflectionr += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTexRight, i.offset.xz);
  90. reflectionr += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTexRight, i.offset.xw);
  91. reflectionr += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTexRight, i.offset.yz);
  92. reflectionr += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_ReflectionTexRight, i.offset.yw);
  93. reflectionr *= 0.2h;
  94. #endif
  95. reflection = lerp(reflection, reflectionr, unity_StereoEyeIndex);
  96. #endif
  97. UNITY_APPLY_FOG(i.fogCoord.x, color);
  98. return (lerp(color, reflection, _RefAlpha * mask.r) + lerp(reflection, color, 1 - _RefAlpha * mask.r))*_Color * 0.5h;
  99. }
  100. ENDCG
  101. }
  102. }
  103. }