How to determine which scenenode shader is rendering?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!

How to determine which scenenode shader is rendering?

Postby robmar » Mon Mar 12, 2012 6:35 pm

Is there a known method for a shader on Irrlicht to determine which scenenode´s material it is rendering? For example, say there are 6 scenenodes and they have materials all with the same Gouch rendering, but each object has different color parameters, it would be very useful if the GLSL shader could identify the node or its material, and look up the required color in a table. Otherwise, the inefficient way is to repeat the shader for each node...
robmar
 
Posts: 594
Joined: Sun Aug 14, 2011 11:30 pm

Re: How to determine which scenenode shader is rendering?

Postby Mel » Mon Mar 12, 2012 7:37 pm

Yes, the "onSetMaterial(SMaterial &material)" mehtod of the shader callbacks.

In it, the parameter is the material that uses the shader, So, there you can read the diffuse color of the material that the scene node is using, and you can set it up on the onSetConstats Callback.
http://santiagong.daportfolio.com/
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
User avatar
Mel
Competition winner
 
Posts: 1788
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: How to determine which scenenode shader is rendering?

Postby robmar » Mon Mar 12, 2012 11:03 pm

Okay, thanks!

Does that means that I need to declare a shader for each scene node, with its own callback handler, when they might all be using the same shader, right?

Or are you saying I could use a variable in the Material to identify each node, coding the ID of the node into the diffuse color for example, and use that to look-up the color for the shader related to each object?
robmar
 
Posts: 594
Joined: Sun Aug 14, 2011 11:30 pm

Re: How to determine which scenenode shader is rendering?

Postby Mel » Tue Mar 13, 2012 10:50 am

No. Each scenenode has its own set of materials, with their corresponding shader. And each shader has its corresponding shader constants callback.

What you could do is to create a callback object (only one!) that held within a variable for the color, and that you wrote both the "onSetConstants" and the "onSetMaterial" callbacks. In the "onSetMaterial" callback, you can read the color from the material (which is diferent per node) and in the "onSetConstants" callback you can expose the color to the shader.

There is no need to create a shader for each scenenode!
http://santiagong.daportfolio.com/
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
User avatar
Mel
Competition winner
 
Posts: 1788
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: How to determine which scenenode shader is rendering?

Postby robmar » Fri Mar 23, 2012 6:52 pm

Thanks for the reply, I think I have it clear now.

I use :

pSceneNode->getMaterial(i) = m_material[i]; // Assign unique material to each node
pSceneNode->setMaterialType( (E_MATERIAL_TYPE)sShader[ iShader ] ); // Set shader, same for many nodes

Then in OnSetMaterial:-

virtual void OnSetMaterial(const video::SMaterial& material)
{
m_tintcolor = material.DiffuseColor;
}

I can access the unique material for each node, and "borrow" one of the colors, such as Diffuse, and use it for the shader, because the shader does all rendering, and the diffuse and other colors are not in use.

Is that basically how to do it?
robmar
 
Posts: 594
Joined: Sun Aug 14, 2011 11:30 pm


Return to Advanced Help

Who is online

Users browsing this forum: No registered users and 0 guests