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
G-buffer emission pre-exposed, so a bright lamp isn't drawn at 0.80 of its light
shinyobjectz79d304f87d13
diff --git a/engine/render/raytrace/src/metalfx_guides.wgsl b/engine/render/raytrace/src/metalfx_guides.wgslindex be68ece8..a0c7e0c6 100644--- a/engine/render/raytrace/src/metalfx_guides.wgsl+++ b/engine/render/raytrace/src/metalfx_guides.wgsl@@ -2,7 +2,7 @@// emission split out; `restore` puts the emission back after the denoiser.// Bevy's G-buffer (bevy_pbr deferred/functions.wesl, types.wesl) to MetalFX's guides: r = base colour (sRGB-ish, pow// 1/2.2) and perceptual roughness as unorm4x8; b = reflectance, metallic, occlusion, clearcoat as unorm4x8; a = a 24-bit-// octahedral normal (two 12-bit halves) and flags; g = emissive as rgb9e5.+// octahedral normal (two 12-bit halves) and flags; g = emissive as rgb9e5, pre-exposed (times the camera's exposure).// What a surface emits is no noise. Denoised as lighting, a screen's picture or a sign's letters came out smeared, its// texture taken for noise against a near-black albedo (photo 2's monitor). So the emission's share of each pixel's// colour goes to MetalFX's denoise strength mask, which leaves a pixel marked 1 undenoised while still gathering its@@ -90,7 +90,8 @@ fn store(p: vec2<i32>, g: vec4<u32>, s: Surface) {textureStore(rough, p, vec4<f32>(s.rough, 0.0, 0.0, 0.0));textureStore(specular, p, vec4<f32>(s.specular, 1.0));let c = textureLoad(color, p);- let e = rgb9e5(g.g) * params[0].x;+ // the G-buffer's emission is pre-exposed already: as Solari adds it to the colour+ let e = rgb9e5(g.g);if (params[0].y > 0.5) {let taken = min(e, c.rgb);textureStore(diffuse, p, vec4<f32>(s.diffuse, 1.0));diff --git a/vendor/bevy_pbr/src/deferred/functions.wesl b/vendor/bevy_pbr/src/deferred/functions.weslindex 5dfca39d..3e310592 100644--- a/vendor/bevy_pbr/src/deferred/functions.wesl+++ b/vendor/bevy_pbr/src/deferred/functions.wesl@@ -76,7 +76,9 @@ fn deferred_gbuffer_from_pbr_input(in: PbrInput) -> vec4<u32> {let deferred = vec4(deferred_types::pack_unorm4x8_(vec4(base_color_srgb, in.material.perceptual_roughness)),- rgb9e5::vec3_to_rgb9e5_(emissive),+ // raea: pre-exposed (times the view's exposure), so a bright emitter (a 75000-nit lamp) keeps its light under+ // rgb9e5's top, 65408; every reader divides it back out+ rgb9e5::vec3_to_rgb9e5_(emissive * view.exposure),props,deferred_types::pack_24bit_normal_and_flags(octahedral_normal, flags),);@@ -94,7 +96,8 @@ fn pbr_input_from_deferred_gbuffer(frag_coord: vec4<f32>, gbuffer: vec4<u32>) ->let base_rough = deferred_types::unpack_unorm4x8_(gbuffer.r);pbr.material.perceptual_roughness = base_rough.a;- let emissive = rgb9e5::rgb9e5_to_vec3_(gbuffer.g);+ // raea: stored pre-exposed (deferred_gbuffer_from_pbr_input)+ let emissive = rgb9e5::rgb9e5_to_vec3_(gbuffer.g) / view.exposure;if ((pbr.material.flags & STANDARD_MATERIAL_FLAGS_UNLIT_BIT) != 0u) {pbr.material.base_color = vec4(emissive, 1.0);pbr.material.emissive = vec4(vec3(0.0), 0.0);diff --git a/vendor/bevy_solari/src/realtime/gbuffer_utils.wesl b/vendor/bevy_solari/src/realtime/gbuffer_utils.weslindex 8bfed6f8..17ca2df7 100644--- a/vendor/bevy_solari/src/realtime/gbuffer_utils.wesl+++ b/vendor/bevy_solari/src/realtime/gbuffer_utils.wesl@@ -3,6 +3,7 @@ import bevy_pbr::render::rgb9e5::rgb9e5_to_vec3_;import bevy_render::utils::octahedral_decode;import bevy_render::view::{View, depth_ndc_to_view_z};import package::scene::bindings::{facing_normal, ResolvedMaterial};+import package::realtime::bindings::view;struct ResolvedGPixel {world_position: vec3<f32>,@@ -30,7 +31,8 @@ fn gpixel_resolve(gpixel: vec4<u32>, depth: f32, pixel_id: vec2<u32>, view_size:let props = unpack4x8unorm(gpixel.b);let reflectance = props.r;let metallic = props.g;- let emissive = rgb9e5_to_vec3_(gpixel.g);+ // raea: Bevy's G-buffer holds it pre-exposed (bevy_pbr deferred/functions.wesl), so a bright lamp doesn't clip+ let emissive = rgb9e5_to_vec3_(gpixel.g) / view.exposure;let material = ResolvedMaterial(base_color, emissive, reflectance, perceptual_roughness, roughness, metallic);return ResolvedGPixel(world_position, world_normal, material);