Scene picking, shadow mapping adjustments
This commit is contained in:
@@ -7,7 +7,6 @@ calc_tight_light_projection :: (camera: Camera, light_direction: Vector3) -> Mat
|
||||
inv_camera_view := inverse(camera.view_matrix);
|
||||
view_frustum_in_world_space := transform(frustum, inv_camera_view);
|
||||
|
||||
// Transform world space camera frustum to light space (with origin in 0,0,0)
|
||||
light_view := look_at_lh(.{0,0,0}, light_direction, .{0,1,0});
|
||||
light_space_frustum := transform(view_frustum_in_world_space, light_view);
|
||||
|
||||
@@ -23,7 +22,22 @@ calc_tight_light_projection :: (camera: Camera, light_direction: Vector3) -> Mat
|
||||
light_space_frustum = transform(view_frustum_in_world_space, light_view);
|
||||
|
||||
final_aabb := get_frustum_aabb(light_space_frustum);
|
||||
// @Incomplete: Padding
|
||||
|
||||
// Texel size calculation based on shadow map resolution (e.g., 2048x2048)
|
||||
texel_size_x := (final_aabb.max.x - final_aabb.min.x) / 4096.0;
|
||||
texel_size_y := (final_aabb.max.y - final_aabb.min.y) / 4096.0;
|
||||
|
||||
// Snap the minimum bounds of the AABB to the nearest texel
|
||||
final_aabb.min.x = floor(final_aabb.min.x / texel_size_x) * texel_size_x;
|
||||
final_aabb.min.y = floor(final_aabb.min.y / texel_size_y) * texel_size_y;
|
||||
|
||||
// Recalculate the max bounds based on snapped min
|
||||
final_aabb.max.x = final_aabb.min.x + (texel_size_x * 4096.0);
|
||||
final_aabb.max.y = final_aabb.min.y + (texel_size_y * 4096.0);
|
||||
|
||||
// Padding
|
||||
final_aabb.min -= .{8,5,8};
|
||||
final_aabb.max += .{8,50, 8};
|
||||
|
||||
light_projection := orthographic_lh_projection_matrix(final_aabb.min.x, final_aabb.max.x, final_aabb.min.y, final_aabb.max.y, final_aabb.min.z, final_aabb.max.z);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user