Sampling.shader 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. Shader "Hidden/Universal Render Pipeline/Sampling"
  2. {
  3. Properties
  4. {
  5. _MainTex("Albedo", 2D) = "white" {}
  6. }
  7. HLSLINCLUDE
  8. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  9. struct Attributes
  10. {
  11. float4 positionOS : POSITION;
  12. float2 texcoord : TEXCOORD0;
  13. UNITY_VERTEX_INPUT_INSTANCE_ID
  14. };
  15. struct Varyings
  16. {
  17. float4 positionCS : SV_POSITION;
  18. float2 uv : TEXCOORD0;
  19. UNITY_VERTEX_INPUT_INSTANCE_ID
  20. };
  21. Varyings Vertex(Attributes input)
  22. {
  23. Varyings output;
  24. UNITY_SETUP_INSTANCE_ID(input);
  25. UNITY_TRANSFER_INSTANCE_ID(input, output);
  26. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  27. output.uv = UnityStereoTransformScreenSpaceTex(input.texcoord);
  28. return output;
  29. }
  30. half4 DownsampleBox4Tap(TEXTURE2D_PARAM(tex, samplerTex), float2 uv, float2 texelSize, float amount)
  31. {
  32. float4 d = texelSize.xyxy * float4(-amount, -amount, amount, amount);
  33. half4 s;
  34. s = (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xy));
  35. s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zy));
  36. s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xw));
  37. s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zw));
  38. return s * 0.25h;
  39. }
  40. ENDHLSL
  41. SubShader
  42. {
  43. Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
  44. LOD 100
  45. // 0 - Downsample - Box filtering
  46. Pass
  47. {
  48. Name "Default"
  49. ZTest Always
  50. ZWrite Off
  51. HLSLPROGRAM
  52. // Required to compile gles 2.0 with standard srp library
  53. #pragma prefer_hlslcc gles
  54. #pragma vertex Vertex
  55. #pragma fragment FragBoxDownsample
  56. TEXTURE2D(_MainTex);
  57. SAMPLER(sampler_MainTex);
  58. float4 _MainTex_TexelSize;
  59. float _SampleOffset;
  60. half4 FragBoxDownsample(Varyings input) : SV_Target
  61. {
  62. half4 col = DownsampleBox4Tap(TEXTURE2D_ARGS(_MainTex, sampler_MainTex), input.uv, _MainTex_TexelSize.xy, _SampleOffset);
  63. return half4(col.rgb, 1);
  64. }
  65. ENDHLSL
  66. }
  67. }
  68. }