Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Wanted: Ocean shader

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

  1. U2

    U2

    Joined:
    Aug 12, 2008
    Posts:
    215
    @bigkahuna

    I have changed the formula in the P_spectrum function to account for wind direction based on other implementations of the FFT + P_Spectrum on the web. It seems thought that the actual FFT classes in the Fourier.cs file take in direction from the FourierDirection.cs file which only gives 1 or -1 on the x axis.. it then uses this integer as a basis for cycling through lists in a for loop which doesn't seem to make sense for the classic implementation that takes in sin and cos direction Vector2. To try and say it a little more clearly... I think that the original implementation of this hard coded the x axis direction into the basic setup. To implement the x y direction would require some rewriting of the basic functionality of the current solution.

    I tried the rotations too for the entire world which seems like it could work if you could account for the rotations with the LOD tiling system, the get height at location etc.. functions as well for buoyancy. I stink at rotations math outside of simply assigning an angle to a pre-existing object so if someone else is good at this kind of thing I'd love their input.
     
  2. erune

    erune

    Joined:
    Nov 14, 2009
    Posts:
    63
    Hi,

    I was trying to involve but your works have progressed so far and it is not easy to follow now. I have managed to implement one of the previous versions ( http://dl.dropbox.com/u/483254/Ocean-v3.4-unity2.6free.unitypackage ) into my RTS game, which I am developing with free version of Unity 2.6, but it has stitching problems. There are gaps between ocean tiles and they are very visible from an RTS camera view.

    In short, is there any better version that can be used with unity free?
     
  3. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    Have you tried scaling the tiles larger, I've found that sometimes helps to eliminate viewing the tile edges?
     
  4. erune

    erune

    Joined:
    Nov 14, 2009
    Posts:
    63
    Thanks for the tip bigkahuna. It helped.

    Now I am trying to figure out how can I scale down the ocean. It looks gigantic in my scene...
     
  5. U2

    U2

    Joined:
    Aug 12, 2008
    Posts:
    215
    Ok so the million dollar question... Shall we try and combine the Community Shader with the new water 3 solution? I like how the community shader handles the LOD system and the P_Spectrum I think gives better wave look than the new Unity shader. The new unity shader has the fft option on it plus a whole lot of other features that would be nice to have... I wonder if we could somehow combine the mesh / LOD system with the Unity shader for a really nice effect? Just saying it because I know everyone is thinking it.
     
  6. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    The way I see it, we now have two ocean water shaders: an "official" one that is maintained by Unity Tech and a "community" shader that is supported by fellow users. The goal of the "official" shader is to be a general purpose water shader, capable of being used for rivers, lakes and to some extent oceans. The "community" shader is pretty much solely useful for large areas of open ocean. IMO the community shader has a number of advantages over the official shader if you plan on using it for an ocean environment and that's the one I plan on using for my projects for the time being. As I understand it, the official shader is a work in progress and UT plans on adding more features and improvements in the future. I wouldn't be surprised if we start seeing bits of one shader ending up in the other, but my impression from UT was that their goal was going to be different than that of the community shader.
     
  7. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
    Hi, i'm a part of a students group that are making a naval strategy game in unity3D. We are trying to get the best water we can find (with waves)
    In the game, you control the ship shooting enemies ships, etc
    It is our first game, we are learning C (on college) and JavaScript by our own way. We can not make a relaistic ocean system... we are very noobs at that..
    We are going to buy the water, but we need the things i told before.
    This project can cover that?
    PD: sorry, i can't read 26 pages right now, please answer me
    Thank you
     
  8. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
  9. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
  10. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    I think that version was for Unity 2.6, but I'm not positive. The one I linked to is the one I use, but it also requires Unity Pro.
     
    Last edited: Feb 15, 2011
  11. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
    i use the one you linked me, but indie version...
    damn it XD the other works for indie version
    thank you anyway
     
  12. BooBi

    BooBi

    Joined:
    Jan 18, 2010
    Posts:
    533
    Hi,

    I'm having problems to use that ocean shader on a Mac.

    The demo crashes when we see the water. But the demo works fine on any pc (even old ones). The new ocean shaders from unity works on the same mac and the normal pro water too.

    Do someone had the same problem and knows how to solve it?

    (I don't know anything about macs... It's time to start learning).

    Thank's for your help

    BooBi
     
    Last edited: Feb 15, 2011
  13. U2

    U2

    Joined:
    Aug 12, 2008
    Posts:
    215
    @bigkahuna

    Hey I have a weird problem that maybe you have some ideas on. Normally with the ocean shader the ocean is moved with the player as you cross the tile boundaries. But since my world is very big I need to use a floating origin script to move the player back to 0,0 occasionally. When I do this though everything is fine except the water almost looks like a variable is changed or something by the move and the waves suddenly change position causing sort of a jitter effect. I have tried making the reset coincide with the border crossing in the Ocean.js file but still get the visual problem.

    What is weird about this is that using the normal solution as is when you cross the tile border and the ocean is moved, or my solution you end up exactly in the same place. But with the 0,0 reset it seams to mess with the shader itself. Are the waves in the shader tied to the world's coordinates in some way that would cause this that you know of?
     
  14. immFX

    immFX

    Joined:
    Mar 20, 2010
    Posts:
    109
    @rutecht
    what happens if you parent your player to the ocean GO?
     
  15. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    There's a toggle to turn off "follow main camera" in Ocean.js, did you try that to see what happens?
     
  16. U2

    U2

    Joined:
    Aug 12, 2008
    Posts:
    215
    @immFX I'll give it a try later today my time

    @bigkahuna
    the follow main camera code is what I'm referring to when I mean the ocean follows the player. The problem with this in a huge endless ocean is that eventually when you go out far enough you start to get spatial drift floating point errors in your game. Physics start acting weird etc.. So to counter this every once in awhile you can actually move the player back to 0,0 and everything else in relation to it. The built in follow camera script works great, but for some strange reason when everything is shifted back to 0,0 it causes the ocean shader to shift slightly.
     
  17. ToreTank

    ToreTank

    Joined:
    Jun 23, 2008
    Posts:
    165
    Just out of curiousity - are you moving the player back to exactly 0,0, or do you move back to a position closer to 0,0, but still relative to some "imaginary" space? For example, do you move from (1300, 1200) back to (0,0), or do you move back to (300,200)? Sorry if this seems like a stupid question, just checking :)
     
  18. U2

    U2

    Joined:
    Aug 12, 2008
    Posts:
    215
    Well I have tested a couple variations of this minus parenting the player to the ocean which I'll try after work and let you guys know (lunch break). But my current solution is to leave the ocean still then when the player reaches the edge say > 200 or < 0 then it shifts the player and everything but the water -200 or +200 depending on which axis had been passed over.

    I should mention too that I added another check box for follow player instead of camera since my camera is trailing behind. This works seamlessly with the normal solution minus the reset to origin.

    When I have more time when I get back I'll try a combination of the above and the original built in solution.. i.e.

    Player reaches 200 units, ocean LOD script moves the ocean object in relation to the player as normal, attach camera to player and player to ocean, move everything in the scene -200 including the ocean, unattach above.. rinse and repeat.. I'll let you know how it goes. If I can get this to work I'll definitely post my function for those of you who want to use something similar.

    ====================

    Ok I tested the parenting solution and no love.. so to simplify my problem if you want to try and replicate what I am seeing here is the code...

    Up in the variable declarations add:

    Code (csharp):
    1.  
    2. var followPlayerObject : GameObject;
    3. var followPlayer : boolean = false;
    4. var physicsThreshold : float = 200.0; // Set to zero to disable
    5. var defaultSleepVelocity : float = 0.14;
    6. var defaultAngularVelocity : float = 0.14;
    7.  
    Right after the
    Code (csharp):
    1.  
    2. if (followMainCamera)
    3.  
    closes with } in Update() add:
    Code (csharp):
    1.  
    2. else if (followPlayer){
    3.         var playerpos : Vector3 = followPlayerObject.transform.position;
    4.         centerOffset = playerpos;
    5.    
    6.         centerOffset.x = Mathf.Floor(playerpos.x/size.x) * size.x;
    7.         centerOffset.z = Mathf.Floor(playerpos.z/size.z) * size.z;
    8.         centerOffset.y = transform.position.y;
    9.  
    10.             // Ok our Ocean object changes position with this line to adjust for crossing border
    11.         transform.position = centerOffset;
    12.    
    13.     if (transform.position.x != 0 || transform.position.z != 0){
    14.         // Means we crossed a tile boundary
    15.        
    16.         Camera.main.gameObject.transform.parent = transform;
    17.         followPlayerObject.transform.parent = transform;
    18.         if (playerpos.x > size.x){
    19.             originReset(new Vector3(-size.x,0f,0f));
    20.         }else if (playerpos.x < 0){
    21.             originReset(new Vector3(size.x,0f,0f));        
    22.         }else if (playerpos.z > size.z){
    23.             originReset(new Vector3(0f,0f,-size.z));       
    24.         }else if (playerpos.z < 0){
    25.             originReset(new Vector3(0f,0f,size.z));    
    26.         }      
    27.         Camera.main.gameObject.transform.parent = null;
    28.         followPlayerObject.transform.parent = null;    
    29.     }
    30. }
    31.  
    Then Outside the Update function, maybe right above it add this function...
    Code (csharp):
    1.  
    2. function originReset(playerPosition : Vector3){
    3.        
    4.         var objects : Object[] = Resources.FindObjectsOfTypeAll(typeof(Transform));
    5.         for (var o : Object in objects){
    6.             var t : Transform = o;
    7.             if (t.parent == null){
    8.                      t.position += playerPosition;
    9.             }
    10.         }
    11.  
    12.         objects = Resources.FindObjectsOfTypeAll(typeof(ParticleEmitter));
    13.         for (var o : Object in objects){
    14.             var pe : ParticleEmitter = o;//.ParticleEmitter;
    15.             var emitterParticles : Particle[] = pe.particles;
    16.             for (var i = 0; i < emitterParticles.Length; ++i){
    17.                 emitterParticles[i].position += playerPosition;
    18.             }
    19.             pe.particles = emitterParticles;
    20.         }
    21.  
    22.         if (physicsThreshold >= 0.0){
    23.             objects = Resources.FindObjectsOfTypeAll(typeof(Rigidbody));
    24.             for (var o : Object in objects){
    25.                 var r : Rigidbody = o;//.Rigidbody;
    26.                 if (r.gameObject.transform.position.magnitude > physicsThreshold){
    27.                     r.sleepAngularVelocity = float.MaxValue;
    28.                     r.sleepVelocity = float.MaxValue;
    29.                 }else{
    30.                     r.sleepAngularVelocity = defaultSleepVelocity;
    31.                     r.sleepVelocity = defaultAngularVelocity;
    32.                 }
    33.             }
    34.         }
    35. }
    36.  
    I should also mention that my Ocean object in the scene and my player object are positioned at 0,0,0 before the scene starts. I have a player object and camera object following it. The follow player check box needs to be selected in your ocean settings and unselect your follow camera box, then drag your player onto the player Object field in order for all this to work.

    If anyone could test this out and walk through my logic I think it'd be a nice addition for a lot of people if we could figure out how to fix it. Parenting the object before making the move doesn't actually seem to help but I left it there in case people wanted to see it for themselves.

    I guess I just don't understand why if you move the ocean object only there is no change in the wave positions but if you move both the ocean object and player together then it changes. Somehow there must be something about the player's change of coords that causes the shader to change.
     
    Last edited: Feb 16, 2011
  19. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
    @bigkahuna i don't know how but now the ocean works for me...
    Only one question, the boyancy script must be atached to the objets that we want?? if it is the case, i put it on one simply cube with rigid body, i get this error (NullReferenceException: Object reference not set to an instance of an object). It must be a stupid thing but i don't see the error XD
    thanks
     
  20. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    Did you assign a value to the "Ocean" field for the "Boyancy" script in the Inspector?
     
  21. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
    yep, the ocean gameobjet...
    for example if i drag the Boyant Object prefab that comes with the examples, i don't have any error
     
  22. ToreTank

    ToreTank

    Joined:
    Jun 23, 2008
    Posts:
    165
    @rutecht: Did you figure out what the problem was with the offsetting?

    @boobi: What kind of mac are you on? Is it a hard crash, or a script exception of some sort? Do you have any log files?

    Btw, did you guys see this one? I particularly liked the wave-break effect: http://www.gamedev.net/blog/715/entry-2249487-ocean-rendering/
     
  23. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    Yes, that shoreline is -very- convincing. About halfway throught the video I'd swear it was video of an actual shoreline. I've looked at Outerra also, but from what I've read it's unknown whether indy's will be able to use it in commercial work. Would be nice to have some of those goodies though. ;)
     
  24. erune

    erune

    Joined:
    Nov 14, 2009
    Posts:
    63
    Divinux likes this.
  25. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    681
    It's awesome to see how far you guys came with your ocean project! I would love to test it as I'm currently looking into some water techniques as well, however, I don't have Unity Pro yet :(

    Keep up the good work!
     
  26. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    I have huge seamless continent (24 2000*2000 terrains) and I would like to put ocean around (we have of course loading and unloading terrains and all necasarry stuff). Problem is, that waves here are going in one direction and it would be nice, to have waves aiming always on the shore. How to approch to such problem?
    Our whole game is seamless, so ocean must be too, because ships will sail around whole continent.

    http://www.dropmocks.com/mR6gj

    Modify waves to be instead of line some tightening circle?Tile this ocean somehow? Use one huge ocean mesh? Rotate whole ocean according to position of player, so the waves will always aim shore?

    I dont have slightest clue, how community ocean works, so thanks for any hints how to approach this.
     
    Last edited: Mar 1, 2011
  27. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,223
    what's on that dropmocks link? i see nothing...
     
  28. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Just schema of my contitent and ocean.
     
  29. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,223
    oh, it doesn't show on IE 9. I had to load it on safari.
     
  30. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Anybody tried to start ocean on diffrent cordinates than 0,0,0? I have starting point aroud 4300,100,655. When I put ocean there, it appears on completely different coordinates. If i put it on 0,0,0 and check follow main camera, it is still somewhere else. I am using first person controller.
     
  31. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
    why this happens?

    thanks
     
  32. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    The ship is probably too big and script is meant only for small objects?
     
  33. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Thats nice freestyle ship:D
     
  34. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
    and how can i do it? i have bought the buoyanci toolkit from the asset store but i would like to use this buoyanci prefab
    thanks XD
     
  35. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    You'll need to contact the kit's developer. His product is completely separate from the community ocean shader project, although I was told it should work with it.
     
  36. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
    @bigkahuna yep i know, but i would like to try first the buoyanci script of this community ocean shader project, but i get the problem of the video
    thanks
     
  37. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    @konedj - Looks to me like the script is using the boat mesh to calculate buoyancy which is making it top heavy. Try parenting to a large cube instead.
     
  38. OutCyder

    OutCyder

    Joined:
    Mar 19, 2009
    Posts:
    2,178
    It happens because that ship was built very very badly!
     
  39. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
    why? it only has 3000 polygons, one requirement of my college to the game...
     
  40. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    @konedj - I think megamaltese was joking. Refer to my answer, I think that'll fix it.
     
  41. BooBi

    BooBi

    Joined:
    Jan 18, 2010
    Posts:
    533
    you should use a really simple version of your hull (a box...) and use the buoyanci on that object the link your boat to it. And it seems like with some script you need to but the rigidbody first then the script or the other way (really not sure that's matters but with one of the script that I used it worked). I had the same problem and I cant really remember how I did solve it, but I'm using a box as parent for my catamaran buoyanci.

    yep
     
  42. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Where is in the script hidden Y axis of the ocean? It is fixed to 0 and i need to put it higher.
     
  43. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Could someone tell me if it is possible to see this ocean from underwater too? I have side view game underwater placed and i would like to use this script however i have also problems with getting it set up. I can run it fine in scene created by Nikko but i cant do it with my own scene. What do i have to set up?
     
  44. konedj

    konedj

    Joined:
    Dec 7, 2010
    Posts:
    84
    If i parent a large cube to my ship, put the buoyancy toolkit to the cube and play the scene, when the shiip touch the ground, it dissapears or goes to the sky XD its hard to explain it.. but nothing is working...
    i have bought 2 days ago, the buoyancy toolkit from the asset server, but when im trying to open an example scene in all the objets put: Mono Behaviour, Script: Missing... and also all the materials are without the pictures... so i can't see that example :S
    thanks
     
  45. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,435
    If you're asking about the "Buoyancy Toolkit" that is sold on Asset store, then you're asking the wrong people for help. As I said above, please contact the author of that script.

    If you're asking about the "boyant" object that is included in the community ocean shader, what you need to do is to drag the prefab into your scene, and make sure you drag the "ocean" object to the prefab's inspector for the "ocean" value. That's really all you need to do. You can then make your sailing ship a child of this prefab and turn of the cube's renderer. Also make sure you're using the latest version of the project that's available on Trond's GIT repository: https://github.com/trond/Unity-Community-Ocean
     
  46. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    327
    Hi, I'm the developer of the buoyancy toolkit. The toolkit does not support the Community Ocean out of the box but you may customize it by overriding the WaveFunction() method of the FluidVolume. There are example scenes included that show how to do non-moving water (the Basic scene), sine-based (the Ocean scene) and using Unity's new Water3 prefab (the Water3 scene) that you may look at to see how they work.

    I have no idea why it wouldn't be possible to open an example scene, have you tried creating a new project and then downloading/importing the package?

    Anyway, we should not hijack this thread, contact me through http://gustavolsson.squarespace.com/ if you still have problems with the toolkit.
     
  47. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Does anyone have screenshots of implement underwater effects from this Ocean shader? It says in description that includes underwater effects.
     
  48. dcyuri7

    dcyuri7

    Joined:
    Mar 9, 2011
    Posts:
    4
    The underwater effects(glow,blur,etc) are based upon Pro assets, so you're probably like me using the free version, and thus no effects.
    You can do as I have and work to convert most of the project to a use-able, tolerable, Unity free version.
    So far it works great for me, right out of box most nearly. Had to move the plugin's C# code around(license intact of course) and modify certain portions(pro assets config) for it to operate.

    To my knowledge, the best you can do with free underwater is apply the material(drag/drop Tex2d) or turn off culling(lighting will not be accurate). No post processing in indie version; great marketing ploy I must say.
    I've attempted making blur via shader attached to a small plane perpendicular to and directly in front of - camera. The result was less than pleasing, however it was in fact quite blurry...

    Perhaps some sort of cube positioned such that the camera looks through(attach to fperson controller?) it as a "looking glass", in which you could add maybe some particles for "god rays" when camera rotation is up, and reflection for glow, perhaps Diffuse layers to blur... sounds shoddy, but heh.. I'm open to ideas on this, any other indie's out there playing with this?
     
  49. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    I am in same poll as you are dcyuri. I really need some underwater effects, and i have tried some few things but there just isnt any good way arround for it. You can do some stuff but basically all will look pretty old-gen or too steady for some dynamic water effect. It is really depressing that anything invloved with water/underwater is tightly connected to pro version. Do you want to make moving projector texture for caustic? Sorry you need Pro. Do you want reflection,refraction or blur? Sorry you need Pro.
    Ok i get it, i need Pro....
     
  50. nikko

    nikko

    Joined:
    Mar 20, 2009
    Posts:
    436
    I have continued to maintain my version published a while ago on Unity V2.6.
    But this version is not compatible with Toretank and other improvements (underwater and boyancy)
    I will probably add underwater and boyancy later.

    Now about this version. I have added:
    - transparency to the water
    - deep water thickness (faked but it works good, cost nothing)
    - unity v3 compatible.
    - infinite ocean of course
    - 4 presets: blue sky ocean, tropical ocean, bad weather ocean and sunset ocean. Here are some pictures

    NO post effects added in the pictures. Should work on the free version of Unity.

    Should take several days to go to the Asset Store... be patient.
     

    Attached Files:

    Last edited: Mar 22, 2011
unityunity