Skip to content

armgit / raea

Public Imported from GitHub
0

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.

A three.js-style emissiveIntensity of 1 is Bevy's 1.0, not 998 nits: glows no longer draw white

shinyobjectz4081e5ac17d6
diff --git a/core/scene/src/props.rs b/core/scene/src/props.rs
index 82ab0974..0bdf5177 100644
--- a/core/scene/src/props.rs
+++ b/core/scene/src/props.rs
@@ -88,9 +88,10 @@ pub fn light_power(kind: &str, p: &Map<String, Value>) -> f64 {
num(p, field).unwrap_or_else(|| num(p, "intensity").unwrap_or(1.0) * k)
}
-/// A three.js-style emissive of intensity 1 in Bevy's units: what Bevy's default exposure (EV100 9.7) shows as 1.0,
-/// 1.2 x 2^9.7 cd/m², so a 3d.tsx material's `emissiveIntensity` glows as three.js's does (docs/control.feature FC1f).
-pub const EMISSIVE: f64 = 998.1;
+/// A three.js-style emissive of intensity 1 in Bevy's units: 1.0, as a StandardMaterial's emissive is drawn past the
+/// camera's exposure (its emissive_exposure_weight 0), so a 3d.tsx material's `emissiveIntensity` glows as three.js's
+/// does (docs/control.feature FC1f). Not 1.2 x 2^9.7 cd/m²: that is an exposed light's unit, and drew every glow white.
+pub const EMISSIVE: f64 = 1.0;
/// A material's emissive power in Bevy's units: a Bevy StandardMaterial's `emissive_nits` as written (bevy3d
/// materials.tsx), else a 3d.tsx material's relative `emissiveIntensity` (1 by default) times EMISSIVE.
pub fn emissive_power(p: &Map<String, Value>) -> f64 {
diff --git a/core/scene/tests/emissive_power.rs b/core/scene/tests/emissive_power.rs
index aa36fc53..a180a53d 100644
--- a/core/scene/tests/emissive_power.rs
+++ b/core/scene/tests/emissive_power.rs
@@ -15,6 +15,7 @@ fn bevy_nits_as_written() {
fn relative_intensity_is_three_js_brightness() {
assert_eq!(emissive_power(json!({ "emissiveIntensity": 4.0 }).as_object().unwrap()), 4.0 * EMISSIVE);
assert_eq!(emissive_power(json!({}).as_object().unwrap()), EMISSIVE);
- // Bevy's default exposure shows EMISSIVE cd/m² as 1.0: 1.2 x 2^9.7
- assert!((EMISSIVE - 1.2 * 2f64.powf(9.7)).abs() < 0.1);
+ // a StandardMaterial's emissive skips the exposure (emissive_exposure_weight 0): three.js's 1 is Bevy's 1.0, not
+ // 1.2 x 2^9.7 cd/m², which drew an emissiveIntensity of 0.25 white
+ assert_eq!(EMISSIVE, 1.0);
}
diff --git a/sdk/r3f/test/parity/fixtures.tsx b/sdk/r3f/test/parity/fixtures.tsx
index aa163f81..e7a6784a 100644
--- a/sdk/r3f/test/parity/fixtures.tsx
+++ b/sdk/r3f/test/parity/fixtures.tsx
@@ -203,6 +203,29 @@ export const INPUTS: Record<string, InputCase> = {
</>
),
},
+ // clear glass over a glow: a transmissive, clearcoated knot seen through to a thin emissive one inside it, at
+ // emissiveIntensity 1 (a glow raea once drew 998 times too bright, so the glass read as opaque white)
+ glass: {
+ canvas: { camera: { position: [0, 0, 5], fov: 40 } },
+ frame: 0,
+ scene: () => (
+ <>
+ <color attach="background" args={["#0e1116"]} />
+ <hemisphereLight args={["#dfe8ff", "#30261c", 1.2]} />
+ <directionalLight position={[3, 4, 5]} intensity={2} />
+ <group rotation={[0.4, 0.6, 0]}>
+ <mesh>
+ <torusKnotGeometry args={[1, 0.34, 320, 56]} />
+ <meshPhysicalMaterial color="#e6f3ff" transmission={1} thickness={1.4} roughness={0.04} ior={1.45} clearcoat={1} />
+ </mesh>
+ <mesh>
+ <torusKnotGeometry args={[1, 0.07, 320, 24]} />
+ <meshStandardMaterial color="#000" emissive="#ff5fa2" emissiveIntensity={1} />
+ </mesh>
+ </group>
+ </>
+ ),
+ },
// lettra's effects: a wipe whose front R3F's clock moves (a uniform set in useFrame), reading the text's own
// attributes (layoutX, glyphIndex, cellUv), and a scramble through a pool of glyphs (a uniformArray)
lettrafx: {
diff --git a/sdk/r3f/tools/parity.sh b/sdk/r3f/tools/parity.sh
index 5055fea5..3fd7f860 100755
--- a/sdk/r3f/tools/parity.sh
+++ b/sdk/r3f/tools/parity.sh
@@ -9,7 +9,7 @@ OUT=${1:-$(mktemp -d)}
URL=${R3F_PARITY_URL:-serve}
[ -f wasm/raea_shape_web.js ] || tools/shape-wasm.sh
MIN=${MIN:-0.92}
-CASES=(in-basic:24 in-lights:0 in-things:0 in-catch:0 in-lettra:12 in-lettrafx:12 in-shader:12 in-post:0 in-drei:12 in-approx:0 out-basic:24 out-tony:24 out-lights:0 out-bloom:0 out-grade:0 out-lens:0 out-catch:0 out-entities:10 src-basic:24 src-tony:24 src-lights:0 src-bloom:0 src-grade:0 src-lens:0 src-catch:0 src-entities:10)
+CASES=(in-basic:24 in-lights:0 in-things:0 in-catch:0 in-lettra:12 in-lettrafx:12 in-shader:12 in-post:0 in-drei:12 in-approx:0 in-glass:0 out-basic:24 out-tony:24 out-lights:0 out-bloom:0 out-grade:0 out-lens:0 out-catch:0 out-entities:10 src-basic:24 src-tony:24 src-lights:0 src-bloom:0 src-grade:0 src-lens:0 src-catch:0 src-entities:10)
mkdir -p "$OUT"
for c in "${CASES[@]}"; do
# a src-* case is its out-* composition, drawn from the R3F source the source export wrote for it
diff --git a/sdk/r3f/tools/shoot.ts b/sdk/r3f/tools/shoot.ts
index 09a3a13e..f718451d 100644
--- a/sdk/r3f/tools/shoot.ts
+++ b/sdk/r3f/tools/shoot.ts
@@ -8,7 +8,7 @@ const [baseArg, out, ...only] = process.argv.slice(2);
if (!baseArg || !out) throw new Error("usage: bun tools/shoot.ts BASE_URL|serve OUT_DIR [in-basic ...]");
const served = baseArg === "serve" ? await serve() : undefined;
const base = served?.url ?? baseArg;
-const cases = only.length ? only : ["in-basic", "in-lights", "in-things", "in-catch", "in-lettra", "in-lettrafx", "in-shader", "in-post", "in-drei", "in-approx", "out-basic", "out-tony", "out-lights", "out-bloom", "out-grade", "out-lens", "out-catch", "out-entities", "src-basic", "src-tony", "src-lights", "src-bloom", "src-grade", "src-lens", "src-catch", "src-entities"];
+const cases = only.length ? only : ["in-basic", "in-lights", "in-things", "in-catch", "in-lettra", "in-lettrafx", "in-shader", "in-post", "in-drei", "in-approx", "in-glass", "out-basic", "out-tony", "out-lights", "out-bloom", "out-grade", "out-lens", "out-catch", "out-entities", "src-basic", "src-tony", "src-lights", "src-bloom", "src-grade", "src-lens", "src-catch", "src-entities"];
let failed = 0;
for (const c of cases) {
const [dir, name] = c.split("-");