In my game the water movement is done in a shader using Gerstner equations. The water movement looks realistic enough for a school project but I encounter serious problem when I wanted to do sailing on waves (similar to this). I managed to do collision with land by calculating quad's vertices and normals beneath ship, however same method can not be applied to water because XZ are displaced and Y is calculated in a shader :(

  1. How to approach this problem ?

  2. Is it possible to retrieve transformed grid from shader?

  3. Unfortunately no external physics libraries can be used.

  • 2
    \$\begingroup\$ The simplest option is to reproduce the equations for your water simulation on the CPU and apply them to the object you want to float. \$\endgroup\$
    – House
    Dec 15, 2012 at 19:32
  • \$\begingroup\$ Perhaps you can define a "floating plane" on the ship where the top of the ocean always intersects. Then, after the water is calculated, orient the ship so the intersection of the water and the ship closely resembles the plane. I might be missing the point of the question, but that is my first thought. \$\endgroup\$
    – Eric Thoma
    Dec 16, 2012 at 1:46
  • 1
    \$\begingroup\$ a bit overkill, but you might find this article on the tech used for the same thing by Assassin's Creed 3 insightful and might give you some ideas \$\endgroup\$
    – codemonkey
    Dec 21, 2012 at 13:06
  • \$\begingroup\$ Your video link is broken. \$\endgroup\$
    – ashes999
    Jul 25, 2014 at 19:22

1 Answer 1

  1. How to approach this problem?

Move the simulation of the wave height to the CPU. Depending on which works better for you and your logic/performance needs, you can move the entire simulation to the CPU and simply send the computed coordinates to the GPU (avoiding duplicate work) or you can do a simpler approximation of the computation on the CPU.

2.Is it possible to retrieve transformed grid from shader?

Not easily. Shaders aren't really designed for that. You can do various things to make the GPU do general purpose computation and read the results back on the CPU, and various GPGPU ("general purpose GPU") libraries and tools exist to wrap and abstract all that complexity, such as OpenCL. However, in this particular case it's unlikely to be that useful for you.

3.Unfortunately no external physics libraries can be used

That's fine, you should not need them, you've already done the majority of work you need.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .