Horde3D

Next-Generation Graphics Engine
It is currently 27.11.2024, 02:55

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: setMaterialUniform
PostPosted: 08.07.2009, 08:45 
Offline

Joined: 01.06.2009, 11:15
Posts: 14
Hello,

I am trying to pass deltatime to my shader in everyframe with setMaterialUniform. I have <Uniform name="time" a="0.1" b="0.1" c="0.1" d="0.1" /> in the material file, and also <Uniform id="time" /> in the beginning of [[FX]] section in my shader.

I try to update "time" with following code:

Code:
...
m_waterMaterial = Horde3D::findResource( ResourceTypes::Material, "models/water/Material__25-material.material.xml" );
...
void GamePlayState::update(float dt)
{
   static float abstime = 0.0f;
   abstime += dt;
   Horde3D::setMaterialUniform(m_waterMaterial, "time", abstime, abstime, abstime, abstime);


Horde3D::setMaterialUniform() returns true, but it doesn't seem to change the uniform vec4 time inside the shader (as nothing changes)...
Any ideas?


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 08.07.2009, 09:13 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
What is the datatype in GLSL? It may need to be a vec4.


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 08.07.2009, 09:40 
Offline

Joined: 01.06.2009, 11:15
Posts: 14
It is.

uniform vec4 time;


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 08.07.2009, 20:00 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
That should definitely work but the problem looks a bit like the one reported here. Unfortunately I could not reproduce it. If you could create a minimal repro case with one of the samples it should be very quick to fix.


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 09.07.2009, 08:31 
Offline

Joined: 01.06.2009, 11:15
Posts: 14
ok, i tried it with the knight sample, and couldn't get it working there either. i am trying to convert ocean shader from rendermonkey samples to horde. here's lines i added to knight Application:init():

Knight Application::init():

Code:
   m_waterMaterial = Horde3D::addResource( ResourceTypes::Material, "models/jokulaatikko/Material__25-material.material.xml", 0 );
   ResHandle waterRes = Horde3D::addResource( ResourceTypes::SceneGraph, "models/jokulaatikko/jokulaatikko.scene.xml", 0 );

   // Load resources
   Horde3DUtils::loadResourcesFromDisk( _contentDir.c_str() );

   NodeHandle waterNode = Horde3D::addNodes( RootNode, waterRes );
   Horde3D::setNodeTransform(waterNode, 30, 0, -20, 0, 0, 0, 1, 1, 1);
        m_counter = 0.0f;


couple of variables to App.h:

Code:
class Application
{
private:

   float            m_counter;
   ResHandle         m_waterMaterial;


Application::mainLoop() :

Code:
void Application::mainLoop( float fps )
{
   Horde3D::setMaterialUniform(m_waterMaterial, "myTime", m_counter, m_counter, m_counter, m_counter);
   m_counter += 1.0f;


and here's link to my relevant shaders/ models/ textures/ :
http://www.drugphish.ch/~thok/monkeywater.rar


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 09.07.2009, 19:44 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
Thanks for the repro case, it helped to find the problem. The bug is very easy to fix; in Renderer::setMaterialRec (Renderer.cpp), modify the line after the comment:
Code:
// Use default values if not found
if( !found && firstRec )


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 10.07.2009, 10:23 
Offline

Joined: 01.06.2009, 11:15
Posts: 14
yaya, thanks for the quick fix :)

btw it would be a good idea to include some kind of a frametimer to horde default shader attributes because so many effects require it.


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 11.07.2009, 09:20 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
torsk wrote:
btw it would be a good idea to include some kind of a frametimer to horde default shader attributes because so many effects require it.

Yes that would be practical. On the other hand Horde does not really have the concept of a global game time. Animation and particles are advanced manually. However, we could add a time parameter to the render function which will just be used as shader uniform.


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 14.07.2009, 07:00 
Offline

Joined: 22.01.2009, 19:49
Posts: 14
Location: Germany
marciano wrote:
However, we could add a time parameter to the render function which will just be used as shader uniform.


I like that idea.


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 14.07.2009, 11:36 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
marciano wrote:
However, we could add a time parameter to the render function which will just be used as shader uniform.
I am not sure global time is a very useful concept in a game renderer - I often need many different timers, so manual uniform upload is better. Also, Horde might be used in contexts where frame-time would be very tricky to determine (i.e. lazy update in a GUI context).

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 15.07.2009, 00:23 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
swiftcoder wrote:
marciano wrote:
However, we could add a time parameter to the render function which will just be used as shader uniform.
I am not sure global time is a very useful concept in a game renderer - I often need many different timers, so manual uniform upload is better. Also, Horde might be used in contexts where frame-time would be very tricky to determine (i.e. lazy update in a GUI context).
I agree.
However, maybe Horde could implement the concept of a "global" uniform? This way the application could set the uniform once, and all materials would receive the value.

This would allow you to easily pass a global timer to all your shaders, but it doesn't directly tie the concept of "time" to Horde ;)


Top
 Profile  
Reply with quote  
 Post subject: Re: setMaterialUniform
PostPosted: 15.07.2009, 03:36 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
Good idea


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 15 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