3D engine that AI agents drive
Merge remote-tracking branch 'origin/main' into 897-cook-regeneration-env-atrous
Nguyen Xuan Ane54d842dbafa
diff --cc packages/render-native/src/cycles/integrator.wgslindex c962da45,ceb2b125..c58f739e--- a/packages/render-native/src/cycles/integrator.wgsl+++ b/packages/render-native/src/cycles/integrator.wgsl@@@ -707,117 -707,65 +707,123 @@@ fn main(@builtin(global_invocation_id)let filter_glossy_enabled = kernel_params.filter_glossy > 0.0;let inv_filter_glossy = select(1.0e30, 1.0 / max(kernel_params.filter_glossy, 1.0e-8), filter_glossy_enabled);- var batch_radiance = vec3<f32>(0.0);- var batch_depth = 0.0;- var batch_albedo = vec3<f32>(0.0);- var batch_normal = vec3<f32>(0.0);+ // The running sums start from what the film holds and take one sample at a time in sample order. That is the same+ // sequence of float additions as adding every sample straight to the film, so the image does not depend on where one+ // dispatch ends and the next begins (summing a batch from zero first would regroup the additions per split).+ let film_radiance_and_depth = film_accumulation[pixel_index];+ var batch_radiance = film_radiance_and_depth.xyz;+ var batch_depth = film_radiance_and_depth.w;+ let film_albedo_lane = film_accumulation[pixel_count + pixel_index];+ let film_normal_lane = film_accumulation[2u * pixel_count + pixel_index];+ var batch_albedo = film_albedo_lane.xyz;+ var batch_normal = film_normal_lane.xyz;var taken_in_batch = 0u;- for (var s = 0u; s < sample_count; s += 1u) {- if (s > 0u && int_pixel_has_converged(stats)) {- stats.z = 1.0;- break;+ // Per-path state lives outside the loops so that, with KERNEL_FLAG_PATH_REGENERATION, a path that ends is replaced by the+ // pixel's next sample at once instead of idling until the longest path of the dispatch ends. Without the flag a whole path+ // runs inside one iteration of the outer loop, which is the order of work before regeneration existed.+ let steps_per_iteration = select(INT_MAX_PATH_STEPS, 1u, (kernel_params.kernel_flags & KERNEL_FLAG_PATH_REGENERATION) != 0u);+ var rng = smp_init(pixel_x, pixel_y, kernel_params.sample_offset, kernel_params.seed);+ var next_sample = 0u;+ var path_active = false;+ var path_step = 0u;++ var ray_origin = vec3<f32>(0.0);+ var ray_dir = vec3<f32>(0.0);+ var ray_t_min = 0.0;+ var ray_t_max = 0.0;+ var ray_visibility = INSTANCE_VISIBILITY_CAMERA;+ var self_instance = INVALID_INDEX;+ var self_triangle = INVALID_INDEX;++ var throughput = vec3<f32>(1.0);+ var medium_sigma = vec3<f32>(0.0);+ var in_medium = false;+ var is_camera_ray = true;+ var is_transparent_bg_ray = false;+ var mis_skip = true;+ var prev_bsdf_pdf = 0.0;+ var min_ray_pdf = 1.0e30;+ var prev_recv_lo = 0xFFFFFFFFu;+ var prev_recv_hi = 0xFFFFFFFFu;+ var terminate_on_hit = false;+ var terminate_on_next_surface = false;++ var bounce = 0u;+ var diffuse_bounces = 0u;+ var glossy_bounces = 0u;+ var transmission_bounces = 0u;+ var volume_bounces = 0u;+ var transparent_bounces = 0u;++ var sample_radiance = vec3<f32>(0.0);+ var first_depth = 0.0;+ var first_albedo = vec3<f32>(0.0);+ var first_normal = vec3<f32>(0.0);+ var recorded_features = false;++ loop {+ if (!path_active) {+ if (next_sample >= sample_count) {+ break;+ }+ if (next_sample > 0u && int_pixel_has_converged(stats)) {+ stats.z = 1.0;+ break;+ }++ let sample_index = kernel_params.sample_offset + next_sample;+ next_sample += 1u;+ rng = smp_init(pixel_x, pixel_y, sample_index, kernel_params.seed);+ let filter_offset = flt_sample_offset(smp_next_2d(&rng));+ let lens_uv = smp_next_2d(&rng);+ let cam_ray = cam_generate_ray(pixel_x, pixel_y, filter_offset, lens_uv);++ ray_origin = cam_ray.origin;+ ray_dir = cam_ray.direction;+ ray_t_min = cam_ray.t_min;+ ray_t_max = cam_ray.t_max;+ ray_visibility = INSTANCE_VISIBILITY_CAMERA;+ self_instance = INVALID_INDEX;+ self_triangle = INVALID_INDEX;++ throughput = vec3<f32>(1.0);+ medium_sigma = vec3<f32>(0.0);+ in_medium = false;+ is_camera_ray = true;+ is_transparent_bg_ray = (kernel_params.kernel_flags & KERNEL_FLAG_TRANSPARENT_BACKGROUND) != 0u;+ mis_skip = true;+ prev_bsdf_pdf = 0.0;+ min_ray_pdf = 1.0e30;+ prev_recv_lo = 0xFFFFFFFFu;+ prev_recv_hi = 0xFFFFFFFFu;+ terminate_on_hit = false;+ terminate_on_next_surface = false;++ bounce = 0u;+ diffuse_bounces = 0u;+ glossy_bounces = 0u;+ transmission_bounces = 0u;+ volume_bounces = 0u;+ transparent_bounces = 0u;++ sample_radiance = vec3<f32>(0.0);+ first_depth = 0.0;+ first_albedo = vec3<f32>(0.0);+ first_normal = vec3<f32>(0.0);+ recorded_features = false;+ path_step = 0u;+ path_active = true;}- let sample_index = kernel_params.sample_offset + s;- var rng = smp_init(pixel_x, pixel_y, sample_index, kernel_params.seed);- let filter_offset = flt_sample_offset(smp_next_2d(&rng));- let lens_uv = smp_next_2d(&rng);- let cam_ray = cam_generate_ray(pixel_x, pixel_y, filter_offset, lens_uv);-- var ray_origin = cam_ray.origin;- var ray_dir = cam_ray.direction;- var ray_t_min = cam_ray.t_min;- var ray_t_max = cam_ray.t_max;- var ray_visibility = INSTANCE_VISIBILITY_CAMERA;- var self_instance = INVALID_INDEX;- var self_triangle = INVALID_INDEX;-- var throughput = vec3<f32>(1.0);- var medium_sigma = vec3<f32>(0.0);- var in_medium = false;- var is_camera_ray = true;- var is_transparent_bg_ray = (kernel_params.kernel_flags & KERNEL_FLAG_TRANSPARENT_BACKGROUND) != 0u;- var mis_skip = true;- var prev_bsdf_pdf = 0.0;- var min_ray_pdf = 1.0e30;- var prev_recv_lo = 0xFFFFFFFFu;- var prev_recv_hi = 0xFFFFFFFFu;- var terminate_on_hit = false;- var terminate_on_next_surface = false;-- var bounce = 0u;- var diffuse_bounces = 0u;- var glossy_bounces = 0u;- var transmission_bounces = 0u;- var volume_bounces = 0u;- var transparent_bounces = 0u;-- var sample_radiance = vec3<f32>(0.0);- var first_depth = 0.0;- var first_albedo = vec3<f32>(0.0);- var first_normal = vec3<f32>(0.0);- var recorded_features = false;-- for (var step = 0u; step < INT_MAX_PATH_STEPS; step += 1u) {+ for (var iteration_step = 0u; iteration_step < steps_per_iteration; iteration_step += 1u) {+ // A `break` below ends the path. Only the places that go on to the next step set `path_active` again.+ path_active = false;+ if (path_step >= INT_MAX_PATH_STEPS) {+ break;+ }+ let step = path_step;+ path_step += 1u;let surface_hit = int_trace_closest_surface(ray_origin,ray_dir,