I just create a shader and it depends on the current time. My fragment is something like this:
varying vec2 vTexCoord;
varying float vAlpha;
uniform sampler2D uImage0;
varying float time;
void main(void)
{
vec4 color = texture2D(uImage0, SomethingTimeDependant(vTexCoord, time);
gl_FragColor = color;
gl_FragColor.rgb *= gl_FragColor.a;
}
So to provide the time I used
var param: ShaderParameter<Float> = new ShaderParameter<Float>();
param.value = [ getTimer() ];
this.data.time = param;
But it only updates when I lost and gain the focus again. Any ideas how to update the time correctly?
Here is the code of the shader class.
I added your WaveShader
to the bitmap in the DisplayABitmap project from openfl-samples, and couldn't find anything wrong with your code. And indeed, simply changing the bitmap's x
every frame "fixes" the issue. Internally, this sets __renderDirty
and some other flags to true, forcing a re-render.
Lib.current.stage.addEventListener(Event.ENTER_FRAME, function(e:Event) {
bitmap.x += 0.0001;
});
This suggests OpenFL has some issues with detecting changes to shader parameters. Consider creating an issue on OpenFL's issue tracker.
Btw, the shader seems to expect seconds, not milliseconds (which getTimer()
returns). You can simply divide by 1000 to get a nice-looking result:
this.data.time.value = [ getTimer() / 1000 ];