You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
Add a supersampling option to LightmapGI
This provides increased lightmap quality with less noise, smoother shadows and better small-scale shadow detail. The downside is that this significantly increases bake times and memory usage while baking lightmaps, so this option is disabled by default. Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro> Co-authored-by: landervr <31851431+CpnWaffle@users.noreply.github.com>
This commit is contained in:
@@ -234,14 +234,14 @@ void LightmapperRD::_sort_triangle_clusters(uint32_t p_cluster_size, uint32_t p_
|
||||
}
|
||||
}
|
||||
|
||||
Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_size, int p_denoiser_range, Vector<Ref<Image>> &albedo_images, Vector<Ref<Image>> &emission_images, AABB &bounds, Size2i &atlas_size, int &atlas_slices, BakeStepFunc p_step_function, void *p_bake_userdata) {
|
||||
Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_size, int p_denoiser_range, Vector<Ref<Image>> &albedo_images, Vector<Ref<Image>> &emission_images, AABB &bounds, Size2i &atlas_size, int &atlas_slices, float p_supersampling_factor, BakeStepFunc p_step_function, void *p_bake_userdata) {
|
||||
Vector<Size2i> sizes;
|
||||
|
||||
for (int m_i = 0; m_i < mesh_instances.size(); m_i++) {
|
||||
MeshInstance &mi = mesh_instances.write[m_i];
|
||||
Size2i s = Size2i(mi.data.albedo_on_uv2->get_width(), mi.data.albedo_on_uv2->get_height());
|
||||
sizes.push_back(s);
|
||||
atlas_size = atlas_size.max(s + Size2i(2, 2).maxi(p_denoiser_range));
|
||||
atlas_size = atlas_size.max(s + Size2i(2, 2).maxi(p_denoiser_range) * p_supersampling_factor);
|
||||
}
|
||||
|
||||
int max = nearest_power_of_2_templated(atlas_size.width);
|
||||
@@ -271,7 +271,10 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_
|
||||
source_sizes.resize(sizes.size());
|
||||
source_indices.resize(sizes.size());
|
||||
for (int i = 0; i < source_indices.size(); i++) {
|
||||
source_sizes.write[i] = sizes[i] + Vector2i(2, 2).maxi(p_denoiser_range); // Add padding between lightmaps.
|
||||
// Add padding between lightmaps.
|
||||
// Scale the padding if the lightmap will be downsampled at the end of the baking process
|
||||
// Otherwise the padding would be insufficient.
|
||||
source_sizes.write[i] = sizes[i] + Vector2i(2, 2).maxi(p_denoiser_range) * p_supersampling_factor;
|
||||
source_indices.write[i] = i;
|
||||
}
|
||||
Vector<Vector3i> atlas_offsets;
|
||||
@@ -1041,7 +1044,7 @@ LightmapperRD::BakeError LightmapperRD::_denoise(RenderingDevice *p_rd, Ref<RDSh
|
||||
return BAKE_OK;
|
||||
}
|
||||
|
||||
LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_denoiser, float p_denoiser_strength, int p_denoiser_range, int p_bounces, float p_bounce_indirect_energy, float p_bias, int p_max_texture_size, bool p_bake_sh, bool p_bake_shadowmask, bool p_texture_for_bounces, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function, void *p_bake_userdata, float p_exposure_normalization) {
|
||||
LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_denoiser, float p_denoiser_strength, int p_denoiser_range, int p_bounces, float p_bounce_indirect_energy, float p_bias, int p_max_texture_size, bool p_bake_sh, bool p_bake_shadowmask, bool p_texture_for_bounces, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function, void *p_bake_userdata, float p_exposure_normalization, float p_supersampling_factor) {
|
||||
int denoiser = GLOBAL_GET("rendering/lightmapping/denoising/denoiser");
|
||||
String oidn_path = EDITOR_GET("filesystem/tools/oidn/oidn_denoise_path");
|
||||
|
||||
@@ -1074,7 +1077,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
|
||||
Vector<Ref<Image>> albedo_images;
|
||||
Vector<Ref<Image>> emission_images;
|
||||
|
||||
BakeError bake_error = _blit_meshes_into_atlas(p_max_texture_size, p_denoiser_range, albedo_images, emission_images, bounds, atlas_size, atlas_slices, p_step_function, p_bake_userdata);
|
||||
BakeError bake_error = _blit_meshes_into_atlas(p_max_texture_size, p_denoiser_range, albedo_images, emission_images, bounds, atlas_size, atlas_slices, p_supersampling_factor, p_step_function, p_bake_userdata);
|
||||
if (bake_error != BAKE_OK) {
|
||||
return bake_error;
|
||||
}
|
||||
@@ -1330,6 +1333,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
|
||||
bake_parameters.shadowmask_light_idx = shadowmask_light_idx;
|
||||
// Same number of rays for transparency regardless of quality (it's more of a retry rather than shooting new ones).
|
||||
bake_parameters.transparency_rays = GLOBAL_GET("rendering/lightmapping/bake_performance/max_transparency_rays");
|
||||
bake_parameters.supersampling_factor = p_supersampling_factor;
|
||||
|
||||
bake_parameters_buffer = rd->uniform_buffer_create(sizeof(BakeParameters));
|
||||
rd->buffer_update(bake_parameters_buffer, 0, sizeof(BakeParameters), &bake_parameters);
|
||||
|
||||
Reference in New Issue
Block a user