Merge pull request #58298 from Calinou/decal-distance-fade-use-easing

This commit is contained in:
Rémi Verschelde 2022-05-04 21:50:20 +02:00 committed by GitHub
commit c114823471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3735,12 +3735,13 @@ void RendererSceneRenderRD::_setup_decals(const PagedArray<RID> &p_decals, const
float fade = 1.0; float fade = 1.0;
if (texture_storage->decal_is_distance_fade_enabled(decal)) { if (texture_storage->decal_is_distance_fade_enabled(decal)) {
real_t distance = -p_camera_inverse_xform.xform(xform.origin).z; const real_t distance = -p_camera_inverse_xform.xform(xform.origin).z;
float fade_begin = texture_storage->decal_get_distance_fade_begin(decal); const float fade_begin = texture_storage->decal_get_distance_fade_begin(decal);
float fade_length = texture_storage->decal_get_distance_fade_length(decal); const float fade_length = texture_storage->decal_get_distance_fade_length(decal);
if (distance > fade_begin) { 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);
} }
} }