Horde3D

Next-Generation Graphics Engine
It is currently 22.11.2024, 13:58

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 17.09.2008, 15:30 
Offline

Joined: 12.08.2008, 16:17
Posts: 7
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


Top
 Profile  
Reply with quote  
PostPosted: 17.09.2008, 16:06 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
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."


Top
 Profile  
Reply with quote  
PostPosted: 19.09.2008, 10:44 
Offline

Joined: 12.08.2008, 16:17
Posts: 7
Thanks for the help! Managed to get my shader working!


Top
 Profile  
Reply with quote  
PostPosted: 20.09.2008, 10:32 
Offline

Joined: 12.08.2008, 16:17
Posts: 7
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.


Top
 Profile  
Reply with quote  
PostPosted: 20.09.2008, 10:45 
Offline

Joined: 12.08.2008, 16:17
Posts: 7
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.


Top
 Profile  
Reply with quote  
PostPosted: 20.09.2008, 18:21 
Offline

Joined: 19.11.2007, 19:35
Posts: 218
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group