Skip to content

Commit

Permalink
Merge pull request #1 from sourcelocation/expose-lightmap-baking
Browse files Browse the repository at this point in the history
Expose runtime baking functionality in LightmapGI
  • Loading branch information
RisingThumb authored Jul 26, 2024
2 parents 7f02383 + 2ba1449 commit 492b447
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
15 changes: 13 additions & 2 deletions modules/lightmapper_rd/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
def can_build(env, platform):
return env.editor_build and platform not in ["android", "ios"]
return (env.editor_build and platform not in ["android", "ios"]) or env["module_lightmapper_rd_enabled"]


def configure(env):
pass
from SCons.Script import BoolVariable, Variables, Help

envvars = Variables()
envvars.Add(
BoolVariable(
"lightmapper_rd",
"Enable Lightmapper functionality in export template builds (increases binary size)",
False,
)
)
envvars.Update(env)
Help(envvars.GenerateHelpText(env))
7 changes: 6 additions & 1 deletion modules/lightmapper_rd/lightmapper_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,9 @@ LightmapperRD::BakeError LightmapperRD::_denoise(RenderingDevice *p_rd, Ref<RDSh

LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_denoiser, float p_denoiser_strength, int p_bounces, float p_bounce_indirect_energy, float p_bias, int p_max_texture_size, bool p_bake_sh, 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) {
int denoiser = GLOBAL_GET("rendering/lightmapping/denoising/denoiser");
String oidn_path = EDITOR_GET("filesystem/tools/oidn/oidn_denoise_path");

#ifdef TOOLS_ENABLED
String oidn_path = p_use_denoiser ? EDITOR_GET("filesystem/tools/oidn/oidn_denoise_path") : Variant();

if (p_use_denoiser && denoiser == 1) {
// OIDN (external).
Expand All @@ -993,6 +995,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
}
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.");
}
#endif

if (p_step_function) {
p_step_function(0.0, RTR("Begin Bake"), p_bake_userdata, true);
Expand Down Expand Up @@ -1788,8 +1791,10 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
{
BakeError error;
if (denoiser == 1) {
#ifdef TOOLS_ENABLED
// OIDN (external).
error = _denoise_oidn(rd, light_accum_tex, normal_tex, light_accum_tex, atlas_size, atlas_slices, p_bake_sh, oidn_path);
#endif
} else {
// JNLM (built-in).
SWAP(light_accum_tex, light_accum_tex2);
Expand Down
15 changes: 13 additions & 2 deletions modules/xatlas_unwrap/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
def can_build(env, platform):
return env.editor_build and platform not in ["android", "ios"]
return env.editor_build and platform not in ["android", "ios"] or env["module_xatlas_unwrap_enabled"]


def configure(env):
pass
from SCons.Script import BoolVariable, Variables, Help

envvars = Variables()
envvars.Add(
BoolVariable(
"xatlas_unwrap",
"Enable xatlas unwrapping functionality in export template builds (increases binary size)",
False,
)
)
envvars.Update(env)
Help(envvars.GenerateHelpText(env))
16 changes: 7 additions & 9 deletions scene/3d/lightmap_gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,18 +1202,16 @@ LightmapGI::BakeError LightmapGI::_bake(Node *p_from_node, String p_image_data_p
textures[i] = t;
} else {
String texture_path = texture_count > 1 ? base_path + "_" + itos(i) + ".res" : base_path + ".res";
Error err = ResourceSaver::save(texture_image, texture_path);
Ref<Image> tex_img = ResourceLoader::load(texture_path);
ERR_FAIL_COND_V(err, BAKE_ERROR_CANT_CREATE_IMAGE);
ERR_FAIL_COND_V(tex_img.is_null(), BAKE_ERROR_CANT_CREATE_IMAGE);

// Convert image to a texturelayered
Vector<Ref<Image>> images_to_add;
images_to_add.push_back(tex_img);
Ref<Texture2DArray> texs;
texs.instantiate();
texs->create_from_images(images_to_add);
textures[i] = texs;
texs->create_from_images(images);

Error err = ResourceSaver::save(texs, texture_path);
ERR_FAIL_COND_V(err, BAKE_ERROR_CANT_CREATE_IMAGE);
Ref<TextureLayered> t = ResourceLoader::load(texture_path);
ERR_FAIL_COND_V(t.is_null(), BAKE_ERROR_CANT_CREATE_IMAGE);
textures[i] = t;
}
}
}
Expand Down

0 comments on commit 492b447

Please sign in to comment.