mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
alpha blending diagnostic shaders
This commit is contained in:
28
src/shaders/diagnose_premult_alpha_detector.frag
Normal file
28
src/shaders/diagnose_premult_alpha_detector.frag
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
in vec2 v_texCoords;
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 c = texture(u_texture, v_texCoords);
|
||||||
|
|
||||||
|
float maxRGB = max(c.r, max(c.g, c.b));
|
||||||
|
|
||||||
|
// Visualise mismatches:
|
||||||
|
// RED = looks like straight alpha
|
||||||
|
// BLUE = looks like premultiplied alpha
|
||||||
|
// GREEN = impossible / corrupted
|
||||||
|
|
||||||
|
if (maxRGB > c.a + 0.001) {
|
||||||
|
// RGB > A → straight alpha
|
||||||
|
fragColor = vec4(1, 0, 0, 1);
|
||||||
|
}
|
||||||
|
else if (maxRGB < c.a - 0.001) {
|
||||||
|
// RGB < A → premultiplied alpha
|
||||||
|
fragColor = vec4(0, 0, 1, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// borderline / linear content
|
||||||
|
fragColor = vec4(0, 1, 0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/shaders/diagnose_premult_alpha_detector_highlight.frag
Normal file
20
src/shaders/diagnose_premult_alpha_detector_highlight.frag
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
in vec2 v_texCoords;
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
// This version highlights pixels that will cause halos
|
||||||
|
// Bright red = guaranteed fringe artifact.
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 c = texture(u_texture, v_texCoords);
|
||||||
|
float maxRGB = max(c.r, max(c.g, c.b));
|
||||||
|
|
||||||
|
float diff = maxRGB - c.a;
|
||||||
|
|
||||||
|
// amplify mismatch
|
||||||
|
float halo = clamp(abs(diff) * 10.0, 0.0, 1.0);
|
||||||
|
|
||||||
|
fragColor = vec4(halo, 0, 0, 1); // red glow where halos will appear
|
||||||
|
}
|
||||||
|
|
||||||
18
src/shaders/diagnose_premult_alpha_simulate_wrong_mode.frag
Normal file
18
src/shaders/diagnose_premult_alpha_simulate_wrong_mode.frag
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
in vec2 v_texCoords;
|
||||||
|
uniform sampler2D u_texture;
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
// This shows how the sprite *would* look if alpha mode were wrong
|
||||||
|
// If you see garbage edges, your texture is premultiplied.
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 c = texture(u_texture, v_texCoords);
|
||||||
|
|
||||||
|
// simulate wrong blending
|
||||||
|
vec3 wrong = c.rgb / max(c.a, 0.001);
|
||||||
|
|
||||||
|
fragColor = vec4(wrong, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user