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

Model barriers with functions to get rid of the blob of minified geometry code. #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xorgy
Copy link

@xorgy xorgy commented Jul 5, 2015

These barriers are fairly elegant, so we don't really need all of that geometry code to model collision.

@xorgy
Copy link
Author

xorgy commented Jul 6, 2015

I have poked at creating some abstract definition language to generate both the collision and the shader programs, but I've not gotten too far yet.

Once I get a glsl optimizer integrated into the build system I might be able to stomach having the shader be automatically generated.

@bwhmather
Copy link
Owner

Would be interesting to define set operations on functions that return the distance from an edge. That would give you a way to render perfect borders and to find collisions with missiles with non-zero diameter. With GLSL it might not even perform that atrociously.

(Also have changed the license from All Rights Reserved to the AGPL so that you can redistribute any changes you make)

@bwhmather
Copy link
Owner

Also missed your first reply. I like it!

@xorgy
Copy link
Author

xorgy commented Jul 7, 2015

One way we could use the same source for both is to modify the collision functions to output signed distance values.
For collision we've collided if it's less than one, and we can use the same functions to compute a signed distance field which a shader can use to give the visual effect.

This would reduce the complexity of the shaders considerably, so we could possibly afford to do non-aliased rendering even on cheap devices.

One concern might be the quality of the visual output though. not sure what kind of resolution the SDF would need.

@xorgy
Copy link
Author

xorgy commented Jul 7, 2015

In any case I can't go with my existing GLSL approach, because there are OpenGL stacks (mostly on ARM SoCs) which just outright crash while compiling my shader, and tend to bring the whole browser down with them(PowerVR SGX on iOS and Adreno 2xx on Android).

@bwhmather
Copy link
Owner

I think we are both thinking the same thing with the signed distance fields. No sure what the error is but I think the shader approach is worth persuing if at all possible (even if you have to wait for browsers to catch up).

@xorgy
Copy link
Author

xorgy commented Jul 7, 2015

To clarify, I mean that my particular shaders crash some OpenGL implementations, rather than shaders in general.

@bwhmather
Copy link
Owner

Have had an experiment with doing set operations on distance fields. Have a look at: https://www.shadertoy.com/view/MlXSDH

ealised that it's actually quite difficult to do corners correctly so I've cheated and used an approximation that gives hard corners rather than rounded ones. I've tried to implement signedDistance in a way that would be trivial to generate using a compiler.

@xorgy
Copy link
Author

xorgy commented Jul 8, 2015

I think it might be a good idea to prepare the distance field onto a texture ahead of time, and write one shader that samples from the texture. The shader on that shadertoy crashes chrome on my phone, and safari on one of my iOS testing devices.

@xorgy
Copy link
Author

xorgy commented Jul 8, 2015

Another good opportunity I forgot to take with my existing shader approach is antialiasing.
Looks like this when applied to your shadertoy.
https://www.shadertoy.com/view/MlfSDH

@xorgy
Copy link
Author

xorgy commented Jul 8, 2015

One nice thing about GLSL is we can mix textures in, though I personally prefer the clean look.
howitis

@bwhmather
Copy link
Owner

Hi - Made any more progress? Was going to dismiss pre-compiling the distance field because of pixelation when you get close to the barriers but it occurs to me that what you would actually get would be a local aproximation of the curve of the same order as the interpolation. Sharp corners will be rounded and you might end up with weird waves but otherwise it could work.

@xorgy
Copy link
Author

xorgy commented Jul 12, 2015

@bwhmather valve has a technique where you polarize the field into two (or I guess technically potentially more) fields, which dramatically improves the fidelity of the test on sharp corners, I'm not sure how they do that though.

@xorgy
Copy link
Author

xorgy commented Jul 12, 2015

I'm poking at the precomputed SDF approach right now, most phones' WebGL stacks don't support floating point texture extensions, so I'm trying to find a good way to compress the distance field into an unsigned fixpoint. Other than that not a lot more progress.

@xorgy
Copy link
Author

xorgy commented Aug 23, 2015

As of xorgy/mg3d@92ba106 I have your sdf functions at parity with my other approach, I'm going to finish modeling the barriers, then make some JSON structure/DSL for defining the distance functions. Then make a javascript-based interpreter for it to do collision.

@bwhmather
Copy link
Owner

Excellent. It's silky smooth even on my phone.
There is some flickering as you go through barriers which I haven't been able to debug but I imagine it will disapear as you carry on refactoring.
I am eagerly watching your progress.

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

Successfully merging this pull request may close these issues.

2 participants