Skip to content

Commit

Permalink
Merge pull request #58100 from Calinou/environment-clamp-sky-contribu…
Browse files Browse the repository at this point in the history
…tion

Clamp environment light sky contribution to the [0.0; 1.0] range
  • Loading branch information
akien-mga authored Feb 15, 2022
2 parents d02db63 + c10e97b commit b3507ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doc/classes/Environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
The ambient light's energy. The higher the value, the stronger the light.
</member>
<member name="ambient_light_sky_contribution" type="float" setter="set_ambient_light_sky_contribution" getter="get_ambient_light_sky_contribution" default="1.0">
Defines the amount of light that the sky brings on the scene. A value of 0 means that the sky's light emission has no effect on the scene illumination, thus all ambient illumination is provided by the ambient light. On the contrary, a value of 1 means that all the light that affects the scene is provided by the sky, thus the ambient light parameter has no effect on the scene.
Defines the amount of light that the sky brings on the scene. A value of [code]0.0[/code] means that the sky's light emission has no effect on the scene illumination, thus all ambient illumination is provided by the ambient light. On the contrary, a value of [code]1.0[/code] means that [i]all[/i] the light that affects the scene is provided by the sky, thus the ambient light parameter has no effect on the scene.
[b]Note:[/b] [member ambient_light_sky_contribution] is internally clamped between [code]0.0[/code] and [code]1.0[/code] (inclusive).
</member>
<member name="ambient_light_source" type="int" setter="set_ambient_source" getter="get_ambient_source" enum="Environment.AmbientSource" default="0">
</member>
Expand Down
4 changes: 3 additions & 1 deletion scene/resources/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ float Environment::get_ambient_light_energy() const {
}

void Environment::set_ambient_light_sky_contribution(float p_ratio) {
ambient_sky_contribution = p_ratio;
// Sky contribution values outside the [0.0; 1.0] range don't make sense and
// can result in negative colors.
ambient_sky_contribution = CLAMP(p_ratio, 0.0, 1.0);
_update_ambient_light();
}

Expand Down

0 comments on commit b3507ab

Please sign in to comment.