material class or material type?

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
gtimworks
Posts: 21
Joined: Sun Nov 03, 2013 8:07 pm

material class or material type?

Post by gtimworks »

Hi all,

I am trying to understand how the class SMaterial is used inside Irrlicht. According to tutorial 10 "Shaders" material is related to shaders. But it looks like I can create my shaders and link them to a new material type, which is a new enum value I defined. I don't see a need to define my own material class.

So I am a little bit confused when I try to implement my own customized scene node. This node class will use the new material type. But how should I implement APIs such as "virtual video::SMaterial& getMaterial(u32 i)"? I don't really have a new SMaterial.

Thanks,

gtimworks
lumirion
Posts: 79
Joined: Tue Sep 13, 2011 7:35 am

Re: material class or material type?

Post by lumirion »

you don't need a custom SMaterial. First you want irrlicht to provide you a new material type id like

Code: Select all

 
MyShaderCallBack* mc = new MyShaderCallBack();
core::string VertexShader = "./path/and/name_of_shader.vsh";
core::string PixelShader = = "./path/and/name_of_shader.psh";
s32 newMaterialType = gpu->addShaderMaterialFromFiles(VertexShader, PixelShader, mc,  video::EMT_TRANSPARENT_ADD_COLOR); // video::EMT_.... are  used to indicate what type of shader technique you are providing with the new materialtype id
 mc->drop();
 
if you don't want to store your shaders in a file you can create a string VertexShader and one PixelShader and fill them with their respective shader's text then use

Code: Select all

 
s32 newMaterialType = gpu->addShaderMaterial(VertexShader, PixelShader, mc,  video::EMT_TRANSPARENT_ADD_COLOR);
 
To use the new shader material type get a material that already exists either directly from the node or from the node's mesh or however and

Code: Select all

 
node->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType); // set the nodes current material to use the shader newly associated with the newMaterialType id we just made
//or
node->getMesh(c)->getMeshBuffer(b)->getMaterial(a)->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType);  // I haven't tried chaining the get commands like this
but that is the order of the gets that must be called to retrieve an SMaterial from an IAnimatedMeshSceneNode
// could also do
SMaterial *material = node->getMesh(c)->getMeshBuffer(b)->getMaterial(a);
material->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType);
 
gtimworks
Posts: 21
Joined: Sun Nov 03, 2013 8:07 pm

Re: material class or material type?

Post by gtimworks »

thanks lumirion.

I was thinking material class is like SceneNode that you need to inherit from it to create your own customized class. That's why I got confused. It is just a data holder for the shaders being used.
Post Reply