diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-05-04 21:50:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-04 21:50:20 +0200 |
commit | c11482347133ac093899d39e5cb2d3221e9a4486 (patch) | |
tree | f295b5117c051e2b966440e9f474903594eef32b | |
parent | d38d05c29818166cfb4aabae9cfa43fdadf50c11 (diff) | |
parent | 618c88c71b842730a93d3e416b787cd265f09d96 (diff) |
Merge pull request #58298 from Calinou/decal-distance-fade-use-easing
-rw-r--r-- | servers/rendering/renderer_rd/renderer_scene_render_rd.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 7f874fc2ef..bf65dca56a 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -3735,12 +3735,13 @@ void RendererSceneRenderRD::_setup_decals(const PagedArray<RID> &p_decals, const float fade = 1.0; if (texture_storage->decal_is_distance_fade_enabled(decal)) { - real_t distance = -p_camera_inverse_xform.xform(xform.origin).z; - float fade_begin = texture_storage->decal_get_distance_fade_begin(decal); - float fade_length = texture_storage->decal_get_distance_fade_length(decal); + const real_t distance = -p_camera_inverse_xform.xform(xform.origin).z; + const float fade_begin = texture_storage->decal_get_distance_fade_begin(decal); + const float fade_length = texture_storage->decal_get_distance_fade_length(decal); if (distance > fade_begin) { - fade = 1.0 - (distance - fade_begin) / fade_length; + // Use `smoothstep()` to make opacity changes more gradual and less noticeable to the player. + fade = Math::smoothstep(0.0f, 1.0f, 1.0f - float(distance - fade_begin) / fade_length); } } |