Skip to content

Commit

Permalink
Slightly improve saddle behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
Swordfish90 committed Jul 9, 2024
1 parent 65de4da commit 0cac511
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
Binary file added public/bof2-snes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/pages/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const images = [
'hqx-patterns.bmp',
'mario-nes.png',
'pokemon-yellow-sgb.png',
'bof2-snes.png',
'advance-wars-gba.png',
'ffvii-psx.png',
'medievil-resurrection-psp.png',
Expand Down
19 changes: 11 additions & 8 deletions src/shaders/cut2/cut2_pass_0.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ lowp float quickPackFloats2(lowp vec2 values) {
return dot(floor(values * vec2(12.0) + vec2(0.5)), vec2(0.0625, 0.00390625));
}

lowp int findPattern(lowp vec4 values, lowp vec2 diagonals) {
lowp int findPattern(lowp vec4 values, lowp vec2 saddleAdjustments) {
lowp vec4 edgesDifferences = abs(values.xxyz - values.yzww);

lowp vec4 patternContrasts = vec4(
Expand All @@ -72,13 +72,16 @@ lowp int findPattern(lowp vec4 values, lowp vec2 diagonals) {
max(edgesDifferences.x + edgesDifferences.y, edgesDifferences.z + edgesDifferences.w)
);

patternContrasts.zw += 0.125 * clamp(diagonals.yx - diagonals.xy, -2.0, +0.125);
patternContrasts.zw += clamp((saddleAdjustments.xy - saddleAdjustments.yx) * 0.125, vec2(-0.20), vec2(0.05));

lowp float maxContrast = max(
max(patternContrasts.x, patternContrasts.y),
max(patternContrasts.z, patternContrasts.w)
);

lowp float maxContrast = max(max(patternContrasts.x, patternContrasts.y), max(patternContrasts.z, patternContrasts.w));
bvec4 isMax = greaterThanEqual(patternContrasts, vec4(maxContrast));
bool isSaddle = all(isMax);

if (maxContrast < EDGE_MIN_VALUE || isSaddle) {
if (maxContrast < EDGE_MIN_VALUE) {
return 0;
} else if (isMax.x) {
return 1;
Expand Down Expand Up @@ -168,12 +171,12 @@ void main() {
softEdgeWeight(l01, l05, l09, l13)
);

edges = clamp(edges + 2.0 * softEdges, min(edges, softEdges), max(edges, softEdges));
edges = clamp(edges + softEdges, min(edges, softEdges), max(edges, softEdges));
#endif

lowp vec2 diagonals = vec2(
(abs(l06 - l01) + abs(l11 - l06) + abs(l14 - l09) + abs(l09 - l04)),
(abs(l08 - l05) + abs(l05 - l02) + abs(l13 - l10) + abs(l10 - l07))
abs(l08 - l05) + abs(l13 - l10) + abs(l10 - l07) + abs(l05 - l02),
abs(l06 - l01) + abs(l09 - l04) + abs(l11 - l06) + abs(l14 - l09)
);

pattern = findPattern(vec4(l05, l06, l09, l10), diagonals);
Expand Down
17 changes: 10 additions & 7 deletions src/shaders/cut3/cut3_pass_0.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ lowp float quickPackFloats2(lowp vec2 values) {
return dot(floor(values * vec2(12.0) + vec2(0.5)), vec2(0.0625, 0.00390625));
}

lowp int findPattern(lowp vec4 values, lowp vec2 diagonals) {
lowp int findPattern(lowp vec4 values, lowp vec2 saddleAdjustments) {
lowp vec4 edgesDifferences = abs(values.xxyz - values.yzww);

lowp vec4 patternContrasts = vec4(
Expand All @@ -72,13 +72,16 @@ lowp int findPattern(lowp vec4 values, lowp vec2 diagonals) {
max(edgesDifferences.x + edgesDifferences.y, edgesDifferences.z + edgesDifferences.w)
);

patternContrasts.zw += 0.125 * clamp(diagonals.yx - diagonals.xy, -2.0, +0.125);
patternContrasts.zw += clamp((saddleAdjustments.xy - saddleAdjustments.yx) * 0.125, vec2(-0.20), vec2(0.05));

lowp float maxContrast = max(
max(patternContrasts.x, patternContrasts.y),
max(patternContrasts.z, patternContrasts.w)
);

lowp float maxContrast = max(max(patternContrasts.x, patternContrasts.y), max(patternContrasts.z, patternContrasts.w));
bvec4 isMax = greaterThanEqual(patternContrasts, vec4(maxContrast));
bool isSaddle = all(isMax);

if (maxContrast < EDGE_MIN_VALUE || isSaddle) {
if (maxContrast < EDGE_MIN_VALUE) {
return 0;
} else if (isMax.x) {
return 1;
Expand Down Expand Up @@ -128,8 +131,8 @@ void main() {
lowp float l14 = luma(t14);

lowp vec2 diagonals = vec2(
(abs(l06 - l01) + abs(l11 - l06) + abs(l14 - l09) + abs(l09 - l04)),
(abs(l08 - l05) + abs(l05 - l02) + abs(l13 - l10) + abs(l10 - l07))
abs(l08 - l05) + abs(l13 - l10) + abs(l10 - l07) + abs(l05 - l02),
abs(l06 - l01) + abs(l09 - l04) + abs(l11 - l06) + abs(l14 - l09)
);

lowp int pattern = findPattern(vec4(l05, l06, l09, l10), diagonals);
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/cut3/cut3_pass_1.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void main() {
quickUnpackFloats2(previousPassPixel.z + 0.001953125) - vec2(0.5)
);

edges = clamp(edges + 2.0 * softEdges, min(edges, softEdges), max(edges, softEdges));
edges = clamp(edges + softEdges, min(edges, softEdges), max(edges, softEdges));
#endif

lowp int originalPattern = pattern >= 0 ? pattern : -pattern;
Expand Down

0 comments on commit 0cac511

Please sign in to comment.