@@ -127,7 +127,8 @@ float lumaYCoCg(const vec3 c) {
127
127
}
128
128
129
129
float luma(const vec3 c) {
130
- return materialConstants_useYCoCg ? lumaYCoCg(c) : lumaRGB(c);
130
+ return (materialConstants_useYCoCg && materialConstants_boxClipping != BOX_CLIPPING_NONE) ?
131
+ lumaYCoCg(c) : lumaRGB(c);
131
132
}
132
133
133
134
vec3 tonemap(const vec3 c) {
@@ -278,10 +279,6 @@ void postProcess(inout PostProcessInputs postProcess) {
278
279
history = textureLod(materialParams_history, uv.zw, 0.0);
279
280
}
280
281
281
- if (materialConstants_useYCoCg) {
282
- history.rgb = RGB_YCoCg(history.rgb);
283
- }
284
-
285
282
highp vec2 size = vec2(textureSize(materialParams_color, 0));
286
283
highp vec2 p = (floor(uv.xy * size) + 0.5) / size;
287
284
vec4 filtered = textureLod(materialParams_color, p, 0.0);
@@ -297,47 +294,46 @@ void postProcess(inout PostProcessInputs postProcess) {
297
294
s[6] = textureLodOffset(materialParams_color, p, 0.0, ivec2(-1, 1)).rgb;
298
295
s[7] = textureLodOffset(materialParams_color, p, 0.0, ivec2( 0, 1)).rgb;
299
296
s[8] = textureLodOffset(materialParams_color, p, 0.0, ivec2( 1, 1)).rgb;
300
- if (materialConstants_useYCoCg) {
301
- for (int i = 0; i < 9; i++) {
302
- s[i] = RGB_YCoCg(s[i]);
303
- }
304
- }
305
297
}
306
298
307
- vec2 subPixelOffset = p - uv.xy; // +/- [0.25, 0.25]
308
- float confidence = materialConstants_upscaling ? 0.0 : 1.0;
299
+ int j = 0;
300
+ float confidence = 1.0;
301
+ if (materialConstants_upscaling) {
302
+ highp vec2 subPixelOffset = (p - uv.xy) * size; // +/- [0.25, 0.25]
303
+
304
+ // we reduce the contribution of a sample based on the distance
305
+ // to the high resolution pixel center
306
+ const float cutoff = 0.5;
307
+ highp float l = length(materialParams.jitter - subPixelOffset) / cutoff;
308
+ confidence = saturate(1.0 - l * l);
309
+
310
+ if (materialConstants_filterInput) {
311
+ int jxp = subPixelOffset.y > 0.0 ? 1 : 2;
312
+ int jxn = subPixelOffset.y > 0.0 ? 0 : 3;
313
+ j = subPixelOffset.x > 0.0 ? jxp : jxn;
314
+ }
315
+ }
309
316
310
317
if (materialConstants_filterInput) {
311
318
// unjitter/filter input
312
- // figure out which set of coeficients to use
313
- filtered = vec4(0, 0, 0, filtered.a);
314
- if (materialConstants_upscaling) {
315
- int jxp = subPixelOffset.y > 0.0 ? 3 : 0;
316
- int jxn = subPixelOffset.y > 0.0 ? 2 : 1;
317
- int j = subPixelOffset.x > 0.0 ? jxp : jxn;
318
- for (int i = 0; i < 9; i++) {
319
- float w = materialParams.filterWeights[i][j];
320
- filtered.rgb += s[i] * w;
321
- confidence = max(confidence, w);
322
- }
323
- } else {
324
- for (int i = 0; i < 9; i++) {
325
- float w = materialParams.filterWeights[i][0];
326
- filtered.rgb += s[i] * w;
327
- }
328
- }
329
- } else {
330
- if (materialConstants_useYCoCg) {
331
- filtered.rgb = RGB_YCoCg(filtered.rgb);
332
- }
333
- if (materialConstants_upscaling) {
334
- confidence = float(materialParams.jitter.x * subPixelOffset.x > 0.0 &&
335
- materialParams.jitter.y * subPixelOffset.y > 0.0);
319
+ filtered = vec4(vec3(0), filtered.a);
320
+ for (int i = 0; i < 9; i++) {
321
+ float w = materialParams.filterWeights[i][j];
322
+ filtered.rgb += s[i] * w;
336
323
}
324
+ filtered.rgb = max(filtered.rgb, vec3(0));
337
325
}
338
326
339
327
// build the history clamping box
340
328
if (materialConstants_boxClipping != BOX_CLIPPING_NONE) {
329
+ if (materialConstants_useYCoCg) {
330
+ history.rgb = RGB_YCoCg(history.rgb);
331
+ filtered.rgb = RGB_YCoCg(filtered.rgb);
332
+ for (int i = 0; i < 9; i++) {
333
+ s[i] = RGB_YCoCg(s[i]);
334
+ }
335
+ }
336
+
341
337
vec3 boxmin;
342
338
vec3 boxmax;
343
339
if (materialConstants_boxType == BOX_TYPE_AABB ||
@@ -346,7 +342,7 @@ void postProcess(inout PostProcessInputs postProcess) {
346
342
boxmax = max(s[4], max(max(s[1], s[3]), max(s[5], s[7])));
347
343
vec3 box9min = min(boxmin, min(min(s[0], s[2]), min(s[6], s[8])));
348
344
vec3 box9max = max(boxmax, max(max(s[0], s[2]), max(s[6], s[8])));
349
- // round the corners of the 3x3 box
345
+ // round the corners of the 3x3 box, giving less importance to the corner samples
350
346
boxmin = (boxmin + box9min) * 0.5;
351
347
boxmax = (boxmax + box9max) * 0.5;
352
348
}
@@ -388,9 +384,11 @@ void postProcess(inout PostProcessInputs postProcess) {
388
384
}
389
385
390
386
// go back to RGB space before tonemapping
391
- if (materialConstants_useYCoCg) {
392
- filtered.rgb = YCoCg_RGB(filtered.rgb);
393
- history.rgb = YCoCg_RGB(history.rgb);
387
+ if (materialConstants_boxClipping != BOX_CLIPPING_NONE) {
388
+ if (materialConstants_useYCoCg) {
389
+ filtered.rgb = YCoCg_RGB(filtered.rgb);
390
+ history.rgb = YCoCg_RGB(history.rgb);
391
+ }
394
392
}
395
393
396
394
// tonemap before mixing
0 commit comments