diff options
| author | Rémi Verschelde <remi@verschelde.fr> | 2021-12-02 21:11:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-02 21:11:32 +0100 |
| commit | 8f00625824169170fcbbd8b75a6f0a76551835aa (patch) | |
| tree | 9169efda1d70b338ed426a4776d76b7f1174f4eb /scene | |
| parent | 3f1a8e2f7708b6a90f888789897e959471bb42b7 (diff) | |
| parent | bad74311dbfd01359a947b3afed28f0a7a725d04 (diff) | |
| download | redot-engine-8f00625824169170fcbbd8b75a6f0a76551835aa.tar.gz | |
Merge pull request #54910 from Calinou/basematerial3d-texture-auto-roughness-metallic
Set roughness/metallic to 1 when assigning a texture in BaseMaterial3D
Diffstat (limited to 'scene')
| -rw-r--r-- | scene/resources/material.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 8399b14a56..00c109f1a6 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -1658,13 +1658,28 @@ bool BaseMaterial3D::get_feature(Feature p_feature) const { void BaseMaterial3D::set_texture(TextureParam p_param, const Ref<Texture2D> &p_texture) { ERR_FAIL_INDEX(p_param, TEXTURE_MAX); + + if (get_texture(TEXTURE_ROUGHNESS).is_null() && p_texture.is_valid() && p_param == TEXTURE_ROUGHNESS) { + // If no roughness texture is currently set, automatically set the recommended value + // for roughness when using a roughness map. + set_roughness(1.0); + } + + if (get_texture(TEXTURE_METALLIC).is_null() && p_texture.is_valid() && p_param == TEXTURE_METALLIC) { + // If no metallic texture is currently set, automatically set the recommended value + // for metallic when using a metallic map. + set_metallic(1.0); + } + textures[p_param] = p_texture; RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); RS::get_singleton()->material_set_param(_get_material(), shader_names->texture_names[p_param], rid); + if (p_texture.is_valid() && p_param == TEXTURE_ALBEDO) { RS::get_singleton()->material_set_param(_get_material(), shader_names->albedo_texture_size, Vector2i(p_texture->get_width(), p_texture->get_height())); } + notify_property_list_changed(); _queue_shader_change(); } |
