Add mipmap support and refactor texture handling
Note: Currently version still have lots of fireflies after applying normal map. And those fireflies are mostly coming from the nee sky. Need to double check the sky cdf and ray intersection. Changed the `hit_result_t` structure to rename a parameter in `RayIntersection.h`. Removed the `normal` field from the `path_output` structure in `Common.h`. Added new fields `screen_size`, `camera_position`, and `camera_direction` in `Material.h`. Changed the `mipmap_t` structure in `Texture.h` to include a `max_mip` field and modify the `data` field. Changed the `texture_load` function in `Texture.c` to include a `mipmap` parameter and improve texture data handling. Changed the `path_trace` function in `PathTracing.c` to update the `shading_context_t` structure and ray creation. Changed the `evaluate_bsdf_directional` function in `LightEvaluation.c` to modify angular radius calculation. Changed the `sky_create_hdr_sky` and `evaluate_bsdf_hdr_sky` functions in `SkyLight.c` to enhance texture sampling. Changed the `get_surface_data` function in `SimpleLit.c` to incorporate camera distance and view direction in calculations. Changed the `texture_get_pixel` function in `Texture.c` to improve pixel data retrieval. Changed the `warp_uv` function to use a `vec2s` structure for UV coordinates. Changed the `texture_sample` function to include additional parameters for improved sampling accuracy. Changed the `scene_setup` function in `main.c` to adjust sun light intensity and HDRI texture loading.
This commit is contained in:
@@ -148,7 +148,8 @@ sky_light_t sky_create_hdr_sky(const texture_collection_t* textures, texture_ent
|
||||
|
||||
for (uint32_t j = 0; j < data.width; ++j)
|
||||
{
|
||||
vec4s pixel = texture_get_pixel(hdri, j, i);
|
||||
vec2s uv = {(float)j / (float)data.width, (float)i / (float)data.height};
|
||||
vec4s pixel = texture_get_pixel(hdri, uv, 0);
|
||||
float lum = luminance(glms_vec3(pixel)); // * sin_theta;
|
||||
|
||||
p_xy_original_pdf[i * data.width + j] = lum;
|
||||
@@ -297,7 +298,7 @@ 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(get_texture(context->textures, sky_data->texture), uv.x, uv.y);
|
||||
vec4s sky_light = texture_sample_lod(get_texture(context->textures, sky_data->texture), uv, 0);
|
||||
output.direct_lighting = glms_vec3_scale(glms_vec3_mul(glms_vec3(sky_light), throughput), sky_data->intensity);
|
||||
output.pdf = 1.0f / (4.0f * PI);
|
||||
return output;
|
||||
@@ -305,12 +306,12 @@ path_output evaluate_bsdf_hdr_sky(const void* data, const light_shading_context_
|
||||
|
||||
uint32_t i,j;
|
||||
// Should we also use sobol numbers for the sky sampling?
|
||||
//uint16_t d1 = sobol_get_dimension(context->bounce_depth, PRNG_LIGHT_U);
|
||||
//uint16_t d2 = sobol_get_dimension(context->bounce_depth, PRNG_LIGHT_V);
|
||||
//float r1 = sobol_sample(sample_index, d1);
|
||||
//float r2 = sobol_sample(sample_index, d2);
|
||||
float r1 = random_float();
|
||||
float r2 = random_float();
|
||||
uint16_t d1 = sobol_get_dimension(context->bounce_depth, PRNG_LIGHT_U);
|
||||
uint16_t d2 = sobol_get_dimension(context->bounce_depth, PRNG_LIGHT_V);
|
||||
float r1 = sobol_sample(sample_index, d1);
|
||||
float r2 = sobol_sample(sample_index, d2);
|
||||
//float r1 = random_float();
|
||||
//float r2 = random_float();
|
||||
|
||||
uv_to_index((vec2s){r1, r2}, sky_data->width, sky_data->height, &j, &i);
|
||||
vec3s cdf = sky_data->cdf_cache[i * sky_data->width + j];
|
||||
@@ -323,7 +324,6 @@ path_output evaluate_bsdf_hdr_sky(const void* data, const light_shading_context_
|
||||
}
|
||||
|
||||
ray_t shadow_ray = ray_create(offset_ray_origin(context->position, context->normal, context->wo), wi);
|
||||
|
||||
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)
|
||||
@@ -334,7 +334,7 @@ path_output evaluate_bsdf_hdr_sky(const void* data, const light_shading_context_
|
||||
vec2s uv = direction_to_equirectangular(wi);
|
||||
|
||||
const texture_t* hdri = get_texture(context->textures, sky_data->texture);
|
||||
vec4s pixel = texture_sample(hdri, uv.x, uv.y);
|
||||
vec4s pixel = texture_sample_lod(hdri, uv, 0);
|
||||
vec3s sky_light = glms_vec3_scale(glms_vec3(pixel), sky_data->intensity);
|
||||
|
||||
float pdf = hdr_pdf(sky_data->cdf_cache, wi, sky_data->height, sky_data->width);
|
||||
|
||||
Reference in New Issue
Block a user