Skip to content

Commit f7dd3a9

Browse files
committed
LightmapGI: Save directional lightmaps as ldr textures
1 parent e1b4101 commit f7dd3a9

24 files changed

+601
-147
lines changed

doc/classes/LightmapGIData.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
</method>
5555
</methods>
5656
<members>
57+
<member name="directional_textures" type="TextureLayered[]" setter="set_directional_textures" getter="get_directional_textures" default="[]">
58+
The directional atlas textures generated by the lightmapper.
59+
</member>
5760
<member name="light_texture" type="TextureLayered" setter="set_light_texture" getter="get_light_texture" deprecated="The lightmap atlas can now contain multiple textures. See [member lightmap_textures].">
5861
The lightmap atlas texture generated by the lightmapper.
5962
</member>

drivers/gles3/rasterizer_scene_gles3.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,14 +2712,14 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
27122712
glBlitFramebuffer(0, 0, size.x, size.y,
27132713
0, 0, size.x, size.y,
27142714
GL_COLOR_BUFFER_BIT, GL_NEAREST);
2715-
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 6);
2715+
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 7);
27162716
glBindTexture(GL_TEXTURE_2D, backbuffer);
27172717
}
27182718
if (scene_state.used_depth_texture) {
27192719
glBlitFramebuffer(0, 0, size.x, size.y,
27202720
0, 0, size.x, size.y,
27212721
GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
2722-
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 7);
2722+
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 8);
27232723
glBindTexture(GL_TEXTURE_2D, backbuffer_depth);
27242724
}
27252725
}
@@ -3478,6 +3478,7 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
34783478
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::LIGHTMAP_TEXTURE_SIZE, light_texture_size, shader->version, instance_variant, spec_constants);
34793479
}
34803480

3481+
// Shadowmasks
34813482
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::LIGHTMAP_SHADOWMASK_MODE, (uint32_t)lm->shadowmask_mode, shader->version, instance_variant, spec_constants);
34823483

34833484
if (lm->shadow_texture.is_valid()) {
@@ -3510,6 +3511,7 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
35103511
GLES3::LightmapInstance *li = GLES3::LightStorage::get_singleton()->get_lightmap_instance(inst->lightmap_instance);
35113512
GLES3::Lightmap *lm = GLES3::LightStorage::get_singleton()->get_lightmap(li->lightmap);
35123513

3514+
// Base lightmap
35133515
GLuint tex = GLES3::TextureStorage::get_singleton()->texture_get_texid(lm->light_texture);
35143516
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 4);
35153517
glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
@@ -3532,6 +3534,16 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
35323534
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::LIGHTMAP_EXPOSURE_NORMALIZATION, exposure_normalization, shader->version, instance_variant, spec_constants);
35333535

35343536
if (lm->uses_spherical_harmonics) {
3537+
// Directional
3538+
if (lm->directional_texture.is_valid()) {
3539+
tex = GLES3::TextureStorage::get_singleton()->texture_get_texid(lm->directional_texture);
3540+
} else {
3541+
tex = GLES3::TextureStorage::get_singleton()->texture_get_texid(GLES3::TextureStorage::get_singleton()->texture_gl_get_default(GLES3::DEFAULT_GL_TEXTURE_2D_ARRAY_WHITE));
3542+
}
3543+
3544+
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 6);
3545+
glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
3546+
35353547
Basis to_lm = li->transform.basis.inverse() * p_render_data->cam_transform.basis;
35363548
to_lm = to_lm.inverse().transposed();
35373549
GLfloat matrix[9] = {
@@ -3580,7 +3592,7 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
35803592
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::REFPROBE1_LOCAL_MATRIX, inst->reflection_probes_local_transform_cache[0], shader->version, instance_variant, spec_constants);
35813593
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::REFPROBE1_BLEND_DISTANCE, probe->blend_distance, shader->version, instance_variant, spec_constants);
35823594

3583-
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 8);
3595+
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 9);
35843596
glBindTexture(GL_TEXTURE_CUBE_MAP, light_storage->reflection_probe_instance_get_texture(inst->reflection_probe_rid_cache[0]));
35853597
}
35863598

@@ -3599,7 +3611,7 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
35993611
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::REFPROBE2_LOCAL_MATRIX, inst->reflection_probes_local_transform_cache[1], shader->version, instance_variant, spec_constants);
36003612
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::REFPROBE2_BLEND_DISTANCE, probe->blend_distance, shader->version, instance_variant, spec_constants);
36013613

3602-
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 9);
3614+
glActiveTexture(GL_TEXTURE0 + config->max_texture_image_units - 10);
36033615
glBindTexture(GL_TEXTURE_CUBE_MAP, light_storage->reflection_probe_instance_get_texture(inst->reflection_probe_rid_cache[1]));
36043616

36053617
spec_constants |= SceneShaderGLES3::SECOND_REFLECTION_PROBE;

drivers/gles3/shaders/scene.glsl

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,11 @@ void main() {
836836
3-shadow
837837
4-lightmap textures
838838
5-shadowmask textures
839-
6-screen
840-
7-depth
841-
8-reflection probe 1
842-
9-reflection probe 2
839+
6-directional textures
840+
7-screen
841+
8-depth
842+
9-reflection probe 1
843+
10-reflection probe 2
843844
844845
*/
845846

@@ -921,7 +922,7 @@ uniform float refprobe1_blend_distance;
921922
uniform int refprobe1_ambient_mode;
922923
uniform vec4 refprobe1_ambient_color;
923924

924-
uniform samplerCube refprobe1_texture; // texunit:-8
925+
uniform samplerCube refprobe1_texture; // texunit:-9
925926

926927
#ifdef SECOND_REFLECTION_PROBE
927928

@@ -935,7 +936,7 @@ uniform float refprobe2_blend_distance;
935936
uniform int refprobe2_ambient_mode;
936937
uniform vec4 refprobe2_ambient_color;
937938

938-
uniform samplerCube refprobe2_texture; // texunit:-9
939+
uniform samplerCube refprobe2_texture; // texunit:-10
939940

940941
#endif // SECOND_REFLECTION_PROBE
941942

@@ -1210,6 +1211,7 @@ float sample_shadow(highp sampler2DShadow shadow, float shadow_pixel_size, vec4
12101211
#ifdef USE_LIGHTMAP
12111212
uniform mediump sampler2DArray lightmap_textures; //texunit:-4
12121213
uniform lowp sampler2DArray shadowmask_textures; //texunit:-5
1214+
uniform mediump sampler2DArray directional_textures; //texunit:-6
12131215
uniform lowp uint lightmap_slice;
12141216
uniform highp vec4 lightmap_uv_scale;
12151217
uniform float lightmap_exposure_normalization;
@@ -1235,17 +1237,17 @@ uniform mediump vec4[9] lightmap_captures;
12351237
#endif // !DISABLE_LIGHTMAP
12361238

12371239
#ifdef USE_MULTIVIEW
1238-
uniform highp sampler2DArray depth_buffer; // texunit:-7
1239-
uniform highp sampler2DArray color_buffer; // texunit:-6
1240+
uniform highp sampler2DArray depth_buffer; // texunit:-8
1241+
uniform highp sampler2DArray color_buffer; // texunit:-7
12401242
vec3 multiview_uv(vec2 uv) {
12411243
return vec3(uv, ViewIndex);
12421244
}
12431245
ivec3 multiview_uv(ivec2 uv) {
12441246
return ivec3(uv, int(ViewIndex));
12451247
}
12461248
#else
1247-
uniform highp sampler2D depth_buffer; // texunit:-7
1248-
uniform highp sampler2D color_buffer; // texunit:-6
1249+
uniform highp sampler2D depth_buffer; // texunit:-8
1250+
uniform highp sampler2D color_buffer; // texunit:-7
12491251
vec2 multiview_uv(vec2 uv) {
12501252
return uv;
12511253
}
@@ -2109,23 +2111,19 @@ void main() {
21092111
#else
21102112
#ifdef USE_LIGHTMAP
21112113
{
2112-
vec3 uvw;
2113-
uvw.xy = uv2 * lightmap_uv_scale.zw + lightmap_uv_scale.xy;
2114-
uvw.z = float(lightmap_slice);
2114+
vec3 uvw = vec3(uv2 * lightmap_uv_scale.zw + lightmap_uv_scale.xy, float(lightmap_slice));
21152115

21162116
#ifdef USE_SH_LIGHTMAP
2117-
uvw.z *= 4.0; // SH textures use 4 times more data.
2118-
21192117
#ifdef LIGHTMAP_BICUBIC_FILTER
2120-
vec3 lm_light_l0 = textureArray_bicubic(lightmap_textures, uvw + vec3(0.0, 0.0, 0.0), lightmap_texture_size).rgb;
2121-
vec3 lm_light_l1n1 = (textureArray_bicubic(lightmap_textures, uvw + vec3(0.0, 0.0, 1.0), lightmap_texture_size).rgb - vec3(0.5)) * 2.0;
2122-
vec3 lm_light_l1_0 = (textureArray_bicubic(lightmap_textures, uvw + vec3(0.0, 0.0, 2.0), lightmap_texture_size).rgb - vec3(0.5)) * 2.0;
2123-
vec3 lm_light_l1p1 = (textureArray_bicubic(lightmap_textures, uvw + vec3(0.0, 0.0, 3.0), lightmap_texture_size).rgb - vec3(0.5)) * 2.0;
2118+
vec3 lm_light_l0 = textureArray_bicubic(lightmap_textures, uvw, lightmap_texture_size).rgb;
2119+
vec3 lm_light_l1n1 = (textureArray_bicubic(directional_textures, vec3(uvw.xy, uvw.z * 3 + 0.0), lightmap_texture_size).rgb - vec3(0.5)) * 2.0;
2120+
vec3 lm_light_l1_0 = (textureArray_bicubic(directional_textures, vec3(uvw.xy, uvw.z * 3 + 1.0), lightmap_texture_size).rgb - vec3(0.5)) * 2.0;
2121+
vec3 lm_light_l1p1 = (textureArray_bicubic(directional_textures, vec3(uvw.xy, uvw.z * 3 + 2.0), lightmap_texture_size).rgb - vec3(0.5)) * 2.0;
21242122
#else
2125-
vec3 lm_light_l0 = textureLod(lightmap_textures, uvw + vec3(0.0, 0.0, 0.0), 0.0).rgb;
2126-
vec3 lm_light_l1n1 = (textureLod(lightmap_textures, uvw + vec3(0.0, 0.0, 1.0), 0.0).rgb - vec3(0.5)) * 2.0;
2127-
vec3 lm_light_l1_0 = (textureLod(lightmap_textures, uvw + vec3(0.0, 0.0, 2.0), 0.0).rgb - vec3(0.5)) * 2.0;
2128-
vec3 lm_light_l1p1 = (textureLod(lightmap_textures, uvw + vec3(0.0, 0.0, 3.0), 0.0).rgb - vec3(0.5)) * 2.0;
2123+
vec3 lm_light_l0 = textureLod(lightmap_textures, uvw, 0.0).rgb;
2124+
vec3 lm_light_l1n1 = (textureLod(directional_textures, vec3(uvw.xy, uvw.z * 3 + 0.0), 0.0).rgb - vec3(0.5)) * 2.0;
2125+
vec3 lm_light_l1_0 = (textureLod(directional_textures, vec3(uvw.xy, uvw.z * 3 + 1.0), 0.0).rgb - vec3(0.5)) * 2.0;
2126+
vec3 lm_light_l1p1 = (textureLod(directional_textures, vec3(uvw.xy, uvw.z * 3 + 2.0), 0.0).rgb - vec3(0.5)) * 2.0;
21292127
#endif
21302128

21312129
vec3 n = normalize(lightmap_normal_xform * normal);

drivers/gles3/storage/light_storage.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,20 @@ void LightStorage::lightmap_set_shadowmask_mode(RID p_lightmap, RS::ShadowmaskMo
12371237
lightmap->shadowmask_mode = p_mode;
12381238
}
12391239

1240+
void LightStorage::lightmap_set_directional_textures(RID p_lightmap, RID p_directional) {
1241+
Lightmap *lightmap = lightmap_owner.get_or_null(p_lightmap);
1242+
ERR_FAIL_NULL(lightmap);
1243+
lightmap->directional_texture = p_directional;
1244+
1245+
GLuint tex = GLES3::TextureStorage::get_singleton()->texture_get_texid(lightmap->directional_texture);
1246+
glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
1247+
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1248+
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1249+
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1250+
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1251+
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
1252+
}
1253+
12401254
/* LIGHTMAP INSTANCE */
12411255

12421256
RID LightStorage::lightmap_instance_create(RID p_lightmap) {

drivers/gles3/storage/light_storage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ struct ReflectionProbeInstance {
176176
struct Lightmap {
177177
RID light_texture;
178178
RID shadow_texture;
179+
RID directional_texture;
179180
bool uses_spherical_harmonics = false;
180181
bool interior = false;
181182
AABB bounds = AABB(Vector3(), Vector3(1, 1, 1));
@@ -740,6 +741,8 @@ class LightStorage : public RendererLightStorage {
740741
virtual RS::ShadowmaskMode lightmap_get_shadowmask_mode(RID p_lightmap) override;
741742
virtual void lightmap_set_shadowmask_mode(RID p_lightmap, RS::ShadowmaskMode p_mode) override;
742743

744+
virtual void lightmap_set_directional_textures(RID p_lightmap, RID p_directional) override;
745+
743746
/* LIGHTMAP INSTANCE */
744747

745748
LightmapInstance *get_lightmap_instance(RID p_rid) { return lightmap_instance_owner.get_or_null(p_rid); }

editor/plugins/lightmap_gi_editor_plugin.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ void LightmapGIEditorPlugin::_bake() {
129129
_bake_select_file("");
130130
}
131131

132+
void LightmapGIEditorPlugin::_upgrade() {
133+
if (lightmap) {
134+
Ref<LightmapGIData> gi_data = lightmap->get_light_data();
135+
if (gi_data.is_valid() && gi_data->is_using_spherical_harmonics() && gi_data->_get_directional_version() < LightmapGIData::DIRECTIONAL_VERSION) {
136+
gi_data->_upgrade_directional_version();
137+
ResourceSaver::save(gi_data);
138+
139+
lightmap->set_light_data(gi_data);
140+
lightmap->update_configuration_warnings();
141+
142+
upgrade->hide();
143+
}
144+
}
145+
}
146+
132147
void LightmapGIEditorPlugin::edit(Object *p_object) {
133148
LightmapGI *s = Object::cast_to<LightmapGI>(p_object);
134149
if (!s) {
@@ -145,8 +160,16 @@ bool LightmapGIEditorPlugin::handles(Object *p_object) const {
145160
void LightmapGIEditorPlugin::make_visible(bool p_visible) {
146161
if (p_visible) {
147162
bake->show();
163+
164+
if (lightmap) {
165+
Ref<LightmapGIData> gi_data = lightmap->get_light_data();
166+
if (gi_data.is_valid() && gi_data->is_using_spherical_harmonics() && gi_data->_get_directional_version() < LightmapGIData::DIRECTIONAL_VERSION) {
167+
upgrade->show();
168+
}
169+
}
148170
} else {
149171
bake->hide();
172+
upgrade->hide();
150173
}
151174
}
152175

@@ -176,6 +199,7 @@ void LightmapGIEditorPlugin::bake_func_end(uint64_t p_time_started) {
176199

177200
void LightmapGIEditorPlugin::_bind_methods() {
178201
ClassDB::bind_method("_bake", &LightmapGIEditorPlugin::_bake);
202+
ClassDB::bind_method("_upgrade", &LightmapGIEditorPlugin::_upgrade);
179203
}
180204

181205
LightmapGIEditorPlugin::LightmapGIEditorPlugin() {
@@ -186,6 +210,10 @@ LightmapGIEditorPlugin::LightmapGIEditorPlugin() {
186210
bake->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Bake"), EditorStringName(EditorIcons)));
187211
bake->set_text(TTR("Bake Lightmaps"));
188212

213+
upgrade = memnew(Button);
214+
upgrade->set_theme_type_variation(SceneStringName(FlatButton));
215+
upgrade->set_text(TTR("Upgrade Lightmaps"));
216+
189217
#ifdef MODULE_LIGHTMAPPER_RD_ENABLED
190218
// Disable lightmap baking if not supported on the current GPU.
191219
if (!DisplayServer::get_singleton()->can_create_rendering_device()) {
@@ -205,6 +233,11 @@ LightmapGIEditorPlugin::LightmapGIEditorPlugin() {
205233
bake->hide();
206234
bake->connect(SceneStringName(pressed), Callable(this, "_bake"));
207235
add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, bake);
236+
237+
upgrade->hide();
238+
upgrade->connect(SceneStringName(pressed), Callable(this, "_upgrade"));
239+
add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, upgrade);
240+
208241
lightmap = nullptr;
209242

210243
file_dialog = memnew(EditorFileDialog);

editor/plugins/lightmap_gi_editor_plugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class LightmapGIEditorPlugin : public EditorPlugin {
4343
LightmapGI *lightmap = nullptr;
4444

4545
Button *bake = nullptr;
46+
Button *upgrade = nullptr;
4647

4748
EditorFileDialog *file_dialog = nullptr;
4849
static EditorProgress *tmp_progress;
@@ -51,6 +52,7 @@ class LightmapGIEditorPlugin : public EditorPlugin {
5152

5253
void _bake_select_file(const String &p_file);
5354
void _bake();
55+
void _upgrade();
5456

5557
protected:
5658
static void _bind_methods();

modules/lightmapper_rd/lightmapper_rd.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
10801080
}
10811081
lightmap_textures.clear();
10821082
shadowmask_textures.clear();
1083+
directional_textures.clear();
10831084
int grid_size = 128;
10841085

10851086
/* STEP 1: Fetch material textures and compute the bounds */
@@ -2133,7 +2134,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
21332134
}
21342135

21352136
#ifdef DEBUG_TEXTURES
2136-
21372137
for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) {
21382138
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i);
21392139
Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
@@ -2299,7 +2299,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
22992299
}
23002300

23012301
#ifdef DEBUG_TEXTURES
2302-
23032302
for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) {
23042303
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i);
23052304
Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
@@ -2311,14 +2310,16 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
23112310
p_step_function(0.9, RTR("Retrieving textures"), p_bake_userdata, true);
23122311
}
23132312

2314-
for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) {
2315-
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i);
2313+
// Retrieve lightmaps.
2314+
for (int i = 0; i < atlas_slices; i++) {
2315+
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, p_bake_sh ? i * 4 : i);
23162316
Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
2317-
img->convert(Image::FORMAT_RGBH); //remove alpha
2317+
img->convert(Image::FORMAT_RGBH); // Remove alpha.
23182318
lightmap_textures.push_back(img);
23192319
}
23202320

23212321
if (p_bake_shadowmask) {
2322+
// Retrieve shadowmasks.
23222323
for (int i = 0; i < atlas_slices; i++) {
23232324
Vector<uint8_t> s = rd->texture_get_data(shadowmask_tex, i);
23242325
Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBA8, s);
@@ -2327,6 +2328,18 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
23272328
}
23282329
}
23292330

2331+
if (p_bake_sh) {
2332+
// Retrieve directional.
2333+
for (int i = 0; i < atlas_slices; i++) {
2334+
for (int j = 1; j < 4; j++) {
2335+
Vector<uint8_t> s = rd->texture_get_data(light_accum_tex, i * 4 + j);
2336+
Ref<Image> img = Image::create_from_data(atlas_size.width, atlas_size.height, false, Image::FORMAT_RGBAH, s);
2337+
img->convert(Image::FORMAT_RGB8);
2338+
directional_textures.push_back(img);
2339+
}
2340+
}
2341+
}
2342+
23302343
if (probe_positions.size() > 0) {
23312344
probe_values.resize(probe_positions.size() * 9);
23322345
Vector<uint8_t> probe_data = rd->buffer_get_data(light_probe_buffer);
@@ -2374,6 +2387,15 @@ Ref<Image> LightmapperRD::get_shadowmask_texture(int p_index) const {
23742387
return shadowmask_textures[p_index];
23752388
}
23762389

2390+
int LightmapperRD::get_directional_texture_count() const {
2391+
return directional_textures.size();
2392+
}
2393+
2394+
Ref<Image> LightmapperRD::get_directional_texture(int p_index) const {
2395+
ERR_FAIL_INDEX_V(p_index, directional_textures.size(), Ref<Image>());
2396+
return directional_textures[p_index];
2397+
}
2398+
23772399
int LightmapperRD::get_bake_mesh_count() const {
23782400
return mesh_instances.size();
23792401
}

modules/lightmapper_rd/lightmapper_rd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class LightmapperRD : public Lightmapper {
266266

267267
Vector<Ref<Image>> lightmap_textures;
268268
Vector<Ref<Image>> shadowmask_textures;
269+
Vector<Ref<Image>> directional_textures;
269270
Vector<Color> probe_values;
270271

271272
struct DilateParams {
@@ -308,6 +309,9 @@ class LightmapperRD : public Lightmapper {
308309
Ref<Image> get_bake_texture(int p_index) const override;
309310
int get_shadowmask_texture_count() const override;
310311
Ref<Image> get_shadowmask_texture(int p_index) const override;
312+
int get_directional_texture_count() const override;
313+
Ref<Image> get_directional_texture(int p_index) const override;
314+
311315
int get_bake_mesh_count() const override;
312316
Variant get_bake_mesh_userdata(int p_index) const override;
313317
Rect2 get_bake_mesh_uv_scale(int p_index) const override;

0 commit comments

Comments
 (0)