Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Wanted: Ocean shader

Discussion in 'Works In Progress - Archive' started by bigkahuna, Jan 8, 2009.

  1. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,487
    Oh forgot to mention....it's only works on Pro since it need depth buffer....(sorry)
     
  2. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    728
    Without using pro only features, is there another way to detect the shoreline? Baking a shoreline region doesn't work well when the water surface is animated. How else can it be done? I was thinking maybe each vertex of the ocean surface could send out rays, and generate foam whenever a ray intersected a terrain or mesh object within a certain radius. I don't know how to actually accomplish this though, how feasible it is, or what the performance hit would be. If someone knows the answers to these questions, I'd love to hear them. Can anyone think of another way?
     
  3. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,487
    Well if you can't use depthbuffer then the only ideal choice is using pregenerated shoreline texture, you might want to read about it here http://www.fxguide.com/featured/assassins-creed-iii-the-tech-behind-or-beneath-the-action/ they explain how they did shoreline/coastal foam
     
  4. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    728
    Thanks for the link. Unfortunately it doesn't change anything for me. I've already admitted the coding required is beyond me. If I could do it myself, I wouldn't be here looking for answers. While I can admire the pretty pictures, I still can't duplicate what they did using the information provided. But if you, or anyone else, understands this stuff enough to reverse engineer it, there's an opportunity here. While I'd love to see some of this stuff incorporated into the community ocean project, I'd settle for an asset that I, and other Unity users, might buy.
     
  5. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    We are implementing water for our current project and have been testing various approaches including the community solution. One strange thing with the community project though is that it seems to occasionally hang the editor. I saw this mentioned earlier in the thread and was perplexed to have it happen to us (repeatedly) even now after a few years have passed. Anyone know why this might be happening? I am especially interested to learn whether it is related to the FFT library since we are considering relying on that.
     
  6. firestorm713q

    firestorm713q

    Joined:
    Jan 6, 2013
    Posts:
    16
    Agreed. There are definitely some major improvements to be made. I've gained a massive interest in this project over the semester, as I wanted to do a naval game, and needed to have an algorithm to study for my Theory of Algorithms class. Not only that, it might be both part of my Software Engineering project, and also end up as my graphics project. I was actually curious if there was a current wish/todo list of features and improvements for the ocean shader.

    So far, my list is:
    • Better shore waves
    • Fewer Pro Only Features(Especially underwater for indie users)
    • Better buoyancy script
    • Wind Direction
    • Unity 4 integration
    I have some basic ideas on some of these, but I want to make sure I have a complete list before I start rewriting the whole thing. I do think that some things will require a massive overhaul, like handling shore waves, wind direction, and making it so that indie users can utilize it (I barely could before I got a pro trial).

    If anyone has anything else to add, please let me know. It's been a good week or two since I combed through the entire thread, so I'm not sure if I was able to remember everything I saw pop up a lot.

    --Q
     
  7. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    6,866
    What are the Pro only features that would hold back the quality? Is it something that is able to be toggled?

    Honestly, if supporting non-pro were make-or-break awesome ocean water, then just use the pro features.
     
  8. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    728
    To quote my own earlier post:

    I think if you choose the right way to produce shoreline foam, e.g. detect anything intersecting the surface and generate foam around it, you should also be able to deliver boat wakes and splashes for free.

    I'd also like to see reasonably good transparency and underwater fog and surface effects, independent of Unity Pro. To answer zerobounds question, the original ocean shader includes things like caustics and reflections that may need Pro, but has check boxes to disable them for Indie users and people with slower game platforms. This is probably still the best way to go, from a performance/compatibility viewpoint.

    My only other major concern is simplicity and stability. The simplest way to do something is often the one with the fewest problems. Too many settings and tweaks can make it a nightmare to set up and maintain, especially when Unity changes something at their end.

    Hope this helps. Good luck.
     
  9. firestorm713q

    firestorm713q

    Joined:
    Jan 6, 2013
    Posts:
    16
    In the realm of programming, nothing is free :p
    But no, seriously. Detecting everything intersecting the surface is a little crazy. You'd basically have to do a triangle collision on every part of the mesh.
    The way I would go about detecting shores and whatnot is by grabbing the actual heightmap from the terrain, and then using that to determine where to place the foam. Then it'd be a "simple" process of making the foam fade out as it gets further away.

    Detecting object collisions is trickier, but I think one could just add a mesh collider onto the whole component, and use collision masks to do buoyancy. A collider would be nice, too, because that also means one could do raycasts from their player to detect whether the player is underwater or not.

    boat wakes could be as simple as having foam trail behind the boat, and splashes could mostly just be foam where an object impacts, plus a simple particle effect, but beyond that, you'd have to layer something like Wave Particles. I'll see what happens over the next few weeks, and report back as I find stuff out.

    @zerobounds
    Underwater is flatly broken without pro, though. Not sure why, but I was not able to get it to work until I got my Pro Trial with my Oculus Dev kit. I'll probably get something set up so I can work on the shader parallel in pro and free, just to see the various differences and modifications needed to switch the shader between.
     
  10. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    728
    Cool. You obviously know more about what's going on under the hood than I do. But the great part is that you seem to know the issues, and have some ideas about how to tackle them. I've seen and tested various water packages that all do things differently. There are some free shoreline foam scripts available that require users to export a mesh terrain to their 3D app, create a shoreline mesh from the terrain, bring this mesh back into Unity, and add an animated foam texture to it. One supposedly does the shoreline generation for you with a script, but I've never had more than mediocre results with it. Water+ is a commercial water package that also forces users to bake the shoreline area in advance. None of these methods looks good on a water surface that's moving up and down all the time due to wave displacement. Unity's own Water4 though seems to do this quite nicely, with no prior user intervention required, so they obviously have a completely different approach. Too bad it's a Pro only feature. My surface intersection detection suggestion was just an ignorant attempt to guess how something like that might be done. Even when I made it, I was thinking you'd need to find a way to limit it to certain areas or it could get expensive. Your answer sounded much more thought out though, so go with the simpler method.
     
  11. neroziros

    neroziros

    Joined:
    Aug 25, 2012
    Posts:
    129
    Hi all!

    Does anyone knows if there have been more progress on this area?

    I tried to port the blender code to Unity to no avail :( If anyone is interested, here is the glsl code:
    http://mysticpaste.com/view/Z8FACihFWA?2
     
    Last edited: Nov 18, 2013
  12. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,444
    Hi guys,

    1. What is the best looking free ocean script/shader/package at the moment?

    2. If you use Water4 and are curious how to calculate water level at any given position (for buoyancy simulation, for example), then here is a helper script. Attach it to the water object and call SampleHeight(x,z) to get the height.

    PHP:
    using UnityEngine;

    public class 
    WaterLevelSampler MonoBehaviour
    {
        private 
    Vector4 amplitude;
        private 
    Vector4 frequency;
        private 
    Vector4 steepness;
        private 
    Vector4 speed;
        private 
    Vector4 directionAB;
        private 
    Vector4 directionCD;
        
        private 
    Material material;

        private 
    void Start()
        {
            var 
    water4 GetComponent<WaterBase>();
            
    material water4.sharedMaterial;
        }

        private 
    void Update()
        {
            
    ReadWaterSettings();
        }

        public 
    float SampleHeight(float xfloat z)
        {
            var 
    offset GerstnerOffset4(new Vector2(xz));
            return 
    transform.position.offset.y;
        }

        private 
    void ReadWaterSettings()
        {
            
    amplitude material.GetVector("_GAmplitude");
            
    frequency material.GetVector("_GFrequency");
            
    steepness material.GetVector("_GSteepness");
            
    speed material.GetVector("_GSpeed");
            
    directionAB material.GetVector("_GDirectionAB");
            
    directionCD material.GetVector("_GDirectionCD");
        }

        private 
    Vector3 GerstnerOffset4(Vector2 xzVtx)
        {
            var 
    xzVtx.x;
            var 
    xzVtx.y;

            var 
    ab Vector4.Scale(steepness.Reassemble(0011), amplitude.Reassemble(0011));
            
    ab Vector4.Scale(abdirectionAB);

            var 
    cd Vector4.Scale(steepness.Reassemble(2233), amplitude.Reassemble(2233));
            
    cd Vector4.Scale(cddirectionCD);

            
    Vector4 dotABCD;
            
    dotABCD.directionAB.directionAB.z;
            
    dotABCD.directionAB.directionAB.z;
            
    dotABCD.directionCD.directionCD.z;
            
    dotABCD.directionCD.directionCD.z;
            
    dotABCD Vector4.Scale(dotABCDfrequency);

            var 
    time Time.time speed;
            
    dotABCD += time;

            var 
    sin dotABCD.Sin();
            var 
    cos dotABCD.Cos();

            
    Vector3 offsets;
            
    offsets.Vector4.Dot(cos, new Vector4(ab.xab.zcd.xcd.z));
            
    offsets.Vector4.Dot(cos, new Vector4(ab.yab.wcd.ycd.w));
            
    offsets.Vector4.Dot(sinamplitude);

            return 
    offsets;
        }
    }

    internal static class Vector4Extensions
    {
        public static 
    Vector4 Reassemble(this Vector4 vint index0int index1int index2int index3)
        {
            return new 
    Vector4(v[index0], v[index1], v[index2], v[index3]);
        }

        public static 
    Vector4 Sin(this Vector4 v)
        {
            return new 
    Vector4(Mathf.Sin(v.x), Mathf.Sin(v.y), Mathf.Sin(v.z), Mathf.Sin(v.w));
        }

        public static 
    Vector4 Cos(this Vector4 v)
        {
            return new 
    Vector4(Mathf.Cos(v.x), Mathf.Cos(v.y), Mathf.Cos(v.z), Mathf.Cos(v.w));
        }
    }
     
    Last edited: Nov 20, 2013
  13. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,646
    Bam!!! :)

     
  14. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I really don't like water4 at all, i actually really like a few versions of the community shader, it can look really nice although its a death knell to performance

    I know it's not free but it is in beta for version 2 so i feel more willing to mess about with it, suimono's probably going to look really good by the end of the beta period, ridiculously good possibly, there's some great work by a fellow doing an ocean in the wip thread that isn't really game friendly as it stands but as its open source any one of you could take it and try and make something super from it, personally i'm going to try every manner feasible to get the fft ocean animation into suimono, not that i work for those guys/guy, but i really like the idea of have a suitably mighty ocean package that turned out a nice investment since i bought it absolutely ages ago
     
  15. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,444
    Holy s...! :eek:
     
  16. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I'm not actually that impressed by that water to be honest, i think i've had similar results with the community water, the physically based lighting is very nice and surface colour wise its attractive and realistic, but quite short on information regarding your options. Also i guess they're still working out their lodding too because you could see where tiles split really obviously at one point
     
  17. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    This looks quite impressive. Now if it had deep fog and caustics, I'd probably buy it.
     
  18. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Sadly, as a DX11 solution, it's not that platform agnostic...
     
  19. nipoco

    nipoco

    Joined:
    Sep 1, 2011
    Posts:
    2,008
    Well that is true.
     
  20. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,487
    True, water4 is kinda limited but it's also somehow flexible. Unity did a great job creating it. With some decent water mesh and little bit modification you can get a good result for ocean, well surprisingly

    Edit:
    @alexzzzz : btw your script for sample water4 height works great
     
    Last edited: Nov 20, 2013
  21. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,961
    Worst thing with water4 is the lack of lighting, if someone could fix that it would be a lot better : )
     
  22. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    6,866
    Way to go, negative Nancy!

    No but really i almost choked on a hweat thin when i saw that video.
     
  23. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,487
    Lol...but he got the point though...it would be better if it's support multiplatform...
     
  24. navalaction

    navalaction

    Joined:
    Jun 18, 2013
    Posts:
    12
    well. trying to appease every platform will achieve mediocre results.
    our custom Unity shader for example can only work on pc and next gen consoles, and our potential players are fine with it.

    trying now to make it change real time from calmness to storm and back.







    http://www.navalaction.com/blog/
     
    Last edited: Nov 25, 2013
  25. norby

    norby

    Joined:
    Jul 10, 2006
    Posts:
    277
    wow wow wow this is fantastic
    unbelievable realistic :)

    Norby
     
  26. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Well that must be best looking ocean shader ever created for gaming industry.
     
  27. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,487
    Hmm...did you guys remove the light scattering in the water? i remember seeing some screen shot with light scattering in it.
     
  28. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,340
    is this last navalaction.com thing using the community ocean shader? :confused:
     
  29. navalaction

    navalaction

    Joined:
    Jun 18, 2013
    Posts:
    12
    We have developed a custom shader.
     
  30. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,340
    hmm so why posting here? I don't want to be a jerk but if it's just promoting a different product it doesn't make sense unless it contributes to the original thread
    it would be great if you can share how to do the shader or some pointers :)
     
  31. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Quite right. My interest has always been focused on higher end PC / Windows machines. Your screenshots look amazing. Very good use of particles and fog. Wish I had your talent. :)
     
  32. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    $Screenshot_2013-11-30-07-47-36.png $Screenshot_2013-11-30-07-48-09.png $Screenshot_2013-11-30-07-48-18.png

    heres screenshots of something i did ages ago with the community ocean, i think its nifty!

    All taken from my phone as screenshots
     
  33. navalaction

    navalaction

    Joined:
    Jun 18, 2013
    Posts:
    12
    beautiful
     
  34. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    since im pimping everywhere else, here's my flavour of the suimono 2 beta, using suimonos shaders mixed with scrawks awesome whitecaps ocean generation and lighting, and some RTP landscape love, 3 days work, ocean's at an easy 300fps on a 580 without terrain



    im hoping that as i cant really do much for the old community shader, i can try help get an affordable package (not my work) full of good stuff, assuming it reaches the standards needed to be released as a little addon for suimono, so, maybe not free but its a contribution to the options
     
  35. navalaction

    navalaction

    Joined:
    Jun 18, 2013
    Posts:
    12
    Our ocean shader in action - with ships

    Frigates in the fog


    Unity3d is amazing!
     
  36. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,114
    Please stop teasing us, and tell us you will be releasing your ocean as a plugin ;)
     
  37. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,273
    I second that.
     
  38. navalaction

    navalaction

    Joined:
    Jun 18, 2013
    Posts:
    12
    we will after the launch of the game next year.
    we promise.
     
  39. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    @navalaction - really great work there! Congratulations with what you have done so far and good luck for the game. Looking forward to you releasing both the game and the plugin ;)

    - Matt.
     
  40. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    It better be better than mine! I like clearly won product battles. Anyways I keed, whatever I achieve with my water, which is really suimono and scrats water, if it turns out good it'll no doubt be available for suimono customers, as it stands anyways. Lookin forwards to much of stuff maturing on unity that is also based around fluids, and i'm hoping upcoming releases that might do a bit of water better than another wont price themselves out of obtainability
     
  41. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,497
    Damned I can not resist to post an answer to this. :D
    Yours look much nicer but my excuse is it that my storm runs on a telephone.

    Corvettes in the fog (on iPhone 4S)

     
  42. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,497
    Youtube often blurs all details :-/
     

    Attached Files:

  43. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Vic20: Really great stuff! And Mobile Ready? Wow!

    The buoyancy scale seems a bit off to me. The ships seem too light and too small... almost as if it were a miniature shoot... But these are picky details!
     
  44. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,340
    Vic20, mobile? using the community ocean shader? or you got your own stuff?
     
  45. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,497
    Thanks.

    Yes made for mobile from ground up. I will not use that for the desktop version. It is not based on the community shader, it's my own solution (I've started working on mobile water solutions in 2009 and also experimented with something based on the community ocean in 2010).

    Ships may look small because that is the highest sea state in the game and because the youtube video blurs all the fine details. Scale looks much better when the details on the surface are crisp. (Also the ships are pretty small, their length is just like 50m and smaller than of a submarine)

    Same for the weight - ships look light because that kind of sea state is really powerful (8 m wave height) and hard to handle, I know I still have to tweak that a bit… for a test I've tried to switch to one (the best free) of the buoyancy scripts available on the forums. But the ships started to fly over the surface during this kind of sea state, 40% of the time they were completely out of the water keel meters above the surface and 40% of the time almost completely submerged (including superstructure). I've tried to tweak that (with the look of buoyancy only in mind), but finally gave up after 5 hours. So I've kept my own buoyancy solution.

    Beside buoyancy the problem is that it is necessary to keep the realistically:
    - turning radius per ship
    - behavior of ship collisions
    - acceleration

    That's more tricky than one would think especially how to handle drag.

    Next problem (with ship seems look light) is that I think most of us people behind computer screens completely underestimate what's going on with ships in a heavy storm on the ocean. This absolutely awesome video shows that it can be scary, heavy ships look much lighter than one would expect:



    Exactly same water, just different weather settings:

     
  46. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,497
    Seems that the forum text editor is not working correctly anymore?

    Anyway I think navalaction did an awesome job when you compare their video to the real storm video I just posted.

    I forgot to add that I still have to add bow spray particles etc. and as you can see in the ocean storm video this might be an important factor for a much more plausible look.
     
  47. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I think your water looks great VIC-20, wouldnt have thought id see water like that on a mobile. I got the community ocean running at an acceptable frame rate on a galaxy s2 but then theres all the other stuff needed! I actually found the way the ships moved the most impressive thing about it, totally prey to the sea, seemed to be fighting the waves and the turning being affected very realistically. Have you got a minimum spec for a phone to run it? I started with an original Destiny when I started with mobile dev but ive decided to be as indulgent with mobile dev as with desktop now so if a make something that needs a phone as strong as my HTC One, its not going to work on anything less hah
     
  48. John-G

    John-G

    Joined:
    Mar 21, 2013
    Posts:
    1,114
    So looking forward to WOTA, switched to iPhone for this and Pacific Fleet titles.
    Ocean looks fantastic on mobil Vic.

    And yes ships in heavy seas are thrown about with little regard for tonnage. Water sure has power behind it.
     
    Last edited: Dec 16, 2013
  49. VIC20

    VIC20

    Joined:
    Jan 19, 2008
    Posts:
    2,497
    I really feared I would hear that someday :D
    I don't like android so I love to hear that.

    As long as I don't run into memory issues (because of the rest of the game) minimum target device is 3GS and iPad1. But with reduced stuff in the fragment shader. The basic line is 4S. Will add more eye candy to the new devices.
     
  50. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I'm stuck on Android.. mainly cause for my uses, having an iphone means having a decent mac too, maybe if i win the lottery

    Ahh well, if it's not coming to android i can at least watch footage of it, and meanwhile try get some well performing water for android figured out, but probably for a less seriously themed game than your own. Targetting Adreno 320 and ogles 3 so eye candy everywhere, but with plans as they are, thats not coming along for quite a while
     
unityunity