Conversation
|
Ah I forgot the case when textures aren't a full 16x16. The trapdoor reuses the top texture for the sides, so the black lines you see in the artifact come from the holes in the top texture. This is probably an easy fix by making the texLimit match the actual size of the used texture. |
and remove uvEpsilon
|
Should be fixed now. I've also removed the |
* Fix artefacts on texture edges fixes misode#57 * set textureLimit according to uv of face and remove uvEpsilon
Removing Edit2: Finally figured it out. It turns out that moving the clamp coordinate calculation from the shader to TypeScript can resolve the minor texture bleeding issue from afar while keeping everything else intact. Before: About 9 pixels (mostly dirt) are bleeding. After: None of the dirt pixels are bleeding. The fix: const [u0, v0, u1, v1] = atlas.getTextureUV(this.getTexture(face.texture))
const du = (u1 - u0) / 16
const dv = (v1 - v0) / 16
const duu = atlas.getPixelSize() * 0.5
const dvv = atlas.getPixelSize() * 0.5
uv[0] = (face.uv?.[0] ?? uv[0]) * du
uv[1] = (face.uv?.[1] ?? uv[1]) * dv
uv[2] = (face.uv?.[2] ?? uv[2]) * du
uv[3] = (face.uv?.[3] ?? uv[3]) * dv
const r = faceRotations[face.rotation ?? 0]
quad.setTexture([
u0 + uv[r[0]], v0 + uv[r[1]],
u0 + uv[r[2]], v0 + uv[r[3]],
u0 + uv[r[4]], v0 + uv[r[5]],
u0 + uv[r[6]], v0 + uv[r[7]],
], [
u0 + Math.min(uv[0], uv[2]) + duu,
v0 + Math.min(uv[1], uv[3]) + dvv,
u0 + Math.max(uv[0], uv[2]) - duu,
v0 + Math.max(uv[1], uv[3]) - dvv,
])
mesh.quads.push(quad) void main(void) {
vec2 clampedCoord = clamp(vTexCoord, vTexLimit.xy, vTexLimit.zw);
vec4 texColor = texture2D(sampler, clampedCoord);
gl_FragColor = vec4(texColor.xyz * vTintColor * vLighting, texColor.a);
} |








This fixes the artifacts that often happen on the edge of textures. Those are caused by the GPU interpolating in the wrong direction: At the very edge of the texture, (UV: 0), we are exactly at a texture border, i.e. equally far (0.5 pixels) from each pixel. Therefore
texture2D(sampler, vTexCoord)in the fragment shader often picks the wrong direction.To fix this, I've modified this to
vTexLimitis a vec4 that stores the uv of both edged of the texture on all vertices. This allows the fragment shader to determine on which edge of the texture it is.The rest of the code changes are to give the fragment shader the necessary information:
pixelSizeandvTexLimit. The pixel size comes from a new methodgetPixelSize()in theTextureAtlasProvider. To provide backwards-compatability, that method is optional and defaults to0(which makes this fix not work).fixes #57