1 #ifndef UNITY_POSTFX_SMAA_BRIDGE
2 #define UNITY_POSTFX_SMAA_BRIDGE
4 #include "../StdLib.hlsl"
6 TEXTURE2D_SAMPLER2D(_MainTex, sampler_MainTex);
7 TEXTURE2D_SAMPLER2D(_BlendTex, sampler_BlendTex);
8 TEXTURE2D_SAMPLER2D(_AreaTex, sampler_AreaTex);
9 TEXTURE2D_SAMPLER2D(_SearchTex, sampler_SearchTex);
10 float4 _MainTex_TexelSize;
12 #define SMAA_RT_METRICS _MainTex_TexelSize
13 #define SMAA_AREATEX_SELECT(s) s.rg
14 #define SMAA_SEARCHTEX_SELECT(s) s.a
15 #define LinearSampler sampler_MainTex
16 #define PointSampler sampler_MainTex
18 #include "SubpixelMorphologicalAntialiasing.hlsl"
20 // ----------------------------------------------------------------------------------------
25 float4 vertex : SV_POSITION;
26 float2 texcoord : TEXCOORD0;
27 float4 offsets[3] : TEXCOORD1;
30 VaryingsEdge VertEdge(AttributesDefault v)
33 o.vertex = float4(v.vertex.xy, 0.0, 1.0);
34 o.texcoord = TransformTriangleVertexToUV(v.vertex.xy);
36 #if UNITY_UV_STARTS_AT_TOP
37 o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
40 o.offsets[0] = mad(SMAA_RT_METRICS.xyxy, float4(-1.0, 0.0, 0.0, -1.0), o.texcoord.xyxy);
41 o.offsets[1] = mad(SMAA_RT_METRICS.xyxy, float4( 1.0, 0.0, 0.0, 1.0), o.texcoord.xyxy);
42 o.offsets[2] = mad(SMAA_RT_METRICS.xyxy, float4(-2.0, 0.0, 0.0, -2.0), o.texcoord.xyxy);
47 float4 FragEdge(VaryingsEdge i) : SV_Target
49 return float4(SMAAColorEdgeDetectionPS(i.texcoord, i.offsets, _MainTex), 0.0, 0.0);
52 // ----------------------------------------------------------------------------------------
53 // Blend Weights Calculation
57 float4 vertex : SV_POSITION;
58 float2 texcoord : TEXCOORD0;
59 float2 pixcoord : TEXCOORD1;
60 float4 offsets[3] : TEXCOORD2;
63 VaryingsBlend VertBlend(AttributesDefault v)
66 o.vertex = float4(v.vertex.xy, 0.0, 1.0);
67 o.texcoord = TransformTriangleVertexToUV(v.vertex.xy);
69 #if UNITY_UV_STARTS_AT_TOP
70 o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
73 o.pixcoord = o.texcoord * SMAA_RT_METRICS.zw;
75 // We will use these offsets for the searches later on (see @PSEUDO_GATHER4):
76 o.offsets[0] = mad(SMAA_RT_METRICS.xyxy, float4(-0.250, -0.125, 1.250, -0.125), o.texcoord.xyxy);
77 o.offsets[1] = mad(SMAA_RT_METRICS.xyxy, float4(-0.125, -0.250, -0.125, 1.250), o.texcoord.xyxy);
79 // And these for the searches, they indicate the ends of the loops:
80 o.offsets[2] = mad(SMAA_RT_METRICS.xxyy, float4(-2.0, 2.0, -2.0, 2.0) * float(SMAA_MAX_SEARCH_STEPS),
81 float4(o.offsets[0].xz, o.offsets[1].yw));
86 float4 FragBlend(VaryingsBlend i) : SV_Target
88 return SMAABlendingWeightCalculationPS(i.texcoord, i.pixcoord, i.offsets, _MainTex, _AreaTex, _SearchTex, 0);
91 // ----------------------------------------------------------------------------------------
92 // Neighborhood Blending
94 struct VaryingsNeighbor
96 float4 vertex : SV_POSITION;
97 float2 texcoord : TEXCOORD0;
98 float4 offset : TEXCOORD1;
101 VaryingsNeighbor VertNeighbor(AttributesDefault v)
104 o.vertex = float4(v.vertex.xy, 0.0, 1.0);
105 o.texcoord = TransformTriangleVertexToUV(v.vertex.xy);
107 #if UNITY_UV_STARTS_AT_TOP
108 o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
111 o.offset = mad(SMAA_RT_METRICS.xyxy, float4(1.0, 0.0, 0.0, 1.0), o.texcoord.xyxy);
115 float4 FragNeighbor(VaryingsNeighbor i) : SV_Target
117 return SMAANeighborhoodBlendingPS(i.texcoord, i.offset, _MainTex, _BlendTex);