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

Cheap cpu approximation #22

Closed
OneManMonkeySquad opened this issue Jun 4, 2018 · 2 comments
Closed

Cheap cpu approximation #22

OneManMonkeySquad opened this issue Jun 4, 2018 · 2 comments
Labels

Comments

@OneManMonkeySquad
Copy link

OneManMonkeySquad commented Jun 4, 2018

Hello,

what a great library :) I was wondering I was wondering whether there is a way to cheaply approximate the water height on the cpu? Maybe even stateless (like gerstner waves). I would love to use this in a client/server game. Currently I'm using gerstner waves which can be evaluated at discrete points on the server.

@huwb huwb added the Question label Jun 5, 2018
@huwb
Copy link
Contributor

huwb commented Jun 5, 2018

Thanks SirPolly! I'll write some thoughts below.

Crest also uses gerstner waves, and there are functions to sample displacement/height - see the ShapeGerstnerBatched component. This is stateless, although the time is currently driven by an internal variable in the OceanRenderer (_elapsedTime) right now. It would be possible to use any time here though.

The unfortunate caveat with the above is that these functions dont take into account the depth of the ocean floor (which dampens the waves which have long wavelengths). This is because the sea depth is rendered on the fly on the GPU, or cached in textures on the GPU. An option here would be to read the sea depth on the CPU and use this when computing the wave shape on the CPU. Another option would be to use some kind of manual dampening of the waves using primitives such as spheres, which could be used on both the CPU and GPU.

The best path to get the collision on the CPU is to read back the GPU shape textures. This has a couple of frames of latency. I'm guessing though that this would not work for a networked game because you probably need the future state of the ocean, and therefore latency is not acceptable.

A final option is to bake out the ocean shape into textures as an offline step instead of computing them on the fly - for example bake out 32 frames of animation from a simulation software such as blender, and then read these textures on both the CPU and GPU. This would be cheap but requires the offline setup steps.

Let me know if this makes sense and if it addresses your questions!

@huwb
Copy link
Contributor

huwb commented Jun 12, 2018

I'll resolve this (I'm a "zero inbox" kind of guy :)) but feel free to keep this conversation going, i'll get notifications if you reply.

I'm interested to know if there are any generic changes i can absorb into crest to make it work better for networking, so it would be good for me to understand this better.

@huwb huwb closed this as completed Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants