Global uniform Time question

I have a need for getting a snapshot of the current value of g_Time when a uniform is changed.



Anyone have an idea of how to do this?



Possibly as a define? Or?

g_Time contains the getTimeInSeconds() of the Application timer attribute.

Keep track on it and just save the value on the java side when you change the uniform.

1 Like
@nehon said:
g_Time contains the getTimeInSeconds() of the Application timer attribute.
Keep track on it and just save the value on the java side when you change the uniform.


Thank you, sir.

I was just reading through UniformBindings.java and saw that. You must be psychic... my next question was how do I get the applications time in seconds >.<

@normen taught me to read minds.

Yet I can assure you it’s very seldom that it works on women…

I always asumed that mindreading on women is an ability every frenchman has by default

yeah…but I traded it against a gameboy when I was 12…

Women have minds? >.<



Ok… one last question.



Does the shader receive the value of getTimeInSeconds() unmodified? i.e. if the shader is loaded 1200 seconds into an application’s start… does it receive 1200 seconds or 1200-1200(init time of shader)?



g_Time-m_CurrentTime doesn’t seem to be producing the correct results (m_CurrentTime being app.getTimer().getTimeInSeconds() at the time the uniform is changed).

@t0neg0d said:
Women have minds? >.<

Several sometime...


@t0neg0d said:
Does the shader receive the value of getTimeInSeconds() unmodified? i.e. if the shader is loaded 1200 seconds into an application's start... does it receive 1200 seconds or 1200-1200(init time of shader)?

g_Time is set on each frame, not when the shader is initialized
@nehon said:
g_Time is set on each frame, not when the shader is initialized


Yep yep... but is it modified at all? Or just the direct value returned by getTimeInSeconds()?

nope direct value, look at http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/shader/UniformBindingManager.java#171



but it might be set slightly after your m_CurrentTime.



What do you want to do?

@nehon said:
What do you want to do?


Basically I was hoping I could use this as a way to push triggered transitional effects off to a shader. Easier way to explain it may be:

Say you wanted to change alpha from 0.0 to 1.0 in a shader... in a raw form, it would look like this (of course)

[java]float alpha = clamp((g_Time * m_Speed), 0.0, 1.0);[/java]

Problem is... this only works once. My hope was to pass in a snapshot of g_Time when I set a uniform to trigger this transition... so I trigger the transition at g_Time 1153.3487... m_CurrentTime should be 1153.3487 so g_Time effectively starts at 0 again. As g_Time increases... m_CurrentTime is still 1153.3487.

[java]float alpha = clamp((g_Time - m_CurrentTime * m_Speed), 0.0, 1.0);[/java]

Hope this makes sense!

Oh… is there anyways of pulling the current value back from the shader bindings… i.e. getShader().getBinding().getValue() sort of thing?

ok got it.

I guess the problem is due to the fact they are not set exactly at the same moment.



Why don’t you just handle it on the java side?

like you have and animationTime variable, that you initialize to 0;

then you stack tpf in it, and send it every frame to your shader.



then you have

[java]

float alpha = clamp((m_AnimationTime * m_Speed), 0.0, 1.0);

[/java]

if you want to trigger the anim from the beginning you just have to reset animationTime to 0.



Also it only does the calculation once instead of for every pixel.

1 Like
@nehon said:
ok got it.
I guess the problem is due to the fact they are not set exactly at the same moment.

Why don't you just handle it on the java side?
like you have and animationTime variable, that you initialize to 0;
then you stack tpf in it, and send it every frame to your shader.

then you have
[java]
float alpha = clamp((m_AnimationTime * m_Speed), 0.0, 1.0);
[/java]
if you want to trigger the anim from the beginning you just have to reset animationTime to 0.

Also it only does the calculation once instead of for every pixel.


This is the way I'm currently doing it. I thought it would be faster to only update the shader uniforms once when you trigger the transition... but that doesn't really make a lot of sense, since g_Time is updated every frame.

Thanks for the help with this!
@t0neg0d said:
This is the way I'm currently doing it. I thought it would be faster to only update the shader uniforms once when you trigger the transition... but that doesn't really make a lot of sense, since g_Time is updated every frame.

Thanks for the help with this!


Not only that, all of the uniforms are sent every frame also.
1 Like