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.

Solari: a surface's normal turned from the eye is bent back to face it in the real-time path, primary and bounce

shinyobjectzd1faf4f06ffb
diff --git a/vendor/bevy_solari/src/realtime/gbuffer_utils.wesl b/vendor/bevy_solari/src/realtime/gbuffer_utils.wesl
index b6dceba7..8bfed6f8 100644
--- a/vendor/bevy_solari/src/realtime/gbuffer_utils.wesl
+++ b/vendor/bevy_solari/src/realtime/gbuffer_utils.wesl
@@ -2,7 +2,7 @@ import bevy_pbr::deferred::types::unpack_24bit_normal;
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::ResolvedMaterial;
+import package::scene::bindings::{facing_normal, ResolvedMaterial};
struct ResolvedGPixel {
world_position: vec3<f32>,
@@ -12,7 +12,16 @@ struct ResolvedGPixel {
fn gpixel_resolve(gpixel: vec4<u32>, depth: f32, pixel_id: vec2<u32>, view_size: vec2<f32>, world_from_clip: mat4x4<f32>) -> ResolvedGPixel {
let world_position = reconstruct_world_position(pixel_id, depth, view_size, world_from_clip);
- let world_normal = octahedral_decode(unpack_24bit_normal(gpixel.a));
+ var world_normal = octahedral_decode(unpack_24bit_normal(gpixel.a));
+ // raea: a smooth surface's interpolated normal past its silhouette (a dune's crest against the ground beyond) faces
+ // away from the eye, and the BRDF gives nothing there: black lines along every crest. Bent back to face the eye a
+ // little, as the path tracer does a hit's (bindings.wesl facing_normal). The eye from the inverse projection: Bevy's
+ // perspective is infinite reverse-z, so clip (0, 0, 1, 0) is the eye; an orthographic view has none and is left be
+ let eye = world_from_clip * vec4(0.0, 0.0, 1.0, 0.0);
+ if abs(eye.w) > 1e-20 {
+ let wo = normalize(eye.xyz / eye.w - world_position);
+ world_normal = facing_normal(world_normal, wo, wo);
+ }
let base_rough = unpack4x8unorm(gpixel.r);
let base_color = pow(base_rough.rgb, vec3(2.2));
diff --git a/vendor/bevy_solari/src/realtime/initial_path.wesl b/vendor/bevy_solari/src/realtime/initial_path.wesl
index a0ca2da0..c38f07ce 100644
--- a/vendor/bevy_solari/src/realtime/initial_path.wesl
+++ b/vendor/bevy_solari/src/realtime/initial_path.wesl
@@ -6,7 +6,7 @@ import package::scene::brdf::{brdf_pdf, evaluate_and_sample_brdf, evaluate_brdf,
import package::realtime::presample_light_tiles::unpack_resolved_light_sample;
import package::realtime::bindings::{empty_reservoir, light_tile_resolved_samples, light_tile_samples, Reservoir, constants, view};
import package::scene::sampling::{calculate_resolved_light_contribution, isinf, LightSample, NULL_LIGHT_ID, power_heuristic, trace_visibility, sample_environment_map_light_and_sun};
-import package::scene::bindings::{light_sources, MIRROR_ROUGHNESS_THRESHOLD, RAY_T_MAX, RAY_T_MIN, resolve_ray_hit_full, ResolvedMaterial, ResolvedRayHitFull, trace_ray};
+import package::scene::bindings::{facing_normal, light_sources, MIRROR_ROUGHNESS_THRESHOLD, RAY_T_MAX, RAY_T_MIN, resolve_ray_hit_full, ResolvedMaterial, ResolvedRayHitFull, trace_ray};
import package::realtime::world_cache_query::{get_cell_size, query_world_cache, query_world_cache_found, WORLD_CACHE_CELL_LIFETIME};
@if(DLSS_RR_GUIDE_BUFFERS)
@@ -131,7 +131,9 @@ fn generate_initial_path(world_position: vec3<f32>, world_normal: vec3<f32>, mat
break;
}
- let ray_hit = resolve_ray_hit_full(ray);
+ var ray_hit = resolve_ray_hit_full(ray);
+ // raea: a hit's normal turned from the ray (a crest seen in a mirror) bent back to face it, as the primary's is
+ ray_hit.world_normal = facing_normal(ray_hit.world_normal, ray_hit.geometric_world_normal, -next_bounce.wi);
let p_brdf = next_bounce.pdf;
@if(DLSS_RR_GUIDE_BUFFERS)