SubpixelMorphologicalAntialiasingBridge.hlsl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef UNIVERSAL_POSTPROCESSING_SMAA_BRIDGE
  2. #define UNIVERSAL_POSTPROCESSING_SMAA_BRIDGE
  3. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  4. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  5. #include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/Common.hlsl"
  6. #define SMAA_HLSL_4_1
  7. #if _SMAA_PRESET_LOW
  8. #define SMAA_PRESET_LOW
  9. #elif _SMAA_PRESET_MEDIUM
  10. #define SMAA_PRESET_MEDIUM
  11. #else
  12. #define SMAA_PRESET_HIGH
  13. #endif
  14. TEXTURE2D_X(_ColorTexture);
  15. TEXTURE2D_X(_BlendTexture);
  16. TEXTURE2D(_AreaTexture);
  17. TEXTURE2D(_SearchTexture);
  18. float4 _Metrics;
  19. #define SMAA_RT_METRICS _Metrics
  20. #define SMAA_AREATEX_SELECT(s) s.rg
  21. #define SMAA_SEARCHTEX_SELECT(s) s.a
  22. #define LinearSampler sampler_LinearClamp
  23. #define PointSampler sampler_PointClamp
  24. #if UNITY_COLORSPACE_GAMMA
  25. #define GAMMA_FOR_EDGE_DETECTION (1)
  26. #else
  27. #define GAMMA_FOR_EDGE_DETECTION (1/2.2)
  28. #endif
  29. #include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/SubpixelMorphologicalAntialiasing.hlsl"
  30. // ----------------------------------------------------------------------------------------
  31. // Edge Detection
  32. struct VaryingsEdge
  33. {
  34. float4 positionCS : SV_POSITION;
  35. float2 uv : TEXCOORD0;
  36. float4 offsets[3] : TEXCOORD1;
  37. UNITY_VERTEX_OUTPUT_STEREO
  38. };
  39. VaryingsEdge VertEdge(Attributes input)
  40. {
  41. VaryingsEdge output;
  42. UNITY_SETUP_INSTANCE_ID(input);
  43. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  44. output.positionCS = TransformFullscreenMesh(input.positionOS.xyz);
  45. output.uv = UnityStereoTransformScreenSpaceTex(input.uv);
  46. SMAAEdgeDetectionVS(output.uv, output.offsets);
  47. return output;
  48. }
  49. float4 FragEdge(VaryingsEdge input) : SV_Target
  50. {
  51. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  52. return float4(SMAAColorEdgeDetectionPS(input.uv, input.offsets, _ColorTexture), 0.0, 0.0);
  53. }
  54. // ----------------------------------------------------------------------------------------
  55. // Blend Weights Calculation
  56. struct VaryingsBlend
  57. {
  58. float4 positionCS : SV_POSITION;
  59. float2 uv : TEXCOORD0;
  60. float2 pixcoord : TEXCOORD1;
  61. float4 offsets[3] : TEXCOORD2;
  62. UNITY_VERTEX_OUTPUT_STEREO
  63. };
  64. VaryingsBlend VertBlend(Attributes input)
  65. {
  66. VaryingsBlend output;
  67. UNITY_SETUP_INSTANCE_ID(input);
  68. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  69. output.positionCS = TransformFullscreenMesh(input.positionOS.xyz);
  70. output.uv = UnityStereoTransformScreenSpaceTex(input.uv);
  71. SMAABlendingWeightCalculationVS(output.uv, output.pixcoord, output.offsets);
  72. return output;
  73. }
  74. float4 FragBlend(VaryingsBlend input) : SV_Target
  75. {
  76. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  77. return SMAABlendingWeightCalculationPS(input.uv, input.pixcoord, input.offsets, _ColorTexture, _AreaTexture, _SearchTexture, 0);
  78. }
  79. // ----------------------------------------------------------------------------------------
  80. // Neighborhood Blending
  81. struct VaryingsNeighbor
  82. {
  83. float4 positionCS : SV_POSITION;
  84. float2 uv : TEXCOORD0;
  85. float4 offset : TEXCOORD1;
  86. UNITY_VERTEX_OUTPUT_STEREO
  87. };
  88. VaryingsNeighbor VertNeighbor(Attributes input)
  89. {
  90. VaryingsNeighbor output;
  91. UNITY_SETUP_INSTANCE_ID(input);
  92. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  93. output.positionCS = TransformFullscreenMesh(input.positionOS.xyz);
  94. output.uv = UnityStereoTransformScreenSpaceTex(input.uv);
  95. SMAANeighborhoodBlendingVS(output.uv, output.offset);
  96. return output;
  97. }
  98. float4 FragNeighbor(VaryingsNeighbor input) : SV_Target
  99. {
  100. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  101. return SMAANeighborhoodBlendingPS(input.uv, input.offset, _ColorTexture, _BlendTexture);
  102. }
  103. #endif // UNIVERSAL_POSTPROCESSING_SMAA_BRIDGE