How could I use a same shader attached to various nodes?

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

How could I use a same shader attached to various nodes?

Post by sylpheed »

First of all, sorry for my poor English.

I have a doubts using shaders. I have no problem rendering a unique SceneNode with a shader. But I dont know how to render many SceneNodes using the same shader AND using different shader parameters for each SceneNode. I can modify shader parameters only one time per frame (using callback method), so all attached SceneNodes will be rendered with the same parameters.

One solution could be create one shader (with same code) per SceneNode, but I have a lot of objects in my SceneGraph. Is there any way to modify shader parameters por each SceneNode in the same frame? I have read something about override the "render ()" method, but it could be a litte trouble...

Thanks a lot.
sylpheed
Posts: 25
Joined: Mon Nov 30, 2009 1:45 pm

Post by sylpheed »

Anybody please? :cry:
DavidJE13
Posts: 165
Joined: Tue Jan 09, 2007 7:17 pm

Post by DavidJE13 »

From what I know, this isn't possible. You *could* create a new scenenode object and (as you mentioned) change the render function to set the material's values before rendering, but really you might as well have separate materials for each object. There isn't a huge amount of overhead from doing so (textures will only be stored once).
Remember that values can also be sent to shaders through vertices (colour, normals, UV, etc.) which may be a better solution if they're animating anyway.
sylpheed
Posts: 25
Joined: Mon Nov 30, 2009 1:45 pm

Post by sylpheed »

Thanks for your answer.

It looks like that is the only solution possible.
Post Reply