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

Commit aee3478

Browse files
committed
Started working on proper alpha propagation
Unfinished, don't use yet
1 parent e93398d commit aee3478

7 files changed

Lines changed: 89 additions & 77 deletions

File tree

PostProcessing/Runtime/Effects/DepthOfField.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public sealed class DepthOfField : PostProcessEffectSettings
3131
}
3232

3333
// TODO: Look into minimum blur amount in the distance, right now it's lerped until a point
34+
// TODO: Doesn't play nice with alpha propagation, see if it can be fixed without killing performances
3435
public sealed class DepthOfFieldRenderer : PostProcessEffectRenderer<DepthOfField>
3536
{
3637
enum Pass

PostProcessing/Shaders/Builtins/Bloom.shader

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ Shader "Hidden/PostProcessing/Bloom"
1717
// ----------------------------------------------------------------------------------------
1818
// Prefilter
1919

20-
half4 Prefilter(half3 color, float2 uv)
20+
half4 Prefilter(half4 color, float2 uv)
2121
{
2222
half autoExposure = SAMPLE_TEXTURE2D(_AutoExposureTex, sampler_AutoExposureTex, uv).r;
2323
color *= autoExposure;
2424
color = QuadraticThreshold(color, _Threshold.x, _Threshold.yzw);
25-
return half4(color, 1.0);
25+
return color;
2626
}
2727

2828
half4 FragPrefilter13(VaryingsDefault i) : SV_Target
2929
{
30-
half3 color = DownsampleBox13Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy);
30+
half4 color = DownsampleBox13Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy);
3131
return Prefilter(SafeHDR(color), i.texcoord);
3232
}
3333

3434
half4 FragPrefilter4(VaryingsDefault i) : SV_Target
3535
{
36-
half3 color = DownsampleBox4Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy);
36+
half4 color = DownsampleBox4Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy);
3737
return Prefilter(SafeHDR(color), i.texcoord);
3838
}
3939

@@ -42,34 +42,34 @@ Shader "Hidden/PostProcessing/Bloom"
4242

4343
half4 FragDownsample13(VaryingsDefault i) : SV_Target
4444
{
45-
half3 color = DownsampleBox13Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy);
46-
return half4(color, 1.0);
45+
half4 color = DownsampleBox13Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy);
46+
return color;
4747
}
4848

4949
half4 FragDownsample4(VaryingsDefault i) : SV_Target
5050
{
51-
half3 color = DownsampleBox4Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy);
52-
return half4(color, 1.0);
51+
half4 color = DownsampleBox4Tap(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy);
52+
return color;
5353
}
5454

5555
// ----------------------------------------------------------------------------------------
5656
// Upsample & combine
5757

58-
half4 Combine(half3 bloom, float2 uv)
58+
half4 Combine(half4 bloom, float2 uv)
5959
{
60-
half3 color = SAMPLE_TEXTURE2D(_BloomTex, sampler_BloomTex, uv).rgb;
61-
return half4(bloom + color, 1.0);
60+
half4 color = SAMPLE_TEXTURE2D(_BloomTex, sampler_BloomTex, uv);
61+
return bloom + color;
6262
}
6363

6464
half4 FragUpsampleTent(VaryingsDefault i) : SV_Target
6565
{
66-
half3 bloom = UpsampleTent(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy, _SampleScale);
66+
half4 bloom = UpsampleTent(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy, _SampleScale);
6767
return Combine(bloom, UnityStereoTransformScreenSpaceTex(i.texcoord));
6868
}
6969

7070
half4 FragUpsampleBox(VaryingsDefault i) : SV_Target
7171
{
72-
half3 bloom = UpsampleBox(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy, _SampleScale);
72+
half4 bloom = UpsampleBox(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), UnityStereoTransformScreenSpaceTex(i.texcoord), _MainTex_TexelSize.xy, _SampleScale);
7373
return Combine(bloom, UnityStereoTransformScreenSpaceTex(i.texcoord));
7474
}
7575

