Horde3D
http://www.horde3d.org/forums/

Procedurally Swiching Shaders
http://www.horde3d.org/forums/viewtopic.php?f=1&t=1632
Page 1 of 1

Author:  ptilton [ 28.01.2012, 03:57 ]
Post subject:  Procedurally Swiching Shaders

Hello all,

I am working on a project that involves picking mesh objects in 3D space and I am looking for a way to convey to the user which rendered object is currently selected by having the object glow, or distinguish itself in a similar way. I have already created a simple shader in a context called "PICKED" and am attempting to use API calls similar to the one below to accomplish this.

h3dSetResParamStr(shaderMatRes, ContextElem, 0, ContNameStr, "PICKED");

The following call gives me the string name of the context that I want to replace, but I cannot seem to figure out how to replace it procedurally.

h3dGetResParamStr(shaderMatRes, ContextElem, 0, ContNameStr);

The message boards and Wiki pages have been an invaluable resource, but I've been unable to find a solution to this task so far.

Any guidance or advice would be greatly appreciated! Thanks!

Author:  Volker [ 28.01.2012, 12:51 ]
Post subject:  Re: Procedurally Swiching Shaders

ContNameStr is a read only attribute as mentioned in the docs. I guess you might want to use uniforms or different materials with different ShaderFlags?

Author:  ptilton [ 31.01.2012, 01:08 ]
Post subject:  Re: Procedurally Swiching Shaders

I was able to utilize a uniform to tell the shader to change it's behavior. I ended up finding a solution to procedurally switching the shader by using the follownig:

Code:
 
//materialRes: texture resource attached to the selected node (cube)

//specularShaderRes: resource handle to shader added with h3dAddResource

h3dSetResParamI(materialRes, MaterialElem, 0, MatShaderI, specularShaderRes);


I guess the thing I can't get my head is around is how to dynamically shade an unknown number of cubes. My project can have anywhere from 1 to about 2000+ cubes render at a time. The user can select a subset of cubes which will glow after being selected. As cubes timeout I would like them to gradually fade out by adjusting their alpha over a timeout. I know I can use a uniform to communicate timing information for the fading to a shader. I'm just not sure how to do this dynamically for each cube. Are there any resources that cover similar situations?

Thanks again for your help!

Author:  Volker [ 31.01.2012, 12:14 ]
Post subject:  Re: Procedurally Swiching Shaders

Maybe you can use the model specific uniforms via h3dSetNodeUniforms as mentioned here.

Unfortunately they are not part of the official beta 5, but only in the current svn trunk.

Author:  ptilton [ 01.02.2012, 16:43 ]
Post subject:  Re: Procedurally Swiching Shaders

Fantastic! Thanks again for all of your help.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/