This commit is contained in:
Kim Ravn Hansen
2025-09-29 08:46:57 +02:00
parent f927971395
commit 8f458fbc34
5 changed files with 107 additions and 98 deletions

View File

@@ -92,14 +92,14 @@ export class Texture {
* @returns {NRGBA}
*/
sample(u, v) {
const x = Math.round(u * this.width);
const y = Math.round(v * this.height);
const x = Math.min(this.width - 1, Math.round(u * this.width));
const y = Math.min(this.height - 1, Math.round(v * this.height));
const index = (y * this.width + x) * 4;
return new NRGBA(
this.data[index + 0] / 255,
this.data[index + 1] / 255,
this.data[index + 2] / 255,
1, // this.data[index + 3] / 255,
this.data[index + 3] / 255,
);
}
}