Skip to content

Commit c5fd4bb

Browse files
committed
Strip VoxelGIData and LightmapGIData using placeholders for dedicated server exports
This greatly reduces PCK size for dedicated servers in projects that use either VoxelGI or LightmapGI for global illumination.
1 parent 5d72153 commit c5fd4bb

File tree

9 files changed

+109
-0
lines changed

9 files changed

+109
-0
lines changed

doc/classes/LightmapGIData.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
Clear all objects that are considered baked within this [LightmapGIData].
2626
</description>
2727
</method>
28+
<method name="create_placeholder" qualifiers="const">
29+
<return type="PlaceholderLightmapGIData" />
30+
<description>
31+
Creates a placeholder version of this resource ([PlaceholderLightmapGIData]).
32+
</description>
33+
</method>
2834
<method name="get_user_count" qualifiers="const">
2935
<return type="int" />
3036
<description>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="PlaceholderLightmapGIData" inherits="LightmapGIData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
Placeholder class for [LightmapGIData].
5+
</brief_description>
6+
<description>
7+
This class is used when loading a project that uses a [LightmapGIData] subclass, if the project was exported in dedicated server mode. In this mode, only the resource reference is kept, with no actual light probe data. This allows reducing the exported PCK's size significantly.
8+
[b]Note:[/b] This is not intended to be used as an actual resource for rendering.
9+
</description>
10+
<tutorials>
11+
</tutorials>
12+
</class>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="PlaceholderVoxelGIData" inherits="VoxelGIData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
Placeholder class for [VoxelGIData].
5+
</brief_description>
6+
<description>
7+
This class is used when loading a project that uses a [VoxelGIData] subclass, if the project was exported in dedicated server mode. In this mode, only the resource reference is kept, with no actual voxel data. This allows reducing the exported PCK's size significantly.
8+
[b]Note:[/b] This is not intended to be used as an actual resource for rendering.
9+
</description>
10+
<tutorials>
11+
</tutorials>
12+
</class>

doc/classes/VoxelGIData.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
<description>
2424
</description>
2525
</method>
26+
<method name="create_placeholder" qualifiers="const">
27+
<return type="PlaceholderVoxelGIData" />
28+
<description>
29+
Creates a placeholder version of this resource ([PlaceholderVoxelGIData]).
30+
</description>
31+
</method>
2632
<method name="get_bounds" qualifiers="const">
2733
<return type="AABB" />
2834
<description>

scene/3d/lightmap_gi.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ Array LightmapGIData::_get_light_textures_data() const {
323323
}
324324
#endif
325325

