Added mip selection using ray differentials
This commit is contained in:
@@ -26,6 +26,7 @@ vec4s path_trace(const scene_t* scene, ray_t ray, uint32_t sample_index, uint16_
|
||||
{
|
||||
.wo = active_ray.direction,
|
||||
.textures = &scene->textures,
|
||||
.spread_angle = active_ray.spread_angle,
|
||||
};
|
||||
path_output sky_output = evaluate_bsdf_sky(&scene->lights, &light_context, throughput, sample_index);
|
||||
|
||||
@@ -48,6 +49,10 @@ vec4s path_trace(const scene_t* scene, ray_t ray, uint32_t sample_index, uint16_
|
||||
|
||||
uint8_t material_id = scene->triangles.buffer[closest_hit.triangle_id].material_id;
|
||||
const material_t* hit_material = &scene->materials.buffer[material_id];
|
||||
|
||||
// Calculate ray cone width at the hit point
|
||||
float current_cone_width = active_ray.width + closest_hit.distance * active_ray.spread_angle;
|
||||
|
||||
shading_context_t shading_context =
|
||||
{
|
||||
.camera_position = scene->camera.position,
|
||||
@@ -67,6 +72,10 @@ vec4s path_trace(const scene_t* scene, ray_t ray, uint32_t sample_index, uint16_
|
||||
.triangles = &scene->triangles,
|
||||
.lights = &scene->lights,
|
||||
.textures = &scene->textures,
|
||||
|
||||
.triangle_id = closest_hit.triangle_id,
|
||||
.cone_width = current_cone_width,
|
||||
.spread_angle = active_ray.spread_angle,
|
||||
};
|
||||
|
||||
path_output material_output = render_material(hit_material, &shading_context);
|
||||
@@ -105,15 +114,16 @@ vec4s path_trace(const scene_t* scene, ray_t ray, uint32_t sample_index, uint16_
|
||||
|
||||
switch (material_output.state)
|
||||
{
|
||||
case PS_TERMINATE:
|
||||
goto end_path_trace;
|
||||
//case PATH_THROUGH:
|
||||
// active_ray = ray_create(BIAS_RAY_ORIGION(closest_hit.point, glms_vec3_negate(closest_hit.normal)), active_ray.direction);
|
||||
// continue;
|
||||
default:
|
||||
active_ray = ray_create(offset_ray_origin(closest_hit.point, closest_hit.normal, shading_context.wo), material_output.wi);
|
||||
case PS_SUCCESS:
|
||||
vec3s origin = offset_ray_origin(closest_hit.point, closest_hit.normal, shading_context.wo);
|
||||
active_ray = ray_create(origin, material_output.wi, current_cone_width, material_output.spread_angle);
|
||||
depth++;
|
||||
break;
|
||||
default:
|
||||
goto end_path_trace;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +161,10 @@ void render_aov(const scene_t* scene, ray_t ray, uint32_t sample_index, uint16_t
|
||||
.triangles = &scene->triangles,
|
||||
.lights = &scene->lights,
|
||||
.textures = &scene->textures,
|
||||
|
||||
.triangle_id = closest_hit.triangle_id,
|
||||
.cone_width = ray.width + closest_hit.distance * ray.spread_angle,
|
||||
.spread_angle = ray.spread_angle,
|
||||
};
|
||||
|
||||
render_material_aov(hit_material, &shading_context, aov_output);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Geometry/Triangle.h"
|
||||
#include "cglm/struct/vec3.h"
|
||||
|
||||
ray_t ray_create(vec3s origin, vec3s direction)
|
||||
ray_t ray_create(vec3s origin, vec3s direction, float cone_width, float spread_angle)
|
||||
{
|
||||
ray_t ray =
|
||||
{
|
||||
@@ -13,7 +13,9 @@ ray_t ray_create(vec3s origin, vec3s direction)
|
||||
.sign =
|
||||
((direction.x < 0.0f) ? 1 : 0) |
|
||||
((direction.y < 0.0f) ? 2 : 0) |
|
||||
((direction.z < 0.0f) ? 4 : 0)
|
||||
((direction.z < 0.0f) ? 4 : 0),
|
||||
.width = cone_width,
|
||||
.spread_angle = spread_angle
|
||||
};
|
||||
|
||||
ray.esp = glms_vec3_max(glms_vec3_abs(ray.origin)) * gamma(15);
|
||||
|
||||
Reference in New Issue
Block a user