Fix several Material texture parameter updates #84303
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resource_local_to_scene
causes emission materials to break visuals of MeshInstance3D half the time #83190Fixes the issues when assigning or initializing a null/default texture to certain material properties doesn't properly update the material state. This can happen in normal use when updating textures in code, but usually this is more noticeable when duplicating a material either explicitly by calling duplicate() or indirectly during instantiation if the material has
Local To Scene
enabled. This bug causes certain empty textures in a material to be initialized incorrectly. Seems like at least emission, back light and height mapping textures are most affected as they usehint_default_black
fallback.I also noticed possible issues in particle process material, so this fix may also affect particle system behavior in certain situations. In normal materials this bug is usually obvious and can be worked around as discussed in the issue reports, but with particle systems the change in behavior might not be immediately clear.
The basic problem is that calling
RenderingServer::material_set_param()
with aVariant::Type::NIL
parameter value will result in different behavior compared to using a zero/null RID. Only a NIL Variant will clear the internal material parameter inside the MaterialStorage:godot/servers/rendering/renderer_rd/storage_rd/material_storage.cpp
Lines 2142 to 2147 in 6afd320
Many places already correctly use the NIL Variant, so I changed all obvious places I could find in this PR. Another alternative is to change
MaterialStorage::material_set_param()
to clear the material (texture) property also when using an empty RID. However, as that API is exposed to scripting it would change existing behavior, although I doubt many people are relying on that behavior and if they are their code is probably buggy in a similar way.