Closed Aeva closed 7 years ago
With some testing, it looks like the glsl sin
function drops a lot of precision. Without doing anything fancy, it looks like a highp float is fine for a day of precision for time if I do something like this first:
float speed = 1.3;
float two_pies = 6.283185307179586;
float time = fract(mgrl_frame_start*speed/two_pies)*two_pies;
float wave = sin((dist - time) * frequency);
So, nothing really to do here.
Currently m.grl provides the
float mgrl_frame_start
uniform, who's value isperformance.now()/1000.0
. Supposedlyperformance.now()
provides accuracy up to 5 microseconds (expressed as milliseconds).Converting seconds and then dumping it into a float is a fast way to loose precision, and makes mgrl_frame_start not as useful for animation. The reason for this, is that as a float's magnitude increases, the fractional part of the float becomes choppy.
It is tempting instead to provide instead just the whole number of milliseconds as an integer instead, and leave it as an exercise for the shaders to extract the relevant fractional component out of that.
It might also be useful to provide the number of seconds as an integer, and the fractional component as a separate floating point.
So, for this ticket:
float mgrl_frame_start
with something betterSome things to consider:
gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT)
on my intel laptop,precision: 23
A possible approach:
seconds
andseconds+1