R3F21: test/parity in-tsl-lit (the noise blob: an icosahedron its positionNode pushes out along the normal by 3D noise, coloured by the same noise, under a directional light; its motion a uniform R3F's clock sets, never TSL's wall-clock time) in test/parity/tsl.tsx, and the node materials' row in kinds.ts says a lit one is lit by Bevy's lights

This commit is contained in:
shinyobjectz committed 2026-11-15 11:33:42 -08:00
1 parent fcd8105d93
commit 52ccddd1df
2 files changed
+54 -1

No files matched your search

+1 -1
View File
@@ -64,7 +64,7 @@ export const CLASSES: Record<string, { status: InputStatus; raea: string; note?:
// three/webgpu's node materials (TSL): one with no node of its own is the classic material it extends, drawn natively;
// one with a graph (colorNode, positionNode, ...) on a mesh is compiled to WGSL by three's own WGSLNodeBuilder and run
// by raea's engine (tsl.ts: ThreeShaderMaterial), lit by three's light nodes when it is a lit material
...Object.fromEntries(["NodeMaterial", "MeshBasicNodeMaterial", "MeshLambertNodeMaterial", "MeshPhongNodeMaterial", "MeshStandardNodeMaterial", "MeshPhysicalNodeMaterial", "MeshSSSNodeMaterial", "MeshToonNodeMaterial", "MeshMatcapNodeMaterial", "MeshNormalNodeMaterial", "VolumeNodeMaterial"].map((k) => [k, { status: "drawn" as const, raea: "its classic material, or its graph as WGSL (ThreeShaderMaterial)", note: "a graph needing more than 4 textures, 254 vec4s of uniforms (uniformArrays included) or 4 attributes of the mesh's own, a storage buffer or a render target is named and drawn flat" }])),
...Object.fromEntries(["NodeMaterial", "MeshBasicNodeMaterial", "MeshLambertNodeMaterial", "MeshPhongNodeMaterial", "MeshStandardNodeMaterial", "MeshPhysicalNodeMaterial", "MeshSSSNodeMaterial", "MeshToonNodeMaterial", "MeshMatcapNodeMaterial", "MeshNormalNodeMaterial", "VolumeNodeMaterial"].map((k) => [k, { status: "drawn" as const, raea: "its classic material, or its graph as WGSL (ThreeShaderMaterial): a lit one's surface (colour, normal, roughness, metalness, emission, opacity, positionNode) lit by Bevy's lights and shadows", note: "a graph needing more than 4 textures, 254 vec4s of uniforms (uniformArrays included) or 4 attributes of the mesh's own, a storage buffer or a render target is named and drawn flat" }])),
...Object.fromEntries(["LineBasicNodeMaterial", "LineDashedNodeMaterial", "Line2NodeMaterial", "PointsNodeMaterial", "SpriteNodeMaterial", "ShadowNodeMaterial"].map((k) => [k, { status: "near" as const, raea: "its classic material (lines, points, a sprite, a shadow catcher)", note: "a graph of its own on lines, points or a sprite is drawn flat" }])),
// helpers: lines (and a plane's mesh), drawn as any lines are
...Object.fromEntries(["ArrowHelper", "AxesHelper", "Box3Helper", "BoxHelper", "CameraHelper", "DirectionalLightHelper", "GridHelper", "HemisphereLightHelper", "PlaneHelper", "PointLightHelper", "PolarGridHelper", "SkeletonHelper", "SpotLightHelper"].map((k) => [k, { status: "drawn" as const, raea: "its lines as Gizmo lines (an arrow's head and a plane's face as meshes)" }])),
+53
View File
@@ -0,0 +1,53 @@
// The TSL parity cases (docs/r3f.feature R3F21, R3F22): node materials three/webgpu draws in Chrome and raea's engine
// draws from three's own WGSL (src/input/tsl.ts, tsl-lit.ts). A graph's motion comes from a uniform R3F's clock sets in
// useFrame, never TSL's `time` (three's renderer counts that from performance.now(), so Chrome's frame would differ).
import { useFrame } from "@react-three/fiber";
import { MeshStandardNodeMaterial } from "three/webgpu";
import * as TSLTyped from "three/tsl";
import type { InputCase } from "./fixtures";
// untyped: @types/three's chained TSL types make tsc take minutes and gigabytes
const { color, mix, mx_noise_float, normalLocal, positionLocal, uniform } = TSLTyped as unknown as Record<string, (...a: unknown[]) => any> & { normalLocal: any; positionLocal: any };
/** three's WebGPURenderer for a TSL scene: its WebGL 2 backend (headless Chrome may have no WebGPU) */
async function nodeRenderer(props: object) {
const { WebGPURenderer } = await import("three/webgpu");
const r = new WebGPURenderer({ ...props, forceWebGL: true, antialias: true });
await r.init();
return r;
}
// the noise blob people post: an icosahedron its positionNode pushes out along the normal by 3D noise, coloured by the
// same noise, lit by the scene's lights (a MeshStandardNodeMaterial with nodes of its own: R3F21)
const blob = (() => {
const t = uniform(0);
const m = new MeshStandardNodeMaterial({ roughness: 0.4, metalness: 0.1 });
const n = mx_noise_float(positionLocal.mul(1.6).add(t.mul(0.5)));
m.positionNode = positionLocal.add(normalLocal.mul(n.mul(0.3)));
m.colorNode = mix(color("#ff7744"), color("#3355ff"), n.mul(0.5).add(0.5));
return { m, t };
})();
function Blob() {
useFrame(({ clock }) => void (blob.t.value = clock.elapsedTime));
return (
<mesh material={blob.m} rotation={[0.2, 0.3, 0]}>
<icosahedronGeometry args={[1, 32]} />
</mesh>
);
}
export const TSL_INPUTS: Record<string, InputCase> = {
"tsl-lit": {
canvas: { camera: { position: [0, 0.4, 4], fov: 45 }, gl: nodeRenderer },
frame: 12,
scene: () => (
<>
<color attach="background" args={["#14161c"]} />
<ambientLight intensity={0.3} />
<directionalLight position={[3, 5, 2]} intensity={2.5} />
<Blob />
</>
),
},
};