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

Commit a0304ce

Browse files
committed
Simplified the code for mobile chromatic aberration and made it slightly faster
1 parent 8b1a6ef commit a0304ce

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

PostProcessing/Shaders/Builtins/Uber.shader

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,18 @@ Shader "Hidden/PostProcessing/Uber"
104104
{
105105
float2 coords = 2.0 * uv - 1.0;
106106
float2 end = uv - coords * dot(coords, coords) * _ChromaticAberration_Amount;
107+
float2 delta = (end - uv) / 3;
107108

108-
float2 diff = end - uv;
109-
float2 delta = diff / 3;
110-
float2 pos = uv;
111-
half4 sum = (0.0).xxxx, filterSum = (0.0).xxxx;
112-
113-
UNITY_UNROLL
114-
for (int i = 0; i < 3; i++)
115-
{
116-
half t = (i + 0.5) / 3;
117-
half4 s = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(pos));
118-
half4 filter = half4(SAMPLE_TEXTURE2D(_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2(t, 0.0)).rgb, 1.0);
109+
half4 filterA = half4(SAMPLE_TEXTURE2D_LOD(_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2(0.5 / 3, 0.0), 0).rgb, 1.0);
110+
half4 filterB = half4(SAMPLE_TEXTURE2D_LOD(_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2(1.5 / 3, 0.0), 0).rgb, 1.0);
111+
half4 filterC = half4(SAMPLE_TEXTURE2D_LOD(_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2(2.5 / 3, 0.0), 0).rgb, 1.0);
119112

120-
sum += s * filter;
121-
filterSum += filter;
122-
pos += delta;
123-
}
113+
half4 texelA = SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(uv), 0);
114+
half4 texelB = SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(delta + uv), 0);
115+
half4 texelC = SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(delta * 2.0 + uv), 0);
124116

117+
half4 sum = texelA * filterA + texelB * filterB + texelC * filterC;
118+
half4 filterSum = filterA + filterB + filterC;
125119
color = sum / filterSum;
126120
}
127121
#else

0 commit comments

Comments
 (0)