Added mip selection using ray differentials
This commit is contained in:
@@ -27,7 +27,7 @@ path_output evaluate_bsdf_directional(directional_light_t light, const light_sha
|
||||
return output;
|
||||
}
|
||||
|
||||
ray_t shadow_ray = ray_create(offset_ray_origin(context->position, context->normal, context->wo), wi);
|
||||
ray_t shadow_ray = ray_create(offset_ray_origin(context->position, context->normal, context->wo), wi, 0.0f, 0.0f);
|
||||
|
||||
float closest = FLT_MAX;
|
||||
hit_result_t shadow_hit = {0};
|
||||
|
||||
@@ -49,7 +49,7 @@ path_output evaluate_bsdf_const_sky(const void* data, const light_shading_contex
|
||||
|
||||
vec3s wi = random_uniform_cdf_direction(context->normal, sample_index, d1, d2, scramble);
|
||||
|
||||
ray_t shadow_ray = ray_create(offset_ray_origin(context->position, context->normal, context->wo), wi);
|
||||
ray_t shadow_ray = ray_create(offset_ray_origin(context->position, context->normal, context->wo), wi, 0.0f, 0.0f);
|
||||
|
||||
hit_result_t shadow_hit = {0};
|
||||
ray_intersect_bvh_any(&shadow_ray, context->bvh_tree->nodes, context->bvh_tree->primitive_indices, context->bvh_tree->triangles, 0, &shadow_hit);
|
||||
@@ -306,7 +306,18 @@ path_output evaluate_bsdf_hdr_sky(const void* data, const light_shading_context_
|
||||
if (context->bvh_tree == NULL)
|
||||
{
|
||||
vec2s uv = direction_to_equirectangular(context->wo);
|
||||
vec4s sky_light = texture_sample_lod(get_texture(context->textures, sky_data->texture), uv, 0);
|
||||
|
||||
// Calculate LOD based on ray spread angle
|
||||
float lod = 0.0f;
|
||||
if (context->spread_angle > 0.0f)
|
||||
{
|
||||
// Approximate texel footprint: spread_angle * resolution / (2*PI)
|
||||
// This is a rough estimation for equirectangular mapping
|
||||
float texels = context->spread_angle * (float)fmax(sky_data->width, sky_data->height) * INV_PI;
|
||||
lod = log2f(fmaxf(texels, 1.0f));
|
||||
}
|
||||
|
||||
vec4s sky_light = texture_sample_lod(get_texture(context->textures, sky_data->texture), uv, lod);
|
||||
output.direct_lighting = glms_vec3_scale(glms_vec3_mul(glms_vec3(sky_light), throughput), sky_data->intensity);
|
||||
// Return the correct environment PDF for MIS when the BSDF-sampled ray escapes to the sky.
|
||||
output.pdf = hdr_sky_pdf_direction(sky_data, context->wo);
|
||||
@@ -340,7 +351,7 @@ path_output evaluate_bsdf_hdr_sky(const void* data, const light_shading_context_
|
||||
return output;
|
||||
}
|
||||
|
||||
ray_t shadow_ray = ray_create(offset_ray_origin(context->position, context->normal, context->wo), wi);
|
||||
ray_t shadow_ray = ray_create(offset_ray_origin(context->position, context->normal, context->wo), wi, 0.0f, 0.0f);
|
||||
hit_result_t shadow_hit = {0};
|
||||
ray_intersect_bvh_any(&shadow_ray, context->bvh_tree->nodes, context->bvh_tree->primitive_indices, context->bvh_tree->triangles, 0, &shadow_hit);
|
||||
if (shadow_hit.hit)
|
||||
|
||||
Reference in New Issue
Block a user