Is it possible to manipulate a mesh's UVs in the mesh data, not the material?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DKesserich
:warning: Old Version Published before Godot 3 was released.

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?

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.

wombatstampede | 2018-01-12 15:07

That’s exactly what I don’t want.

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

AB
XY

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

DKesserich | 2018-01-13 21:11

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 set_vertex_uv2. (You init an Instance of MeshDataTool with the method create_from_surface. You get the mesh with get_mesh() from the MeshInstance.

!!But:
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…

wombatstampede | 2018-01-14 15:25