+ | Better bouncing

This commit is contained in:
TheRedShip
2025-03-04 21:15:04 +01:00
committed by tomoron
parent 507b8fef04
commit ecc1f68329
3 changed files with 23 additions and 14 deletions

View File

@ -5,7 +5,7 @@ MAT 150 150 150 0.0 1.0 0.0 //grey
MAT 255 255 255 1.0 0.0 0.0 //light MAT 255 255 255 1.0 0.0 0.0 //light
sp -10 5 0 0.01 2 sp -10 7 0 0.1 2
# qu -5 0 -2.5 0 5 0 0 0 5 0 2 # qu -5 0 -2.5 0 5 0 0 0 5 0 2

View File

@ -2,7 +2,7 @@ hitInfo traceRay(inout Ray ray);
vec3 GetEnvironmentLight(Ray ray) vec3 GetEnvironmentLight(Ray ray)
{ {
return vec3(0.); // return vec3(0.);
vec3 sun_pos = vec3(-0.5, 0.5, 0.5); vec3 sun_pos = vec3(-0.5, 0.5, 0.5);
float SunFocus = 1.5; float SunFocus = 1.5;
float SunIntensity = 1.; float SunIntensity = 1.;
@ -37,17 +37,26 @@ vec3 sampleSphereLight(vec3 position, GPUObject obj, int light_index, GPUMateria
Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir, (1.0 / light_dir)); Ray shadow_ray = Ray(position + light_dir * 0.001, light_dir, (1.0 / light_dir));
hitInfo shadow_hit = traceRay(shadow_ray); hitInfo shadow_hit = traceRay(shadow_ray);
vec3 dir = normalize(vec3(-0.5, 0.2, 0.)); vec3 dir = normalize(vec3(-0.5, 0.15, 0.));
if (dot(shadow_ray.direction, dir) < 0.995 || shadow_hit.obj_index != light_index) if (dot(shadow_ray.direction, dir) < 0.995 || shadow_hit.obj_index != light_index)
{ {
theta = 2.0 * M_PI * randomValue(rng_state); float circleRadius = light_dist * tan(acos(0.995));
phi = acos(2.0 * randomValue(rng_state) - 1.0);
// Uniformly sample a point in a disk.
sample_point = obj.position + tan(acos(0.995)) * light_dist * vec3( float r = circleRadius * sqrt(randomValue(rng_state));
sin(phi) * cos(theta), float theta = 2.0 * M_PI * randomValue(rng_state);
sin(phi) * sin(theta), vec2 diskSample = vec2(r * cos(theta), r * sin(theta));
cos(phi)
); // Build an orthonormal basis for the plane perpendicular to 'dir'.
vec3 up = abs(dir.y) < 0.99 ? vec3(0, 1, 0) : vec3(1, 0, 0);
vec3 tangent = normalize(cross(up, dir));
vec3 bitangent = cross(dir, tangent);
// Determine the center of the projected circle on the wall.
vec3 circleCenter = obj.position + light_dist * dir;
// Compute the final sample point on the projected circle.
vec3 sample_point = circleCenter + diskSample.x * tangent + diskSample.y * bitangent;
Ray light_ray = Ray(sample_point, -dir, (1.0 / -dir)); Ray light_ray = Ray(sample_point, -dir, (1.0 / -dir));
hitInfo light_ray_hit = traceRay(light_ray); hitInfo light_ray_hit = traceRay(light_ray);
@ -66,6 +75,8 @@ vec3 sampleSphereLight(vec3 position, GPUObject obj, int light_index, GPUMateria
if (dot(reflect_ray.direction, reflect_to_particle) < 0.995) if (dot(reflect_ray.direction, reflect_to_particle) < 0.995)
return vec3(0.0); return vec3(0.0);
mat.color *= light_ray_mat.color;
return mat.emission * mat.color * vec3(10.0);
} }
float cos_theta = max(0.0, -dot(light_dir, normalize(sample_point - obj.position))); float cos_theta = max(0.0, -dot(light_dir, normalize(sample_point - obj.position)));

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */ /* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */ /* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
/* Updated: 2025/03/18 16:23:10 by tomoron ### ########.fr */ /* Updated: 2025/03/18 16:24:39 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -326,7 +326,6 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
has_changed |= ImGui::SliderInt("Triangle treshold", &_scene->getDebug().triangle_treshold, 1, 2000); has_changed |= ImGui::SliderInt("Triangle treshold", &_scene->getDebug().triangle_treshold, 1, 2000);
} }
_renderer->renderImgui(*_clusterizer); _renderer->renderImgui(*_clusterizer);
_clusterizer->imguiRender(); _clusterizer->imguiRender();
@ -335,7 +334,6 @@ void Window::imGuiRender(ShaderProgram &raytracing_program)
ImGui::Render(); ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
if (has_changed) if (has_changed)
_frameCount = (accumulate == 0) - 1; _frameCount = (accumulate == 0) - 1;
} }