Im creating a game where water speed gives illusion of ship in motion (high water speed), and that works great. But when ship is hit, and I change speed of water - waves suddenly change its position, as changing water speed changes also its position... Is there any remedy for that problem? Can I calculate same position of water textures for different speeds? And there is actually no tiling position of those wave textures, so I don`t know if it is even possible.
I'm assuming you're doing the offset via speed in the shader? In which case the Time variable is "Time from the start of the app" so changing speed is effectively going "backwards in time", that's why you're seeing that jump, not just less offset. You'll want to manage your UV offset in C# more, and pass an X/Y offset to the shader, not a speed and direction.
Yea, that explains why changing speed looks like fast forward. So probably it is doable, but calculating right UV offset for actual time... this will be challenging. Thanks, I have really much to think about now.
Calculate your speed like normal. Add this frames speed value to the x and y uv offsets based on the direction you want to appear to be traveling. It's the same concept you've already done, just rearranged a bit.
Surely I will try that! Thank You! Now I just need to figure out how to access UV coordinates in water shader. Long time since I last do anything with shaders.
Finally got it working, no shader coding just waters script, here is code for anyone interested: Code (CSharp): double t = Time.timeSinceLevelLoad / 20.0 * waterSpeedMultilier; Vector4 offsetClamped = new Vector4( (float)Math.IEEERemainder(waveSpeed.x * waveScale4.x * t, 1.0), (float)Math.IEEERemainder(waveSpeed.y * waveScale4.y * t, 1.0), (float)Math.IEEERemainder(waveSpeed.z * waveScale4.z * t, 1.0), (float)Math.IEEERemainder(waveSpeed.w * waveScale4.w * t, 1.0) ); if (waterSpeedMultilier != waterSpeedMultilierLastFrame) { t = timeSinceLoadLastFrame / 20.0 * waterSpeedMultilier; Vector4 offsetClampedDifference = new Vector4( (float)Math.IEEERemainder(waveSpeed.x * waveScale4.x * t, 1.0), (float)Math.IEEERemainder(waveSpeed.y * waveScale4.y * t, 1.0), (float)Math.IEEERemainder(waveSpeed.z * waveScale4.z * t, 1.0), (float)Math.IEEERemainder(waveSpeed.w * waveScale4.w * t, 1.0) ); offSetModifier = offSetLastFrame - offsetClampedDifference; } offsetClamped += offSetModifier; waterSpeedMultilierLastFrame = waterSpeedMultilier; timeSinceLoadLastFrame = Time.timeSinceLevelLoad; offSetLastFrame = offsetClamped; mat.SetVector("_WaveOffset", offsetClamped); mat.SetVector("_WaveScale4", waveScale4);