Skip to content

Commit

Permalink
Align CUT2 to new CUT3 behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
Swordfish90 committed Sep 12, 2024
1 parent 8390e8d commit 0c7deb8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/shaders/cut2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const CUT2_DEFINES = `
#define BLEND_MAX_SHARPNESS 0.75
#define STATIC_BLEND_SHARPNESS 0.00
#define EDGE_USE_FAST_LUMA 0
#define EDGE_MIN_VALUE 0.025
#define EDGE_MIN_VALUE 0.05
#define SOFT_EDGES_SHARPENING 1
#define SOFT_EDGES_SHARPENING_AMOUNT 1.00
`
Expand Down
21 changes: 8 additions & 13 deletions src/shaders/cut2/cut2_pass_0.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ lowp float quickPackFloats2(lowp vec2 values) {

struct Quad {
lowp vec4 scores;
lowp float localContrast;
};

Quad quad(lowp vec4 values) {
Expand All @@ -82,28 +81,25 @@ Quad quad(lowp vec4 values) {
max(abs(edges.x - edges.y), abs(edges.w - edges.z)),
max(abs(edges.x + edges.w), abs(edges.y + edges.z))
);
result.localContrast = maxOf(values) - minOf(values);
return result;
}

lowp int computePattern(lowp vec4 scores, lowp vec4 neighborsScores, lowp float localContrast) {
lowp int computePattern(lowp vec4 scores, lowp vec4 neighborsScores) {
bool isDiagonal = max(scores.z, scores.w) > max(scores.x, scores.y);

scores += 0.25 * neighborsScores;

lowp int result = 0;
if (localContrast < EDGE_MIN_VALUE) {
result = 0;
} else if (!isDiagonal) {
if (scores.x > scores.y + EPSILON) {
if (!isDiagonal) {
if (scores.x > scores.y + EDGE_MIN_VALUE) {
result = 1;
} else if (scores.y > scores.x + EPSILON) {
} else if (scores.y > scores.x + EDGE_MIN_VALUE) {
result = 2;
}
} else {
if (scores.z > scores.w + EPSILON) {
if (scores.z > scores.w + EDGE_MIN_VALUE) {
result = 3;
} else if (scores.w > scores.z + EPSILON) {
} else if (scores.w > scores.z + EDGE_MIN_VALUE) {
result = 4;
}
}
Expand All @@ -112,17 +108,16 @@ lowp int computePattern(lowp vec4 scores, lowp vec4 neighborsScores, lowp float
}

lowp int findPattern(Quad quad) {
return computePattern(quad.scores, vec4(0.0), quad.localContrast);
return computePattern(quad.scores, vec4(0.0));
}

lowp int findPattern(Quad quads[5]) {
lowp vec4 scores = quads[0].scores;
lowp vec4 adjustments = vec4(0.0);
adjustments += quads[1].scores;
adjustments += quads[2].scores;
adjustments += quads[3].scores;
adjustments += quads[4].scores;
return computePattern(scores, adjustments, quads[0].localContrast);
return computePattern(quads[0].scores, adjustments);
}

lowp float softEdgeWeight(lowp float a, lowp float b, lowp float c, lowp float d) {
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/cut3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const CUT3_DEFINES = `
#define BLEND_MAX_SHARPNESS 0.75
#define STATIC_BLEND_SHARPNESS 0.00
#define EDGE_USE_FAST_LUMA 0
#define EDGE_MIN_VALUE 0.025
#define EDGE_MIN_VALUE 0.05
#define SOFT_EDGES_SHARPENING 1
#define SOFT_EDGES_SHARPENING_AMOUNT 1.00
#define SEARCH_MIN_CONTRAST 0.85
Expand Down

0 comments on commit 0c7deb8

Please sign in to comment.