diff --git a/doc/classes/SpatialMaterial.xml b/doc/classes/SpatialMaterial.xml index e9fa25a3eb1..aeb1b052309 100644 --- a/doc/classes/SpatialMaterial.xml +++ b/doc/classes/SpatialMaterial.xml @@ -366,6 +366,7 @@ A lower number blends the texture more softly while a higher number blends the texture more sharply. + [b]Note:[/b] [member uv1_triplanar_sharpness] is clamped between [code]0.0[/code] and [code]150.0[/code] (inclusive) as values outside that range can look broken depending on the mesh. How much to offset the [code]UV2[/code] coordinates. This amount will be added to [code]UV2[/code] in the vertex function. This can be used to offset a texture. @@ -378,6 +379,7 @@ A lower number blends the texture more softly while a higher number blends the texture more sharply. + [b]Note:[/b] [member uv2_triplanar_sharpness] is clamped between [code]0.0[/code] and [code]150.0[/code] (inclusive) as values outside that range can look broken depending on the mesh. If [code]true[/code], the model's vertex colors are processed as sRGB mode. diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 2d15641aaf8..fcbfd6c0187 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -1534,8 +1534,9 @@ Vector3 SpatialMaterial::get_uv1_offset() const { } void SpatialMaterial::set_uv1_triplanar_blend_sharpness(float p_sharpness) { - uv1_triplanar_sharpness = p_sharpness; - VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_blend_sharpness, p_sharpness); + // Negative values or values higher than 150 can result in NaNs, leading to broken rendering. + uv1_triplanar_sharpness = CLAMP(p_sharpness, 0.0, 150.0); + VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_blend_sharpness, uv1_triplanar_sharpness); } float SpatialMaterial::get_uv1_triplanar_blend_sharpness() const { @@ -1561,8 +1562,9 @@ Vector3 SpatialMaterial::get_uv2_offset() const { } void SpatialMaterial::set_uv2_triplanar_blend_sharpness(float p_sharpness) { - uv2_triplanar_sharpness = p_sharpness; - VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_blend_sharpness, p_sharpness); + // Negative values or values higher than 150 can result in NaNs, leading to broken rendering. + uv2_triplanar_sharpness = CLAMP(p_sharpness, 0.0, 150.0); + VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_blend_sharpness, uv2_triplanar_sharpness); } float SpatialMaterial::get_uv2_triplanar_blend_sharpness() const {