PostProcessing/Shaders/Builtins/DepthOfField.hlsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,22 @@ half4 FragCombine(VaryingsDefault i) : SV_Target
226226
// Convert CoC to far field alpha value.
227227
float ffa = smoothstep(_MainTex_TexelSize.y * 2.0, _MainTex_TexelSize.y * 4.0, coc);
228228

229-
half3 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord).rgb;
229+
half4 color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord);
230230

231231
#if defined(UNITY_COLORSPACE_GAMMA)
232232
color = SRGBToLinear(color);
233233
#endif
234234

235+
half alpha = Max3(dof.r, dof.g, dof.b);
236+
235237
// lerp(lerp(color, dof, ffa), dof, dof.a)
236-
color = lerp(color, dof.rgb, ffa + dof.a - ffa * dof.a);
238+
color = lerp(color, float4(dof.rgb, alpha), ffa + dof.a - ffa * dof.a);
237239

238240
#if defined(UNITY_COLORSPACE_GAMMA)
239241
color = LinearToSRGB(color);
240242
#endif
241243

242-
return half4(color, 1.0);
244+
return color;
243245
}
244246

245247
#endif // UNITY_POSTFX_DEPTH_OF_FIELD

PostProcessing/Shaders/Builtins/FinalPass.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Shader "Hidden/PostProcessing/FinalPass"
7373
#endif
7474

7575
color.rgb = Dither(color.rgb, i.texcoord);
76-
return float4(color.rgb, 1.0);
76+
return color;
7777
}
7878

7979
ENDHLSL

PostProcessing/Shaders/Builtins/Uber.shader

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Shader "Hidden/PostProcessing/Uber"
6969
float2 uv = i.texcoord;
7070
float2 uvSPR = UnityStereoTransformScreenSpaceTex(i.texcoord);
7171
half autoExposure = SAMPLE_TEXTURE2D(_AutoExposureTex, sampler_AutoExposureTex, uv).r;
72-
half3 color = (0.0).xxx;
72+
half4 color = (0.0).xxxx;
7373

7474
// Inspired by the method described in "Rendering Inside" [Playdead 2016]
7575
// https://twitter.com/pixelmager/status/717019757766123520
@@ -82,13 +82,13 @@ Shader "Hidden/PostProcessing/Uber"
8282
int samples = clamp(int(length(_MainTex_TexelSize.zw * diff / 2.0)), 3, MAX_CHROMATIC_SAMPLES);
8383
float2 delta = diff / samples;
8484
float2 pos = uv;
85-
half3 sum = (0.0).xxx, filterSum = (0.0).xxx;
85+
half4 sum = (0.0).xxxx, filterSum = (0.0).xxxx;
8686

8787
for (int i = 0; i < samples; i++)
8888
{
8989
half t = (i + 0.5) / samples;
90-
half3 s = SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(pos), 0).rgb;
91-
half3 filter = SAMPLE_TEXTURE2D_LOD(_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2(t, 0.0), 0).rgb;
90+
half4 s = SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(pos), 0);
91+
half4 filter = half4(SAMPLE_TEXTURE2D_LOD(_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2(t, 0.0), 0).rgb, 1.0);
9292

9393
sum += s * filter;
9494
filterSum += filter;
@@ -105,14 +105,14 @@ Shader "Hidden/PostProcessing/Uber"
105105
float2 diff = end - uv;
106106
float2 delta = diff / 3;
107107
float2 pos = uv;
108-
half3 sum = (0.0).xxx, filterSum = (0.0).xxx;
108+
half4 sum = (0.0).xxxx, filterSum = (0.0).xxxx;
109109

110110
UNITY_UNROLL
111111
for (int i = 0; i < 3; i++)
112112
{
113113
half t = (i + 0.5) / 3;
114-
half3 s = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(pos)).rgb;
115-
half3 filter = SAMPLE_TEXTURE2D(_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2(t, 0.0)).rgb;
114+
half4 s = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, UnityStereoTransformScreenSpaceTex(pos));
115+
half4 filter = half4(SAMPLE_TEXTURE2D(_ChromaticAberration_SpectralLut, sampler_ChromaticAberration_SpectralLut, float2(t, 0.0)).rgb, 1.0);
116116

117117
sum += s * filter;
118118
filterSum += filter;
@@ -123,7 +123,7 @@ Shader "Hidden/PostProcessing/Uber"
123123
}
124124
#else
125125
{
126-
color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uvSPR).rgb;
126+
color = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uvSPR);
127127
}
128128
#endif
129129

@@ -134,17 +134,17 @@ Shader "Hidden/PostProcessing/Uber"
134134
}
135135
#endif
136136

137-
color *= autoExposure;
137+
color.rgb *= autoExposure;
138138

139139
#if BLOOM
140140
{
141-
half3 bloom = UpsampleTent(TEXTURE2D_PARAM(_BloomTex, sampler_BloomTex), uvSPR, _BloomTex_TexelSize.xy, _Bloom_Settings.x).rgb;
142-
half3 dirt = SAMPLE_TEXTURE2D(_Bloom_DirtTex, sampler_Bloom_DirtTex, i.texcoord).rgb;
141+
half4 bloom = UpsampleTent(TEXTURE2D_PARAM(_BloomTex, sampler_BloomTex), uvSPR, _BloomTex_TexelSize.xy, _Bloom_Settings.x);
142+
half4 dirt = half4(SAMPLE_TEXTURE2D(_Bloom_DirtTex, sampler_Bloom_DirtTex, i.texcoord).rgb, 0.0);
143143

144144
// Additive bloom (artist friendly)
145145
bloom *= _Bloom_Settings.y;
146146
dirt *= _Bloom_Settings.z;
147-
color += bloom * _Bloom_Color;
147+
color += bloom * half4(_Bloom_Color, 1.0);
148148
color += dirt * bloom;
149149
}
150150
#endif
@@ -157,39 +157,48 @@ Shader "Hidden/PostProcessing/Uber"
157157
d.x *= lerp(1.0, _ScreenParams.x / _ScreenParams.y, _Vignette_Settings.w);
158158
d = pow(saturate(d), _Vignette_Settings.z); // Roundness
159159
half vfactor = pow(saturate(1.0 - dot(d, d)), _Vignette_Settings.y);
160-
color *= lerp(_Vignette_Color, (1.0).xxx, vfactor);
160+
color.rgb *= lerp(_Vignette_Color, (1.0).xxx, vfactor);
161+
color.a = lerp(1.0, color.a, vfactor);
161162
}
162163
else
163164
{
164165
half vfactor = SAMPLE_TEXTURE2D(_Vignette_Mask, sampler_Vignette_Mask, uv).a;
166+
167+
#if !UNITY_COLORSPACE_GAMMA
168+
{
169+
vfactor = SRGBToLinear(vfactor);
170+
}
171+
#endif
172+
165173
half3 new_color = color * lerp(_Vignette_Color, (1.0).xxx, vfactor);
166-
color = lerp(color, new_color, _Vignette_Opacity);
174+
color.rgb = lerp(color, new_color, _Vignette_Opacity);
175+
color.a = lerp(1.0, color.a, vfactor);
167176
}
168177
}
169178
#endif
170179

171180
#if GRAIN
172181
{
173-
float3 grain = SAMPLE_TEXTURE2D(_GrainTex, sampler_GrainTex, uvSPR * _Grain_Params2.xy + _Grain_Params2.zw).rgb;
182+
half3 grain = SAMPLE_TEXTURE2D(_GrainTex, sampler_GrainTex, uvSPR * _Grain_Params2.xy + _Grain_Params2.zw).rgb;
174183

175184
// Noisiness response curve based on scene luminance
176185
float lum = 1.0 - sqrt(Luminance(saturate(color)));
177186
lum = lerp(1.0, lum, _Grain_Params1.x);
178187

179-
color += color * grain * _Grain_Params1.y * lum;
188+
color.rgb += color.rgb * grain * _Grain_Params1.y * lum;
180189
}
181190
#endif
182191

183192
#if COLOR_GRADING_HDR
184193
{
185194
color *= _PostExposure; // Exposure is in ev units (or 'stops')
186-
float3 colorLutSpace = saturate(LUT_SPACE_ENCODE(color));
187-
color = ApplyLut3D(TEXTURE3D_PARAM(_Lut3D, sampler_Lut3D), colorLutSpace, _Lut3D_Params);
195+
float3 colorLutSpace = saturate(LUT_SPACE_ENCODE(color.rgb));
196+
color.rgb = ApplyLut3D(TEXTURE3D_PARAM(_Lut3D, sampler_Lut3D), colorLutSpace, _Lut3D_Params);
188197
}
189198
#elif COLOR_GRADING_LDR
190199
{
191200
color = saturate(color);
192-
color = ApplyLut2D(TEXTURE2D_PARAM(_Lut2D, sampler_Lut2D), color, _Lut2D_Params);
201+
color.rgb = ApplyLut2D(TEXTURE2D_PARAM(_Lut2D, sampler_Lut2D), color.rgb, _Lut2D_Params);
193202
}
194203
#endif
195204

@@ -198,14 +207,14 @@ Shader "Hidden/PostProcessing/Uber"
198207
#if FINALPASS
199208
{
200209
color.rgb = Dither(color.rgb, i.texcoord);
201-
output = half4(color, 1.0);
210+
output = color;
202211
}
203212
#else
204213
{
205214
// Put saturated luma in alpha for FXAA - higher quality than "green as luma" and
206215
// necessary as RGB values will potentially still be HDR for the FXAA pass
207216
half luma = Luminance(saturate(color));
208-
output = half4(color, luma);
217+
output = half4(color.rgb, luma);
209218
}
210219
#endif
211220

PostProcessing/Shaders/Colors.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ half Luminance(half4 linearRgba)
192192
// Quadratic color thresholding
193193
// curve = (threshold - knee, knee * 2, 0.25 / knee)
194194
//
195-
half3 QuadraticThreshold(half3 color, half threshold, half3 curve)
195+
half4 QuadraticThreshold(half4 color, half threshold, half3 curve)
196196
{
197197
// Pixel brightness
198198
half br = Max3(color.r, color.g, color.b);

PostProcessing/Shaders/Sampling.hlsl

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@
1212
// . . I . J . .
1313
// . K . L . M .
1414
// . . . . . . .
15-
half3 DownsampleBox13Tap(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texelSize)
15+
half4 DownsampleBox13Tap(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texelSize)
1616
{
17-
half3 A = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-1.0, -1.0)).rgb;
18-
half3 B = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 0.0, -1.0)).rgb;
19-
half3 C = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 1.0, -1.0)).rgb;
20-
half3 D = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-0.5, -0.5)).rgb;
21-
half3 E = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 0.5, -0.5)).rgb;
22-
half3 F = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-1.0, 0.0)).rgb;
23-
half3 G = SAMPLE_TEXTURE2D(tex, samplerTex, uv ).rgb;
24-
half3 H = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 1.0, 0.0)).rgb;
25-
half3 I = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-0.5, 0.5)).rgb;
26-
half3 J = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 0.5, 0.5)).rgb;
27-
half3 K = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-1.0, 1.0)).rgb;
28-
half3 L = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 0.0, 1.0)).rgb;
29-
half3 M = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 1.0, 1.0)).rgb;
17+
half4 A = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-1.0, -1.0));
18+
half4 B = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 0.0, -1.0));
19+
half4 C = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 1.0, -1.0));
20+
half4 D = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-0.5, -0.5));
21+
half4 E = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 0.5, -0.5));
22+
half4 F = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-1.0, 0.0));
23+
half4 G = SAMPLE_TEXTURE2D(tex, samplerTex, uv );
24+
half4 H = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 1.0, 0.0));
25+
half4 I = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-0.5, 0.5));
26+
half4 J = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 0.5, 0.5));
27+
half4 K = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2(-1.0, 1.0));
28+
half4 L = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 0.0, 1.0));
29+
half4 M = SAMPLE_TEXTURE2D(tex, samplerTex, uv + texelSize * float2( 1.0, 1.0));
3030

3131
half2 div = (1.0 / 4.0) * half2(0.5, 0.125);
3232

33-
half3 o = (D + E + I + J) * div.x;
33+
half4 o = (D + E + I + J) * div.x;
3434
o += (A + B + G + F) * div.y;
3535
o += (B + C + H + G) * div.y;
3636
o += (F + G + L + K) * div.y;
@@ -40,50 +40,50 @@ half3 DownsampleBox13Tap(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texe
4040
}
4141

4242
// Standard box filtering
43-
half3 DownsampleBox4Tap(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texelSize)
43+
half4 DownsampleBox4Tap(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texelSize)
4444
{
4545
float4 d = texelSize.xyxy * float4(-1.0, -1.0, 1.0, 1.0);
4646

47-
half3 s;
48-
s = (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xy)).rgb;
49-
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zy)).rgb;
50-
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xw)).rgb;
51-
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zw)).rgb;
47+
half4 s;
48+
s = (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xy));
49+
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zy));
50+
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xw));
51+
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zw));
5252

5353
return s * (1.0 / 4.0);
5454
}
5555

5656
// 9-tap bilinear upsampler (tent filter)
57-
half3 UpsampleTent(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texelSize, float sampleScale)
57+
half4 UpsampleTent(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texelSize, float sampleScale)
5858
{
5959
float4 d = texelSize.xyxy * float4(1.0, 1.0, -1.0, 0.0) * sampleScale;
6060

61-
half3 s;
62-
s = SAMPLE_TEXTURE2D(tex, samplerTex, uv - d.xy).rgb;
63-
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv - d.wy).rgb * 2.0;
64-
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv - d.zy).rgb;
61+
half4 s;
62+
s = SAMPLE_TEXTURE2D(tex, samplerTex, uv - d.xy);
63+
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv - d.wy) * 2.0;
64+
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv - d.zy);
6565

66-
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zw).rgb * 2.0;
67-
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv ).rgb * 4.0;
68-
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xw).rgb * 2.0;
66+
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zw) * 2.0;
67+
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv ) * 4.0;
68+
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xw) * 2.0;
6969

70-
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zy).rgb;
71-
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.wy).rgb * 2.0;
72-
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xy).rgb;
70+
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zy);
71+
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.wy) * 2.0;
72+
s += SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xy);
7373

7474
return s * (1.0 / 16.0);
7575
}
7676

7777
// Standard box filtering
78-
half3 UpsampleBox(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texelSize, float sampleScale)
78+
half4 UpsampleBox(TEXTURE2D_ARGS(tex, samplerTex), float2 uv, float2 texelSize, float sampleScale)
7979
{
8080
float4 d = texelSize.xyxy * float4(-1.0, -1.0, 1.0, 1.0) * (sampleScale * 0.5);
8181

82-
half3 s;
83-
s = (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xy)).rgb;
84-
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zy)).rgb;
85-
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xw)).rgb;
86-
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zw)).rgb;
82+
half4 s;
83+
s = (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xy));
84+
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zy));
85+
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.xw));
86+
s += (SAMPLE_TEXTURE2D(tex, samplerTex, uv + d.zw));
8787

8888
return s * (1.0 / 4.0);
8989
}

0 commit comments

Comments
 (0)