Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle Drift on Mobile #3

Open
aferriss opened this issue May 4, 2017 · 8 comments
Open

Particle Drift on Mobile #3

aferriss opened this issue May 4, 2017 · 8 comments

Comments

@aferriss
Copy link

aferriss commented May 4, 2017

It seems like the particles drift left and upwards on mobile devices (both android and ios). I'm wondering if this is caused by the browser scaling the gl viewport to compensate for high dpi screens? You can see the effect by viewing the demo on any mobile device. I tried on a Samsung Galaxy S6 and iPhone 6S.

Any other ideas as to why this might be happening? Could there be a loss of precision or some kind of rounding error going on?

I checked and both devices have 16 slots for textures in the vertex shader with:

var vertexUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);

FWIW window.devicePixelRatio is 4 on my Android and 3 on my iPhone.

Thanks!

@aferriss
Copy link
Author

aferriss commented May 4, 2017

After messing with this a bit more, I'm almost 100% certain that this is caused by a lack of precision on mobile, even with highp in all the shaders. I removed the updatePosition and updateVelocity functions from the shaders, so it was just a loop of decoding -> encoding and to my surprise the particles still drift (but only on mobile)! I also tried adding a bias to the encoding thinking that things were getting weird when the value equals 1, but I was never able to narrow in on a value that seemed to stop the drift completely.

Not sure what to do about this. I think if you wanted to continue avoiding float textures you could do the encoding across all four channels instead of just two, but that would require some extra passes.

There is a bit of chatter from almost a decade ago scattered about the web...
http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/#comment-16380

@skeeto
Copy link
Owner

skeeto commented May 4, 2017 via email

@skeeto
Copy link
Owner

skeeto commented May 4, 2017 via email

@skeeto skeeto closed this as completed in ab255f2 May 4, 2017
@aferriss
Copy link
Author

aferriss commented May 4, 2017

I think some devices may not support highp, leading to unexpected behavior. Since mediump causes the problem though, I'd say it's a change worth making :)

highp doesn't seem to be fixing things for me, so maybe my problem is actually else where...

@skeeto
Copy link
Owner

skeeto commented May 4, 2017

Since ab255f2 doesn't fix yours, I'll reopen this.

@skeeto skeeto reopened this May 4, 2017
@aferriss
Copy link
Author

aferriss commented May 5, 2017

Just a note that highp does fix things on the iPhone, but it's still whacked out on the Galaxy S6.

@Farkal
Copy link

Farkal commented Oct 4, 2018

Same issue here -> mapbox/webgl-wind#12 with a project inspired by your code.
I am trying to find another way to encode / decode particles (webgl 2 not yet supported on mobile/tablet and same for float textures) if you already find something I am interested.

@aferriss
Copy link
Author

aferriss commented Oct 6, 2018

Sorry, my solution was just to implement the physics of my particle sim on the cpu. Not ideal, but it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants