Skip to content

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.

1.7 KB
Raw Blame
// What is seen through many alpha-tested cards: a glowing floor behind ten cards that are cut out everywhere reads as
// it does beside them. A ray that sees asks every card's alpha on its way (hardware traversal: a ray query for each,
// sixteen at most). The cards are black: one taken for solid shows nothing of the light around it.
import { camera, result, sceneWithSky, type TestMeta } from "./lib.ts";
import { Color, DataTexture, Mesh, MeshStandardMaterial, PlaneGeometry } from "@threert/scene";

export const test: TestMeta = {
  id: "cutout/deep", features: ["alpha-test", "emissive"], reference: "analytic", temporal: false,
  metric: { kind: "ratio", a: [0.2, 0.45, 0.3, 0.55], b: [0.7, 0.45, 0.8, 0.55], expected: 1, tolerance: 0.02 },
  note: "ten cards 4 x 4 m over the left of the view, 0.1 m apart; the floor glows at 10 nits",
};

export default function () {
  const scene = sceneWithSky(0);
  const floor = new Mesh(new PlaneGeometry(400, 400), new MeshStandardMaterial({ name: "floor", color: new Color(0, 0, 0), emissive: new Color(1, 1, 1), emissiveIntensity: 10, roughness: 1 }));
  floor.name = "floor";
  floor.rotation.x = -Math.PI / 2;
  const clear = new DataTexture(2, 2, new Uint8Array([255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0]));
  const cards = Array.from({ length: 10 }, (_, k) => {
    const card = new Mesh(new PlaneGeometry(4, 4), new MeshStandardMaterial({ name: "card", color: 0x000000, map: clear, alphaTest: 0.5, roughness: 1, side: "double" }));
    card.name = `card${k}`;
    card.rotation.x = -Math.PI / 2;
    card.position.set(-2.5, 0.1 * (k + 1), 0);
    return card;
  });
  return result(scene, camera(scene, [0, 6, 3], [0, 0, 0]), [floor, ...cards]);
}