fix: replace CLAMP_TO_EDGE with MIRRORED_REPEAT for ambient texture
CLAMP_TO_EDGE stretched edge pixels when ambient shader UVs exceeded [0,1] range, creating visible dark rectangles on simple/dark artwork (e.g. Metallica's black album). MIRRORED_REPEAT seamlessly mirrors the texture instead. Also removed the hard clamp() in the fragment shader so the mirrored wrapping actually takes effect.
This commit is contained in:
2 files changed
+7
-5
No files matched your search
@@ -42,8 +42,8 @@ vec3 sampleLayer(vec2 uv, vec2 offset, float scale, float rotation) {
|
||||
vec2 scaledUV = center + (rotatedUV - center) * scale;
|
||||
// Apply offset
|
||||
scaledUV += offset;
|
||||
// Clamp to valid range
|
||||
scaledUV = clamp(scaledUV, 0.0, 1.0);
|
||||
// Let GL_MIRRORED_REPEAT handle out-of-range UVs seamlessly
|
||||
// (no hard clamp — avoids visible edge rectangles on dark artwork)
|
||||
return texture(u_texture, scaledUV).rgb;
|
||||
}
|
||||
|
||||
|
||||
@@ -167,9 +167,11 @@ export function createTextureFromImage(
|
||||
|
||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||
|
||||
// Set texture parameters for smooth scaling
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
// Mirrored repeat: when ambient shader UVs exceed [0,1] range,
|
||||
// the texture mirrors back smoothly instead of stretching edge pixels
|
||||
// (CLAMP_TO_EDGE caused visible dark rectangles on simple/dark artwork)
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
|
||||
|
||||
Reference in new issue
Block a user