Assign Shader to a Texture (in BSP Map) [SOLVED]

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
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Assign Shader to a Texture (in BSP Map) [SOLVED]

Post by Rytz »

This is the only thread I could find on this topic (directly):

http://irrlicht.sourceforge.net/phpBB2/ ... ure+shader

I'm starting a new thread in the "Beginners Help" forum because I think it's more appropriate.

Been looking for a couple hours on how to accomplish this task. I learned a lot about shaders in the mean time and got some examples working. Pretty cool stuff.

So, as for my situation, lets say I load my map / mesh (BSP) in like this:

Code: Select all

EHwdwRoom->meshRoom = EHwdwRoom->smgrRoom->getMesh("test1.bsp");
Inside of that map, I have 1 texture that I want to have use a shader (like a ceiling light).

Can I call to the specific texture in a node / mesh by filename or some other identifier? Or is there a better approach?

Any help would be appreciate. Thanks in advance.
Last edited by Rytz on Sat Apr 14, 2007 9:38 am, edited 1 time in total.
Image
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

I'm not sure, but i think that the bsp node should have one material for each texture. so by getting the number of materials, looping trough each, getting the material and checking it against a certain texture, you could find the right material. Then you just have to change the material type. Good Luck.
If you don't have anything nice to say, don't say anything at all.
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

Luben wrote:I'm not sure, but i think that the bsp node should have one material for each texture. so by getting the number of materials, looping trough each, getting the material and checking it against a certain texture, you could find the right material. Then you just have to change the material type. Good Luck.
Thanks I'll take a look at the API for going through mesh materials.
Image
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

Well I looked through some API information regarding mesh buffers, SMaterials, and getChildren. Did some testing but it doesn't seem like those are what I'm looking for.

Does irrLicht store any texture "filename" information when textures get loaded? How can I setup my BSP maps so that I can select specific textures later on through irrLicht so that I can use shaders on them?

Hopefully I'm not missing something totally obvious...
Image
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

getChildren shouldn't be necessary, i might have been a bit vague. I meant something like this

Code: Select all

ISceneNode *BspNode;

for(int i=0;i<BspNode->getMaterialCount();i++)
{
	if(BspNode->getMaterial(i).Textures[0]->getName()=="TargetTexName")
		BspNode->getMaterial(i).MaterialType=EMT_TRANSPARENT_ALPHA_CHANNEL;
}
To break it up, we'd get

Code: Select all

ISceneNode *BspNode;

for(int i=0;i<BspNode->getMaterialCount();i++)
{
	SMaterial* Mat;
	ITexture *Tex;
	Mat=&BspNode->getMaterial(i);
	Tex=Mat->Textures[0];
	if(Tex->getName()=="TargetTexName")
		Mat.MaterialType=EMT_TRANSPARENT_ALPHA_CHANNEL;
}
If you don't have anything nice to say, don't say anything at all.
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

Luben wrote:getChildren shouldn't be necessary, i might have been a bit vague. I meant something like this

Code: Select all

ISceneNode *BspNode;

for(int i=0;i<BspNode->getMaterialCount();i++)
{
	if(BspNode->getMaterial(i).Textures[0]->getName()=="TargetTexName")
		BspNode->getMaterial(i).MaterialType=EMT_TRANSPARENT_ALPHA_CHANNEL;
}
To break it up, we'd get

Code: Select all

ISceneNode *BspNode;

for(int i=0;i<BspNode->getMaterialCount();i++)
{
	SMaterial* Mat;
	ITexture *Tex;
	Mat=&BspNode->getMaterial(i);
	Tex=Mat->Textures[0];
	if(Tex->getName()=="TargetTexName")
		Mat.MaterialType=EMT_TRANSPARENT_ALPHA_CHANNEL;
}
Awesome, thanks for the reply. Looks very promising. I'll give this a shot later tonight :D.
Image
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

Thanks again, Luben. Got it working correctly with your advice. Below is the code I ended up using:

Code: Select all

        // sort through the textures to assign specific shaders...
        for (int i = 0; i < EHwdwRoom->nodeRoom->getMaterialCount(); i++){

            // if name matches for this shader...
            if (EHwdwRoom->nodeRoom->getMaterial(i).Textures[0]->getName() == "textures/gothic_wall/goldbrick.jpg"){
                EHwdwRoom->nodeRoom->getMaterial(i).setFlag(video::EMF_LIGHTING, false);
                EHwdwRoom->nodeRoom->getMaterial(i).MaterialType = (video::E_MATERIAL_TYPE) newMaterialType1;
            }
        }
Image
Image
Post Reply