Multiple textures on one model.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Multiple textures on one model.

Post by monkeycracks »

I know this has been asked many many times before but I never really understood the answers. So how can I have multiple textures on a terrain, scene node, etc.

Please post links to articles or examples or explain it in 'lamense terms' for me if you don't mind ;)
stodge
Posts: 216
Joined: Fri Dec 05, 2003 5:57 pm

Post by stodge »

I think you mean "laymans terms".

http://en.wikipedia.org/wiki/Layman
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Surely it's simply the following:

node->setMaterialTexture(0, texture1);
node->setMaterialTexture(1, texture2);
and so on...

The first param is the layer for the texture to go on (4 allowed?) and then you just set it to the desired texture with the second param.
Image Image Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, a mesh can have only 1 texture (build out of up to 4 texture layers) !!!
If you look at a multi textured mesh you'll see that it is build out of many mesh buffers !!!
Each buffer is representing a single, one texture mesh !!!
You can iterate through the mesh buffers and get their textures by using meshbuffer->getMaterial()->Texture1 to Texture4 (the 4 texture layers)...

But I don't know how to do this with a terrain scene node !?!?!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

the vertex data needs to have texture coordinates for each stage, or number of textures on a single mesh buffer. For example, the reason detail mapping works with terrain, is because terrain uses S3DVertex2TCoords vertices.

You can get around this, at least in DirectX, by setting up the other ( 1-3)TextureStageStates to use the texture coords from texture stage 0. Not sure if it's possible in OpenGL to do that.

Terrain already supports 2 textures. Most meshes are loaded into the standard S3DVertex vertex format and only have 1 texture coordinate. I'm not sure if Irrlicht added it, but I posted somewhere on this forum, a function to convert a mesh from S3DVertex to S3DVertex2TCoords, and posted some screenshots with the sydney.md2 model with detail mapping.

If you need that function again, I can provide it for you( or IrrSpintz has it if you want to download that source and merge it into your custom Irrlicht ). Or, you could just write a custom function to do that, without modifying the Irrlicht source.
Image
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

I could never get IrrSprintz to compile, but here are some screenies of what happens when you use two different textures on the same cube node. in different layers.


layer 0, before adding in layer 1

Image

and after adding in layer 1.

Image


If I use the same texture for layer one as in layer 0 it gives the same bland look.

But still, neither of the textures are visible, and texture in layer one is just a darker version of the texture in layer 0. (in case thats important).
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

maybe I misunderstood something, but didn't you read my post ???
the texture layers have nothing to do with multi texturing !!!
They all affect just one texture by mixing the graphics several ways !!!
Have a look at the water scene node, the 1st layer (0) represents the ground and the 2nd layer (1) represents the water surface !!!

Or is this what you mean by multi texturing !?!?!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

I mean so you could texture a road or something onto a node.

TerrainNode or SceneNode it makes no difference.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

hmm, but not by using the texture layers !!!

Once again: the 4 t.layers are building one texture by mixing the layers !!!
If you need more than one texture the mesh the node is build from must contain different mesh buffers (for each texture one mesh buffer).
I don't really know, but AFAIK the terrain scene node uses just one mesh buffer so it can only have one texture !!!
The 4 texture layers have nothing to do with multi texturing !!!

For example have a look inside a multi textured .x file !!!
for each texture there is a single mesh buffer (called frames in .x files)...

Or let's say you have a mesh with 5 textures, how would you change the 5th texture, since there are just 4 layers ???
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I'm not trying to add confusion here, but texture layers have everything to do with multitexture. Multitexture is applying/blending multiple textures to a single primitive simultaneously. If you are using multiple texture stages/layers in Irrlicht, you are most definitely using multitexture. The textures for each stage are blended together.

If you are applying one texture to one set of vertices [a single mesh buffer] and a different texture to another set of vertices [another mesh buffer], then this is not multitexturing.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, I see, it's a question of definition the word multitexturing...
that's what I meant by "maybe I misunderstood" earlier...

You're right, even if I have only one mesh buffer and using more than one texture layer of it, there are multiple textures, so you can call it multi texturing...

But also if I have a mesh with a texture on a part of it (for example the head) and another texture on another part of it (for example the body), it's multi texturing, isn't it ???

So, in fact there is now the question, what exactly was asked for ??? :lol:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Acki was right, its more of a texture the head and the body with different textures on the same model in irrlicht.

How do I access mesh buffers, etc.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

To display roads, you need to "texture splat" the roads onto the original textures.

Image

The sand is 1 texture, the grass is another texture and the stone for the mountain is yet another. 3 Texutres, alpha blended on a single mesh. This is what you want to accomplish, but with roads, right?
Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

ahh, alpha blending would be interesting, too !!! :D
But I never did this and have no clue how to (yet)... :oops:

@monke: every mesh has functions t access the buffers:

Code: Select all

mesh->getMeshBufferCount();
mesh->getMeshBuffer();
and every mesh buffer has a function to access the material:

Code: Select all

buffer->getMaterial();
If you finally got the material of a buffer you have access to its texture layers colors...
You should have a look at the doku for this...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Sprintz you got it right on the dot. I also needed to know how to do that.

Any code you have or anything?
Post Reply