From 01dd5bd91e01d75b237faa66f4e833ebd75b13af Mon Sep 17 00:00:00 2001 From: ternaryop8479 Date: Sun, 8 Feb 2026 23:46:46 +0800 Subject: [PATCH] Last commit today --- examples/04_phase5_test/main.cpp | 18 +++++++++++++++--- src/raytracer/cpu_raytracer.cpp | 24 ++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/04_phase5_test/main.cpp b/examples/04_phase5_test/main.cpp index d21c52c..452de16 100644 --- a/examples/04_phase5_test/main.cpp +++ b/examples/04_phase5_test/main.cpp @@ -3,6 +3,7 @@ * @brief Phase 5 verification program - CPU ray tracing test (RGBA16F output) */ +#include #include #include #include @@ -265,9 +266,9 @@ void main() { rtc.backend = RayTracingBackend::ARE_RT_BACKEND_CPU; rtc.spp = 1; rtc.max_depth = 4; - rtc.enable_gi = true; - rtc.enable_ao = true; - rtc.ao_samples = 8; + rtc.enable_gi = false; + rtc.enable_ao = false; + rtc.ao_samples = 1; rtc.ao_radius = 1.0f; CPURayTracer tracer(rtc); @@ -283,6 +284,7 @@ void main() { bool request_render = true; while (!window.should_close()) { + std::cout << "RENDERING" << std::endl; window.poll_events(); if (window.is_key_pressed(256)) { @@ -314,14 +316,24 @@ void main() { int new_fb_w = 0; int new_fb_h = 0; window.get_framebuffer_size(new_fb_w, new_fb_h); + + // If minimized / invalid size: keep window responsive, skip rendering + if (new_fb_w <= 0 || new_fb_h <= 0) { + window.swap_buffers(); + continue; + } + if (new_fb_w != fb_w || new_fb_h != fb_h) { fb_w = new_fb_w; fb_h = new_fb_h; + rasterizer.resize(fb_w, fb_h); glDeleteTextures(1, &output_tex); output_tex = create_output_texture_rgba16f(fb_w, fb_h); + camera.set_aspect_ratio(static_cast(fb_w) / static_cast(fb_h)); + request_render = true; } diff --git a/src/raytracer/cpu_raytracer.cpp b/src/raytracer/cpu_raytracer.cpp index 45f3f80..3de3b79 100644 --- a/src/raytracer/cpu_raytracer.cpp +++ b/src/raytracer/cpu_raytracer.cpp @@ -163,47 +163,35 @@ Vec3 CPURayTracer::trace_ray(const Ray& ray, int depth) { } Vec3 CPURayTracer::shade(const HitRecord& hit, const Ray& ray, int depth) { - ARE_PROFILE_FUNCTION(); - Vec3 albedo(0.8f); - Real metallic = 0.0f; - Real roughness = 0.5f; - if (scene_) { const Material* mat = scene_->get_material(hit.material_); if (mat) { albedo = mat->get_albedo(); - metallic = mat->get_metallic(); - roughness = mat->get_roughness(); } } Vec3 direct = compute_direct_lighting(hit); Real ao = 1.0f; - if (config_.enable_ao) { ao = compute_ambient_occlusion(hit); } - Vec3 result = direct * ao; + // Direct term (Lambert) + Vec3 Lo = albedo * direct * ao; + // Diffuse GI (cosine-weighted) if (config_.enable_gi && depth > 1) { RandomGenerator& rng = get_thread_random(); Vec3 bounce_dir = rng.random_cosine_direction(hit.normal_); Ray bounce_ray(offset_ray_origin(hit.position_, hit.normal_), bounce_dir, are_epsilon, 1e30f); - Vec3 bounced = trace_ray(bounce_ray, depth - 1); - result += albedo * bounced * 0.5f; + Vec3 Li = trace_ray(bounce_ray, depth - 1); + Lo += albedo * Li; } - // Phase 5: Lambert base - result *= albedo; - (void)ray; - (void)metallic; - (void)roughness; - - return result; + return Lo; } Vec3 CPURayTracer::compute_direct_lighting(const HitRecord& hit) {