Multiple UV Distinct Maps for the Same Mesh

Godot Version

4.2

Question

How can I setup multiple UV maps for the same mesh? What is the limit for distinct UV mappings in Godot 4.2?

e.g. Say I want to map my mesh to a 4k resolution texture for repeatable/tile materials it shares with other meshes (big size in memory but recycled between many meshes), and then also map it to a low resolution texture (simple graffiti) small size in memory, but unique to each mesh, meaning there will be hundreds of different textures loaded in memory (but will still not take up too much memory since each individual texture is small).

I kept looking into this on my side and ultimately found a hack / workaround for the time being. I was hoping to use a “Visual” Shader for this (which unlike a regular shader, offers a fun and tidy visual node editor similar to what you might see in the Blender modelling app).

I am not going to write a tutorial at this time, but in case anyone else needs to learn how to do this, take a look at the video and accompanying demo project in this link where they use multiple UV mappings on the same mesh inside a (non-visual) shader. They use the four available vec4 structures called CUSTOM0, CUSTOM1, CUSTOM2, and CUSTOM3 to import distinct UV mappings/channels from the modelling application (e.g. Blender). Thank you to whoever did me the favor of implementing this. The reader should open the demo project in that link and read the Shader file in order to see how it is used.

If the reader needs to learn how to create multiple UV mappings for the same mesh inside of the Blender application (which will be saved to the glTF 2.0 file and imported into Godot out of the box), I learned how to make them by watching this video.

I think the documentation is pending as of now, AND these custom channels can ONLY be accessed from the non-visual version of the Shader, which is why I struggled so much to understand how to do this and accidentally watched dozens of unrelated shader tutorials instead (I am so dull).

From Blender I think you can create up to 10 distinct UV mappings. When you import the glTF 2.0 format file, these will be assigned to the variables in the following order:

UV
UV2 (is it intended for lightmapsd?)
CUSTOM0.xy
CUSTOM0.wz
CUSTOM1.xy
CUSTOM1.wz
CUSTOM2.xy
CUSTOM2.wz
CUSTOM3.xy
CUSTOM3.wz

Each of these vec4 can fit in 2 UV mappings each, one in the xy portion, and another in the wz portion.

And I could NOT figure out how to access the CUSTOM0-3 vec4 structures via the VisualShader, if THERE IS a way to access them in Godot 4.2, I’d appreciate if someone could share how they do it. For the time being, I’ll be using the VisualShader’s non-visual preview in order to replicate VisualShader logic in the non-Visual shader (where I now know how to access the UV mappings from).

I still love this engine. Forced me to learn much more than I’d like (ew), but I am unblocked once again!