Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 7546428

Browse files
authored
Merge pull request #7 from Kink3d/DebugTools
Add TAA stable ghosty variant option
2 parents 641fd38 + 66d58d2 commit 7546428

File tree

5 files changed

+67
-34
lines changed

5 files changed

+67
-34
lines changed

PostProcessing/Editor/Models/AntialiasingModelEditor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class AntialiasingModelEditor : PostProcessingModelEditor
1818
SerializedProperty m_TaaStationaryBlending;
1919
SerializedProperty m_TaaMotionBlending;
2020

21+
SerializedProperty m_TaaStableVariant;
22+
2123
static string[] s_MethodNames =
2224
{
2325
"Fast Approximate Anti-aliasing",
@@ -34,6 +36,8 @@ public override void OnEnable()
3436
m_TaaSharpen = FindSetting((Settings x) => x.taaSettings.sharpen);
3537
m_TaaStationaryBlending = FindSetting((Settings x) => x.taaSettings.stationaryBlending);
3638
m_TaaMotionBlending = FindSetting((Settings x) => x.taaSettings.motionBlending);
39+
40+
m_TaaStableVariant = FindSetting((Settings x) => x.taaSettings.useStableVariant);
3741
}
3842

3943
public override void OnInspectorGUI()
@@ -65,6 +69,13 @@ public override void OnInspectorGUI()
6569
EditorGUILayout.Space();
6670

6771
EditorGUILayout.PropertyField(m_TaaSharpen);
72+
73+
EditorGUILayout.Space();
74+
75+
EditorGUILayout.LabelField("Debug", EditorStyles.boldLabel);
76+
EditorGUI.indentLevel++;
77+
EditorGUILayout.PropertyField(m_TaaStableVariant, EditorGUIHelper.GetContent("Use Stable Variant"));
78+
EditorGUI.indentLevel--;
6879
}
6980
}
7081
}

PostProcessing/Resources/Shaders/TAA.cginc

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#define TAA_USE_GATHER4_FOR_DEPTH_SAMPLE (SHADER_TARGET >= 41)
1414

15-
#define TAA_USE_STABLE_BUT_GHOSTY_VARIANT 0
15+
//#define TAA_USE_STABLE_BUT_GHOSTY_VARIANT 0
1616

1717
#if !defined(TAA_DILATE_MOTION_VECTOR_SAMPLE)
1818
#define TAA_DILATE_MOTION_VECTOR_SAMPLE 1
@@ -54,6 +54,10 @@ float2 _Jitter;
5454
float4 _SharpenParameters;
5555
float4 _FinalBlendParameters;
5656

57+
//Debug
58+
float _StableVariant;
59+
//End Debug
60+
5761
VaryingsSolver VertSolver(AttributesDefault input)
5862
{
5963
VaryingsSolver output;
@@ -128,56 +132,63 @@ float4 ClipToAABB(float4 color, float p, float3 minimum, float3 maximum)
128132
OutputSolver FragSolver(VaryingsSolver input)
129133
{
130134
#if TAA_DILATE_MOTION_VECTOR_SAMPLE
131-
float2 motion = tex2D(_CameraMotionVectorsTexture, GetClosestFragment(input.uv.zw)).xy;
135+
float2 motion = tex2D(_CameraMotionVectorsTexture, GetClosestFragment(input.uv.zw)).xy;
132136
#else
133-
// Don't dilate in ortho !
134-
float2 motion = tex2D(_CameraMotionVectorsTexture, input.uv.zw).xy;
137+
// Don't dilate in ortho !
138+
float2 motion = tex2D(_CameraMotionVectorsTexture, input.uv.zw).xy;
135139
#endif
136140

137-
const float2 k = _MainTex_TexelSize.xy;
138-
float2 uv = input.uv.xy;
141+
const float2 k = _MainTex_TexelSize.xy;
142+
float2 uv = input.uv.xy;
139143

140144
#if UNITY_UV_STARTS_AT_TOP
141-
uv -= _MainTex_TexelSize.y < 0 ? _Jitter * float2(1.0, -1.0) : _Jitter;
145+
uv -= _MainTex_TexelSize.y < 0 ? _Jitter * float2(1.0, -1.0) : _Jitter;
142146
#else
143-
uv -= _Jitter;
147+
uv -= _Jitter;
144148
#endif
145149

146-
float4 color = tex2D(_MainTex, uv);
150+
float4 color = tex2D(_MainTex, uv);
147151

148-
float4 topLeft = tex2D(_MainTex, uv - k * 0.5);
149-
float4 bottomRight = tex2D(_MainTex, uv + k * 0.5);
152+
float4 topLeft = tex2D(_MainTex, uv - k * 0.5);
153+
float4 bottomRight = tex2D(_MainTex, uv + k * 0.5);
150154

151-
float4 corners = 4.0 * (topLeft + bottomRight) - 2.0 * color;
155+
float4 corners = 4.0 * (topLeft + bottomRight) - 2.0 * color;
152156

153-
// Sharpen output
154-
color += (color - (corners * 0.166667)) * 2.718282 * _SharpenParameters.x;
155-
color = max(0.0, color);
157+
// Sharpen output
158+
color += (color - (corners * 0.166667)) * 2.718282 * _SharpenParameters.x;
159+
color = max(0.0, color);
156160

157-
// Tonemap color and history samples
158-
float4 average = FastToneMap((corners + color) * 0.142857);
161+
// Tonemap color and history samples
162+
float4 average = FastToneMap((corners + color) * 0.142857);
159163

160-
topLeft = FastToneMap(topLeft);
161-
bottomRight = FastToneMap(bottomRight);
164+
topLeft = FastToneMap(topLeft);
165+
bottomRight = FastToneMap(bottomRight);
162166

163-
color = FastToneMap(color);
167+
color = FastToneMap(color);
164168

165-
float4 history = tex2D(_HistoryTex, input.uv.zw - motion);
169+
float4 history = tex2D(_HistoryTex, input.uv.zw - motion);
166170

167-
// Only use this variant for arch viz or scenes that don't have any animated objects (camera animation is fine)
168-
#if TAA_USE_STABLE_BUT_GHOSTY_VARIANT
169-
float4 luma = float4(Luminance(topLeft.rgb), Luminance(bottomRight.rgb), Luminance(average.rgb), Luminance(color.rgb));
170-
float nudge = lerp(6.28318530718, 0.5, saturate(2.0 * history.a)) * max(abs(luma.z - luma.w), abs(luma.x - luma.y));
171+
// Only use this variant for arch viz or scenes that don't have any animated objects (camera animation is fine)
171172

172-
float4 minimum = lerp(bottomRight, topLeft, step(luma.x, luma.y)) - nudge;
173-
float4 maximum = lerp(topLeft, bottomRight, step(luma.x, luma.y)) + nudge;
174-
#else
175-
float2 luma = float2(Luminance(average.rgb), Luminance(color.rgb));
176-
float nudge = 4.0 * abs(luma.x - luma.y);
173+
float4 minimum = float4(0, 0, 0, 0);
174+
float4 maximum = float4(0, 0, 0, 0);
177175

178-
float4 minimum = min(bottomRight, topLeft) - nudge;
179-
float4 maximum = max(topLeft, bottomRight) + nudge;
180-
#endif
176+
if (_StableVariant == 1)
177+
{
178+
float4 luma = float4(Luminance(topLeft.rgb), Luminance(bottomRight.rgb), Luminance(average.rgb), Luminance(color.rgb));
179+
float nudge = lerp(6.28318530718, 0.5, saturate(2.0 * history.a)) * max(abs(luma.z - luma.w), abs(luma.x - luma.y));
180+
181+
minimum = lerp(bottomRight, topLeft, step(luma.x, luma.y)) - nudge;
182+
maximum = lerp(topLeft, bottomRight, step(luma.x, luma.y)) + nudge;
183+
}
184+
else
185+
{
186+
float2 luma = float2(Luminance(average.rgb), Luminance(color.rgb));
187+
float nudge = 4.0 * abs(luma.x - luma.y);
188+
189+
minimum = min(bottomRight, topLeft) - nudge;
190+
maximum = max(topLeft, bottomRight) + nudge;
191+
}
181192

182193
history = FastToneMap(history);
183194

PostProcessing/Runtime/Components/TaaComponent.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static class Uniforms
1111
internal static int _FinalBlendParameters = Shader.PropertyToID("_FinalBlendParameters");
1212
internal static int _HistoryTex = Shader.PropertyToID("_HistoryTex");
1313
internal static int _MainTex = Shader.PropertyToID("_MainTex");
14+
internal static int _StableVariant = Shader.PropertyToID("_StableVariant");
1415
}
1516

1617
const string k_ShaderString = "Hidden/Post FX/Temporal Anti-aliasing";
@@ -83,6 +84,11 @@ public void Render(RenderTexture source, RenderTexture destination)
8384

8485
var settings = model.settings.taaSettings;
8586

87+
//Debug
88+
int i = settings.useStableVariant ? 1 : 0;
89+
material.SetFloat(Uniforms._StableVariant, i);
90+
//End debug
91+
8692
if (m_ResetHistory || m_HistoryTexture == null || m_HistoryTexture.width != source.width || m_HistoryTexture.height != source.height)
8793
{
8894
if (m_HistoryTexture)

PostProcessing/Runtime/Models/AntialiasingModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ public struct TaaSettings
189189
[Range(0f, 0.99f)]
190190
public float motionBlending;
191191

192+
[Tooltip("DEBUG")]
193+
public bool useStableVariant;
194+
192195
public static TaaSettings defaultSettings
193196
{
194197
get
@@ -198,7 +201,8 @@ public static TaaSettings defaultSettings
198201
jitterSpread = 0.75f,
199202
sharpen = 0.3f,
200203
stationaryBlending = 0.95f,
201-
motionBlending = 0.85f
204+
motionBlending = 0.85f,
205+
useStableVariant = false
202206
};
203207
}
204208
}

PostProcessing/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TEST

0 commit comments

Comments
 (0)