0 votes

I'd like to be able to use the same material on a bunch of different objects, but be able to animate textures on the objects independently by manipulating the UVs of the mesh. The only way I can find to alter the UVs is to change them in the material properties, which means that every object using that material will have its UVs distorted in the same way.

I'd prefer to avoid having a whole bunch of instances of the same material because as I understand it that can lead to less than optimal draw calls.

Is it possible to animate the UV coordinates in the vertex data of the mesh itself?

in Engine by (29 points)

Animated textures are often done via fragment shaders.
There are is a "shader_material" demo for 2.1 unsure if somebody has already ported the demo to 3.0 beta.

That's exactly what I don't want.

Say I have a material with a texture that looks like:


And I have two objects using the same material. Object 1's UVs are set up so that only A is shown. Object 2's UVs are set so that only B is shown. I want to be able to move Object 1's UVs so that X is shown without Object 2's UVs moving, and without creating a new instance of the material.

Pseudo-code would be something like

if state = someState:
    for vertex in Object_1:
        vertex.uv.y = vertex.uv.y - 1

This sounds difficult, without making a new instance.

I just tried the "shader-method" in the editor. UVs (or other shader parameters) only works inidividually when the mesh is a new instance (= "make unique" in the editor) and the material is a new instance ("make unique" again). So just the shader stays the same (parametrized via the materials parameters).

Back to your last question. Yes, you should be able to to change the UV-Mapping in a mesh. This should be possible via the MeshDataTool with the method setvertexuv2. (You init an Instance of MeshDataTool with the method createfromsurface. You get the mesh with get_mesh() from the MeshInstance.

If you change the mesh, then it would be for every node which uses the same instance.

I think that you HAVE to have an own instance for each mesh which is animated individually. Personally, I see no other possibility. But perhaps someone else has a better idea...

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.