Multiple textures on a mesh

Hello, sorry for the noob question.
I’m trying to make a terrain mesh with multiple textures (e.g. grass, sand, snow).
I can make a single texture mesh by doing this in draw():


Is there a way to choose which texture gets used for some mesh faces?

Hi, you can do so in a shader. Take a look at the example in examples/gl/multiTextureShaderExample
Although you’ll need to define a way for the shader to determine which texture to use.

Thank you, I will take a look at it.

I found a workaround by putting all the textures in a single file so I can choose which texture to use in a vertex by specifying the coordinates of the file in mesh.addTexCoord() .

Though I’m probably doing something wrong with this method because the blending between textures is inconsistent.

It seems like working with shaders is a better option.

you’ll have that problem with that approach if you use an indexed triangle mesh. You need to create a mesh where each triangle’s vertex is unique and not shared with any other triangle. This means that you’ll end up with a lot of vertices sitting in the exact same position, but doing it this way means that you will be able to specify texCoords for each triangle regardles of what the neighbour triangles have.