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
material class or material type?
Re: material class or material type?
you don't need a custom SMaterial. First you want irrlicht to provide you a new material type id like
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
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
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();
Code: Select all
s32 newMaterialType = gpu->addShaderMaterial(VertexShader, PixelShader, mc, video::EMT_TRANSPARENT_ADD_COLOR);
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);
Re: material class or material type?
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.
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.