| 1066 | } |
| 1067 | |
| 1068 | 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) { |
| 1069 | int denoiser = GLOBAL_GET("rendering/lightmapping/denoising/denoiser"); |
| 1070 | String oidn_path = EDITOR_GET("filesystem/tools/oidn/oidn_denoise_path"); |
| 1071 | |
| 1072 | if (p_use_denoiser && denoiser == 1) { |
| 1073 | // OIDN (external). |
| 1074 | Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); |
| 1075 | |
| 1076 | if (da->dir_exists(oidn_path)) { |
| 1077 | if (OS::get_singleton()->get_name() == "Windows") { |
| 1078 | oidn_path = oidn_path.path_join("oidnDenoise.exe"); |
| 1079 | } else { |
| 1080 | oidn_path = oidn_path.path_join("oidnDenoise"); |
| 1081 | } |
| 1082 | } |
| 1083 | ERR_FAIL_COND_V_MSG(oidn_path.is_empty() || !da->file_exists(oidn_path), BAKE_ERROR_LIGHTMAP_CANT_PRE_BAKE_MESHES, "OIDN denoiser is selected in the project settings, but no or invalid OIDN executable path is configured in the editor settings."); |
| 1084 | } |
| 1085 | |
| 1086 | if (p_step_function) { |
| 1087 | p_step_function(0.0, RTR("Begin Bake"), p_bake_userdata, true); |
| 1088 | } |
| 1089 | lightmap_textures.clear(); |
| 1090 | shadowmask_textures.clear(); |
| 1091 | int grid_size = 128; |
| 1092 | |
| 1093 | /* STEP 1: Fetch material textures and compute the bounds */ |
| 1094 | |
| 1095 | AABB bounds; |
| 1096 | Size2i atlas_size; |
| 1097 | int atlas_slices; |
| 1098 | Vector<Ref<Image>> albedo_images; |
| 1099 | Vector<Ref<Image>> emission_images; |
| 1100 | |
| 1101 | 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); |
| 1102 | if (bake_error != BAKE_OK) { |
| 1103 | return bake_error; |
| 1104 | } |
| 1105 | |
| 1106 | // Find any directional light suitable for shadowmasking. |
| 1107 | if (p_bake_shadowmask) { |
| 1108 | bool found = false; |
| 1109 | for (int i = 0; i < lights.size(); i++) { |
| 1110 | if (lights[i].type == LightType::LIGHT_TYPE_DIRECTIONAL && !lights[i].static_bake) { |
| 1111 | found = true; |
| 1112 | break; |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | if (!found) { |
| 1117 | p_bake_shadowmask = false; |
| 1118 | WARN_PRINT("Shadowmask disabled: no directional light with their bake mode set to dynamic exists."); |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | #ifdef DEBUG_TEXTURES |
| 1123 | for (int i = 0; i < atlas_slices; i++) { |
| 1124 | albedo_images[i]->save_png("res://0_albedo_" + itos(i) + ".png"); |
| 1125 | emission_images[i]->save_png("res://0_emission_" + itos(i) + ".png"); |
nothing calls this directly
no test coverage detected