Godot 4
I have a 3d model that is already uv wrapped and painted with Blender.
In Godot. How can I use multiple texture images in one mesh, like in layers?
Also, how can I change the color in certain parts of the textures with code?
Godot 4
I have a 3d model that is already uv wrapped and painted with Blender.
In Godot. How can I use multiple texture images in one mesh, like in layers?
Also, how can I change the color in certain parts of the textures with code?
Maybe you want to assign multiple materials to the mesh in blender, then Godot can override each material individually. This allows you to set separate textures/materials for certain faces of the mesh.
If it’s just for layering textures you can try the “Next pass” parameter in the standard material 3D, though the textures will need to be transparent and/or set to blend mode “Add”/“Multiply”/“Subtract” to be useful.
You may have to delve into custom shaders. Shouldn’t be too difficult though. With the method above you can set some passes to use vertex coloring.
Basically i’m making a character similar to the furby toy. It has a base color texture for the body and feet, then on top of that it has another transparent texture that adds details like ear details and a belly color, and then more images for the eyes and mouth so i can animate them by moving the uvs. The thing is that all of that are in one material. So that’s what i wonder if it’s possible to export the model and use layered texture images.
Yes! I’ve seen some methods but they were only for the whole model in general or for 2d characters, not in specific parts of the image textures for 3d models.
Might be better off separating the materials to selected faces. Overlaying an entire texture for just detail parts sounds more expensive and potentially complicating. In blender select the object, add more materials, then in edit mode you can select faces i.e. the belly, select the material then click assign.
For moving the eyes/eye UVs I would again use a separate material and then try overriding that with a custom shader material.
oh okay! so should i separate the ears and the other parts that have overlaying parts in a separate sheet?
and yeah, the eyes are a separate material, they are in a duplicated part of the model. maybe I should do the same for the belly and ears
In blender they do not have to be separated meshes, Godot will import separate materials and allow “Surface Material Override” to have overrides per material in blender.
Very good! The face/eyes also do not need to be a separate mesh, though I understand if you’d like to do that. You will not need a custom shader, godot’s standard material can alter UV coordinates like that without a custom shader, you will have to do a little math when switching faces.
Sample of a 2x4 scaled grid like in the tutorial
With these settings we could use this function to set which face
@export var mat: StandardMaterial3D
func pick_face(x: int, y: int) -> void:
mat.uv1_offset = Vector3(0.5 * x, 0.25 * y, 0)
pick_face(0, 0) # top left
pick_face(0, 1) # below top left
oh that’s amazing! For the custom colors i’ll try to search for shader tutorials.
i’m not into that part yet, i’m still learning gdscript, and i barely know about gdscript lol.
But still, thank you so much for all the help so far! this is actually the first time i post in the forum and i feel so happy that i got answers for these doubts
For custom colors you might also be able to get away with changing the albedo
and using a bright base texture, this will modulate the texture
to what ever color you like over the entire material. If for example you are using this for fur, it would change the color of all fur. For the belly, entire color of the belly. If you wanted spots of color, or only in certain tufts of fur then this one trick will not work on it’s own.
Also if you like, search for this plugin from the AssetLib, I love it for making fur
Oh okok but does it work for certain parts? Because, as you can see here, the ears, body and feet are all in one image.
And for the eyes animation, is it possible to change the image texture in an animation? because i want to add more eye variants even after i have some in one image. Because I don’t want to make the image too big.
Yes the assigned material will still use the UVs they are given, even with the same image. If you were to use white feet/antenna textures then the material’s Albedo could determine it’s color dynamically
Hello! I could change the colors of both the textures and base colors, but i can’t get to change it via code. The editor doesn’t get an error at all.
Node layout:
Script:
The result:
Also, how do you do the same but with the next pass materials?
Oh wait, i think it’s because i directly imported it from the .blend file instead of a .glb file. Maybe that’s the issue?
I used the surface material overrides personally
@export var colorized_mesh: MeshInstance3D
func set_color(color: Color) -> void:
var mat: StandardMaterial3D = colorized_mesh.get("surface_material_override/0")
mat.albedo_color = color
This does mean that I had to add a override material, but I can tell which slot it is in. get_active_material
seems to go through a couple options, 5 might not be what you expect.
Ooh okok so for the rest of the body parts should i copy and paste that code? What about the next passes?
I don’t think you will need next passes, but they can be accessed easily too mat.next_pass
Ooh okok thank you so much! I wanted to also use the next passes because I did what you told me about the layered texture on top of the base color, it worked perfectly! I only have to change the image color to white so I can use the albedo properly.
I have one last doubt tho, how do you change the texture image of a material in the animation player? I want to make more eye variations in animations but i have to use more images to do so, i can duplicate the eye mesh and asign the new textures, then use shape keys to change them.
But i wanted to know if it’s possible using just the animation player or maybe i can use the image sequence node in blender.
You should use the AnimationPlayer, I do not believe blender’s image sequences are support as a GLTF export nor Godot import.
We talked about a uv-based solution here, to use this in the animation player you would need to key the uv1_offset
, but it will try to interpolate the offset by default, so make sure the animation tracks are set to Discrete
Oh yeah yeah, what i mean is if there’s a possibility to change the image texture with another one using the animation player but also using the uv_offset like you said.
Like for example image1 has only normal eyes (with a blink uv and looking at 4 directions), but i want to change it to image2 that has sad or angry eyes that also has looking variations.
Sorry for the bad drawing, i’m on my phone right now lol