Making meshes suitable for texture blending

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.
Post Reply
kjkrum
Posts: 26
Joined: Wed Oct 29, 2003 5:34 pm

Making meshes suitable for texture blending

Post by kjkrum »

I just finished my first trivial Irrlicht demo: a fully UV-mapped and textured cube. Thanks to all who answered my noob questions! I'm a long way from writing a game (actually, my goal is just a UI mockup for a game) but I'm having fun learning stuff.

My next step will be writing functions to generate all the regular polyhedra inscribed within spheres of a given radius. As I do this, I want to make sure that my meshes will be suitable for texture blending, which I totally don't understand yet. For example, I want to be able to have an icosahedron with some of its points splatted with a different texture. Do I need to do anything special with the meshes to make this possible (or easier)?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, points are actually not textured at all - at least it's hard to say how their texture looks like. But areas can be textured differently. In general you have to put all the points belonging to that area into a different mesh buffer with different material and textures. Another way would be to use a second texture coord set (with EVT_2TCOORDS) and use an overlay texture. Depends on your application.
kjkrum
Posts: 26
Joined: Wed Oct 29, 2003 5:34 pm

Post by kjkrum »

Isn't there some way to set up a material so that it has multiple layers of textures, and then vary how they're blended in each triangle by changing the alpha component of the vertex colors? I'm not interested in exactly how to do that yet... just whether something like that can be done.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, for two textures we have such a material predefined, for up to four (up to 8 with recompilation of the engine) could be provided by yourself using fixed function, up to 16 with shaders.
kjkrum
Posts: 26
Joined: Wed Oct 29, 2003 5:34 pm

Post by kjkrum »

[complete edit]

Turns out it is, in fact, working more or less how I expected. I just didn't expect it to blend all the way across the poly. The two textures I was using had very different amounts of contrast, so the blending was difficult to see. It's more clear with different textures:

http://www.flickr.com/photos/76481772@N00/4474248559/

Code: Select all

video::SColor clr0(255,255,255,255);
video::SColor clr1(0,255,255,255);
		
buffer->Vertices.push_back(video::S3DVertex(xyz[0], norm, clr0, uv[0]));
buffer->Vertices.push_back(video::S3DVertex(xyz[1], norm, clr0, uv[1]));
buffer->Vertices.push_back(video::S3DVertex(xyz[2], norm, clr1, uv[2]));
buffer->Vertices.push_back(video::S3DVertex(xyz[3], norm, clr1, uv[3]));

node->setMaterialType( video::EMT_SOLID_2_LAYER );		
node->setMaterialTexture(0, driver->getTexture("red.png"));
node->setMaterialTexture(1, driver->getTexture("blue.png"));
I still don't understand how the color attributes affect which texture is shown. I expected it to work like this:

Code: Select all

video::SColor clr0(255,0,0,0); // all texture 0
video::SColor clr1(0,255,0,0); // all texture 1
But changing the r,g,b values only desaturates the texture. So... how do I do this with 4 or 8 textures? I found the place in the code where max textures is defined as 4. Just change that to 8 and recompile? And is there a way I can alter the blending behavior so the texture transition occurs in about the middle third of the triangle rather than across the entire surface?

Hybrid, I hope you're not getting a notification every time I edit this comment. If you are, I'm terribly sorry for the spam. :-P
kjkrum
Posts: 26
Joined: Wed Oct 29, 2003 5:34 pm

Post by kjkrum »

BTW, the docs say that EMT_SOLID_2_LAYER isn't implemented for OpenGL, but that's what I'm using.
kjkrum
Posts: 26
Joined: Wed Oct 29, 2003 5:34 pm

Post by kjkrum »

To blend more than two textures, do I need to do something like what arras describes here?

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=37696
Post Reply