diff options
| author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-11-12 12:37:04 +0100 |
|---|---|---|
| committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-11-13 17:46:22 +0100 |
| commit | bad74311dbfd01359a947b3afed28f0a7a725d04 (patch) | |
| tree | 55e91cbbc35103b80fe08b0268c9bf2f21265f2d /scene | |
| parent | 55b49dc71b687b9edf640ae2264879852f0b0503 (diff) | |
| download | redot-engine-bad74311dbfd01359a947b3afed28f0a7a725d04.tar.gz | |
Set roughness/metallic to 1 when assigning a texture in BaseMaterial3D
This makes material setup faster and avoids mistakes, especially with
the metallic channel which defaults to 0.
The value is only changed when adding a texture when none was
previously assigned, not when assigning a different texture.
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(); } |
