1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

Added material_overlay property to MeshInstance

Applying overlay materials into multi-surface meshes currently
requires adding a next pass material to all the surfaces, which
might be cumbersome when the material is to be applied to a range
of different geometries. This also makes it not trivial to use
AnimationPlayer to control the material in case of visual effects.
The material_override property is not an option as it works
replacing the active material for the surfaces, not adding a new pass.

This commit adds the material_overlay property to GeometryInstance
(and therefore MeshInstance), having the same reach as
material_override (that is, all surfaces) but adding a new material
pass on top of the active materials, instead of replacing them.

Implemented in rasterizer of both GLES2 and GLES3.
This commit is contained in:
Fernando Cosentino
2021-07-24 21:45:51 +01:00
parent 3ac698750b
commit cc8846bef6
17 changed files with 124 additions and 0 deletions

View File

@@ -1520,6 +1520,20 @@ void VisualServerScene::instance_geometry_set_material_override(RID p_instance,
VSG::storage->material_add_instance_owner(instance->material_override, instance);
}
}
void VisualServerScene::instance_geometry_set_material_overlay(RID p_instance, RID p_material) {
Instance *instance = instance_owner.get(p_instance);
ERR_FAIL_COND(!instance);
if (instance->material_overlay.is_valid()) {
VSG::storage->material_remove_instance_owner(instance->material_overlay, instance);
}
instance->material_overlay = p_material;
instance->base_changed(false, true);
if (instance->material_overlay.is_valid()) {
VSG::storage->material_add_instance_owner(instance->material_overlay, instance);
}
}
void VisualServerScene::instance_geometry_set_draw_range(RID p_instance, float p_min, float p_max, float p_min_margin, float p_max_margin) {
}
@@ -3988,6 +4002,11 @@ void VisualServerScene::_update_dirty_instance(Instance *p_instance) {
}
}
if (p_instance->material_overlay.is_valid()) {
can_cast_shadows = can_cast_shadows || VSG::storage->material_casts_shadows(p_instance->material_overlay);
is_animated = is_animated || VSG::storage->material_is_animated(p_instance->material_overlay);
}
if (can_cast_shadows != geom->can_cast_shadows) {
//ability to cast shadows change, let lights now
for (List<Instance *>::Element *E = geom->lighting.front(); E; E = E->next()) {
@@ -4057,6 +4076,7 @@ bool VisualServerScene::free(RID p_rid) {
instance_set_scenario(p_rid, RID());
instance_set_base(p_rid, RID());
instance_geometry_set_material_override(p_rid, RID());
instance_geometry_set_material_overlay(p_rid, RID());
instance_attach_skeleton(p_rid, RID());
update_dirty_instances(); //in case something changed this