WebGL-Fluid-Simulation icon indicating copy to clipboard operation
WebGL-Fluid-Simulation copied to clipboard

Seems to depends on framerate and not time ?

Open flyingrub opened this issue 5 years ago • 6 comments

The simulation works great on my phone but is way to fast on a gtx1080 without vsync.

flyingrub avatar May 20 '19 15:05 flyingrub

I think all browsers lock framerate to 60. Are you testing it in chrome?

PavelDoGreat avatar May 21 '19 10:05 PavelDoGreat

Also simulation splat's force differs on different screen resolutions

PavelDoGreat avatar May 21 '19 11:05 PavelDoGreat

I am on firefox and forced v-sync off, to benchmark shadertoy

flyingrub avatar May 21 '19 11:05 flyingrub

I think all browsers lock framerate to 60.

This is not the case. I get 240 fps at https://testufo.com/

In WebGL-Fluid-Simulation, the simulation is completely dark about half a second after I stop clicking. I assume it's not supposed to run that fast, as there's little time to observe any details.

vith avatar May 22 '19 01:05 vith

ok I have to add code that would limit framerate to 60 regardless of screen refresh rate

PavelDoGreat avatar May 22 '19 15:05 PavelDoGreat

Hmm, I think you should definitely render at screen refresh rate, but you might want to run/adjust the simulation at a different rate. How about using performance.now() / or the time argument you get through the requestAnimationFrame callback.

Otherwise you are not really using hardware to give the user the best experience possible, if they decided to get a good GPU and fast display to enjoy it with.

In the following: https://github.com/PavelDoGreat/WebGL-Fluid-Simulation/blob/d20a9bb69df9816543970c452f030149b5c8cb60/script.js#L969-L978

The MDN example of rAF with the high resolution timestamp argument: https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame#Notes

So maybe something like:

update(performance.now());

let start = null;
function update (timestamp) {
    resizeCanvas();
    input();
    if (!config.PAUSED) {
        if (!start) start = timestamp;
        let delta = timestamp - start;
        step(delta / 1000);
    }
    
    render(null);
    requestAnimationFrame(update);
}

Since 2013 Firefox, Chrome and even Edge/IE all have supported rates greater than 60Hz.

Martin-Pitt avatar May 22 '19 17:05 Martin-Pitt