Horde3D http://horde3d.org/forums/ |
|
Modifying material colour/transparency with a shader http://horde3d.org/forums/viewtopic.php?f=2&t=504 |
Page 1 of 1 |
Author: | jazza [ 17.09.2008, 15:30 ] |
Post subject: | Modifying material colour/transparency with a shader |
Hey guys, I'm a bit stuck with a little project that I'm working on. I need to be able to change the transparency and colour of a material that I have applied to a scene node. After reading through a few related posts on this forum, I've come to the conclusion that I might have to create my own shader and declare a "uniform" variable to hold the colour and transparency that I want to render. How do I go about doing this? I've written shaders before but I'm not sure I understand Horde's XML format for shaders. Also how do I ensure that a uniform variable that I've declared in the material.xml file is being passed to the shader? Any help/advice is greatly appreciated. Cheers, Jarryd |
Author: | AcidFaucet [ 17.09.2008, 16:06 ] |
Post subject: | Re: Modifying material colour/transparency with a shader |
A material.xml file looks like: Code: <Material class="theClassofTheMaterial"> <Shader source="nameOfTheShader" /> <TexUnit unit="#" map="imageFile" /> <Uniform name="myUniform" a="float" b="float" c="float" d="float /> </Material> Your shader contexts then access the uniform by declaring it at as normal: uniform vec4f myUniform; The Data Format reference in the Horde3D manual covers this material in greater detail. You can take a look at a palette recoloration technique I put up in the wiki under "Community Tutorials." |
Author: | jazza [ 19.09.2008, 10:44 ] |
Post subject: | Re: Modifying material colour/transparency with a shader |
Thanks for the help! Managed to get my shader working! |
Author: | jazza [ 20.09.2008, 10:32 ] |
Post subject: | Re: Modifying material colour/transparency with a shader |
Alright. Perhaps I spoke to soon.... . Let me clarify my problem first. I'm loading a resource as follows: ResHandle modelRes = Horde3D::addResource( ResourceTypes::SceneGraph, "model.scene.xml", 0 ); NodeHandle modelNode = Horde3D::addNodes( RootNode, modelRes ); The model then loads and displays correctly using a custom shader that I've specified in the material.xml file. The shader is also properly accessing the values of the uniforms declared in the xml file. My question is, how do I then modify these uniforms at runtime? The API seems to have commands that allow you to modify the material resource for a "mesh node" but not for a "scene graph" node. |
Author: | jazza [ 20.09.2008, 10:45 ] |
Post subject: | Re: Modifying material colour/transparency with a shader |
Just a quick update. I've managed to use setMaterialUniform(materialRes,"particleColour",1.0,0.0,0.0,1.0) but that seems to change the uniforms for all scene nodes that use this material. Is there some way to set these uniforms on a "per mesh/node" basis? I'm guessing I'll have to clone the material resource in order to do that :S. |
Author: | AcidFaucet [ 20.09.2008, 18:21 ] |
Post subject: | Re: Modifying material colour/transparency with a shader |
You have to clone. A varying uniform is on my own to-do list, if you'd like me to bounce you some code that does the trick (though it's a quirky proof of concept that will look nothing like a final write) then PM me your email address. |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |