Splitting a texture into multiple materials

Godot Version

4.3.stable

Question

How can I use GDscript to create multiple materials using different regions of a texture? I tried creating an AtlasTexture but that doesn't seem to work with meshes for some reason and I found bug reports lamenting that fact, so I'm not sure how to move forward

What exactly you’re trying to do? Describe in more detail.

I am trying to split a single texture into several individual textures to apply as materials to multiple surfaces of a 3D mesh

Applying the texture as a whole as a material is working fine, but I can’t figure out how to only use a specific region of the texture for each material

No, that’s your attempted solution. What’s the actual goal? What are you making?

I am trying to make a plugin that is essentially a 3D equivalent of a NinePatchRect. I’ve got the mesh generation part pretty much down, so now I’m trying to figure out how to use a single texture for the whole thing rather than 9 individual files

Just generate UVs that utilize only a part of the whole texture.

1 Like

That leads to issues with tiling

You’ll need to be more specific.

If each part of the mesh uses only a portion of the whole UV space, it’ll be exactly as if each part is having its own texture assigned.

You can do a lot of stuff with clever manipulation of UVs.

1 Like

Based on your suggestion I simply shrank the UV coordinate numbers, which works fine if each tile is 1x1. However, if I make the tiles each 2x2 then I either A) stretch the texture to fill it (which isn’t what I want) or B) don’t do that, which normally means it tiles as with any small texture on a mesh, but it shows the rest of the texture when tiling

Can you post some images of what you’re having vs what you actually want?

Here is my base image

template_texture

Here is how my mesh generates currently, with each surface using the same texture

My GOAL is for each of those 9 surfaces to instead be the corresponding sections of the base image

If I change the UV map to values of .3 instead of 1 for every surface, I get this result, which looks perfect aside from the fact I’ll need to vary that for each surface to get the correct texture

HOWEVER. That method doesn’t work when relying on tiling

For reference, here is it being stretched and tiling normally

Why just not do it with a shader?

1 Like