Skip to content
Open
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
7 changes: 7 additions & 0 deletions doc/classes/Light3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
[b]Note:[/b] Unlike [BaseMaterial3D] whose filter mode can be adjusted on a per-material basis, the filter mode for light projector textures is set globally with [member ProjectSettings.rendering/textures/light_projectors/filter].
[b]Note:[/b] Light projector textures are only supported in the Forward+ and Mobile rendering methods, not Compatibility.
</member>
<member name="light_projector_offset" type="Vector2" setter="set_projector_offset" getter="get_projector_offset" default="Vector2(0, 0)">
Comment thread
TheMagnat marked this conversation as resolved.
Resolved
Positional offset of the projector texture in local space to the directional light, specifically the [code]x[/code] and [code]y[/code] components, so to translate a worldspace position to a offset position would be to convert it to local space of the directional light and take the [code]x[/code] and [code]y[/code].
</member>
<member name="light_projector_repeat" type="bool" setter="set_projector_repeat" getter="get_projector_repeat" default="true">
</member>
<member name="light_projector_size" type="Vector2" setter="set_projector_size" getter="get_projector_size" default="Vector2(100, 100)">
</member>
<member name="light_size" type="float" setter="set_param" getter="get_param" default="0.0" keywords="pcss">
The simulated size of the light in Godot units, affecting shading and shadows. For [OmniLight3D]s and [SpotLight3D]s, increasing this value simulates a spherical area light, expanding the size of specular highlights. If shadows are enabled, a penumbra is rendered, making shadows appear blurrier. For [AreaLight3D]s, only the shadows are affected. Penumbras are simulated with percentage-closer soft shadows, or PCSS, which has a noticeable performance cost for values above [code]0.0[/code].
[b]Note:[/b] [member light_size] is not affected by [member Node3D.scale] (the light's scale or its parent's scale).
Expand Down
31 changes: 25 additions & 6 deletions drivers/gles3/storage/light_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,37 @@ void LightStorage::light_set_projector(RID p_light, RID p_texture) {
return;
}

if (light->type != RSE::LIGHT_DIRECTIONAL && light->projector.is_valid()) {
if (light->projector.is_valid()) {
texture_storage->texture_remove_from_decal_atlas(light->projector, light->type == RSE::LIGHT_OMNI);
}

light->projector = p_texture;

if (light->type != RSE::LIGHT_DIRECTIONAL) {
if (light->projector.is_valid()) {
texture_storage->texture_add_to_decal_atlas(light->projector, light->type == RSE::LIGHT_OMNI);
}
light->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_LIGHT_SOFT_SHADOW_AND_PROJECTOR);
if (light->projector.is_valid()) {
texture_storage->texture_add_to_decal_atlas(light->projector, light->type == RSE::LIGHT_OMNI);
}
light->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_LIGHT_SOFT_SHADOW_AND_PROJECTOR);
}

void LightStorage::light_set_projector_size(RID p_light, const Vector2 &p_size) {
Light *light = light_owner.get_or_null(p_light);
ERR_FAIL_NULL(light);

light->projector_size = p_size;
}

void LightStorage::light_set_projector_offset(RID p_light, const Vector2 &p_offset) {
Light *light = light_owner.get_or_null(p_light);
ERR_FAIL_NULL(light);

light->projector_offset = p_offset;
}

void LightStorage::light_set_projector_repeat(RID p_light, bool p_repeat) {
Light *light = light_owner.get_or_null(p_light);
ERR_FAIL_NULL(light);

light->projector_repeat = p_repeat;
}

void LightStorage::light_set_negative(RID p_light, bool p_enable) {
Expand Down
6 changes: 6 additions & 0 deletions drivers/gles3/storage/light_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ struct Light {
float param[RSE::LIGHT_PARAM_MAX];
Color color = Color(1, 1, 1, 1);
RID projector;
Vector2 projector_size;
Vector2 projector_offset;
bool projector_repeat = true;
bool shadow = false;
bool negative = false;
bool reverse_cull = false;
Expand Down Expand Up @@ -329,6 +332,9 @@ class LightStorage : public RendererLightStorage {
virtual void light_set_param(RID p_light, RSE::LightParam p_param, float p_value) override;
virtual void light_set_shadow(RID p_light, bool p_enabled) override;
virtual void light_set_projector(RID p_light, RID p_texture) override;
virtual void light_set_projector_size(RID p_light, const Vector2 &p_size) override;
virtual void light_set_projector_offset(RID p_light, const Vector2 &p_offset) override;
virtual void light_set_projector_repeat(RID p_light, bool p_repeat) override;
virtual void light_set_negative(RID p_light, bool p_enable) override;
virtual void light_set_cull_mask(RID p_light, uint32_t p_mask) override;
virtual void light_set_distance_fade(RID p_light, bool p_enabled, float p_begin, float p_shadow, float p_length) override;
Expand Down
80 changes: 55 additions & 25 deletions scene/3d/light_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ PackedStringArray Light3D::get_configuration_warnings() const {
warnings.push_back(RTR("A light's scale does not affect the visual size of the light."));
}

if (!has_shadow() && get_projector().is_valid()) {
warnings.push_back(RTR("Projector texture only works with shadows active."));
}

if (get_projector().is_valid() && (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" || OS::get_singleton()->get_current_rendering_method() == "dummy")) {
warnings.push_back(RTR("Projector textures are not supported when using the Compatibility renderer yet. Support will be added in a future release."));
}

return warnings;
}

Expand Down Expand Up @@ -243,6 +251,33 @@ Ref<Texture2D> Light3D::get_projector() const {
return projector;
}

void Light3D::set_projector_size(const Vector2 &p_size) {
projector_size = p_size;
RS::get_singleton()->light_set_projector_size(light, p_size);
}

Vector2 Light3D::get_projector_size() const {
return projector_size;
}

void Light3D::set_projector_offset(const Vector2 &p_offset) {
projector_offset = p_offset;
RS::get_singleton()->light_set_projector_offset(light, p_offset);
}

Vector2 Light3D::get_projector_offset() const {
return projector_offset;
}

void Light3D::set_projector_repeat(bool p_repeat) {
projector_repeat = p_repeat;
RS::get_singleton()->light_set_projector_repeat(light, p_repeat);
}

bool Light3D::get_projector_repeat() const {
return projector_repeat;
}

void Light3D::owner_changed_notify() {
// For cases where owner changes _after_ entering tree (as example, editor editing).
_update_visibility();
Expand Down Expand Up @@ -344,8 +379,8 @@ bool Light3D::is_editor_only() const {
}

void Light3D::_validate_property(PropertyInfo &p_property) const {
if (get_light_type() != RSE::LIGHT_DIRECTIONAL && (p_property.name == "light_angular_distance" || p_property.name == "light_intensity_lux")) {
// Angular distance and Light Intensity Lux are only used in DirectionalLight3D.
if (get_light_type() != RSE::LIGHT_DIRECTIONAL && (p_property.name == "light_angular_distance" || p_property.name == "light_intensity_lux" || p_property.name == "Projector" || p_property.name == "light_projector_size" || p_property.name == "light_projector_offset" || p_property.name == "light_projector_repeat")) {
// Angular distance, Light Intensity Lux and Projector Subgroup/Size/Offset/Repeat are only used in DirectionalLight3D.
p_property.usage = PROPERTY_USAGE_NONE;
} else if (get_light_type() == RSE::LIGHT_DIRECTIONAL && p_property.name == "light_intensity_lumens") {
p_property.usage = PROPERTY_USAGE_NONE;
Expand Down Expand Up @@ -405,6 +440,15 @@ void Light3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_projector", "projector"), &Light3D::set_projector);
ClassDB::bind_method(D_METHOD("get_projector"), &Light3D::get_projector);

ClassDB::bind_method(D_METHOD("set_projector_size", "size"), &Light3D::set_projector_size);
ClassDB::bind_method(D_METHOD("get_projector_size"), &Light3D::get_projector_size);

ClassDB::bind_method(D_METHOD("set_projector_offset", "offset"), &Light3D::set_projector_offset);
ClassDB::bind_method(D_METHOD("get_projector_offset"), &Light3D::get_projector_offset);

ClassDB::bind_method(D_METHOD("set_projector_repeat", "repeat"), &Light3D::set_projector_repeat);
ClassDB::bind_method(D_METHOD("get_projector_repeat"), &Light3D::get_projector_repeat);

ClassDB::bind_method(D_METHOD("set_temperature", "temperature"), &Light3D::set_temperature);
ClassDB::bind_method(D_METHOD("get_temperature"), &Light3D::get_temperature);
ClassDB::bind_method(D_METHOD("get_correlated_color"), &Light3D::get_correlated_color);
Expand All @@ -417,8 +461,15 @@ void Light3D::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_energy", PROPERTY_HINT_RANGE, "0,16,0.001,or_greater"), "set_param", "get_param", PARAM_ENERGY);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_indirect_energy", PROPERTY_HINT_RANGE, "0,16,0.001,or_greater"), "set_param", "get_param", PARAM_INDIRECT_ENERGY);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_volumetric_fog_energy", PROPERTY_HINT_RANGE, "0,16,0.001,or_greater"), "set_param", "get_param", PARAM_VOLUMETRIC_FOG_ENERGY);

// Only allow texture types that display correctly.
ADD_SUBGROUP("Projector", "light_projector_");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "light_projector", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D,-AnimatedTexture,-AtlasTexture,-CameraTexture,-CanvasTexture,-MeshTexture,-Texture2DRD,-ViewportTexture"), "set_projector", "get_projector");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "light_projector_size", PROPERTY_HINT_LINK, "suffix:m"), "set_projector_size", "get_projector_size");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "light_projector_offset", PROPERTY_HINT_NONE, "suffix:m"), "set_projector_offset", "get_projector_offset");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_projector_repeat"), "set_projector_repeat", "get_projector_repeat");
ADD_SUBGROUP("", "");

ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_size", PROPERTY_HINT_RANGE, "0,1,0.001,or_greater,suffix:m"), "set_param", "get_param", PARAM_SIZE);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_angular_distance", PROPERTY_HINT_RANGE, "0,90,0.01,degrees"), "set_param", "get_param", PARAM_SIZE);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "is_negative");
Expand Down Expand Up @@ -589,7 +640,7 @@ void DirectionalLight3D::_validate_property(PropertyInfo &p_property) const {
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
}
}
if (p_property.name == "light_size" || p_property.name == "light_projector") {
if (p_property.name == "light_size") {
// Not implemented in DirectionalLight3D (`light_size` is replaced by `light_angular_distance`).
p_property.usage = PROPERTY_USAGE_NONE;
} else if (p_property.name == "distance_fade_enabled" || p_property.name == "distance_fade_begin" || p_property.name == "distance_fade_shadow" || p_property.name == "distance_fade_length") {
Expand Down Expand Up @@ -641,6 +692,7 @@ DirectionalLight3D::DirectionalLight3D() :
set_shadow_mode(SHADOW_PARALLEL_4_SPLITS);
blend_splits = false;
set_sky_mode(SKY_MODE_LIGHT_AND_SKY);
set_projector_size(Vector2(100.0, 100.0));
}

void OmniLight3D::set_shadow_mode(ShadowMode p_mode) {
Expand All @@ -652,20 +704,6 @@ OmniLight3D::ShadowMode OmniLight3D::get_shadow_mode() const {
return shadow_mode;
}

PackedStringArray OmniLight3D::get_configuration_warnings() const {
PackedStringArray warnings = Light3D::get_configuration_warnings();

if (!has_shadow() && get_projector().is_valid()) {
warnings.push_back(RTR("Projector texture only works with shadows active."));
}

if (get_projector().is_valid() && (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" || OS::get_singleton()->get_current_rendering_method() == "dummy")) {
warnings.push_back(RTR("Projector textures are not supported when using the Compatibility renderer yet. Support will be added in a future release."));
}

return warnings;
}

void OmniLight3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &OmniLight3D::set_shadow_mode);
ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight3D::get_shadow_mode);
Expand All @@ -691,14 +729,6 @@ PackedStringArray SpotLight3D::get_configuration_warnings() const {
warnings.push_back(RTR("A SpotLight3D with an angle wider than 90 degrees cannot cast shadows."));
}

if (!has_shadow() && get_projector().is_valid()) {
warnings.push_back(RTR("Projector texture only works with shadows active."));
}

if (get_projector().is_valid() && (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" || OS::get_singleton()->get_current_rendering_method() == "dummy")) {
warnings.push_back(RTR("Projector textures are not supported when using the Compatibility renderer yet. Support will be added in a future release."));
}

return warnings;
}

Expand Down
14 changes: 12 additions & 2 deletions scene/3d/light_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class Light3D : public VisualInstance3D {
void _update_visibility();
BakeMode bake_mode = BAKE_DYNAMIC;
Ref<Texture2D> projector;
Vector2 projector_size;
Vector2 projector_offset;
bool projector_repeat = true;
Color correlated_color = Color(1.0, 1.0, 1.0);
float temperature = 6500.0;
bool allow_contact_shadows = true;
Expand Down Expand Up @@ -149,6 +152,15 @@ class Light3D : public VisualInstance3D {
void set_projector(const Ref<Texture2D> &p_texture);
Ref<Texture2D> get_projector() const;

void set_projector_size(const Vector2 &p_scale);
Vector2 get_projector_size() const;

void set_projector_offset(const Vector2 &p_offset);
Vector2 get_projector_offset() const;

void set_projector_repeat(bool p_repeat);
bool get_projector_repeat() const;

void set_temperature(const float p_temperature);
float get_temperature() const;
Color get_correlated_color() const;
Expand Down Expand Up @@ -224,8 +236,6 @@ class OmniLight3D : public Light3D {
void set_shadow_mode(ShadowMode p_mode);
ShadowMode get_shadow_mode() const;

PackedStringArray get_configuration_warnings() const override;

OmniLight3D();
};

Expand Down
4 changes: 4 additions & 0 deletions servers/rendering/dummy/storage/light_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class LightStorage : public RendererLightStorage {
virtual void light_set_param(RID p_light, RSE::LightParam p_param, float p_value) override {}
virtual void light_set_shadow(RID p_light, bool p_enabled) override {}
virtual void light_set_projector(RID p_light, RID p_texture) override {}
virtual void light_set_projector_size(RID p_light, const Vector2 &p_size) override {}
virtual void light_set_projector_offset(RID p_light, const Vector2 &p_offset) override {}
virtual void light_set_projector_repeat(RID p_light, bool p_repeat) override {}

virtual void light_set_negative(RID p_light, bool p_enable) override {}
virtual void light_set_cull_mask(RID p_light, uint32_t p_mask) override {}
virtual void light_set_distance_fade(RID p_light, bool p_enabled, float p_begin, float p_shadow, float p_length) override {}
Expand Down
7 changes: 5 additions & 2 deletions servers/rendering/renderer_rd/effects/copy_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ void CopyEffects::copy_depth_to_rect_and_linearize(RID p_source_rd_texture, RID
RD::get_singleton()->compute_list_end();
}

void CopyEffects::copy_to_atlas_fb(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_uv_rect, RD::DrawListID p_draw_list, bool p_flip_y, bool p_panorama) {
void CopyEffects::copy_to_atlas_fb(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_uv_rect, RD::DrawListID p_draw_list, bool p_flip_y, bool p_panorama, Vector2 uv_offset) {
UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
ERR_FAIL_NULL(uniform_set_cache);
MaterialStorage *material_storage = MaterialStorage::get_singleton();
Expand All @@ -586,8 +586,11 @@ void CopyEffects::copy_to_atlas_fb(RID p_source_rd_texture, RID p_dest_framebuff

copy_to_fb.push_constant.luminance_multiplier = 1.0;

copy_to_fb.push_constant.set_color[0] = uv_offset.x;
copy_to_fb.push_constant.set_color[1] = uv_offset.y;

// setup our uniforms
RID default_sampler = material_storage->sampler_rd_get_default(RSE::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RSE::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
RID default_sampler = material_storage->sampler_rd_get_default(RSE::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RSE::CANVAS_ITEM_TEXTURE_REPEAT_ENABLED);

RD::Uniform u_source_rd_texture(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_rd_texture }));

Expand Down
2 changes: 1 addition & 1 deletion servers/rendering/renderer_rd/effects/copy_effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class CopyEffects {
void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);
void copy_depth_to_rect_and_linearize(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y, float p_z_near, float p_z_far);
void copy_to_fb_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false, bool p_force_luminance = false, bool p_alpha_to_zero = false, bool p_srgb = false, RID p_secondary = RID(), bool p_multiview = false, bool alpha_to_one = false, bool p_linear = false, bool p_normal = false, const Rect2 &p_src_rect = Rect2(), float p_linear_luminance_multiplier = 1.0, bool p_bilinear_filtering = true);
void copy_to_atlas_fb(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_uv_rect, RD::DrawListID p_draw_list, bool p_flip_y = false, bool p_panorama = false);
void copy_to_atlas_fb(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_uv_rect, RD::DrawListID p_draw_list, bool p_flip_y = false, bool p_panorama = false, Vector2 uv_offset = Vector2());
void copy_to_drawlist(RD::DrawListID p_draw_list, RD::FramebufferFormatID p_fb_format, RID p_source_rd_texture, bool p_linear = false, float p_linear_luminance_multiplier = 1.0);
void copy_raster(RID p_source_texture, RID p_dest_framebuffer);

Expand Down
Loading
Loading