@@ -3,163 +3,99 @@ Shader "Hidden/PostProcessing/SubpixelMorphologicalAntialiasing"
3
3
HLSLINCLUDE
4
4
5
5
#pragma exclude_renderers d3d11_9x
6
- #include "../StdLib.hlsl"
7
6
8
- // High/Very-high settings
9
- #define SMAA_THRESHOLD 0.08
10
- #define SMAA_MAX_SEARCH_STEPS 16
11
- #define SMAA_MAX_SEARCH_STEPS_DIAG 8
12
- #define SMAA_CORNER_ROUNDING 25
13
-
14
- TEXTURE2D_SAMPLER2D (_MainTex, sampler_MainTex);
15
- TEXTURE2D_SAMPLER2D (_BlendTex, sampler_BlendTex);
16
- TEXTURE2D_SAMPLER2D (_AreaTex, sampler_AreaTex);
17
- TEXTURE2D_SAMPLER2D (_SearchTex, sampler_SearchTex);
18
- float4 _MainTex_TexelSize;
19
-
20
- #define SMAA_RT_METRICS _MainTex_TexelSize
21
- #define SMAA_AREATEX_SELECT (s) s.rg
22
- #define SMAA_SEARCHTEX_SELECT (s) s.a
23
- #define LinearSampler sampler_MainTex
24
- #define PointSampler sampler_MainTex
25
-
26
- #include "SubpixelMorphologicalAntialiasing.hlsl"
27
-
28
- // ----------------------------------------------------------------------------------------
29
- // Edge Detection
7
+ ENDHLSL
30
8
31
- struct VaryingsEdge
32
- {
33
- float4 vertex : SV_POSITION ;
34
- float2 texcoord : TEXCOORD0 ;
35
- float4 offsets[3 ] : TEXCOORD1 ;
36
- };
9
+ SubShader
10
+ {
11
+ Cull Off ZWrite Off ZTest Always
37
12
38
- VaryingsEdge VertEdge (AttributesDefault v)
13
+ // 0 - Edge detection (Low)
14
+ Pass
39
15
{
40
- VaryingsEdge o;
41
- o.vertex = float4 (v.vertex.xy, 0.0 , 1.0 );
42
- o.texcoord = TransformTriangleVertexToUV (v.vertex.xy);
43
-
44
- #if UNITY_UV_STARTS_AT_TOP
45
- o.texcoord = o.texcoord * float2 (1.0 , -1.0 ) + float2 (0.0 , 1.0 );
46
- #endif
47
-
48
- o.offsets[0 ] = mad (SMAA_RT_METRICS.xyxy, float4 (-1.0 , 0.0 , 0.0 , -1.0 ), o.texcoord.xyxy);
49
- o.offsets[1 ] = mad (SMAA_RT_METRICS.xyxy, float4 ( 1.0 , 0.0 , 0.0 , 1.0 ), o.texcoord.xyxy);
50
- o.offsets[2 ] = mad (SMAA_RT_METRICS.xyxy, float4 (-2.0 , 0.0 , 0.0 , -2.0 ), o.texcoord.xyxy);
16
+ HLSLPROGRAM
51
17
52
- return o;
53
- }
18
+ #pragma vertex VertEdge
19
+ #pragma fragment FragEdge
20
+ #define SMAA_PRESET_LOW
21
+ #include "SubpixelMorphologicalAntialiasingBridge.hlsl"
54
22
55
- float4 FragEdge (VaryingsEdge i) : SV_Target
56
- {
57
- return float4 (SMAAColorEdgeDetectionPS (i.texcoord, i.offsets, _MainTex), 0.0 , 0.0 );
23
+ ENDHLSL
58
24
}
59
25
60
- // ----------------------------------------------------------------------------------------
61
- // Blend Weights Calculation
62
-
63
- struct VaryingsBlend
64
- {
65
- float4 vertex : SV_POSITION ;
66
- float2 texcoord : TEXCOORD0 ;
67
- float2 pixcoord : TEXCOORD1 ;
68
- float4 offsets[3 ] : TEXCOORD2 ;
69
- };
70
-
71
- VaryingsBlend VertBlend (AttributesDefault v)
26
+ // 1 - Edge detection (Medium)
27
+ Pass
72
28
{
73
- VaryingsBlend o;
74
- o.vertex = float4 (v.vertex.xy, 0.0 , 1.0 );
75
- o.texcoord = TransformTriangleVertexToUV (v.vertex.xy);
76
-
77
- #if UNITY_UV_STARTS_AT_TOP
78
- o.texcoord = o.texcoord * float2 (1.0 , -1.0 ) + float2 (0.0 , 1.0 );
79
- #endif
80
-
81
- o.pixcoord = o.texcoord * SMAA_RT_METRICS.zw;
82
-
83
- // We will use these offsets for the searches later on (see @PSEUDO_GATHER4):
84
- o.offsets[0 ] = mad (SMAA_RT_METRICS.xyxy, float4 (-0.250 , -0.125 , 1.250 , -0.125 ), o.texcoord.xyxy);
85
- o.offsets[1 ] = mad (SMAA_RT_METRICS.xyxy, float4 (-0.125 , -0.250 , -0.125 , 1.250 ), o.texcoord.xyxy);
86
-
87
- // And these for the searches, they indicate the ends of the loops:
88
- o.offsets[2 ] = mad (SMAA_RT_METRICS.xxyy, float4 (-2.0 , 2.0 , -2.0 , 2.0 ) * float (SMAA_MAX_SEARCH_STEPS),
89
- float4 (o.offsets[0 ].xz, o.offsets[1 ].yw));
29
+ HLSLPROGRAM
90
30
91
- return o;
92
- }
31
+ #pragma vertex VertEdge
32
+ #pragma fragment FragEdge
33
+ #define SMAA_PRESET_MEDIUM
34
+ #include "SubpixelMorphologicalAntialiasingBridge.hlsl"
93
35
94
- float4 FragBlend (VaryingsBlend i) : SV_Target
95
- {
96
- return SMAABlendingWeightCalculationPS (i.texcoord, i.pixcoord, i.offsets, _MainTex, _AreaTex, _SearchTex, 0 );
36
+ ENDHLSL
97
37
}
98
38
99
- // ----------------------------------------------------------------------------------------
100
- // Neighborhood Blending
101
-
102
- struct VaryingsNeighbor
103
- {
104
- float4 vertex : SV_POSITION ;
105
- float2 texcoord : TEXCOORD0 ;
106
- float4 offset : TEXCOORD1 ;
107
- };
108
-
109
- VaryingsNeighbor VertNeighbor (AttributesDefault v)
39
+ // 2 - Edge detection (High)
40
+ Pass
110
41
{
111
- VaryingsNeighbor o;
112
- o.vertex = float4 (v.vertex.xy, 0.0 , 1.0 );
113
- o.texcoord = TransformTriangleVertexToUV (v.vertex.xy);
42
+ HLSLPROGRAM
114
43
115
- #if UNITY_UV_STARTS_AT_TOP
116
- o.texcoord = o.texcoord * float2 (1.0 , -1.0 ) + float2 (0.0 , 1.0 );
117
- #endif
44
+ #pragma vertex VertEdge
45
+ #pragma fragment FragEdge
46
+ #define SMAA_PRESET_HIGH
47
+ #include "SubpixelMorphologicalAntialiasingBridge.hlsl"
118
48
119
- o.offset = mad (SMAA_RT_METRICS.xyxy, float4 (1.0 , 0.0 , 0.0 , 1.0 ), o.texcoord.xyxy);
120
- return o;
49
+ ENDHLSL
121
50
}
122
51
123
- float4 FragNeighbor (VaryingsNeighbor i) : SV_Target
52
+ // 3 - Blend Weights Calculation (Low)
53
+ Pass
124
54
{
125
- return SMAANeighborhoodBlendingPS (i.texcoord, i.offset, _MainTex, _BlendTex);
126
- }
55
+ HLSLPROGRAM
127
56
128
- ENDHLSL
57
+ #pragma vertex VertBlend
58
+ #pragma fragment FragBlend
59
+ #define SMAA_PRESET_LOW
60
+ #include "SubpixelMorphologicalAntialiasingBridge.hlsl"
129
61
130
- SubShader
131
- {
132
- Cull Off ZWrite Off ZTest Always
62
+ ENDHLSL
63
+ }
133
64
134
- // 0 - Edge detection
65
+ // 4 - Blend Weights Calculation (Medium)
135
66
Pass
136
67
{
137
68
HLSLPROGRAM
138
69
139
- #pragma vertex VertEdge
140
- #pragma fragment FragEdge
70
+ #pragma vertex VertBlend
71
+ #pragma fragment FragBlend
72
+ #define SMAA_PRESET_MEDIUM
73
+ #include "SubpixelMorphologicalAntialiasingBridge.hlsl"
141
74
142
75
ENDHLSL
143
76
}
144
77
145
- // 1 - Blend Weights Calculation
78
+ // 5 - Blend Weights Calculation (High)
146
79
Pass
147
80
{
148
81
HLSLPROGRAM
149
82
150
83
#pragma vertex VertBlend
151
84
#pragma fragment FragBlend
85
+ #define SMAA_PRESET_HIGH
86
+ #include "SubpixelMorphologicalAntialiasingBridge.hlsl"
152
87
153
88
ENDHLSL
154
89
}
155
90
156
- // 2 - Neighborhood Blending
91
+ // 6 - Neighborhood Blending
157
92
Pass
158
93
{
159
94
HLSLPROGRAM
160
95
161
96
#pragma vertex VertNeighbor
162
97
#pragma fragment FragNeighbor
98
+ #include "SubpixelMorphologicalAntialiasingBridge.hlsl"
163
99
164
100
ENDHLSL
165
101
}
0 commit comments