Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
2  
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. –  Byte56 Dec 15 '12 at 19:32
    
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. –  Eric Thoma Dec 16 '12 at 1:46
1  
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 –  codemonkey Dec 21 '12 at 13:06
    
Your video link is broken. –  ashes999 Jul 25 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.