Search Unity

Question Simulating Infinite Ocean

Discussion in 'General Graphics' started by ThatProgrammerJack, Aug 6, 2021.

  1. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    32
    I am creating a 3D demo game in the Universal Render Pipeline featuring an island surrounded by ocean. Currently, I have a beautiful ocean shader which uses the vertices of a plane to simulate waves, and includes sea foam, normal maps, and mixed colors to make a decently convincing look.

    The problem is that I want the player to be able to go to the highest peak of the island and be able to see the sun set on the water, with ocean as far as the eye can see. My GPU would hate me if I tried to add in giant tiles of ocean in an enormous grid to create the effect. (Actually, it does hate me, because that's my current solution.)

    I want to know how to use my ocean shader and have it apply pretty much everywhere, or seem to, at least. I am following a tutorial on making a procedural skybox shader, so I could make everything below the horizon of the skybox look like my ocean shader. But I don't think that would blend well at all with the ocean tiles that have to be on the island's shoreline.

    Maybe fog would help mask the seam between practical ocean and fictional ocean, but I don't know how to prevent fog from masking the island while masking the ocean horizon; it's a big island, so if you're in a corner of it, the distant ocean will be about as far away as the opposite corner of the island. The fog might also block out the sun.

    This seems like a really huge problem to me, but plenty of games create infinite oceans, and I know for certain that they aren't trying to render in tens of thousands of planes within the player's view distance. Right now, I have around 450 giant tiles of ocean, and my computer isn't happy. How do games like Just Cause 4 and RDR2 do it? 0.png 1.png 2.png
     
    Magic-Thor likes this.
  2. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Creating Infinite horizons is a simple art
    I have provided a simple video for you:




     
    Magic-Thor likes this.
  3. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    32
    Thank you. I'll check it out and see if I can use it.
     
  4. kripto289

    kripto289

    Joined:
    Feb 21, 2013
    Posts:
    505
    You can create a mesh with the size of the current camera far distance. (for example 2000 meters for default main camera) and use relative rendering:
    water.transform.position.xz = camera.transform.position.xz;

    Also in the shader instead of
    i.uv = v.uv;
    you need to use
    i.uv = mul(unity_ObjectToWorld, v.vertex).xz * uvScale;
     
    Magic-Thor likes this.