Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reflection mask to reflection probes #50196

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/classes/ReflectionProbe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
If [code]true[/code], enables box projection. This makes reflections look more correct in rectangle-shaped rooms by offsetting the reflection center depending on the camera's location.
</member>
<member name="cull_mask" type="int" setter="set_cull_mask" getter="get_cull_mask" default="1048575">
Sets the cull mask which determines what objects are drawn by this probe. Every [VisualInstance3D] with a layer included in this cull mask will be rendered by the probe. It is best to only include large objects which are likely to take up a lot of space in the reflection in order to save on rendering cost.
Sets the cull mask which determines what objects have reflections applied from this probe. Every [VisualInstance3D] with a layer included in this cull mask will have reflections applied from this probe.
</member>
<member name="enable_shadows" type="bool" setter="set_enable_shadows" getter="are_shadows_enabled" default="false">
If [code]true[/code], computes shadows in the reflection probe. This makes the reflection probe slower to render; you may want to disable this if using the [constant UPDATE_ALWAYS] [member update_mode].
Expand All @@ -45,6 +45,9 @@
<member name="origin_offset" type="Vector3" setter="set_origin_offset" getter="get_origin_offset" default="Vector3(0, 0, 0)">
Sets the origin offset to be used when this reflection probe is in box project mode.
</member>
<member name="reflection_mask" type="int" setter="set_reflection_mask" getter="get_reflection_mask" default="1048575">
Sets the reflection mask which determines what objects are drawn by this probe. Every [VisualInstance3D] with a layer included in this reflection mask will be rendered by the probe. It is best to only include large objects which are likely to take up a lot of space in the reflection in order to save on rendering cost.
</member>
<member name="update_mode" type="int" setter="set_update_mode" getter="get_update_mode" enum="ReflectionProbe.UpdateMode" default="0">
Sets how frequently the probe is updated. Can be [constant UPDATE_ONCE] or [constant UPDATE_ALWAYS].
</member>
Expand Down
13 changes: 12 additions & 1 deletion doc/classes/RenderingServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3419,7 +3419,7 @@
<argument index="1" name="layers" type="int">
</argument>
<description>
Sets the render cull mask for this reflection probe. Only instances with a matching cull mask will be rendered by this probe. Equivalent to [member ReflectionProbe.cull_mask].
Sets the render cull mask for this reflection probe. Only instances with a matching cull mask will have reflections applied from this probe. Equivalent to [member ReflectionProbe.cull_mask].
</description>
</method>
<method name="reflection_probe_set_enable_box_projection">
Expand Down Expand Up @@ -3498,6 +3498,17 @@
Sets the origin offset to be used when this reflection probe is in box project mode. Equivalent to [member ReflectionProbe.origin_offset].
</description>
</method>
<method name="reflection_probe_set_reflection_mask">
<return type="void">
</return>
<argument index="0" name="probe" type="RID">
</argument>
<argument index="1" name="layers" type="int">
</argument>
<description>
Sets the render reflection mask for this reflection probe. Only instances with a matching reflection mask will be rendered by this probe. Equivalent to [member ReflectionProbe.reflection_mask].
</description>
</method>
<method name="reflection_probe_set_resolution">
<return type="void">
</return>
Expand Down
13 changes: 13 additions & 0 deletions scene/3d/reflection_probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ uint32_t ReflectionProbe::get_cull_mask() const {
return cull_mask;
}

void ReflectionProbe::set_reflection_mask(uint32_t p_layers) {
reflection_mask = p_layers;
RS::get_singleton()->reflection_probe_set_reflection_mask(probe, p_layers);
}

uint32_t ReflectionProbe::get_reflection_mask() const {
return reflection_mask;
}

