Last commit today
parent
8ce33436d5
commit
01dd5bd91e
|
|
@ -3,6 +3,7 @@
|
||||||
* @brief Phase 5 verification program - CPU ray tracing test (RGBA16F output)
|
* @brief Phase 5 verification program - CPU ray tracing test (RGBA16F output)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <are/core/config.h>
|
#include <are/core/config.h>
|
||||||
#include <are/core/logger.h>
|
#include <are/core/logger.h>
|
||||||
#include <are/core/profiler.h>
|
#include <are/core/profiler.h>
|
||||||
|
|
@ -265,9 +266,9 @@ void main() {
|
||||||
rtc.backend = RayTracingBackend::ARE_RT_BACKEND_CPU;
|
rtc.backend = RayTracingBackend::ARE_RT_BACKEND_CPU;
|
||||||
rtc.spp = 1;
|
rtc.spp = 1;
|
||||||
rtc.max_depth = 4;
|
rtc.max_depth = 4;
|
||||||
rtc.enable_gi = true;
|
rtc.enable_gi = false;
|
||||||
rtc.enable_ao = true;
|
rtc.enable_ao = false;
|
||||||
rtc.ao_samples = 8;
|
rtc.ao_samples = 1;
|
||||||
rtc.ao_radius = 1.0f;
|
rtc.ao_radius = 1.0f;
|
||||||
|
|
||||||
CPURayTracer tracer(rtc);
|
CPURayTracer tracer(rtc);
|
||||||
|
|
@ -283,6 +284,7 @@ void main() {
|
||||||
bool request_render = true;
|
bool request_render = true;
|
||||||
|
|
||||||
while (!window.should_close()) {
|
while (!window.should_close()) {
|
||||||
|
std::cout << "RENDERING" << std::endl;
|
||||||
window.poll_events();
|
window.poll_events();
|
||||||
|
|
||||||
if (window.is_key_pressed(256)) {
|
if (window.is_key_pressed(256)) {
|
||||||
|
|
@ -314,14 +316,24 @@ void main() {
|
||||||
int new_fb_w = 0;
|
int new_fb_w = 0;
|
||||||
int new_fb_h = 0;
|
int new_fb_h = 0;
|
||||||
window.get_framebuffer_size(new_fb_w, new_fb_h);
|
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) {
|
if (new_fb_w != fb_w || new_fb_h != fb_h) {
|
||||||
fb_w = new_fb_w;
|
fb_w = new_fb_w;
|
||||||
fb_h = new_fb_h;
|
fb_h = new_fb_h;
|
||||||
|
|
||||||
rasterizer.resize(fb_w, fb_h);
|
rasterizer.resize(fb_w, fb_h);
|
||||||
|
|
||||||
glDeleteTextures(1, &output_tex);
|
glDeleteTextures(1, &output_tex);
|
||||||
output_tex = create_output_texture_rgba16f(fb_w, fb_h);
|
output_tex = create_output_texture_rgba16f(fb_w, fb_h);
|
||||||
|
|
||||||
|
camera.set_aspect_ratio(static_cast<Real>(fb_w) / static_cast<Real>(fb_h));
|
||||||
|
|
||||||
request_render = true;
|
request_render = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,47 +163,35 @@ Vec3 CPURayTracer::trace_ray(const Ray& ray, int depth) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3 CPURayTracer::shade(const HitRecord& hit, const Ray& ray, int depth) {
|
Vec3 CPURayTracer::shade(const HitRecord& hit, const Ray& ray, int depth) {
|
||||||
ARE_PROFILE_FUNCTION();
|
|
||||||
|
|
||||||
Vec3 albedo(0.8f);
|
Vec3 albedo(0.8f);
|
||||||
Real metallic = 0.0f;
|
|
||||||
Real roughness = 0.5f;
|
|
||||||
|
|
||||||
if (scene_) {
|
if (scene_) {
|
||||||
const Material* mat = scene_->get_material(hit.material_);
|
const Material* mat = scene_->get_material(hit.material_);
|
||||||
if (mat) {
|
if (mat) {
|
||||||
albedo = mat->get_albedo();
|
albedo = mat->get_albedo();
|
||||||
metallic = mat->get_metallic();
|
|
||||||
roughness = mat->get_roughness();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3 direct = compute_direct_lighting(hit);
|
Vec3 direct = compute_direct_lighting(hit);
|
||||||
Real ao = 1.0f;
|
Real ao = 1.0f;
|
||||||
|
|
||||||
if (config_.enable_ao) {
|
if (config_.enable_ao) {
|
||||||
ao = compute_ambient_occlusion(hit);
|
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) {
|
if (config_.enable_gi && depth > 1) {
|
||||||
RandomGenerator& rng = get_thread_random();
|
RandomGenerator& rng = get_thread_random();
|
||||||
Vec3 bounce_dir = rng.random_cosine_direction(hit.normal_);
|
Vec3 bounce_dir = rng.random_cosine_direction(hit.normal_);
|
||||||
Ray bounce_ray(offset_ray_origin(hit.position_, hit.normal_), bounce_dir, are_epsilon, 1e30f);
|
Ray bounce_ray(offset_ray_origin(hit.position_, hit.normal_), bounce_dir, are_epsilon, 1e30f);
|
||||||
|
|
||||||
Vec3 bounced = trace_ray(bounce_ray, depth - 1);
|
Vec3 Li = trace_ray(bounce_ray, depth - 1);
|
||||||
result += albedo * bounced * 0.5f;
|
Lo += albedo * Li;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phase 5: Lambert base
|
|
||||||
result *= albedo;
|
|
||||||
|
|
||||||
(void)ray;
|
(void)ray;
|
||||||
(void)metallic;
|
return Lo;
|
||||||
(void)roughness;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3 CPURayTracer::compute_direct_lighting(const HitRecord& hit) {
|
Vec3 CPURayTracer::compute_direct_lighting(const HitRecord& hit) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue