Skip to content

Commit

Permalink
Implement per-light Specular property in DirectionalLight3D
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewShobbrook authored and Calinou committed Dec 16, 2024
1 parent 08508d2 commit e42def1
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doc/classes/Light3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
[b]Note:[/b] [member light_size] is not affected by [member Node3D.scale] (the light's scale or its parent's scale).
[b]Note:[/b] PCSS for positional lights is only supported in the Forward+ and Mobile rendering methods, not Compatibility.
</member>
<member name="light_specular" type="float" setter="set_param" getter="get_param" default="0.5">
<member name="light_specular" type="float" setter="set_param" getter="get_param" default="1.0">
The intensity of the specular blob in objects affected by the light. At [code]0[/code], the light becomes a pure diffuse light. When not baking emission, this can be used to avoid unrealistic reflections when placing lights above an emissive surface.
</member>
<member name="light_temperature" type="float" setter="set_temperature" getter="get_temperature">
Expand Down
1 change: 1 addition & 0 deletions doc/classes/OmniLight3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<link title="Faking global illumination">$DOCS_URL/tutorials/3d/global_illumination/faking_global_illumination.html</link>
</tutorials>
<members>
<member name="light_specular" type="float" setter="set_param" getter="get_param" overrides="Light3D" default="0.5" />
<member name="omni_attenuation" type="float" setter="set_param" getter="get_param" default="1.0">
Controls the distance attenuation function for omnilights.
A value of [code]0.0[/code] will maintain a constant brightness through most of the range, but smoothly attenuate the light at the edge of the range. Use a value of [code]2.0[/code] for physically accurate lights as it results in the proper inverse square attenutation.
Expand Down
1 change: 1 addition & 0 deletions doc/classes/SpotLight3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<link title="Third Person Shooter (TPS) Demo">https://godotengine.org/asset-library/asset/2710</link>
</tutorials>
<members>
<member name="light_specular" type="float" setter="set_param" getter="get_param" overrides="Light3D" default="0.5" />
<member name="shadow_bias" type="float" setter="set_param" getter="get_param" overrides="Light3D" default="0.03" />
<member name="shadow_normal_bias" type="float" setter="set_param" getter="get_param" overrides="Light3D" default="1.0" />
<member name="spot_angle" type="float" setter="set_param" getter="get_param" default="45.0">
Expand Down
4 changes: 2 additions & 2 deletions drivers/gles3/shaders/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ void main() {
continue;
}
#endif
light_compute(normal, normalize(directional_lights[i].direction), normalize(view), directional_lights[i].size, directional_lights[i].color * directional_lights[i].energy, true, 1.0, f0, roughness, metallic, 1.0, albedo, alpha, screen_uv,
light_compute(normal, normalize(directional_lights[i].direction), normalize(view), directional_lights[i].size, directional_lights[i].color * directional_lights[i].energy, true, 1.0, f0, roughness, metallic, directional_lights[i].specular, albedo, alpha, screen_uv,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
Expand Down Expand Up @@ -2440,7 +2440,7 @@ void main() {
#endif // SHADOWS_DISABLED

#ifndef USE_VERTEX_LIGHTING
light_compute(normal, normalize(directional_lights[directional_shadow_index].direction), normalize(view), directional_lights[directional_shadow_index].size, directional_lights[directional_shadow_index].color * directional_lights[directional_shadow_index].energy, true, directional_shadow, f0, roughness, metallic, 1.0, albedo, alpha, screen_uv,
light_compute(normal, normalize(directional_lights[directional_shadow_index].direction), normalize(view), directional_lights[directional_shadow_index].size, directional_lights[directional_shadow_index].color * directional_lights[directional_shadow_index].energy, true, directional_shadow, f0, roughness, metallic, directional_lights[directional_shadow_index].specular, albedo, alpha, screen_uv,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
Expand Down
3 changes: 2 additions & 1 deletion scene/3d/light_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,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" || p_property.name == "light_specular") {
if (p_property.name == "light_size" || p_property.name == "light_projector") {
// Not implemented in DirectionalLight3D (`light_size` is replaced by `light_angular_distance`).
p_property.usage = PROPERTY_USAGE_NONE;
}
Expand Down Expand Up @@ -595,6 +595,7 @@ DirectionalLight3D::DirectionalLight3D() :
// Increase the default shadow normal bias to better suit most scenes.
set_param(PARAM_SHADOW_NORMAL_BIAS, 2.0);
set_param(PARAM_INTENSITY, 100000.0); // Specified in Lux, approximate mid-day sun.
set_param(PARAM_SPECULAR, 1.0);
set_shadow_mode(SHADOW_PARALLEL_4_SPLITS);
blend_splits = false;
set_sky_mode(SKY_MODE_LIGHT_AND_SKY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,7 @@ void fragment_shader(in SceneData scene_data) {
#else
directional_lights.data[i].color * directional_lights.data[i].energy * tint,
#endif
true, shadow, f0, orms, 1.0, albedo, alpha, screen_uv,
true, shadow, f0, orms, directional_lights.data[i].specular, albedo, alpha, screen_uv,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ void main() {

light_compute(normal, directional_lights.data[i].direction, view, size_A,
directional_lights.data[i].color * directional_lights.data[i].energy * tint,
true, shadow, f0, orms, 1.0, albedo, alpha, screen_uv,
true, shadow, f0, orms, directional_lights.data[i].specular, albedo, alpha, screen_uv,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
Expand Down

0 comments on commit e42def1

Please sign in to comment.