Horde3D http://horde3d.org/forums/ |
|
setMaterialUniform http://horde3d.org/forums/viewtopic.php?f=2&t=832 |
Page 1 of 1 |
Author: | torsk [ 08.07.2009, 08:45 ] |
Post subject: | setMaterialUniform |
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? |
Author: | DarkAngel [ 08.07.2009, 09:13 ] |
Post subject: | Re: setMaterialUniform |
What is the datatype in GLSL? It may need to be a vec4. |
Author: | torsk [ 08.07.2009, 09:40 ] |
Post subject: | Re: setMaterialUniform |
It is. uniform vec4 time; |
Author: | marciano [ 08.07.2009, 20:00 ] |
Post subject: | Re: setMaterialUniform |
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. |
Author: | torsk [ 09.07.2009, 08:31 ] |
Post subject: | Re: setMaterialUniform |
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 |
Author: | marciano [ 09.07.2009, 19:44 ] |
Post subject: | Re: setMaterialUniform |
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 ) |
Author: | torsk [ 10.07.2009, 10:23 ] |
Post subject: | Re: setMaterialUniform |
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. |
Author: | marciano [ 11.07.2009, 09:20 ] |
Post subject: | Re: setMaterialUniform |
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. |
Author: | Expandable [ 14.07.2009, 07:00 ] |
Post subject: | Re: setMaterialUniform |
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. |
Author: | swiftcoder [ 14.07.2009, 11:36 ] |
Post subject: | Re: setMaterialUniform |
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).
|
Author: | DarkAngel [ 15.07.2009, 00:23 ] |
Post subject: | Re: setMaterialUniform |
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).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 |
Author: | Siavash [ 15.07.2009, 03:36 ] |
Post subject: | Re: setMaterialUniform |
Good idea |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |