Apply a shader per MeshBuffer

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
sylpheed
Posts: 25
Joined: Mon Nov 30, 2009 1:45 pm

Apply a shader per MeshBuffer

Post by sylpheed »

Hi. I want to apply a different shader for each MeshBuffer of a Mesh. I have followed Tutorial 10 and no problems showing shaders in a whole Mesh, but I can't apply in a single MeshBuffer.

Code look like this:

Code: Select all

/** Code 1 **/
s32 material_type = gpu->addHighLevelShaderMaterialFromFiles(...)
node->setMaterialType ((video::E_MATERIAL_TYPE)material_type);

/** Code 2 **/
s32 material_type = gpu->addHighLevelShaderMaterialFromFiles(...)
node->getMesh ()->getMeshBuffer (0)->getMaterial ().MaterialType = (video::E_MATERIAL_TYPE)material_type;
Code 1 is success, the whole Mesh is rendered with shader.
Code 2 is fail, all MeshBuffers from the mesh are "normal" rendered (no shaders applied).

How could I apply a shader for a single MeshBuffer?

Thanks in advance
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Your code is correct. This should work if certain conditions are met. Question is if meshbuffer 0 contains any geometry and is the one you want to alter. Also make sure you have the proper texture coords, maybe you need two sets or tangent meshes?
sylpheed
Posts: 25
Joined: Mon Nov 30, 2009 1:45 pm

Post by sylpheed »

hybrid wrote:Your code is correct. This should work if certain conditions are met. Question is if meshbuffer 0 contains any geometry and is the one you want to alter. Also make sure you have the proper texture coords, maybe you need two sets or tangent meshes?
The Mesh is a group of 3 MeshBuffer, and all MeshBuffer has a geometry. I have tried to modify each one, and no results. Geometry doesn't need tangents nor binormals, shader code is very simply (it's the same shader code from the examples).

It's very odd, if I apply the shader to the whole Mesh it renders Perfectly.

Does Irrlicht need some type of call to a function for updating the material?

Thanks for all.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Try to change the other material parameters, e.g rendering in wireframe only one of the meshbuffers. This will make sure you're really changing the correct material. Besides that, nothing special is necessary.
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

Have you tried node->getMaterial( meshBufferIndex ).MaterialType = .. ?
sylpheed
Posts: 25
Joined: Mon Nov 30, 2009 1:45 pm

Post by sylpheed »

Eigen wrote:Have you tried node->getMaterial( meshBufferIndex ).MaterialType = .. ?
No results :(

Something is definitely wrong in my code. If I type this:

Code: Select all

IMesh *sphere = smgr->getGeometryCreator ()->createSphereMesh (0.5f, 8, 8);
IMeshSceneNode *point_node = smgr->addMeshSceneNode (sphere);		
point_node->getMaterial (0).Wireframe = true;
point_node->setMaterialFlag (EMF_LIGHTING, false);
It shows a beautiful grey wireframed sphere. But, if a type this:

Code: Select all

IMesh *sphere = smgr->getGeometryCreator ()->createSphereMesh (0.5f, 8, 8);
IMeshSceneNode *point_node = smgr->addMeshSceneNode (sphere);				
point_node->getMaterial (0).DiffuseColor = SColor (255, 0, 0, 255);
point_node->setMaterialFlag (EMF_LIGHTING, false);
It shows a grey solid sphere, instead a BLUE solid sphere. So, some parameters are updated (wireframe), other don't (color). What's wrong in the code?

Thanks for your time.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, in the second case you alter the lighting color properties. If lighting is off, this obviously has no effect. So just try the same code with your shader.
erivera
Posts: 3
Joined: Mon Mar 22, 2010 1:23 am

Post by erivera »

sylpheed wrote:
Eigen wrote:Have you tried node->getMaterial( meshBufferIndex ).MaterialType = .. ?
No results :(

Something is definitely wrong in my code. If I type this:

Code: Select all

IMesh *sphere = smgr->getGeometryCreator ()->createSphereMesh (0.5f, 8, 8);
IMeshSceneNode *point_node = smgr->addMeshSceneNode (sphere);		
point_node->getMaterial (0).Wireframe = true;
point_node->setMaterialFlag (EMF_LIGHTING, false);
It shows a beautiful grey wireframed sphere. But, if a type this:

Code: Select all

IMesh *sphere = smgr->getGeometryCreator ()->createSphereMesh (0.5f, 8, 8);
IMeshSceneNode *point_node = smgr->addMeshSceneNode (sphere);				
point_node->getMaterial (0).DiffuseColor = SColor (255, 0, 0, 255);
point_node->setMaterialFlag (EMF_LIGHTING, false);
It shows a grey solid sphere, instead a BLUE solid sphere. So, some parameters are updated (wireframe), other don't (color). What's wrong in the code?

Thanks for your time.






This runs (':wink:'):

IMesh *sphere = smgr->getGeometryCreator ()->createSphereMesh (100.f, 200, 200);
IMeshSceneNode *point_node = smgr->addMeshSceneNode (sphere);
point_node->getMaterial (0).Wireframe = true;
point_node->setMaterialFlag (EMF_LIGHTING, true);
point_node->getMaterial (0).EmissiveColor = SColor (255, 0, 0, 255);
To share is great! Thanks.
Post Reply