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
// An emitter's shadow ray at a card that is solid on one side and cut out on the other: a 0.2 m emissive panel 2 m
// above an albedo-0.5 Lambert plane at x = 2.05, and at 1 m a black card that is there from x = 0.75 on and cut out
// before it. The ray from the plane's middle meets the card at x = 1.025, in its solid part: no light. The ray from
// 1.1 m to the left meets it at x = 0.475, in the hole: lit. The middle against that reads 0.
// (Which side is which is what this holds: a card read mirrored, or with its two texture coordinates the other way
// round, lets the middle's ray through.)
import { Color, DataTexture, Mesh, MeshStandardMaterial, PlaneGeometry } from "@threert/scene";
import { camera, lambert, plane, result, sceneWithSky, type TestMeta } from "./lib.ts";
export const test: TestMeta = {
id: "shadow/cutout-emitter-side", features: ["emissive", "alpha-test", "shadows"], reference: "analytic", temporal: false,
metric: { kind: "ratio", a: [0.48, 0.48, 0.52, 0.52], b: [0.1, 0.48, 0.14, 0.52], expected: 0, tolerance: 0.02 },
spp: 256,
note: "the card 12 x 12 m at y = 1, its texture 96 texels wide: solid from the 54th on; the camera at y = 0.6 under it",
};
export default function () {
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);
// (Texel k lies at x = (k + 0.5) / 96 * 12 - 6: between the 53rd and the 54th the alpha crosses a half at 0.75.)
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.rotation.x = -Math.PI / 2;
card.position.set(0, 1, 0);
return result(scene, camera(scene, [0, 0.6, 3], [0, 0, 0]), [panel, card, plane(20, lambert(0.5))]);
}