MultiMeshInstance2D with a shader and a texture

Godot Version

4.4RC1

Question

I have a multimeshinstance2d with a quad mesh and a material with a canvasitem shader that just sets every fragment to magenta. the mmi also has a texture assigned to it. None of the instances uses the shader. Is this a bug?


what is a bug?
your shader does what it says. set the color to magenta.

you need to read the docs to learn how to use shaders.

and this is a multimeshinstance2D. setting the texture allows it to use a texture, but a shader overrides the material used by 2D nodes, so you need to get the texture with a sampler2D and draw it in fragment.

and I’m not sure but since multimeshinstance2D uses a common multimesh, it might use a 3D mesh (it can be seen 3D in the preview). so it needs a SPATIAL shader, not canvasItem. canvasItem is for 2D.

I am sorry but I do not think you have understood at all. I’ll try to elaborate:

As you can see in the image, the mesh instances are drawing using the texture, but not the shader. If they were drawing using the shader they would be magenta. The scene is 2D, the root node is a Node2D.

The MultiMeshInstance2D class is for 2D nodes, which use canvas item shaders. The Multimesh is set to use 2D transforms, so it is expecting a 2D mesh, which is what a QuadMesh is designed for.

I filled the 2D transform buffer with garbage as there is no editor functionality for MultiMesh2Ds that I can find. That’s why the instances are skewed and look like they might be 3D. They’re not, they’re 2D with nonsense transforms, but it is enough for them to be visible so that we can determine that they are not drawing using the assigned shader.

multimesh is a single class that is shared between 2D and 3D nodes. it works with both and probably needs a rework.

no. you used 3D meshes.
we can see in the picture that the quad is in perspective.

after some research, first:

the only way to generate a 2D mesh within the editor is by either importing an OBJ file as a mesh, or converting it from a Sprite2D.

godot does not provide 2D meshes. all the default meshes are 3D.

after some testing, the skewed shape is from using 3D meshes.
I was also unable to use a converted Sprite2D.

second:
multimeshinstance2D requires code to work. I tried setting it up without and it just doesn’t work.
MMI2D is designed to serve as a base for 2D particles. It currently has no documentation and it might be broken.

and you don’t need it.
either use particles, or use individual nodes, 2D is very fast and able to render several Sprites on screen at the same time, it might even be faster.

If you don’t know what you are talking about, please don’t clog this thread. It’s a 2D mesh. I told you that the transforms are garbage and that’s why they’re skewed. Please read things fully before responding.

It literally doesn’t matter whether the mesh is 3d or 2d because the fact is that it isn’t using the shader as is clearly obvious from the scene view.

I have a code version of this, that exhibits the same behaviour. I created this in order to have a minimum reproduction project. If it hadn’t worked by creating the resources in the editor, I would have done it with code. My first industry game programming job was in 2001.

Sorry I was grumpy, I had been knocking my head against this for a whole afternoon. What’s mad is I have another MultiMeshInstance2D that IS correctly using a shader, so I don’t know what’s going wrong there, or here, which is a fresh project.

Opened an issue: MultiMeshInstance2D fails to render with a shader · Issue #104875 · godotengine/godot · GitHub

So the issue here was me assigning the material to the Mesh and not the MultiMeshInstance2D. After doing that, it works.