diff options
-rw-r--r-- | doc/classes/BaseMaterial3D.xml | 1 | ||||
-rw-r--r-- | scene/resources/material.cpp | 13 |
2 files changed, 13 insertions, 1 deletions
diff --git a/doc/classes/BaseMaterial3D.xml b/doc/classes/BaseMaterial3D.xml index a9c6030809..d3ae85101d 100644 --- a/doc/classes/BaseMaterial3D.xml +++ b/doc/classes/BaseMaterial3D.xml @@ -359,6 +359,7 @@ </member> <member name="texture_filter" type="int" setter="set_texture_filter" getter="get_texture_filter" enum="BaseMaterial3D.TextureFilter" default="3"> Filter flags for the texture. See [enum TextureFilter] for options. + [b]Note:[/b] [member heightmap_texture] is always sampled with linear filtering, even if nearest-neighbor filtering is selected here. This is to ensure the heightmap effect looks as intended. If you need sharper height transitions between pixels, resize the heightmap texture in an image editor with nearest-neighbor filtering. </member> <member name="texture_repeat" type="bool" setter="set_flag" getter="get_flag" default="true"> Repeat flags for the texture. See [enum TextureFilter] for options. diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index fb50b2d779..b88817782d 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -472,24 +472,33 @@ void BaseMaterial3D::_update_shader() { } String texfilter_str; + // Force linear filtering for the heightmap texture, as the heightmap effect + // looks broken with nearest-neighbor filtering (with and without Deep Parallax). + String texfilter_height_str; switch (texture_filter) { case TEXTURE_FILTER_NEAREST: texfilter_str = "filter_nearest"; + texfilter_height_str = "filter_linear"; break; case TEXTURE_FILTER_LINEAR: texfilter_str = "filter_linear"; + texfilter_height_str = "filter_linear"; break; case TEXTURE_FILTER_NEAREST_WITH_MIPMAPS: texfilter_str = "filter_nearest_mipmap"; + texfilter_height_str = "filter_linear_mipmap"; break; case TEXTURE_FILTER_LINEAR_WITH_MIPMAPS: texfilter_str = "filter_linear_mipmap"; + texfilter_height_str = "filter_linear_mipmap"; break; case TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC: texfilter_str = "filter_nearest_mipmap_anisotropic"; + texfilter_height_str = "filter_linear_mipmap_anisotropic"; break; case TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC: texfilter_str = "filter_linear_mipmap_anisotropic"; + texfilter_height_str = "filter_linear_mipmap_anisotropic"; break; case TEXTURE_FILTER_MAX: break; // Internal value, skip. @@ -497,8 +506,10 @@ void BaseMaterial3D::_update_shader() { if (flags[FLAG_USE_TEXTURE_REPEAT]) { texfilter_str += ",repeat_enable"; + texfilter_height_str += ",repeat_enable"; } else { texfilter_str += ",repeat_disable"; + texfilter_height_str += ",repeat_disable"; } //must create a shader! @@ -763,7 +774,7 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_HEIGHT_MAPPING]) { - code += "uniform sampler2D texture_heightmap : hint_default_black," + texfilter_str + ";\n"; + code += "uniform sampler2D texture_heightmap : hint_default_black," + texfilter_height_str + ";\n"; code += "uniform float heightmap_scale;\n"; code += "uniform int heightmap_min_layers;\n"; code += "uniform int heightmap_max_layers;\n"; |