Real Ocean Waves On Water

Discussion in 'Wish List' started by Red Ocktober, Jul 5, 2008.

  1. Red Ocktober

    Red Ocktober

    New Member

    Joined:
    Oct 28, 2005
    Messages:
    84
    while the shader effects look great, real time wave action is a must for anything more than water in a pond or swimming pool...

    is there any chance this feature will see the light of day...

    thx

    --Mike
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    25,938
    That's quite possible right now; you can deform the ocean mesh in realtime. For example, if you take the sinus curve modifier example from the procedural mesh examples, and apply the script to a plane, and change the "vertex.y += ..." line to:

    Code (csharp):
    1.         vertex.y += Mathf.Sin(Time.time * speed+ baseHeight[i].x + baseHeight[i].y) * (scale*.5)
    2.                  + Mathf.Sin(Time.time * speed+ baseHeight[i].z + baseHeight[i].y) * (scale*.5);
    then you get some nice rolling waves. If you're using reflective water, the reflection will be kinda wonky, but short of ray-tracing I'm not sure if there's much to be done about that.

    --Eric
     
  3. bigkahuna

    bigkahuna

    Member

    Joined:
    Apr 30, 2006
    Messages:
    5,423
    I'm guessing that what you're looking for is more of a "realistic ocean water shader" similar to what Quest3D and DX Studio have. There have been several posts by people who may be working on this, not sure of their progress:

    http://forum.unity3d.com/viewtopic.php?t=9676&highlight=waves

    http://forum.unity3d.com/viewtopic.php?t=9425&postdays=0&postorder=asc&highlight=waves&start=0

    An ocean wave shader is on my "want" list also. If someone develops such a thing for Unity and is interested in licensing it, I'm interested.
     
  4. Jessy

    Jessy

    Member

    Joined:
    Jun 7, 2007
    Messages:
    7,187
    I don't get that impression. I think he means the kind of thing that Wave Race 64 introduced.

    I'll be interested in doing this when I have time, so thanks, Eric, for a method to get started.
     
  5. mojojojo

    mojojojo

    New Member

    Joined:
    Dec 16, 2009
    Messages:
    137
    That's quite possible right now; you can deform the ocean mesh in realtime. For example, if you take the sinus curve modifier example from the procedural mesh examples, and apply the script to a plane, and change the "vertex.y += ..." line to:

    Code:
    vertex.y += Mathf.Sin(Time.time * speed+ baseHeight.x + baseHeight.y) * (scale*.5)
    + Mathf.Sin(Time.time * speed+ baseHeight.z + baseHeight.y) * (scale*.5);


    then you get some nice rolling waves. If you're using reflective water, the reflection will be kinda wonky, but short of ray-tracing I'm not sure if there's much to be done about that.


    I'm completely lost as to what that means, could you walk me through your instructions?
     
  6. mojojojo

    mojojojo

    New Member

    Joined:
    Dec 16, 2009
    Messages:
    137
    Is there a way to alter the mesh resolution for a plane. I'm trying to create a object whereby I can adjust the wavelength so that I can show a boat traveling through the water and through a gui change the wave height and "speed" of the waves. I put speed in quotes because I'm planning on having the boat stationary and have the water oscillate faster to simulate the boat moving. The problem I'm having w/ this particular code is that I can't get a good wavelength.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    25,938
    The resolution is whatever you make it.

    --Eric
     
  8. mojojojo

    mojojojo

    New Member

    Joined:
    Dec 16, 2009
    Messages:
    137
    I mean can I alter the resolution based on a game input?
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Messages:
    25,938
  10. mojojojo

    mojojojo

    New Member

    Joined:
    Dec 16, 2009
    Messages:
    137
    I'm trying to have a single wave travel across the plane to start slow. In this script I've tried just to deform the mesh but it's not working. Can anyone tell me what I'm doing wrong?

    private var baseHeight : Vector3[];

    function Update () {
    var mesh : Mesh = GetComponent(MeshFilter).mesh;

    if (baseHeight == null)
    baseHeight = mesh.vertices;

    var vertices = new Vector3[baseHeight.Length];
    for (var i=0;i<vertices.Length;i++)
    {
    var vertex = baseHeight;
    vertex.y = vertex.y * 1.1*Time.time;
    vertices = vertex;
    }
    mesh.vertices = vertices;
    mesh.RecalculateNormals();
    }
     
  11. mojojojo

    mojojojo

    New Member

    Joined:
    Dec 16, 2009
    Messages:
    137
  12. podperson

    podperson

    Member

    Joined:
    Jun 6, 2006
    Messages:
    1,364
    I think the problem with providing a general solution here is that everyone will want different things. Is it cosmetic or is it supposed to drive physics?

    As Eric points point, the basic math for propagating waves through a mesh is trivial (and indeed running "swell" (tidal wave action) and "chop" (wind-driven waves) at different angles is just a matter of picking frequencies, amplitudes, and directions and adding offsets.) But if you want to be able to do bouyancy or displacement by ships or splashes... Foam?

    Even in the non-realtime world water is a huge issue and tends to be handled as a special case pretty much every time.