alpha blending diagnostic shaders

This commit is contained in:
minjaesong
2026-02-13 21:03:01 +09:00
parent 93c5822c7b
commit 9efb800d47
3 changed files with 66 additions and 0 deletions

View 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);
}
}

View 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
}

View 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);
}