Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
Update Shader variable in realtime

codemastermike
Registered User
Quote
2011-09-30 11:31:51

I want to update a uniform float every frame.

And I have put the code below in a "BeforeDrawAll" function.
But it sets the value only once and doesnt set the new value after the first time. So the first round Counter is 1, and the shader set the value correctly. Next frame the Counter variable has gotten bigger, but the shader doesnt change, it still has the same original value.

I use the shader from the "Custom materials and shaders" tutorial, I only changed the float value into a "uniform float FragmentExtraColor;" value, which I change with the code below.


var ShaderMaterial = ShaderEntity.getMaterial(0);
if(ShaderMaterial)
{
var renderer = m_CurrentGameEngine.getRenderer();
var CurrentShader = renderer.getGLProgramFromMaterialType(ShaderMaterial.Type);
var variableLocation = renderer.gl.getUniformLocation(CurrentShader, "FragmentExtraColor");

Counter += 1.0;
renderer.gl.uniform1f(variableLocation, Counter);
}


Is this the wrong way to update Shader variables in realtime, or
am I missing something completly?


codemastermike
Registered User
Quote
2011-09-30 13:03:14

Ok, silly me, I should have read the documentation more carefully :-)

So I found that I have to use the "Material" event to update the variables in the shader. So, in the beginning I save my own function to the Material-event:

Engine getRenderer() Material = UpdateShaderVariables

And then it will update the shader as it should!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internation?l" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact