3D engine that AI agents drive
Repeat path tracer textures that name no wrap mode (closes #813)
Nguyen Xuan An9df5fccb33bb
diff --git a/changes/813.md b/changes/813.mdnew file mode 100644index 00000000..e8b70c89--- /dev/null+++ b/changes/813.md@@ -0,0 +1 @@+- Path tracer: a texture with no wrap mode now repeats, as the rasteriser and glTF draw it, so box-projected pattern walls such as the brick room keep their bricks instead of stretching the edge row (#813)diff --git a/src/path-tracer-scene.js b/src/path-tracer-scene.jsindex b92faf4e..b9b65561 100644--- a/src/path-tracer-scene.js+++ b/src/path-tracer-scene.js@@ -110,7 +110,8 @@ function resolveTexture(descriptor) {height: image.height,data,colorLookup: descriptor.colorSpace === 'linear' ? null : SRGB_TO_LINEAR,- repeat: descriptor.wrapS === REPEAT_WRAP,+ // A map without a wrap mode repeats: the rasteriser and glTF both default to repeat.+ repeat: (descriptor.wrapS ?? REPEAT_WRAP) === REPEAT_WRAP,};}diff --git a/tests/path-tracer-texture-wrap.test.js b/tests/path-tracer-texture-wrap.test.jsnew file mode 100644index 00000000..f5a2b7f6--- /dev/null+++ b/tests/path-tracer-texture-wrap.test.js@@ -0,0 +1,22 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { buildTraceScene } from '../src/path-tracer-scene.js';+import { box } from '../src/geometry.js';++const REPEAT_WRAP = 10497;+const CLAMP_TO_EDGE = 33071;+const image = { data: new Uint8Array([255, 0, 0, 255, 0, 255, 0, 255]), width: 2, height: 1 };++function textureOf(map) {+ const part = { name: 'wall', geometry: box(0, 1), matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], material: { color: [1, 1, 1], map } };+ return buildTraceScene([part]).materials[0].texture;+}++test('a map with no wrap mode repeats, as the rasteriser draws it', () => {+ assert.equal(textureOf({ image, colorSpace: 'srgb' }).repeat, true);+});++test('a map that asks for repeat or clamp keeps that wrap mode', () => {+ assert.equal(textureOf({ image, wrapS: REPEAT_WRAP }).repeat, true);+ assert.equal(textureOf({ image, wrapS: CLAMP_TO_EDGE }).repeat, false);+});