暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SubpixelMorphologicalAntialiasingBridge.hlsl 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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(_BlendTexture);
  15. TEXTURE2D(_AreaTexture);
  16. TEXTURE2D(_SearchTexture);
  17. float4 _Metrics;
  18. #define SMAA_RT_METRICS _Metrics
  19. #define SMAA_AREATEX_SELECT(s) s.rg
  20. #define SMAA_SEARCHTEX_SELECT(s) s.a
  21. #define LinearSampler sampler_LinearClamp
  22. #define PointSampler sampler_PointClamp
  23. #if UNITY_COLORSPACE_GAMMA
  24. #define GAMMA_FOR_EDGE_DETECTION (1)
  25. #else
  26. #define GAMMA_FOR_EDGE_DETECTION (1/2.2)
  27. #endif
  28. #include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/SubpixelMorphologicalAntialiasing.hlsl"
  29. // ----------------------------------------------------------------------------------------
  30. // Edge Detection
  31. struct VaryingsEdge
  32. {
  33. float4 positionCS : SV_POSITION;
  34. float2 texcoord : TEXCOORD0;
  35. float4 offsets[3] : TEXCOORD1;
  36. UNITY_VERTEX_OUTPUT_STEREO
  37. };
  38. VaryingsEdge VertEdge(Attributes input)
  39. {
  40. VaryingsEdge output;
  41. UNITY_SETUP_INSTANCE_ID(input);
  42. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  43. float4 pos = GetFullScreenTriangleVertexPosition(input.vertexID);
  44. float2 uv = GetFullScreenTriangleTexCoord(input.vertexID);
  45. output.positionCS = pos;
  46. output.texcoord = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
  47. SMAAEdgeDetectionVS(output.texcoord, output.offsets);
  48. return output;
  49. }
  50. float4 FragEdge(VaryingsEdge input) : SV_Target
  51. {
  52. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  53. return float4(SMAAColorEdgeDetectionPS(input.texcoord, input.offsets, _BlitTexture), 0.0, 0.0);
  54. }
  55. // ----------------------------------------------------------------------------------------
  56. // Blend Weights Calculation
  57. struct VaryingsBlend
  58. {
  59. float4 positionCS : SV_POSITION;
  60. float2 texcoord : TEXCOORD0;
  61. float2 pixcoord : TEXCOORD1;
  62. float4 offsets[3] : TEXCOORD2;
  63. UNITY_VERTEX_OUTPUT_STEREO
  64. };
  65. VaryingsBlend VertBlend(Attributes input)
  66. {
  67. VaryingsBlend output;
  68. UNITY_SETUP_INSTANCE_ID(input);
  69. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  70. float4 pos = GetFullScreenTriangleVertexPosition(input.vertexID);
  71. float2 uv = GetFullScreenTriangleTexCoord(input.vertexID);
  72. output.positionCS = pos;
  73. output.texcoord = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
  74. SMAABlendingWeightCalculationVS(output.texcoord, output.pixcoord, output.offsets);
  75. return output;
  76. }
  77. float4 FragBlend(VaryingsBlend input) : SV_Target
  78. {
  79. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  80. return SMAABlendingWeightCalculationPS(input.texcoord, input.pixcoord, input.offsets, _BlitTexture, _AreaTexture, _SearchTexture, 0);
  81. }
  82. // ----------------------------------------------------------------------------------------
  83. // Neighborhood Blending
  84. struct VaryingsNeighbor
  85. {
  86. float4 positionCS : SV_POSITION;
  87. float2 texcoord : TEXCOORD0;
  88. float4 offset : TEXCOORD1;
  89. UNITY_VERTEX_OUTPUT_STEREO
  90. };
  91. VaryingsNeighbor VertNeighbor(Attributes input)
  92. {
  93. VaryingsNeighbor output;
  94. UNITY_SETUP_INSTANCE_ID(input);
  95. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  96. float4 pos = GetFullScreenTriangleVertexPosition(input.vertexID);
  97. float2 uv = GetFullScreenTriangleTexCoord(input.vertexID);
  98. output.positionCS = pos;
  99. output.texcoord = DYNAMIC_SCALING_APPLY_SCALEBIAS(uv);
  100. SMAANeighborhoodBlendingVS(output.texcoord, output.offset);
  101. return output;
  102. }
  103. float4 FragNeighbor(VaryingsNeighbor input) : SV_Target
  104. {
  105. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  106. return SMAANeighborhoodBlendingPS(input.texcoord, input.offset, _BlitTexture, _BlendTexture);
  107. }
  108. #endif // UNIVERSAL_POSTPROCESSING_SMAA_BRIDGE