FauxBlurURP.shader 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. Shader "SpatialFramework/FauxBackgroundOverlayBlurURP"
  2. {
  3. Properties
  4. {
  5. _Blur("Blur", Range(0, 10)) = 1.5
  6. _Alpha("Alpha", Range(0, 1)) = 1
  7. _GradientSize("Gradient Size", Range(0, 6)) = 2
  8. _MainTex("Noise Texture (REQUIRED for Blur Noise)", 2D) = "white" {}
  9. }
  10. SubShader
  11. {
  12. PackageRequirements
  13. {
  14. "com.unity.render-pipelines.universal": "12.1.3"
  15. }
  16. Tags { "RenderPipeline" = "UniversalRenderPipeline" "Queue" = "Transparent-1" "LightMode" = "Always" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
  17. ZWrite On
  18. ZTest LEqual
  19. Lighting Off
  20. Blend SrcAlpha OneMinusSrcAlpha
  21. Pass
  22. {
  23. Tags { "LightMode" = "UniversalForward" }
  24. HLSLPROGRAM
  25. #pragma vertex vert
  26. #pragma fragment frag
  27. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  28. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl"
  29. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
  30. SAMPLER(_MainTex);
  31. CBUFFER_START(UnityPerMaterial)
  32. half _Alpha;
  33. half _Blur;
  34. half _GradientSize;
  35. CBUFFER_END
  36. struct appdata_t
  37. {
  38. half4 position : POSITION;
  39. half3 normal : NORMAL;
  40. half2 texcoord : TEXCOORD0;
  41. UNITY_VERTEX_INPUT_INSTANCE_ID
  42. };
  43. struct v2f
  44. {
  45. half4 position : POSITION;
  46. half3 worldPos : TEXCOORD0;
  47. half2 cleanUV : TEXCOORD2;
  48. UNITY_VERTEX_OUTPUT_STEREO
  49. };
  50. v2f vert(appdata_t v)
  51. {
  52. v2f output;
  53. UNITY_SETUP_INSTANCE_ID(v);
  54. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  55. output.position = TransformObjectToHClip(v.position.xyz);
  56. output.worldPos = mul(unity_ObjectToWorld, v.position).xyz;
  57. output.cleanUV = v.texcoord;
  58. return output;
  59. }
  60. half4 frag(v2f input) : SV_Target
  61. {
  62. half2 uvPos = abs(input.cleanUV - float2(0.5, 0.5));
  63. half uvMax = max(uvPos.x, uvPos.y);
  64. half fadeFromBorderAmount = 1 - clamp(0, 1, pow(uvMax, _GradientSize) * 2);
  65. half3 reflectionDir = -normalize(GetWorldSpaceViewDir(input.worldPos));
  66. half noise = tex2D(_MainTex, input.cleanUV).r;
  67. half4 reflectionData = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectionDir, 1.5);
  68. half3 reflectionColor = DecodeHDREnvironment(reflectionData, unity_SpecCube0_HDR);
  69. return half4(reflectionColor, clamp(0, 1 - pow((uvMax * 2), _GradientSize * (_Blur / 10)), fadeFromBorderAmount) * _Alpha * noise);
  70. }
  71. ENDHLSL
  72. }
  73. }
  74. SubShader
  75. {
  76. Tags{ "RenderPipeline" = " " "Queue" = "Transparent-1" "LightMode" = "Always" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
  77. ZWrite On
  78. ZTest LEqual
  79. Lighting Off
  80. Blend SrcAlpha OneMinusSrcAlpha
  81. Pass
  82. {
  83. CGPROGRAM
  84. #pragma vertex vert
  85. #pragma fragment frag
  86. #include "UnityCG.cginc"
  87. half _Alpha;
  88. half _Blur;
  89. half _GradientSize;
  90. sampler2D _MainTex;
  91. struct appdata_t
  92. {
  93. half4 position : POSITION;
  94. half3 normal : NORMAL;
  95. half2 texcoord : TEXCOORD0;
  96. UNITY_VERTEX_INPUT_INSTANCE_ID
  97. };
  98. struct v2f
  99. {
  100. half4 position : POSITION;
  101. half3 worldPos : TEXCOORD0;
  102. half2 cleanUV : TEXCOORD2;
  103. UNITY_VERTEX_OUTPUT_STEREO
  104. };
  105. v2f vert(appdata_t v)
  106. {
  107. v2f output;
  108. UNITY_SETUP_INSTANCE_ID(v);
  109. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  110. output.position = UnityObjectToClipPos(v.position);
  111. output.worldPos = mul(unity_ObjectToWorld, v.position).xyz;
  112. output.cleanUV = v.texcoord;
  113. return output;
  114. }
  115. fixed4 frag(v2f input) : SV_Target
  116. {
  117. half2 uvPos = abs(input.cleanUV - float2(0.5, 0.5));
  118. half uvMax = max(uvPos.x, uvPos.y);
  119. half fadeFromBorderAmount = 1 - clamp(0, 1, pow(uvMax, _GradientSize) * 2);
  120. half3 reflectionDir = -normalize(UnityWorldSpaceViewDir(input.worldPos));
  121. half noise = tex2D(_MainTex, input.cleanUV).r;
  122. half4 reflectionData = UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, reflectionDir, 1.5);
  123. half3 reflectionColor = DecodeHDR(reflectionData, unity_SpecCube0_HDR);
  124. return half4(reflectionColor, clamp(0, 1 - pow((uvMax * 2), _GradientSize * (_Blur / 10)), fadeFromBorderAmount) * _Alpha * noise);
  125. }
  126. ENDCG
  127. }
  128. }
  129. }