Describe the project you are working on:
City builder
Describe the problem or limitation you are having in your project:
I am using multimeshes to render many city objects at once, such as road elements or buildings. When the player uses a tool to interact with the game, the game needs to show a preview of their actions, for ex. if the player builds a rood, the game needs to show a preview of the road while the user drags the mouse until the user releases it. I would like to highlight the road in red or yellow depending if the preview is considered succesful or not as a visual hint to the player. I would like to do that by rendering the previewed objects as multimeshe instances, but pass them custom parameters to highlight them.
As far as I can tell there's no way to do that today if the multimesh uses surfaces which are SpatialMaterial, which it will if the rendered objects are imported from collada exports.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
A possible way to overcome the limitation would be that Multimesh.SetInstanceColor is used as a multiplier for each fragment when used with a SpatialMaterial.
Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
See above
If this enhancement will not be used often, can it be worked around with a few lines of script?:
The current workaround is as follows:
a) take the SpatialMaterial, convert it to a ShaderMaterial
b) change the ShaderMaterial to make it process INSTANCE_CUSTOM_DATA as highlight
c) use Multimesh.SetInstanceCustomData to highlight selected multimeshes
The most inconvenient thing about this workflow is that it requires to re execute steps a) and b) whenver the material is changed using an external editor. I am open to other suggestions.
Is there a reason why this should be core and not an add-on in the asset library?:
This is a minor enhancement to existing concepts; I do not think it makes sense to develop it as add-on.
The a)b)c) workflow is pretty much what you'd have to do for a custom effect, because a MultiMesh can only have one material and you are the one to define how the highight looks like. That is, if you still want to use a MultiMeshInstance. Also you don't need an external editor, not sure where you saw that.
What you can do otherwise, is to remove the highlighted instance from the multimesh, and instance a regular MeshInstance in its place (or move it to another multimesh), with whatever options you need. This is relatively normal given the uses those nodes were made for: plenty of similar things, and one with particular visual.
A last thing your proposal seems to ask for, is the ability to override the material of a particular item in your MultiMeshInstance. I don't know what this would entail for the renderer, but in userland it would pretty much be down to the same thing I explained above. My opinion is that something like this doesn't need to be core because it can be solved with a bit of code.
A possible way to overcome the limitation would be that Multimesh.SetInstanceColor is used as a multiplier for each fragment when used with a SpatialMaterial.
That looks more likely to be available in SpatialMaterial. In fact, it is already possible according to the docs:
For the color to take effect, ensure that color_format is non-null on the MultiMesh and SpatialMaterial.vertex_color_use_as_albedo is true on the material.
Thank you for your answer.
That looks more likely to be available in SpatialMaterial. In fact, it is already possible according to the docs.
Right. I had seen this but I didn't use it properly. Going back to this it looks like it's exactly what I need. Awesome!
Also you don't need an external editor, not sure where you saw that.
What I mean is that if I change the material out of bend, using blender, I need to reapply steps a)b)c).
What you can do otherwise, is to remove the highlighted instance from the multimesh, and instance a regular MeshInstance in its place (or move it to another multimesh), with whatever options you need. This is relatively normal given the uses those nodes were made for: plenty of similar things, and one with particular visual.
Yes, I am currently exploring this path. This sounds like a way to go if I want more elaborate effects than vertex_color_use_as_albedo.
A last thing your proposal seems to ask for, is the ability to override the material of a particular item in your MultiMeshInstance.
To be precise I am not asking to override the material of a particular item; as far as I understand this would not be possible as all items need to use the same material given that a MultiMeshInstance uses a single draw call. But it could be powerful if the custom data that could be passed to MultiMeshInstance ShaderMaterials were a bit more flexible. Although at this point I have no specific need for that.
Thank you for the prompt and useful response; I'll close this seeing as I am able to unblock myself leveraging existing features.
Most helpful comment
The a)b)c) workflow is pretty much what you'd have to do for a custom effect, because a
MultiMeshcan only have one material and you are the one to define how the highight looks like. That is, if you still want to use aMultiMeshInstance. Also you don't need an external editor, not sure where you saw that.What you can do otherwise, is to remove the highlighted instance from the multimesh, and instance a regular
MeshInstancein its place (or move it to another multimesh), with whatever options you need. This is relatively normal given the uses those nodes were made for: plenty of similar things, and one with particular visual.A last thing your proposal seems to ask for, is the ability to override the material of a particular item in your
MultiMeshInstance. I don't know what this would entail for the renderer, but in userland it would pretty much be down to the same thing I explained above. My opinion is that something like this doesn't need to be core because it can be solved with a bit of code.That looks more likely to be available in
SpatialMaterial. In fact, it is already possible according to the docs: