Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upTerrain collision processing on GPU #45
Conversation
kvark
added some commits
Mar 7, 2018
kvark
merged commit 9c02fa2
into
master
Mar 16, 2018
kvark
deleted the
gpu-collision
branch
Mar 16, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
kvark commentedMar 16, 2018
•
edited
Closes #44
What is it
Main purpose of the PR is to introduce an alternative code path for processing terrain collisions. The original game used software rasterization with per-pixel collisions, so doing it on GPU now is much closer in spirit than trying to tessellate the bounding shape geometry and process the samples on CPU like the old code path did.
On the way to the goal, I introduced a few more architectural changes that were needed in order to fight the technical debt but are independent:
AppAPI that combines all the methods usinggfx::Factoryinto a single oneHow it works
Every car/object gets assigned a rectangle corresponding to it's local bounds in world scale. The rectangle is allocated in an atlas texture. The object is rendered into it, with the fragment shader fetching the terrain data and producing a spring force vector, which is written into the RGBA32F pixel.
After all the tracked objects are rendered, the down-sampling begins. A number of passes that play ping-pong between two render targets and carefully down-sample each of the object footprints (individually!) by summing (not averaging!) the samples inside 2x2 grid. Extra care is taken of the odd sizes. It's using instanced quad rendering, one instance per down-sampled rectangle, with coordinates generated in the vertex shader.
Resulting target has 1 texel per object, which is then copied into a download buffer for reading on the next frame.
Why this is cool
Appendix
Notice the debug rendering of the GPU collision mipmap at the bottom left:

PR has a run-time dependency on gfx-rs/gfx#1882 for fixed texture readbacks. That new
gfx_device_glversion needs to be published, but it's not a blocker to merge this.As for the results, well, they need more work. The car feels very bouncy, and some investigation is needed to figure out what makes the collision contact hard in the original game.
Future work: