Search Unity

Crest [Advanced Ocean Renderer][OPEN SOURCE]

Discussion in 'Shaders' started by RealmLord, Aug 28, 2018.

  1. RealmLord

    RealmLord

    Joined:
    Aug 25, 2018
    Posts:
    5
    CREST
    Crest is a technically advanced ocean renderer implemented in Unity3D 2018.2+.


    https://github.com/huwb/crest-oceanrender

    The Tech
    Some of the core ideas were described at SIGGRAPH 2017 in the Advances in Real-Time Rendering course (course page link). Since this initial publication we have been actively working to extend the feature set, which includes innovations in the following areas.

    Shape
    It is well known that ocean shape can be well approximated by summing Gerstner waves. Dozens of these are required to obtain an interesting shape. In previous implementations this has been prohibitively expensive and shape is either generated using an online FFT, or precomputed and baked into textures.

    We generate shape from Gerstner waves efficiently at runtime by rendering at multiple scales, and ensure that waves are never over-sampled (inefficient) or under-sampled (bad quality, aliasing). This is highly performant and gives detail close to the viewer, and shape to the horizon. This gives considerable flexibility in shape and opens possibilities such as attenuating waves based on ocean depth around shorelines.

    To control the ocean shape, we introduce an intuitive and fun shape authoring interface - an equalizer style editor which makes it fast and easy to achieve surface shape. Art direction such as small choppy waves with longer waves rolling in from a storm at the horizon is simple to achieve in this framework. We also support empirical ocean spectra from the literature (Phillips, JONSWAP, etc) which can be used directly or as a comparison.

    For interactivity we add a dynamic wave simulation on top of the ocean waves. The simulation is computed on a heightfield and then converted into displacements, which trigger foam generation and enable boat wakes to be generated. This is demonstrated in the boat and threeboats example scenes.

    The final shape is asynchronously read back to the CPU for gameplay/physics use. This gives access to the full, rich shape without requiring expensive CPU calculations or pipeline stalls.

    Mesh
    We implement a 100% pop-free meshing solution, which follows the same unified multi-scale structure/layout as the shape data. The vertex densities and locations match the shape texels 1:1. This ensures that the shape is never over-sampled or under-sampled, giving the same guarantees as described above.

    Our meshing approach requires only simple shader instructions in a vertex shader, and does not rely on tessellation or compute shaders or any other advanced shader model features. The geometry is composed of tiles which have strictly no overlap, and support frustum culling. These tiles are generated quickly on startup.

    The multi-resolution representation (shape textures and geometry) is scaled horizontally when the camera changes altitude to ensure appropriate level of detail and good visual range for all viewpoints. To further extend the surface to the horizon we also add a strip of triangles at the mesh boundary.

    Shading / VFX
    Normal maps are elegantly incorporated into our multi-scale framework. Normal map textures are treated as a slightly different form of shape that is too detailed to be efficiently sampled by geometry, and are sampled at a scale just below the shape textures. This combats typical normal map sampling issues such as lack of detail in the foreground, or a glassy flat appearance in the background.

    The ocean colour comes from a subsurface scattering approximation based on view and normal vectors, and primary light direction.

    Foam is shaded in two layers. Underwater bubbles have parallax and refraction offsets to give an impression of depth. White foam on top of the water is shaded with a simple 3D lighting model using procedurally generated normals.

    Transparency and refraction are also supported, and Schlick's fresnel approximation selects between the refracted colour and a reflected colour. There is an option on the material to boost specular highlights by adding directional lighting if needed.

    All shading features are on static switches and can be disabled if not required.

    As an area of future work, the branch fx_test explores dynamically generating spray particle effects by randomly sampling points on the surface to detect wave peaks.

    P.S: Please check the github for author information. I am just posting this here
     
    Last edited: Aug 30, 2018
  2. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,763
    hmm.. not 5.6 friendly. shame. Ah well, if you will use GPU readback... ;)
     
  3. RealmLord

    RealmLord

    Joined:
    Aug 25, 2018
    Posts:
    5
    Hi sorry, that just went over my head. Could you please elaborate whether this is good or bad?
     
    twobob likes this.
  4. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,763
    well it's only bad for people who use the older version of unity :)
    "GPU readback" is the commit where you switch across to a later version of unity "and no going back"
    Yes, I was trawling your commits to see if I could use it in 5.6.

    @RealmLord thanks anyway though. nice project
     
  5. RealmLord

    RealmLord

    Joined:
    Aug 25, 2018
    Posts:
    5
    Apologies,op
    This isn't my project, I just came across it and thought might interest everyone here.
     
    twobob likes this.
  6. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,763
    Hah sure man.
    It did. I'll make a few notes on the repo and see if it gets tidied up

    It is 2018.x minimum anyway :)

    Appreciate it :)
     
    Last edited: Aug 28, 2018
  7. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    4,881
    I like this, but it should go in its own thread, instead of in the Community Ocean Shader thread.
     
    erenaydin and twobob like this.
  8. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,763
    My thoughts exactly
     
  9. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    379
    if you go back far enough in the commits, there's a 2017 version. It just lacks a few of the newer features.
     
    twobob likes this.
  10. VavylonaEntertainment

    VavylonaEntertainment

    Joined:
    Oct 21, 2015
    Posts:
    143
    Just tested it, easy to setup, realistic waves but:

    1) You need to make a realistic shader/textures
    2) Expose the visual settings to the main menu so the user doesnt have to edit the material itself
    3) The system should automatically add the required layers

    Keep up!
     
  11. Dekata

    Dekata

    Joined:
    May 20, 2016
    Posts:
    46
    ocean is very nice, maybe the best for unity atm, but foam isn't clear, how to add more to boat?
     
  12. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,111
    Looks great. Does it support wakes and reflections? A good ocean system seems to be a holy grail for Unity.
     
    Bartolomeus755 likes this.
  13. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,474
    You should be aware there is no active development on this as the author does not have time. If you have to ask if something is supported, then it is best to change the question to how you can do it yourself.
     
  14. ekergraphics

    ekergraphics

    Joined:
    Feb 22, 2017
    Posts:
    257
    This is amazing. I completely missed this. As for the development, I see on Github that a pull request was just merged 3 days ago, so it does seem to have some life!

    EDIT: Should this thread be merged with this one, perhaps?

    https://forum.unity.com/threads/crest-open-source-unity-ocean-renderer.548212/
     
    Last edited: Oct 30, 2018
  15. christal-gary

    christal-gary

    Joined:
    Aug 28, 2013
    Posts:
    1
    Thank you Crest! This is rendered using crest!
     
    huwb, ceebeee and erenaydin like this.
  16. Parallel_

    Parallel_

    Joined:
    Dec 9, 2012
    Posts:
    90
    How would one best get the foam coordinates for adding particles in those areas?
    I'm not really C# litterate but trying to understand the process to reverse engineer to playmaker. I see a float4 for vertex position in UpdateFoam.shader but is this where you'd get the final calculations after sim-settings have been taken into account? I would have tried this option out but the relevant action doesn't exist for PM yet.
     
  17. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,022
    anyone knows how well this runs on mobile?
     
  18. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,474
    I would err on the side of "it doesn't run". More like hobble or sink.
     
    ceebeee likes this.
  19. dimitris_baud

    dimitris_baud

    Joined:
    Jan 15, 2018
    Posts:
    4
    Hi, first of all Crest is amazing, thank you for sharing!

    I am trying it out and have several objects deforming the water which after some time gets out of control. Is there a way to gracefully "flatten" the water to its original state, removing all information added on top by objects registering waves?

    `OceanRenderer.RegenMesh()` didn't seem intended for that purpose.

    Thank you.
     
  20. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
    Looks great. Constructive criticism: you're going to need a bigger boat

    tone
     
  21. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    717
    Any plans for supporting point and spot lights anytime soon?
     
  22. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    717
    I am looking into limiting the size of the ocean so that it is not infinite but instead limited to a length/width of quads.

    For performance reasons and the fact that I won't always be needing an infinite ocean but just a water plane that fits within a certain area.
     
  23. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    717
    Hrmph it appears I would need to basically strip out this Lod system and rewrite the whole section entirely to be able to set a set width and length of the ocean quads.

    From what I can tell messing around with the LOD system, this seems possible to do.
     
  24. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    717
    Oh and by the way ive just done an underwater shader with Fog and perfect clipping with wave height as the character controller traverses the waves normal height.

    Ill see if i cant show that in the video as well by making some large wave clip the player so you can see the underwater view and above water view perfectly transition. ;)

    Ill go ahead and post a few pics without revealing my scene yet, dont want to show you guys what im working on until its .. abit more ready.
     
  25. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    717
    Ok here is my underwater shader.

    Still a work in progress and there is only one drawback, cant have transparent objects under the surface yet.

    For my purposes i may not need to have transparency on other objects under the water. Like i said still working on it so I may find a solution to that.

    Going to add underwater debrees as well as a transition FX screen shader for splashes.

    I noticed doing a search alot of people were trying to figure out how to do exactly what I've just done ;)

    To make it look better a blur effect would need to be added where the seam meets. I think that is doable as well but will have an impact on performance.
     

    Attached Files:

  26. blogsabout

    blogsabout

    Joined:
    Aug 20, 2014
    Posts:
    43
    Have anyone experienced that your ocean turns pink when opening the file after it has been closed down?
    It was looking so gorgeous and I can see the settings are the same and enabled...but now pink?

    PS. For those wanting to use the planer reflections and can't get it to work, remember to add the Planer reflection script to the camera.

    EDIT: I noticed that in the material editor all settings are disabled and therefore the pink color.
    The material doesn't exist in the list ("Crest>Ocean")
    When opening the full package and opening one of the projects, playing around the materials is in the shaderlist (Crest>Ocean).

    When closing the project down and opening again it's all pink and this error:
    Shader error in 'Crest/Ocean': 'SkyProceduralDP': no matching 2 parameter function at Assets/Crest/Crest/Shaders/OceanReflection.hlsl(74) (on metal)"

    ...so weird? Reflections worked perfectly before closing the project down. (using MacBook Pro mid 2018)
     
    Last edited: May 22, 2019
  27. rafayel_v_unity

    rafayel_v_unity

    Joined:
    Nov 21, 2018
    Posts:
    1
    Is there a way to change size of the LOD for wave/fom for spectrums, the tiling can be seen even if the waves are relatively small and little or no foam is generated.
    Basically we would want to get rid of the square shaped area of single spectrum.

    upload_2019-8-23_17-25-59.png