The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.
Rust electron-alternativegame-engineglobal-illuminationgraphicsjavascript-runtimemetalpath-tracingray-tracingreal-time-renderingrenderingrustthreejstypescriptvoxelvulkanwebgpuwgpu
// shadow/cutout-emitter-side's card with its texture coordinates mirrored at run time, where it lies (a
// `dynamicGeometry` mesh, its sections and triangles as many as they were): the card is then cut out from x = -0.75 on
// and solid before it. Its map (renderer/src/cutout.rs) was made of the coordinates it had, which let the panel's
// light through to the plane's point 1.1 m to the left (the ray meets the card at x = 0.475) and stopped it for the
// middle. A geometry an edit writes has no map: to an emitter's shadow ray the card is whole again, as a cutout was
// before the maps (`APPROX.cutoutEmitters`), until the scene is prepared again, and the point to the left has none of
// the panel's light. It is read against the point 1.1 m to the right, which a lamp under the card lights (0.5 m above
// it; the card hides the panel from that point in every case but the true one): the lamp's own light at the left
// point is 0.0024 of that, and the picture reads 0.003. With the old map still asked it read 0.25, under both
// traversals; with the alpha tested (`THREERT_APPROX=0`), which is what a map made again would give, 0.085.
import { Color, DataTexture, Mesh, MeshStandardMaterial, PlaneGeometry } from "@threert/scene";
import { defineGame } from "@threert/gameplay";
import { camera, lambert, plane, result, sceneWithSky, type TestMeta } from "./lib.ts";
export const test: TestMeta = {
id: "shadow/cutout-emitter-geometry-edit-live", features: ["emissive", "alpha-test", "shadows", "edits"], reference: "analytic", temporal: true,
metric: { kind: "ratio", a: [0.1, 0.48, 0.14, 0.52], b: [0.86, 0.48, 0.9, 0.52], expected: 0, tolerance: 0.02 },
live: 120,
note: "the card's u mirrored after three frames, in place: no map of the old coordinates answers for it",
};
let elapsed = 0;
let edited = false;
export default defineGame<Record<string, never>>({
state: {},
setup: () => {
elapsed = 0;
edited = false;
const scene = sceneWithSky(0);
const panel = new Mesh(new PlaneGeometry(0.2, 0.2), new MeshStandardMaterial({ name: "panel", color: new Color(0, 0, 0), emissive: new Color(1, 1, 1), emissiveIntensity: 20000, roughness: 1 }));
panel.name = "panel";
panel.rotation.x = Math.PI / 2;
panel.position.set(2.05, 2, 0);
const texels = new Uint8Array(96 * 4);
for (let k = 0; k < 96; k++) texels.set([255, 255, 255, k >= 54 ? 255 : 0], k * 4);
const card = new Mesh(new PlaneGeometry(12, 12), new MeshStandardMaterial({ name: "card", color: 0x000000, map: new DataTexture(96, 1, texels), alphaTest: 0.5, roughness: 1, side: "double" }));
card.name = "card";
card.dynamicGeometry = true;
card.rotation.x = -Math.PI / 2;
card.position.set(0, 1, 0);
const lamp = new Mesh(new PlaneGeometry(0.2, 0.2), new MeshStandardMaterial({ name: "lamp", color: new Color(0, 0, 0), emissive: new Color(1, 1, 1), emissiveIntensity: 500, roughness: 1 }));
lamp.name = "lamp";
lamp.rotation.x = Math.PI / 2;
lamp.position.set(1.1, 0.5, 0);
return result(scene, camera(scene, [0, 0.6, 3], [0, 0, 0]), [panel, lamp, card, plane(20, lambert(0.5))]);
},
frame(f) {
elapsed += f.dt;
if (edited || elapsed <= 3 / 60) return;
edited = true;
const card = f.scene.getObjectByName("card") as Mesh;
const uv = card.geometry.attributes.uv;
for (let i = 0; i < uv.count; i++) uv.setX(i, 1 - uv.getX(i));
uv.needsUpdate = true;
},
handlers: {},
});