Search Unity

Seamless transition between different wave speed FX/Water

Discussion in 'Shaders' started by PhilippL, Feb 8, 2016.

  1. PhilippL

    PhilippL

    Joined:
    Sep 1, 2015
    Posts:
    2
    Hello,

    I want to visualize a liquid-simulation. The simulation calculates periodically values for the speed of the liquid. I'm using these values to set some properties in the FX/Water shader (in this case the Wave speed map). This method works greatly for constant values. But if I change the values more often the visualization becomes bad. For example if the value decreases, the liquid seems to flow backwards (but the value remains positive). Is there someone with an idea, how to change the water-shader or water-script to achieve my goal? To gain a seamless transition from one wave speed to another wave speed.

    Thanks in advance,
    Philipp
     
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    If you're using _Time in your formula for the scroll you're effectively rewinding toward start time when you change your rate or whatever. You'll need to track and manage a global variable that stands in as _Time.
     
  3. PhilippL

    PhilippL

    Joined:
    Sep 1, 2015
    Posts:
    2
    Thank you for your answer! The _Time variable wasn't the issue here. I have read several scroll texture scripts and came up with this code:
    Code (CSharp):
    1. float waveScale = mat.GetFloat("_WaveScale");
    2. Vector4 waveScale4 = new Vector4(waveScale, waveScale, waveScale * 0.4f, waveScale * 0.45f);
    3. myOffset -= Time.deltaTime * 0.5f * liquidSpeed;
    4. mat.SetVector("_WaveOffset", new Vector4(10, waveScale4.y * myOffset, 10, waveScale4.w*myOffset / 2));
    5. mat.SetVector("_WaveScale4", waveScale4);
    In the Update()-Function of the water script. LiquidSpeed is my external parameter.
     
    Karwoch likes this.
  4. Karwoch

    Karwoch

    Joined:
    Sep 16, 2014
    Posts:
    111