void ReflectionProbe::set_update_mode(UpdateMode p_mode) {
update_mode = p_mode;
RS::get_singleton()->reflection_probe_set_update_mode(probe, RS::ReflectionProbeUpdateMode(p_mode));
Expand Down Expand Up @@ -227,6 +236,9 @@ void ReflectionProbe::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_cull_mask", "layers"), &ReflectionProbe::set_cull_mask);
ClassDB::bind_method(D_METHOD("get_cull_mask"), &ReflectionProbe::get_cull_mask);

ClassDB::bind_method(D_METHOD("set_reflection_mask", "layers"), &ReflectionProbe::set_reflection_mask);
ClassDB::bind_method(D_METHOD("get_reflection_mask"), &ReflectionProbe::get_reflection_mask);

ClassDB::bind_method(D_METHOD("set_update_mode", "mode"), &ReflectionProbe::set_update_mode);
ClassDB::bind_method(D_METHOD("get_update_mode"), &ReflectionProbe::get_update_mode);

Expand All @@ -239,6 +251,7 @@ void ReflectionProbe::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior"), "set_as_interior", "is_set_as_interior");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enable_shadows"), "set_enable_shadows", "are_shadows_enabled");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask");
ADD_PROPERTY(PropertyInfo(Variant::INT, "reflection_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_reflection_mask", "get_reflection_mask");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lod_threshold", PROPERTY_HINT_RANGE, "0,1024,0.1"), "set_lod_threshold", "get_lod_threshold");

ADD_GROUP("Ambient", "ambient_");
Expand Down
4 changes: 4 additions & 0 deletions scene/3d/reflection_probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ReflectionProbe : public VisualInstance3D {
float lod_threshold = 1.0;

uint32_t cull_mask = (1 << 20) - 1;
uint32_t reflection_mask = (1 << 20) - 1;
UpdateMode update_mode = UPDATE_ONCE;

protected:
Expand Down Expand Up @@ -112,6 +113,9 @@ class ReflectionProbe : public VisualInstance3D {
void set_cull_mask(uint32_t p_layers);
uint32_t get_cull_mask() const;

void set_reflection_mask(uint32_t p_layers);
uint32_t get_reflection_mask() const;

void set_update_mode(UpdateMode p_mode);
UpdateMode get_update_mode() const;

Expand Down
2 changes: 2 additions & 0 deletions servers/rendering/rasterizer_dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,13 @@ class RasterizerStorageDummy : public RendererStorage {
void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) override {}
void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) override {}
void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) override {}
void reflection_probe_set_reflection_mask(RID p_probe, uint32_t p_layers) override {}
void reflection_probe_set_resolution(RID p_probe, int p_resolution) override {}

AABB reflection_probe_get_aabb(RID p_probe) const override { return AABB(); }
RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const override { return RenderingServer::REFLECTION_PROBE_UPDATE_ONCE; }
uint32_t reflection_probe_get_cull_mask(RID p_probe) const override { return 0; }
uint32_t reflection_probe_get_reflection_mask(RID p_probe) const override { return 0; }
Vector3 reflection_probe_get_extents(RID p_probe) const override { return Vector3(); }
Vector3 reflection_probe_get_origin_offset(RID p_probe) const override { return Vector3(); }
float reflection_probe_get_origin_max_distance(RID p_probe) const override { return 0.0; }
Expand Down
15 changes: 15 additions & 0 deletions servers/rendering/renderer_rd/renderer_storage_rd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6179,6 +6179,14 @@ void RendererStorageRD::reflection_probe_set_cull_mask(RID p_probe, uint32_t p_l
reflection_probe->dependency.changed_notify(DEPENDENCY_CHANGED_REFLECTION_PROBE);
}

void RendererStorageRD::reflection_probe_set_reflection_mask(RID p_probe, uint32_t p_layers) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);

reflection_probe->reflection_mask = p_layers;
reflection_probe->dependency.changed_notify(DEPENDENCY_CHANGED_REFLECTION_PROBE);
}

void RendererStorageRD::reflection_probe_set_resolution(RID p_probe, int p_resolution) {
ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND(!reflection_probe);
Expand Down Expand Up @@ -6221,6 +6229,13 @@ uint32_t RendererStorageRD::reflection_probe_get_cull_mask(RID p_probe) const {
return reflection_probe->cull_mask;
}

uint32_t RendererStorageRD::reflection_probe_get_reflection_mask(RID p_probe) const {
const ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND_V(!reflection_probe, 0);

return reflection_probe->reflection_mask;
}

Vector3 RendererStorageRD::reflection_probe_get_extents(RID p_probe) const {
const ReflectionProbe *reflection_probe = reflection_probe_owner.getornull(p_probe);
ERR_FAIL_COND_V(!reflection_probe, Vector3());
Expand Down
3 changes: 3 additions & 0 deletions servers/rendering/renderer_rd/renderer_storage_rd.h
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ class RendererStorageRD : public RendererStorage {
bool box_projection = false;
bool enable_shadows = false;
uint32_t cull_mask = (1 << 20) - 1;
uint32_t reflection_mask = (1 << 20) - 1;
float lod_threshold = 0.01;

Dependency dependency;
Expand Down Expand Up @@ -1920,12 +1921,14 @@ class RendererStorageRD : public RendererStorage {
void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable);
void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable);
void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers);
void reflection_probe_set_reflection_mask(RID p_probe, uint32_t p_layers);
void reflection_probe_set_resolution(RID p_probe, int p_resolution);
void reflection_probe_set_lod_threshold(RID p_probe, float p_ratio);

AABB reflection_probe_get_aabb(RID p_probe) const;
RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const;
uint32_t reflection_probe_get_cull_mask(RID p_probe) const;
uint32_t reflection_probe_get_reflection_mask(RID p_probe) const;
Vector3 reflection_probe_get_extents(RID p_probe) const;
Vector3 reflection_probe_get_origin_offset(RID p_probe) const;
float reflection_probe_get_origin_max_distance(RID p_probe) const;
Expand Down
2 changes: 1 addition & 1 deletion servers/rendering/renderer_scene_cull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3228,7 +3228,7 @@ bool RendererSceneCull::_render_reflection_probe_step(Instance *p_instance, int
RendererSceneRender::CameraData camera_data;
camera_data.set_camera(xform, cm, false, false);

_render_scene(&camera_data, RID(), environment, RID(), RSG::storage->reflection_probe_get_cull_mask(p_instance->base), p_instance->scenario->self, RID(), shadow_atlas, reflection_probe->instance, p_step, lod_threshold, use_shadows);
_render_scene(&camera_data, RID(), environment, RID(), RSG::storage->reflection_probe_get_reflection_mask(p_instance->base), p_instance->scenario->self, RID(), shadow_atlas, reflection_probe->instance, p_step, lod_threshold, use_shadows);

} else {
//do roughness postprocess step until it believes it's done
Expand Down
2 changes: 2 additions & 0 deletions servers/rendering/renderer_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,13 @@ class RendererStorage {
virtual void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) = 0;
virtual void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) = 0;
virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) = 0;
virtual void reflection_probe_set_reflection_mask(RID p_probe, uint32_t p_layers) = 0;
virtual void reflection_probe_set_lod_threshold(RID p_probe, float p_ratio) = 0;

virtual AABB reflection_probe_get_aabb(RID p_probe) const = 0;
virtual RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const = 0;
virtual uint32_t reflection_probe_get_cull_mask(RID p_probe) const = 0;
virtual uint32_t reflection_probe_get_reflection_mask(RID p_probe) const = 0;
virtual Vector3 reflection_probe_get_extents(RID p_probe) const = 0;
virtual Vector3 reflection_probe_get_origin_offset(RID p_probe) const = 0;
virtual float reflection_probe_get_origin_max_distance(RID p_probe) const = 0;
Expand Down
1 change: 1 addition & 0 deletions servers/rendering/rendering_server_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ class RenderingServerDefault : public RenderingServer {
FUNC2(reflection_probe_set_enable_box_projection, RID, bool)
FUNC2(reflection_probe_set_enable_shadows, RID, bool)
FUNC2(reflection_probe_set_cull_mask, RID, uint32_t)
FUNC2(reflection_probe_set_reflection_mask, RID, uint32_t)
FUNC2(reflection_probe_set_resolution, RID, int)
FUNC2(reflection_probe_set_lod_threshold, RID, float)

Expand Down
1 change: 1 addition & 0 deletions servers/rendering_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,7 @@ void RenderingServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_box_projection", "probe", "enable"), &RenderingServer::reflection_probe_set_enable_box_projection);
ClassDB::bind_method(D_METHOD("reflection_probe_set_enable_shadows", "probe", "enable"), &RenderingServer::reflection_probe_set_enable_shadows);
ClassDB::bind_method(D_METHOD("reflection_probe_set_cull_mask", "probe", "layers"), &RenderingServer::reflection_probe_set_cull_mask);
ClassDB::bind_method(D_METHOD("reflection_probe_set_reflection_mask", "probe", "layers"), &RenderingServer::reflection_probe_set_reflection_mask);
ClassDB::bind_method(D_METHOD("reflection_probe_set_resolution", "probe", "resolution"), &RenderingServer::reflection_probe_set_resolution);
ClassDB::bind_method(D_METHOD("reflection_probe_set_lod_threshold", "probe", "pixels"), &RenderingServer::reflection_probe_set_lod_threshold);

Expand Down
1 change: 1 addition & 0 deletions servers/rendering_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ class RenderingServer : public Object {
virtual void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) = 0;
virtual void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) = 0;
virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) = 0;
virtual void reflection_probe_set_reflection_mask(RID p_probe, uint32_t p_layers) = 0;
virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution) = 0;
virtual void reflection_probe_set_lod_threshold(RID p_probe, float p_pixels) = 0;

Expand Down