Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
IR2, IR5: an R3F scene's lights and overlays as three draws them
shinyobjectzdb3cbfcaf5a5
diff --git a/docs/img2raea.feature b/docs/img2raea.featureindex 577fe663..0d0084c1 100644--- a/docs/img2raea.feature+++ b/docs/img2raea.feature@@ -45,7 +45,7 @@ Feature: img2raea: a picture made into raea objects, props, environments and scenegative repeat is the first suspect) and the truck's ground ring loses its soft glow (additive blending ismapped, input/material.ts, so something else)- @needs+ @doneScenario: IR2. No ambient light means noneGiven a three.js scene with no AmbientLight, HemisphereLight or LightProbeThen raea draws it with no ambient light either@@ -56,6 +56,12 @@ Feature: img2raea: a picture made into raea objects, props, environments and sce0.996; the chest 0.88 to 0.94, the Gerber knife 0.94 to 0.98And the fix is one of: sdk/r3f's input/lights.ts sends AmbientLight 0 when the scene has none, or raea's enginesets GlobalAmbientLight to 0 (a raea scene without an ambient light would then be darker too: decide which)+ And 11-16, built in sdk/r3f (input/scene.ts convert): a scene with no AmbientLight, HemisphereLight or LightProbe+ gets an AmbientLight of 0, white so it lends no colour (raea sums a camera's ambient lights and takes the first+ non-white one's colour, so a composition's own AmbientLight beside the <R3F> is kept as it was); the engine's+ GlobalAmbientLight is unchanged (Shane's call, through the 0.1.6 release session). Measured: under the direct+ rig the earbuds' case 0.83 to 0.996, the Gerber knife 0.94 to 0.98, the chest 0.88 to 0.94, the mascot 0.96+ to 0.99; R3F8's 43 cases as before (one, in-drei, 0.9935 to 0.9943); test/input.test.tsx "ambient light"@needsScenario: IR3. three.js's ambient lights only diffuse@@ -83,6 +89,14 @@ Feature: img2raea: a picture made into raea objects, props, environments and scethe face is a small part of the box; IR1's sheet shows it); sdk/r3f passes depthTest on for a patched orshader material (input/patched.ts, input/shader.ts) but not for the standard ones (input/material.ts), andrenderOrder is read only for render targets (input/targets.ts)+ And 11-16, built in sdk/r3f: a basic material drawn without the depth test is three's own basic program+ (shader.ts builtinPart, as matcap and normal are), a standard or physical one its patched program (patched.ts),+ and any ThreeShaderMaterial without the depth test goes with the transparent ones, after everything opaque, as+ raea's opaque pass has no order; the mascot's face is drawn (crop SSIM 0.96 to 0.99 under the direct rig);+ test/patched.test.ts "a material drawn without the depth test"+ And left: renderOrder among such overlays (the eye's highlight over the eye) is still raea's transparent sort,+ by distance; three's order needs a sort bias from renderOrder in raea-sys-three-shader (Material::depth_bias),+ an engine change@needsScenario: IR6. A browser's globals a factory readsdiff --git a/sdk/r3f/src/input/material.ts b/sdk/r3f/src/input/material.tsindex d6da9944..78816f2a 100644--- a/sdk/r3f/src/input/material.ts+++ b/sdk/r3f/src/input/material.ts@@ -169,6 +169,9 @@ export function materialOf(m: THREE.Material, vertexColors: boolean, at?: NodeAtreturn { type: "MeshToonMaterial", props: p };}case "MeshBasicMaterial":+ // drawn without the depth test (a face's decals on its shell): three's own program, which can be (IR5)+ if (!m.depthTest) return builtinPart(m as THREE.MeshBasicMaterial);+ // falls throughcase "SpriteMaterial":case "PointsMaterial":case "LineBasicMaterial":diff --git a/sdk/r3f/src/input/patched.ts b/sdk/r3f/src/input/patched.tsindex cf926809..5b37a11e 100644--- a/sdk/r3f/src/input/patched.ts+++ b/sdk/r3f/src/input/patched.ts@@ -20,8 +20,9 @@ type Program = THREE.WebGLProgramParametersWithUniforms & { shaderName: string;/** whether a material has an onBeforeCompile of its own (three's own is empty) */export const isPatched = (m: THREE.Material): boolean => m.onBeforeCompile !== THREE.Material.prototype.onBeforeCompile;-/** whether raea draws a material as its patched program (a lit standard or physical one with a patch) */-export const drawsPatched = (m: THREE.Material): boolean => (m.type === "MeshStandardMaterial" || m.type === "MeshPhysicalMaterial") && isPatched(m);+/** whether raea draws a material as its patched program (a lit standard or physical one with a patch, or drawn without+ * the depth test, which Bevy's standard material can't be: docs/img2raea.feature IR5) */+export const drawsPatched = (m: THREE.Material): boolean => (m.type === "MeshStandardMaterial" || m.type === "MeshPhysicalMaterial") && (isPatched(m) || !m.depthTest);const LIGHTS_AT = "#include <lights_physical_fragment>";/** what follows the cut in three's own program: a patched program whose tail differs changed the light or output */diff --git a/sdk/r3f/src/input/scene.ts b/sdk/r3f/src/input/scene.tsindex 7ea76d3b..1031384b 100644--- a/sdk/r3f/src/input/scene.ts+++ b/sdk/r3f/src/input/scene.ts@@ -451,5 +451,10 @@ export function convert(scene: THREE.Scene, camera: THREE.Camera, gl: THREE.WebG// compute's among them): the composer's own (the scene into its buffer, a bloom's mip chain) are raea's effects now,// and would draw the scene againconst passes = passesOf(gl, composer.found ? [...sky.parts, ...post.parts, ...(computes ? [computes] : []), ...w.world, ...drawn] : undefined);- return { parts: [...(cam ? [cam] : []), tone, ...(fog ? [fog] : []), ...sky.parts, ...post.parts, ...(computes ? [computes] : []), ...w.world, ...passes, ...drawn], background: sky.background };+ // a scene with no ambient light has none in three; a raea camera that sees no AmbientLight keeps Bevy's default (80),+ // which lights every metal evenly where three leaves it black outside its highlights (docs/img2raea.feature IR2: the+ // earbuds' case 0.83 to 0.996). One of 0 sends the camera's ambient column; raea sums a camera's ambient lights and+ // takes no colour from a white one, so a composition's own AmbientLight beside the <R3F> is kept as it was+ const ambient: Part[] = w.world.some((p) => p.type === "AmbientLight") ? [] : [{ type: "AmbientLight", props: { name: "r3f/no-ambient", color: "#ffffff", intensity: 0 } }];+ return { parts: [...(cam ? [cam] : []), tone, ...(fog ? [fog] : []), ...sky.parts, ...post.parts, ...(computes ? [computes] : []), ...w.world, ...ambient, ...passes, ...drawn], background: sky.background };}diff --git a/sdk/r3f/src/input/shader.ts b/sdk/r3f/src/input/shader.tsindex cfc7061e..7f305086 100644--- a/sdk/r3f/src/input/shader.ts+++ b/sdk/r3f/src/input/shader.ts@@ -234,7 +234,10 @@ export function shaderPart(m: THREE.ShaderMaterial, points = false): Part {depthTest: m.depthTest,color: color ?? "#ffffff",};- if (m.transparent) props.transparent = true;+ // what draws without the depth test (a face's decals on its shell, an outline) three draws over what it drew before,+ // by renderOrder; raea's opaque pass has no order, so it goes with the transparent ones, after everything opaque+ // (docs/img2raea.feature IR5). Its depthWrite stays the material's+ if (m.transparent || !m.depthTest) props.transparent = true;if (m.blending === THREE.AdditiveBlending) props.blending = "additive";else if (m.blending === THREE.MultiplyBlending) props.blending = "multiply";if (m.alphaTest > 0) props.alphaTest = m.alphaTest;@@ -271,19 +274,20 @@ export function ownAttributes(g: THREE.BufferGeometry): Record<string, { size: n}/**- * A built-in material three draws with a program of its own that needs no lights (matcap, normal) as raea's- * <ThreeShaderMaterial> of that same program: three's ShaderLib source, the defines its WebGLProgram would set for- * this material (map, matcap, flat shading, sides) and its uniforms, so it looks as three draws it.+ * A built-in material three draws with a program of its own that needs no lights (matcap, normal; a basic one drawn+ * without the depth test, which raea's MeshBasicMaterial can't be) as raea's <ThreeShaderMaterial> of that same+ * program: three's ShaderLib source, the defines its WebGLProgram would set for this material (map, matcap, flat+ * shading, sides) and its uniforms, its depth test and write, so it looks as three draws it.*/-export function builtinPart(m: THREE.MeshMatcapMaterial | THREE.MeshNormalMaterial): Part {- const lib = m.type === "MeshMatcapMaterial" ? THREE.ShaderLib.matcap : THREE.ShaderLib.normal;+export function builtinPart(m: THREE.MeshMatcapMaterial | THREE.MeshNormalMaterial | THREE.MeshBasicMaterial): Part {+ const lib = m.type === "MeshMatcapMaterial" ? THREE.ShaderLib.matcap : m.type === "MeshBasicMaterial" ? THREE.ShaderLib.basic : THREE.ShaderLib.normal;const uniforms = THREE.UniformsUtils.clone(lib.uniforms) as Record<string, THREE.IUniform>;const defines: Record<string, string | boolean> = {};- if (m.flatShading) defines.FLAT_SHADED = true;+ if ((m as { flatShading?: boolean }).flatShading) defines.FLAT_SHADED = true;if (m.side === THREE.DoubleSide) defines.DOUBLE_SIDED = true;if (m.side === THREE.BackSide) defines.FLIP_SIDED = true;uniforms.opacity.value = m.opacity;- if (m.type === "MeshMatcapMaterial") {+ if (m.type === "MeshMatcapMaterial" || m.type === "MeshBasicMaterial") {const mc = m as THREE.MeshMatcapMaterial;uniforms.diffuse.value = mc.color.clone();if (mc.matcap) {@@ -298,7 +302,7 @@ export function builtinPart(m: THREE.MeshMatcapMaterial | THREE.MeshNormalMateriuniforms.mapTransform.value = mc.map.matrix.clone();}}- const sm = new THREE.ShaderMaterial({ uniforms, vertexShader: lib.vertexShader, fragmentShader: lib.fragmentShader, defines, transparent: m.transparent, side: m.side, toneMapped: m.toneMapped });+ const sm = new THREE.ShaderMaterial({ uniforms, vertexShader: lib.vertexShader, fragmentShader: lib.fragmentShader, defines, transparent: m.transparent, side: m.side, toneMapped: m.toneMapped, depthTest: m.depthTest, depthWrite: m.depthWrite, vertexColors: m.vertexColors });sm.opacity = m.opacity;return shaderPart(sm);}diff --git a/sdk/r3f/test/input.test.tsx b/sdk/r3f/test/input.test.tsxindex f5a01e89..82c53b6a 100644--- a/sdk/r3f/test/input.test.tsx+++ b/sdk/r3f/test/input.test.tsx@@ -231,3 +231,13 @@ describe("textures", () => {expect([...rows.subarray(1, 4), ...rows.subarray(6, 9)]).toEqual([255, 0, 0, 0, 0, 255]);});});++describe("ambient light (docs/img2raea.feature IR2)", () => {+ test("a scene with none gets one of 0, so a raea camera doesn't keep Bevy's default; a scene's own is kept alone", () => {+ const none = flat(partsOf(() => <directionalLight position={[1, 2, 3]} />).parts).filter((p) => p.type === "AmbientLight");+ expect(none.map((p) => p.props.intensity)).toEqual([0]);+ const own = flat(partsOf(() => <ambientLight intensity={0.5} />).parts).filter((p) => p.type === "AmbientLight");+ expect(own.length).toBe(1);+ expect(own[0].props.intensity as number).toBeGreaterThan(0);+ });+});diff --git a/sdk/r3f/test/patched.test.ts b/sdk/r3f/test/patched.test.tsindex 301c1a3e..857cf109 100644--- a/sdk/r3f/test/patched.test.ts+++ b/sdk/r3f/test/patched.test.ts@@ -86,3 +86,16 @@ describe("a material patched by onBeforeCompile", () => {expect(materialOf(new THREE.MeshStandardMaterial(), false).type).toBe("MeshStandardMaterial");});});++describe("a material drawn without the depth test (docs/img2raea.feature IR5)", () => {+ test("is three's own program, drawn after what is opaque, as three draws it over what it drew before", () => {+ for (const m of [new THREE.MeshBasicMaterial({ color: 0xff0000, depthTest: false, depthWrite: false }), new THREE.MeshStandardMaterial({ depthTest: false })]) {+ const part = materialOf(m, false);+ expect(part.type).toBe("ThreeShaderMaterial");+ expect(part.props.depthTest).toBe(false);+ expect(part.props.transparent).toBe(true);+ }+ expect(props(new THREE.MeshBasicMaterial({ color: 0xff0000, depthTest: false })).color).toBe("#ff0000");+ expect(materialOf(new THREE.MeshBasicMaterial(), false).type).toBe("MeshBasicMaterial");+ });+});