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.

R3F22: an unlit node material's colour is tone-mapped by Bevy's own tone_mapping after the camera's colour grading (three-shader tone.wesl, the prelude importing it where the camera tone-maps in its materials' shaders), as a lit or standard material's is. It had a curve of three-shader's own without the Grade exposure that stands for three's ACES 1/0.6, so it came out darker and redder: in-tsl-particles 0.9510 to 0.9799; in-tsl-lit, in-lettra, in-tslpost and in-tslpost2 unchanged. module.rs test: the prelude's import and the entry's tone_mapping. docs/r3f.feature R3F22 status

shinyobjectzf2372ad82bdd
diff --git a/docs/r3f.feature b/docs/r3f.feature
index d51e3da6..25cf3d72 100644
--- a/docs/r3f.feature
+++ b/docs/r3f.feature
@@ -480,9 +480,13 @@ Feature: React Three Fiber both ways: an R3F scene drawn by raea, a raea composi
raea-sys-compute three.rs and three-shader storage.rs tests (runs packed once by (epoch, seq), copies repeated
with their number, matrix and values), tools/parity.sh in-tsl-particles. Not yet: Points and a Sprite with a
count (drawn as before), per-vertex storage reads, indirect dispatch, a compute first dispatched after frame 0
- (runtime-scene makes compute rows from the first frame's items), and a texture bound in a compute. Dense
- additive particles come out more saturated than three's: raea's camera without Hdr tone-maps each fragment in
- its shader before the blend, where three tone-maps the sum
+ (runtime-scene makes compute rows from the first frame's items), and a texture bound in a compute. Later the
+ same day: an unlit node material's colour is tone-mapped by Bevy's own tone_mapping after the camera's colour
+ grading (tone.wesl), as a lit or standard material's is, where it had a curve of three-shader's own without
+ the Grade exposure that stands for three's ACES 1/0.6 (R3F25), so it came out darker and redder:
+ in-tsl-particles 0.9799 (it was 0.9510, the "saturation" was this), and in-tsl-fbo, a node material reading a
+ target raea draws on its GPU (flipsY, onGpu), 0.9397 (0.9125 before); in-tsl-lit, in-lettra, in-tslpost and
+ in-tslpost2 unchanged, in-lettrafx 0.9890 (0.9855 on main without it, its last glyph mid-wipe narrower)
Scenario: R3F23. Render targets are drawn on the GPU
Given what an app draws into a render target itself (`gl.setRenderTarget(t); gl.render(scene, camera)`, drei's
diff --git a/systems/three-shader/src/module.rs b/systems/three-shader/src/module.rs
index 1d409964..038dcfe2 100644
--- a/systems/three-shader/src/module.rs
+++ b/systems/three-shader/src/module.rs
@@ -193,7 +193,8 @@ const GROUP: &str = "constants::MATERIAL_BIND_GROUP";
pub fn prelude(uniforms: &[Uniform], textures: Option<&[String]>, attributes: usize) -> String {
let mut m = String::from(
"import bevy_pbr::render::mesh_functions::get_world_from_local;\n\
- import bevy_pbr::render::mesh_view_bindings::{view, globals};\n\n",
+ import bevy_pbr::render::mesh_view_bindings::{view, globals};\n\
+ @if(TONEMAP_IN_SHADER) import bevy_core_pipeline::tonemapping::tone_mapping;\n\n",
);
m += &format!("struct ThreeSlots {{ s: array<vec4<f32>, {SLOTS}> }};\n@group({GROUP}) @binding(0) var<uniform> three_slots: ThreeSlots;\n");
if let Some(ts) = textures {
@@ -318,6 +319,15 @@ pub fn flip_samples(src: &str, names: &[String]) -> String {
mod tests {
use super::*;
+ #[test]
+ fn scene_light_is_tone_mapped_by_bevy_with_the_cameras_grading() {
+ // an unlit node material's linear colour, where the camera tone-maps in its materials' shaders, goes through
+ // Bevy's tone_mapping and the camera's colour grading (a Grade's exposure: three's ACES 1/0.6), as a standard
+ // material's does (docs/r3f.feature R3F22)
+ assert!(prelude(&[], None, 0).contains("@if(TONEMAP_IN_SHADER) import bevy_core_pipeline::tonemapping::tone_mapping;"));
+ assert!(fragment_entry().contains("return tone_mapping(vec4(c.rgb * three_exposure(), c.a), view.color_grading);"));
+ }
+
#[test]
fn flipped_textures_are_read_upside_down() {
let s = "let a = textureSample(rgt0x, rgs0x, vUv);\nlet b = textureSampleLevel(rgt1x, rgs1x, f(x, y), 0.0);\nlet c = textureLoad(rgt0x, p, 0);";
diff --git a/systems/three-shader/src/tone.wesl b/systems/three-shader/src/tone.wesl
index 7ad5fa55..2584eda2 100644
--- a/systems/three-shader/src/tone.wesl
+++ b/systems/three-shader/src/tone.wesl
@@ -106,14 +106,12 @@ fn three_untone(c: vec4<f32>) -> vec4<f32> {
let mode = u32(three_slots.s[DISPLAY_SLOT].x + 0.5);
let display = three_slots.s[DISPLAY_SLOT].y > 0.5;
@if(TONEMAP_IN_SHADER) {
- // and a linear (scene-light) colour is mapped here, as Bevy's own materials map theirs
+ // and a linear (scene-light) colour is mapped here by Bevy's own tone mapping, as its materials' are
+ // (pbr_functions): the camera's method after its colour grading, a Grade's exposure among it (three's ACES
+ // scales by 1/0.6 first: R3F25), so an unlit node material comes out as a lit one and a standard one do
if !display {
// scene light takes the camera's exposure, as three's renderer scales it before its tone mapping
- let lit = c.rgb * three_exposure();
- if mode == 0u {
- return vec4(lit, c.a);
- }
- return vec4(three_tonemap(lit, mode - 1u), c.a);
+ return tone_mapping(vec4(c.rgb * three_exposure(), c.a), view.color_grading);
}
return vec4(three_srgb_decode(clamp(c.rgb, vec3(0.0), vec3(1.0))), c.a);
}