shader vertex position

Hi.

I wrote vertex shader that simulates water waves.
There probably isn’t any simple way to get wave height that shader calculates back into Unity. Or is it?
I must place a ship on these waves. Obviously I need to move ship up and down according to wave height.
How could I do this?
Maybe I could simulate wave height, where the ship is located, on CPU?
The problem is, that shader uses _Time.y, and I don’t know what value this variable has at given time.

thank you for your help…

No, there is no simple/fast way how to access vertex shader output on CPU. Calculating waves on CPU is your best bet. _Time.y should be the same as Time.timeSinceLevelLoad in C#.

1 Like

Ok. Great. Thank you for your answer. I will calculate wave height on ship position on CPU.

This is true on PC, but not all platforms. Mobile and consoles are inconsistent. So if you’re PC only you can get away with this, otherwise you’ll want to pass your own time value to shaders to use to keep things in sync.

Thank you for the tip bgolus. I’m using this shader for mobile platform, so I’ll probably have to pass time to the shader.