326+
Ref<Resource> LightmapGIData::create_placeholder() const {
327+
Ref<PlaceholderLightmapGIData> data;
328+
data.instantiate();
329+
return data;
330+
}
331+
326332
void LightmapGIData::_bind_methods() {
327333
ClassDB::bind_method(D_METHOD("_set_user_data", "data"), &LightmapGIData::_set_user_data);
328334
ClassDB::bind_method(D_METHOD("_get_user_data"), &LightmapGIData::_get_user_data);
@@ -347,6 +353,8 @@ void LightmapGIData::_bind_methods() {
347353
ClassDB::bind_method(D_METHOD("_set_probe_data", "data"), &LightmapGIData::_set_probe_data);
348354
ClassDB::bind_method(D_METHOD("_get_probe_data"), &LightmapGIData::_get_probe_data);
349355

356+
ClassDB::bind_method(D_METHOD("create_placeholder"), &LightmapGIData::create_placeholder);
357+
350358
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "lightmap_textures", PROPERTY_HINT_ARRAY_TYPE, "TextureLayered", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_READ_ONLY), "set_lightmap_textures", "get_lightmap_textures");
351359
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "shadowmask_textures", PROPERTY_HINT_ARRAY_TYPE, "TextureLayered", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_READ_ONLY), "set_shadowmask_textures", "get_shadowmask_textures");
352360
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uses_spherical_harmonics", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_uses_spherical_harmonics", "is_using_spherical_harmonics");
@@ -381,6 +389,21 @@ LightmapGIData::~LightmapGIData() {
381389

382390
///////////////////////////
383391

392+
RID PlaceholderLightmapGIData::get_rid() const {
393+
return lightmap;
394+
}
395+
396+
PlaceholderLightmapGIData::PlaceholderLightmapGIData() {
397+
lightmap = RS::get_singleton()->lightmap_create();
398+
}
399+
400+
PlaceholderLightmapGIData::~PlaceholderLightmapGIData() {
401+
ERR_FAIL_NULL(RenderingServer::get_singleton());
402+
RS::get_singleton()->free_rid(lightmap);
403+
}
404+
405+
///////////////////////////
406+
384407
void LightmapGI::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound> &meshes, Vector<LightsFound> &lights, Vector<Vector3> &probes) {
385408
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_at_node);
386409
if (mi && mi->get_gi_mode() == GeometryInstance3D::GI_MODE_STATIC && mi->is_visible_in_tree()) {

scene/3d/lightmap_gi.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
class Sky;
3939
class CameraAttributes;
40+
class PlaceholderLightmapGIData;
4041

4142
class LightmapGIData : public Resource {
4243
GDCLASS(LightmapGIData, Resource);
@@ -138,11 +139,24 @@ class LightmapGIData : public Resource {
138139
void clear_shadowmask_textures();
139140
bool has_shadowmask_textures();
140141

142+
Ref<Resource> create_placeholder() const;
143+
141144
virtual RID get_rid() const override;
142145
LightmapGIData();
143146
~LightmapGIData();
144147
};
145148

149+
class PlaceholderLightmapGIData : public LightmapGIData {
150+
GDCLASS(PlaceholderLightmapGIData, LightmapGIData);
151+
152+
RID lightmap;
153+
154+
public:
155+
virtual RID get_rid() const override;
156+
PlaceholderLightmapGIData();
157+
~PlaceholderLightmapGIData();
158+
};
159+
146160
class LightmapGI : public VisualInstance3D {
147161
GDCLASS(LightmapGI, VisualInstance3D);
148162

scene/3d/voxel_gi.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ void VoxelGIData::_bind_methods() {
225225
ClassDB::bind_method(D_METHOD("_set_data", "data"), &VoxelGIData::_set_data);
226226
ClassDB::bind_method(D_METHOD("_get_data"), &VoxelGIData::_get_data);
227227

228+
ClassDB::bind_method(D_METHOD("create_placeholder"), &VoxelGIData::create_placeholder);
229+
228230
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data");
229231

230232
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dynamic_range", PROPERTY_HINT_RANGE, "1,8,0.01"), "set_dynamic_range", "get_dynamic_range");
@@ -264,6 +266,16 @@ VoxelGIData::~VoxelGIData() {
264266
}
265267

266268
//////////////////////
269+
270+
PlaceholderVoxelGIData::PlaceholderVoxelGIData() {
271+
probe = RS::get_singleton()->voxel_gi_create();
272+
}
273+
274+
PlaceholderVoxelGIData::~PlaceholderVoxelGIData() {
275+
ERR_FAIL_NULL(RenderingServer::get_singleton());
276+
RS::get_singleton()->free_rid(probe);
277+
}
278+
267279
//////////////////////
268280

269281
void VoxelGI::set_probe_data(const Ref<VoxelGIData> &p_data) {
@@ -537,6 +549,12 @@ AABB VoxelGI::get_aabb() const {
537549
return AABB(-size / 2, size);
538550
}
539551

552+
Ref<Resource> VoxelGIData::create_placeholder() const {
553+
Ref<PlaceholderVoxelGIData> data;
554+
data.instantiate();
555+
return data;
556+
}
557+
540558
PackedStringArray VoxelGI::get_configuration_warnings() const {
541559
PackedStringArray warnings = VisualInstance3D::get_configuration_warnings();
542560

scene/3d/voxel_gi.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "scene/3d/visual_instance_3d.h"
3434

3535
class CameraAttributes;
36+
class PlaceholderVoxelGIData;
3637

3738
class VoxelGIData : public Resource {
3839
GDCLASS(VoxelGIData, Resource);
@@ -88,12 +89,27 @@ class VoxelGIData : public Resource {
8889
void set_use_two_bounces(bool p_enable);
8990
bool is_using_two_bounces() const;
9091

92+
Ref<Resource> create_placeholder() const;
93+
9194
virtual RID get_rid() const override;
9295

9396
VoxelGIData();
9497
~VoxelGIData();
9598
};
9699

100+
class PlaceholderVoxelGIData : public VoxelGIData {
101+
GDCLASS(PlaceholderVoxelGIData, VoxelGIData);
102+
103+
RID probe;
104+
105+
public:
106+
// void _set_data(const Dictionary &p_data);
107+
// Dictionary _get_data() const;
108+
109+
PlaceholderVoxelGIData();
110+
~PlaceholderVoxelGIData();
111+
};
112+
97113
class VoxelGI : public VisualInstance3D {
98114
GDCLASS(VoxelGI, VisualInstance3D);
99115

scene/register_scene_types.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,10 @@ void register_scene_types() {
643643
GDREGISTER_CLASS(Decal);
644644
GDREGISTER_CLASS(VoxelGI);
645645
GDREGISTER_CLASS(VoxelGIData);
646+
GDREGISTER_CLASS(PlaceholderVoxelGIData);
646647
GDREGISTER_CLASS(LightmapGI);
647648
GDREGISTER_CLASS(LightmapGIData);
649+
GDREGISTER_CLASS(PlaceholderLightmapGIData);
648650
GDREGISTER_CLASS(LightmapProbe);
649651
GDREGISTER_ABSTRACT_CLASS(Lightmapper);
650652
GDREGISTER_CLASS(GPUParticles3D);

0 commit comments

Comments
 (0)