From ef88325fc85637b972cf52bf838c35076f6d3eb6 Mon Sep 17 00:00:00 2001 From: Paul Mathieu Date: Tue, 18 Oct 2022 14:01:02 -0700 Subject: [PATCH] geometry: sample pixels from their centers --- geometry.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/geometry.js b/geometry.js index d930c2a..9d0a067 100644 --- a/geometry.js +++ b/geometry.js @@ -1,18 +1,22 @@ import { memoize } from "./memoize"; function _makeTextureFace(texture) { - const textMul = 0.0625; - const textOff = texture.map(x => x * textMul); + const textureWidth = 16; + const texturesPerAtlas = 16; + const textMul = 1 / texturesPerAtlas; + const halfPixel = 1 / texturesPerAtlas / textureWidth / 2; + const textOff = texture.map(x => x * textMul + halfPixel); + const a = textMul / textureWidth * (textureWidth - 1); const textuv = [ - [0.99, 0.99], - [0.01, 0.99], - [0.01, 0.01], - [0.99, 0.99], - [0.01, 0.01], - [0.99, 0.01], + [1, 1], + [0, 1], + [0, 0], + [1, 1], + [0, 0], + [1, 0], ]; - const textures = textuv.map(uv => uv.map((x, j) => textMul * x + textOff[j])); + const textures = textuv.map(uv => uv.map((x, j) => a * x + textOff[j])); return textures; } @@ -124,4 +128,4 @@ export function makeBufferFromFaces(gl, faces) { numVertices, delete: () => gl.deleteBuffer(glBuffer), }; -} \ No newline at end of file +}