Search Unity

Surface Waves - Dynamic Rivers, Lakes and Oceans

Discussion in 'Works In Progress - Archive' started by RC-1290, Jun 6, 2014.

  1. jiezhixing009

    jiezhixing009

    Joined:
    Jun 13, 2014
    Posts:
    2
    How do I use Surface Waves

    Hello, dear author, I now have to buy the you of the plug-in, from the unity of the AssetStore, but why you this plugin without any demo or readme?

    I think a river flood flow simulations, the swamping effect of, for example, it can control the flow of water velocity, water level and so on, but I don't know how to start, I am very confused, I don't know how to use.

    I hope you can instruct me how to use your plugin, to hope to be able to reach you on AssetStore brilliant effect.

    If you can give me an existing Demo project is good.

    Very urgent. Urgent urgent!

    Looking forward to your reply.

    Thank you.
     
  2. jiezhixing009

    jiezhixing009

    Joined:
    Jun 13, 2014
    Posts:
    2
    I hope you can instruct me how to use your plugin, to hope to be able to reach you on AssetStore brilliant effect.

    If you can give me an existing Demo project is good.

    Very urgent. Urgent urgent!

    Looking forward to your reply.

    Thank you. upload_2015-5-18_1-27-9.png

    upload_2015-5-18_1-27-9.png
     
  3. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    You can customize the shader in whatever way you want. It needs to be able to displace the vertices, and generate the normals, other than that it is entirely up to you :).

    Sorry for the lack of updates on this product.
     
  4. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    The i7 has a built in graphics chip, which the online demo is probably using. If you can force your browser to run with the high performance graphics chip, it should run a lot faster.
     
  5. Charles-Van-Norman

    Charles-Van-Norman

    Joined:
    Aug 10, 2010
    Posts:
    86
    Have you fixed the draw call issue yet? I will purchase this for my game (Mathbreakers) if the draw calls are reasonable.
     
  6. mruce

    mruce

    Joined:
    Jul 23, 2012
    Posts:
    28
    Hi RC-1290,
    I'm using Surface Waves for a while now and I love it. For a project I'm working on now (interactive installation about flood propagation/prevention) I need to start simulation from a certain state. Is there a way to save current state and load it afterwords? I'd like to run simulation in editor, take a state snapshot and use it as the input data for another run.
     
  7. Fodalichking

    Fodalichking

    Joined:
    Mar 18, 2015
    Posts:
    14
    Hi RC-1290,
    You've done a really good job with Surface Waves, congrats. I've bought it and while integrating I've noticed some weird bugs related to transparency regarding the use of the Ocean(Complex) shader in unity 5(I also didn't like the look of it). I end up rewriting the Water4 shader with the input for the height and water data and it worked great with no transparency issues.


    I still have a handful issues, like:
    1 - Real time (accurate) Reflections! I've been doing some research trying to make them look right, but it seems to be a really hard task. I even saw your comments on a post suggesting reflection probes, but the results of it are not that great. The standard planar reflection doesn't really work since we can have many "lakes/puddles" in different heights. Do you think a solution with Screen space reflection could solve this issue? I saw a solution with it, but the water had no transparency...
    2 - Fog underwater. Most of the solutions I've found are based on water planes that have a specific height which is not our case here.
    3 - Depths. I would like to have a nice depth effect just like in this video
    . Is that possible?

    Anyway, I have a complete list of features I want to implement over that
    - Support wind forces
    - Fog underwater
    - Support floating objects (Like SUIMONO or Dynamic water system does)
    - Trails
    - Depth
    - Ripples
    - Mesh tessellation ( optimization )
    - Caustics
    - Non planar reflections ( Change shader by distance to use SSR by being opaque)
    - Drains to avoid water retained on the sides.
    - Waterfalls

    Cheers,
     
  8. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Hey Fodalichking

    I haven't worked on Surface Waves in a while, but maybe I can at least help answer some of your questions.

    1. Screen Space Reflections would probably be the most appropriate approach, since it's most important to see terrain reflected in the water.
    2. Underwater fog is a bit of a nasty (but not impossible) problem, especially when waves get very high, because when you look through a wave, onto the rest of the water, you have a complex air, water, air, water, situation going on. So unless you want to use ray marching or depth peeling, you might want to ignore that case.

    It should be possible to generalize the depth fog by rendering separate depth passes for the front and the back of the water, and then using that depth information to determine how much fog there is. That might require some more meshes affected by the simulation data though.
    3. Surface Waves comes with a shader with a depth effect (besides the simple transparency one), so I'm not sure what you're after specifically.

    - Wind would be cool.
    - I wrote a bit about underwater fog above.
    - There is rudimentary floating object support in DX11 mode. The problem is getting data back from the GPU to the CPU, which is slow, and would require some clever hacking to do on non-compute systems.
    - Trails? Are you talking about the effect of floating objects on the water? Yeah... it was near the top of my todo list, when I stopped working on it :(.
    - The fancy shader has a depth effect. It's the one I used in the trailer.
    - The whole simulation is like a ripple tank. But I'm guessing you want a similar effect on a smaller scale, right?
    - The tessellation problem should really be solved with a projected grid mesh, so that the level of detail is directly based on the amount it takes up on screen.
    - Caustics... are tricky. Especially if you want both volumetric caustics visible in the fog, and the caustics created on surfaces. I saw some experiments that faked the effect using height data, so it should be possible to make something plausible. But I'd say it's only worth it if underwater fog is a thing.
    - Having Screen Space Reflections would indeed be nice ^_^
    - There are drains. Just set an input to negative. Or are you talking about modifying the simulation to drain water from the edges?
    - Waterfalls are so inherently 3D, that it would have to be done separately. I guess you could integrate it with the Surface Waves simulation with some drains and sources, but since Surface Waves uses a 2D mesh, 3D waterfalls just won't look great.
     
  9. Fodalichking

    Fodalichking

    Joined:
    Mar 18, 2015
    Posts:
    14
    Hey RC-1290
    Thanks for the answers.
    The depth that I'm looking for is something similar to the video that I've posted in my previous comment. You can see that the guy controls the colors, etc.

    About the SSR, it seems to work only on opaque surfaces.

    I would like to ask you, is there is an easy way to identify the places where the water is elevated ( forming lakes or puddles )?

    The trail that I'm talking about is something like a boat or a ship passes and leaves a trail behind it.

    You're right about the ripple effect. I want it in a smaller scale and when the mouse moves. The problem is I don't want to add or remove water while doing that. Is that possible?

    About the drain, I'll see if I can explain better, the game that I'm doing has a big static terrain and a custom terrain in the center. The simulation happens only over the custom one, so when I'm adding water on the custom terrain over the boundaries, the water should kinda flow off it ( right now it retains and looks like a water tank with invisible walls, lol ).
    I guess I'll have to create a drain with a texture represented by a line and put it on the sides of the terrain, right?

    thank you again,
     
  10. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    That's why I'm confused. I have depth based fog that can have any color you want:
    (if the timestamp doesn't work, 2 minutes, 6 seconds)

    Technically, SSR should work for any surface. But I guess that an existing product from the Asset store might need some change to pick up on transparent objects.

    The water height texture has this information. I suppose you want access to it on the CPU, which is tricky. I only really have code for that in Surface Waves for the experimental buoyancy simulation (using DX11)

    Yeah, I didn't make the top-down displacement effect. You could render things on the terrain camera to create ripples through its bottom up displacement though, which you can see at 2 minutes and 19 seconds of the video I linked above.

    Yeah, that seems like a workaround that would work. I believe there are ways to change a simulation like this one to have different boundary conditions, where the water just flows out. But I never got that to work without creating odd waves coming from the edges. It should technically be possible though.
     
  11. Fodalichking

    Fodalichking

    Joined:
    Mar 18, 2015
    Posts:
    14
    Hi RC-1290,
    I have both SSR and Candela SSR solutions and both don't work with transparent objects.
    I sent them an e-mail and the answer I got was "SSR cannot reflect anything transparent, since transparent object is not writing to the Z buffer.
    That's not our limitation, it's in general - any SSR cannot reflect transparent objects."

    About the features, I was able to do the ripples with the technique you showed on the video, thank you.
    I don't know if I was clear in my previous messages, but your Ocean shader has a transparency problem (I'm using unity 5 with deferred render technique). Also the fog doesn't work when I go underwater. I'll post some print-screens whenever I have some time.

    I have 2 new questions:
    - Is it possible to do/calculate a water flow like the one on Cities Skylines?
    - Do you have any guide on how to save and load the water configuration?

    Thanks,
     
    Last edited: Sep 29, 2015
  12. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Fair enough. The solution to that is doing a separate render of the mesh to the Z buffer without transparency. I can't remember how difficult (or not) that is in Unity. Probably not a problem Candela would have to solve in a general case, but you could consider customizing it.

    Surface Waves was written for Unity 4, it doesn't take Unity 5's new rendering systems into account.

    Unfortunately underwater fog is a feature I never got round to implementing.

    You mean the textures that follow the direction of the water flow? Yes, but just like underwater fog, I never got around to implementing it. You could use the same information that the foam simulation uses to create scrolling textures on top of the simulation.

    Kind of. Before I stopped development, I had tool for that planned. I only finished the first half, loading an initial state: Under repeatable steps, on the 'Wave Height Step' Game Object, there's a Step State Manager component at the bottom. It accepts a start map, which it should assign at the start of the simulation. If you're restoring state from an earlier simulation, you have to do the same with the 'Wave Flow Step' texture, because otherwise your first simulation frame will seem jumpy.

    Saving state is more difficult. On DX11 systems you could make a system that copies the simulation textures from the GPU back to the CPU. On non-compute systems (non DX11), you could manually make a screenshot of the texture, which works, but isn't ideal.
     
  13. zackrump

    zackrump

    Joined:
    Jan 19, 2014
    Posts:
    9
    Hi, I was wondering what the current state of things was. It looks like things are running properly in Unity 5 now, no? Also, have improvements to the buoyant objects made it from the wish list to the the current version? Finally, what are the limitations for underwater scenes?

    cheers
     
  14. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    The current status is unchanged. I'm working on non-Unity projects at the moment. Making and especially maintaining tools for Unity made me sad. Sorry.

    Apparently it runs in Unity 5. Kind of. In some cases Unity initially imports the help asset files incorrectly, requiring a restart and a re-import. I never rewrote anything to work better with Unity 5 though (including the graphics)
    The limitations of underwater scenes are that there aren't any underwater graphics built-in.
     
  15. Fodalichking

    Fodalichking

    Joined:
    Mar 18, 2015
    Posts:
    14
    Hey RC 1290,

    Do you think it's possible to do a Mesh LOD solution to minimize the geometry draw when seeing the all terrain and water? I mean, when I'm looking from close, I execute the simulation with high mesh specs, ex: Sizes 768, 300, 768 and resolutions 768x768 and then same sizes but resolution 512x512 on a second lod level and then resolution 256x256 on third lod level?
    Or do you think this would mess up the simulation?

    thanks,
     
    Last edited: Oct 12, 2015
  16. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    A projected mesh would be ideal for something like this, because the entire mesh is always in view, and detail is used based on the size of screen.

    The mesh and the simulation resolution are independent of each other, so you can change the resolution of the mesh without having to do anything different with the simulation.
     
  17. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Occasionally I get questions about whether Surface Waves works in Unity 5, since I never officially ported it. There have been some bugs on the machines of some users, but I just loaded up Surface Waves in Unity 5 Free again and everything does seem to work fine (assuming legacy graphics are used, otherwise the fancier water shaders aren't lit correctly).
    When I tried it Unity initially chrashed its own shader compiler, but when it was done with that, everything seemed to work fine. If you get an issue where the help files aren't imported correctly, you might have to re-import those. Some users have reported the help files turning unreadable.

    It also occurred to me that I never really wrote any kind of guide about using Surface Waves, and that it probably wouldn't hurt to have a basic runthrough that shows you a bunch of functionality.

    This is how I usually set up a scene:
    GameObject > 3D Object > Terrain
    GameObject > Create Other > Wave simulation
    I then reposition the scene camera to look at the whole thing, select the main camera,and use Ctrl+Shift+F to make it match the scene camera.
    Then I add my Camera Free Flight Script to the camera (Included as part of Surface Waves)

    If you set Edit > Project Settings > Player to 'Legacy Deferred', the fancier water shaders also work (which you can drag to the "Selected Material" slot on the Wave Surface Game object.)

    For the advanced users who want to see details about what is going on: Under the Repeatable Steps GameObject you can see the simulation textures when Unity is in play mode. You can right click those previews and click "Open In Texture Viewer" to go to the zoomable texture viewer.


    Hopefully that helps someone.
     
    Last edited: Nov 17, 2015
    jdraper3 likes this.
  18. mruce

    mruce

    Joined:
    Jul 23, 2012
    Posts:
    28
    RC-1290 likes this.
  19. nubdev

    nubdev

    Joined:
    Mar 30, 2013
    Posts:
    87
    How do you get an effect similar to that in the demo?
    That is to say, adding water to the scene. Does it require a wave simulation gameobject present? If so, does the water simulation need to have water to start or can it be empty, waiting on the water added by mouse click?

    If you could share the code or point me in the right direction to have a situation where water is created from mouse click as in the demo it would be greatly appreciated, I am a little lost in the asset as there are a lot of folders yet no documentation or examples beyond the direction to create a wave simulation..

    regards
     
  20. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    If you create a wave simulation from the menu, it will have a mouse input by default. It's parent GameObject has a button for creating constant water input as well. Then you can animate its 'amount' property in any way you wish.
    GameObject -> Create Other -> Wave Simulation.

    This game object will also have an interactive support component on it, that can tell you things about the components on each of the Surface Waves GameObjects. (Except in some rare situations where Unity didn't import the help text correctly, in which case a re-import usually works)

    In the Code Animo folder there is a "Getting Started With Code Animo" asset, which shows you (in the inspector) how to get started with products that are installed, and where they are installed. There are also 'About' and 'Readme' files in several of the folders, with some basic information in the various folders they belong to.

    In the case of Surface Waves the "getting started" asset says:
    "From the GameObject creation menu:
    Create Other > Wave Simulation, and read the 'Getting Started' component."
     
    nubdev likes this.
  21. nubdev

    nubdev

    Joined:
    Mar 30, 2013
    Posts:
    87
    Thanks, I'll take a look now and see if I can get things working
     
  22. lancer

    lancer

    Joined:
    Aug 1, 2013
    Posts:
    231
    I'm trying to use surface waves in a webgl export, but if I run the project in the editor I get the warning:

    Code (CSharp):
    1. Compute kernel name: ComputeMap given, but the correct index was not -or could not be- found
    2. UnityEngine.Debug:LogWarning(Object, Object)
    3. CodeAnimo.GPGPU.ComputeKernel:LogKernelNotFoundWarning()
    And if I run an exported Webgl build, I get the error:

    Code (CSharp):
    1. RenderTexture.Create failed: format unsupported
    In both instances no water comes from the sources. But if I run it set to standalone, it works fine. I'm curious if there are any plans to support WebGL exports, or are you not developing it anymore?
     
  23. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    I didn't have any plans to specifically support new platforms, but it might be worth trying to remove the compute kernels for the WebGL version. It should fall back onto the SM3kernel. The particular ComputeKernel that message is talking about is on the Wave Height Offset Step GameObject. But there's a good chance the others don't work either.

    In the Hierarchy, do a search for t:computekernel, that should show you all the DirectCompute versions.
     
    lancer likes this.
  24. lancer

    lancer

    Joined:
    Aug 1, 2013
    Posts:
    231
    Ok, thanks, I'll give that a try then when I get the chance :)
     
    RC-1290 likes this.
  25. davidchaseling

    davidchaseling

    Joined:
    Apr 20, 2015
    Posts:
    8
    Hi RC-1290,

    I have been following along with this project for a bit and decided to make the purchase the other day. The current project I am working in requires a spherical water simulator, something which to my knowledge has not been done before in Unity. The effect I am going for is actually an inverse water simulation (Imagine a hollow planet with gravity pushing away from the center of the planet). I understand you have mostly moved on from this project, but any pointers on whether its possible or how to go about achieving this would be much appreciated!
     
  26. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Hehe, you're making the Game of Thrones intro sequence with simulated water in stead of just having the waves animated a bit? Cool idea.

    If you're not comfortable with complex programming puzzles, then the answer is no, because I didn't build it into Surface Waves.

    If you're up for a long project with lots of challenges, I'll go over some options here, starting with the option of the least re-writes:

    I think it could maybe be done if you find clever ways to avoid having to perfectly map the simulation to the entire sphere. If you look at map projections, every kind of rectangle projected to/from a sphere has some inaccuracies, and I think that will show up in the simulation somewhere, if not everywhere. You would have to adjust the wave displacement shader to use 3D addressing, in stead of just adjusting the height of a grid. You would also have to think about the way you stitch the ends of the simulation together. This is already tricky in a flat grid, but when you map it onto a sphere, you might get results quicker by just having an area where the water is not allowed to pass.

    You could look at how they handled curved terrain in Planetary Annihilation, for the 3D addressing.

    I think you would get the best result by building the simulation from the ground up with a sphere in mind. This simulation assumes that each cell has four neighbours, which works great for a grid, and means you can just assume every connection between neighbours is unit length, meaning pressure is the same in all directions. But with a sphere like that, you might want to have more or less than 4 neighbours, with different lengths between them. This might be trickier to do on the GPU, because you can no longer simply use grid indices(which map directly to texture addresses) for addressing. In stead you would probably have to use DX11 ByteAddressBuffers/ UAVs. With the scattered reads and writes, your performance might also be lower. So it might be just as effective to write a simulation on the CPU that makes heavy use of threading and SSE instructions, like the simulation in From Dust.


    Or you could hope that NVIDIA finds a way to make their 3D simulation fast enough for a huge simulation like that.



    I understand if this sounds like a disappointing amount of work left to do. I hope Surface Waves will still be of use to you, but feel free to contact me on the e-mail listed on the asset store, if you regret your purchase decision :).
     
  27. davidchaseling

    davidchaseling

    Joined:
    Apr 20, 2015
    Posts:
    8
    Wow that was fast! Thanks you for your response RC-1290.

    Haha no but the game of thrones thing would be cool! The effect I am looking for is more like this picture: http://aetherforce.com/wp-content/uploads/2013/09/geocosmos.png
    Basically the world is inside out, gravity pushing objects outward and the walkable surface been on the inside of the earths crust.

    I've looking into some of the water physics required and its far beyond me. This is the approach I have used to create the mesh: http://i.stack.imgur.com/hFgRJ.png
    Its not perfect but its good enough for what I need. Ideally I was hoping that I could simply deform the mesh and deal with connections between the surfaces not been perfect.

    Thanks again for the ideas. For what I need and my current skill level in this area it sounds like building something else from the ground up that mimics/fakes water simulation will be the best approach (it doesn't need to be perfect). When I am more confident I will come back and try out the ideas you've mentioned.

    I don't have use for the asset now but I am sure it will come in handy in future projects. I did my research and roughly knew what the limitations of the asset were before I bought it so my bad. You just don't know what will work until you try it haha :)
     
    RC-1290 likes this.
  28. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Yeah, that could work. It'll probably seems to change in velocity, because of the stretching, and you would still need a way to stitch 6 simulations together, but it could work.
     
  29. davidchaseling

    davidchaseling

    Joined:
    Apr 20, 2015
    Posts:
    8
    Hey RC-1290, back again!

    Since my first post I have experimented a lot with the spherical world and in the end decided a flat planet was more feasible and appropriate for what I am wanting to do. At the moment I have voxel terrain that can be moved using the htc Vive controllers and a few other cool interactions.

    https://drive.google.com/file/d/0B_Qa5QMmTUZzOXd4cE9obEszbTA/view?usp=sharing

    The next thing I need to tackle is putting a mesh collider on the water itself. The reason I need this is A: I need a collider to determine what terrain is walkable/not walkable for my A* pathfinding and B: because various other objects need to know when they are interacting with the water. For B I know I can get away with using the buoy script (kind of dodgy) and measuring how much force is applied but for A I can't think of a way to make it work without colliders.

    Usually I would say updating the colliders dynamically would be way too taxing but I will be going for a super low poly style and will not need to update them every frame. I have looked endlessly through your code to try and make this work but something appears to be going wrong when I try to do a basic create mesh collider from the mesh filters mesh( i have tried loads of variations on the code below).

    Code (CSharp):
    1. Mesh myMesh = this.GetComponent<MeshFilter> ().sharedMesh;
    2.                 DestroyImmediate (this.GetComponent<MeshCollider> ());
    3.                 MeshCollider myCol = this.gameObject.AddComponent<MeshCollider> ();
    4.                 myCol.sharedMesh = myMesh;
    I know this was probably on your list of things to do back when you were still working on it so I would really appreciate if you had or have any insight on the way to achieve this?
     
  30. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    All of the Surface Waves height data is in video memory by default; the mesh itself is a tessellated flat plane (not talking about GPU Tessellation here, just the mesh itself), which is deformed by a vertex shader. Getting the simulation textures back to system memory, where the CPU can access it isn't straight forward. There is some rudimentary DX11 code for getting data back from the simulation in the buoyancy code provided with Surface Waves.
     
  31. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    This can be the best water system.... but last update from 2014?
    What's going on? Is it dead? :(
     
  32. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Thanks for the compliment!

    Unfortunately I wasn't really good with marketing, and what I've earned so far from this asset isn't enough to cover the initial investment, let alone continued development, and while it can run okay on Unity 5, it really asks for a rewrite of the graphics, which would take a lot of time. So I've moved to other projects. I do still try to offer some limited customer support though.

    In case you're wondering why you wouldn't use this for every game, there are several big disadvantages to running the simulation on the GPU. Here are two of them:
    - Having scripts react to the water height requires costly texture transfers from the GPU to the CPU.
    - There's a decent chance your game's performance is already GPU bound, with several CPU cores having little to do. Running physics compute tasks interleaved with graphics work is hard to schedule correctly, and even more so when you don't have full control over it, like in a pre-made game engine such as Unity.

    Anyway, thanks for your interest. For what it's worth, the asset does still work, and it comes with the entire source code, so it is adjustable if you need to do so for your game.
     
    Neo-Gamefactory and protopop like this.
  33. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,560
    Sorry to hear that:( I know that its hard to both create AND market something you make yourself. Someday i think someone will come along with a simple marketing service for the rest of us - cool projects like yours deserve to flourish.
     
    RC-1290 and Neo-Gamefactory like this.
  34. patchworkx

    patchworkx

    Joined:
    Nov 8, 2014
    Posts:
    20
    Hey RC-1290

    Happy new 2017'
    About:
    davidchaseling said: ↑
    Since my first post I have experimented a lot with the spherical world and in the end decided a flat planet was more feasible and appropriate for what I am wanting to do. At the moment I have voxel terrain that can be moved using the htc Vive controllers and a few other cool interactions.
    .....

    Will u might come up with an planetary wave system that jear?-
    Halfpast unity 6 now..

    I' not to deep into scriptin- but i see stuff comin up like nvida flex in the asset store..
    https://www.assetstore.unity3d.com/en/#!/content/59843
    ??
    Might its possible to get the waves physsical atractive to gravitational effects..
    Might is more easy jet solver that??

    Best regards -
    Hope i can motivate u a bit
     
  35. davidchaseling

    davidchaseling

    Joined:
    Apr 20, 2015
    Posts:
    8
    Hey Mate, back at it again here!

    I have been using your asset for my latest project and I have managed to add a bit of functionality where needed. I have a script that pulls the wave height data from the GPU and is able to tell if any object is submerged or not and I have also managed to use your Step State Manager to save and load wave maps. (Side note if there is anyone else still using the plugin who would find either of these useful please let me know and I will share the code).

    My next obstacle is changing the wave graphics. Right now the advanced wave graphics look super nice and impressive however they don't suit the low poly style I am going for in my VR game. I am looking to make the graphics look somewhat like the following image:

    https://s-media-cache-ak0.pinimg.com/originals/f5/68/75/f568753d25224271b5cb882f926cfe6b.jpg

    I am hoping that graphics like these will not only look great but help reduce the frame rate. I know you have no future plans to improve the asset but I was hoping you could lend me a few minutes of advice on how you would go about achieving this look!

    Cheers, David!
     
  36. davidchaseling

    davidchaseling

    Joined:
    Apr 20, 2015
    Posts:
    8
    Hey there! I have seen this asset and ones like it before. They look impressive but I do not have the required GPU for them. I also wonder how this works when you go to publish a game that not everyone has the required type of GPU to run a component.

    Yes I am sure it is possible but from what I have found with this asset sometimes it is easier to come up with workaround solutions, eg In my project I need to be able to create massive waves that start in the ocean. To do this I have an invisible wave shape that moves under the surface waves and it works great. Dodgy but works!

    As for the rest I have to apologise as I can not understand what you are saying?
     
  37. nemesiswes

    nemesiswes

    Joined:
    May 16, 2015
    Posts:
    10
    Hello,

    I was reading your posts davidchaseling about surface waves and you said you were able to get the wave height data. I don't suppose you could tell me how you did that, script example? It would save me alot of time, lol.

    I need to find the height of the water at the players position so I can figure out if he is under water or not, if he is I was planning to use a camera image effect for fog that I would adjust based on depth in the water.
     
  38. nemesiswes

    nemesiswes

    Joined:
    May 16, 2015
    Posts:
    10
    nvm i got it working

    For anyone in the future that needs to figure out if a player is underwater using surface waves, Here is everything I modified:

    BuoyancyManager class:

    Add:
    Vector3[] height_pos_test;

    Above:
    computeForces() function

    ----------------------------------------------------

    Add:
    ComputeBuffer pos_out_Buffer = new ComputeBuffer(elementCount, 12);// stride of 3 floats

    After:
    ComputeBuffer forceBuffer = new ComputeBuffer(elementCount, 12);// stride of 3 floats

    -----------------------------------------------------

    Add:
    this.simKernel.SetBuffer("PositionOut", pos_out_Buffer);

    After:
    this.simKernel.SetBuffer("ForceOut", forceBuffer);

    -----------------------------------------------------

    Add this:
    Code (CSharp):
    1. //For height just do exactly like force except get height
    2.             height_pos_test = new Vector3[elementCount];
    3.             pos_out_Buffer.GetData(height_pos_test);// Remember, this might be 'really slow'
    4.  
    After:
    forceBuffer.GetData(forceData);// Remember, this might be 'really slow'


    ---------------------------------------------------------

    Add:
    pos_out_Buffer.Release();

    After:
    positionBuffer.Release();

    -------------------------------------------------------

    Add:
    currentBuoy.surface_height_check(height_pos_test);

    After:
    //currentBuoy.applyBuoyancy(buoyForces);

    -----------------------------------------------------------------------------------------------
    -----------------------------------------------------------------------------------------------

    Buoy class:

    add this code:
    Code (CSharp):
    1. public void surface_height_check(Vector3 pos)
    2.         {
    3.             print("surface height at bouy = " + pos);
    4.             print("bouy height = " + transform.position);
    5.  
    6.             if(transform.position.y < pos.y)
    7.             {
    8.                 print("Your under water");
    9.             }
    10.          
    11.         }
    -----------------------------------------------------------------------------------------------
    -----------------------------------------------------------------------------------------------

    Last inside folder Surface waves->Buoyancy->DX11 open the file Buoyancy

    Add:
    RWStructuredBuffer<float3> PositionOut;

    After:
    RWStructuredBuffer<float3> ForceOut;

    ---------------------------------

    Add
    PositionOut[flatIndex] = waveHeight + terrainHeight;

    After
    ForceOut[flatIndex] = outputForce;



    Lastly add a Bouy component to whatever u want to check if its under water.

    As a side note, you can also call calculateBuoyancy (which is in the BuoyancyManager class) from a Coroutine to make it faster instead of running at inside FixedUpdate.

    I added it like i did since I don't know if the author would be ok with just posting modified versions of his code up here.
     
    Lesnikus5 likes this.
  39. nemesiswes

    nemesiswes

    Joined:
    May 16, 2015
    Posts:
    10
    I do have one other question though, how can i make the water mesh visible from above and below? I sorta got it to work by turning cull off in the shaders but it doesnt apply any lighting or transperency to the boitom.
     
  40. nemesiswes

    nemesiswes

    Joined:
    May 16, 2015
    Posts:
    10
    nvm figure it out, just use this in Complexwater.cginc under the vertex shader portion

    add it right under:
    o.worldNormal = mul ((float3x3)unity_ObjectToWorld, gridNormal);

    Code (CSharp):
    1. o.viewDirection = WorldSpaceViewDir(v.vertex);
    2.  
    3.        // View Direction:
    4.     if (dot(o.worldNormal, o.viewDirection) > 0)
    5.     {
    6.         //above water do nothing
    7.     }
    8.     else
    9.     {
    10.         //flip
    11.         o.viewDirection = -o.viewDirection;
    12.     }
     
  41. HakiZ

    HakiZ

    Joined:
    Nov 6, 2015
    Posts:
    10
    Hello,
    I have imported the plugin into unity 5.6 but the game object Surface Waves is not working properly.
    I created the demo scene in 2 steps:
    1. GameObject> 3D Object> Terrain
    2. GameObject> Create Other> Wave simulation
    When playing, no waves appear.
    Can someone help me solve this problem?
    Thank you very much
    Screen Shot 2017-07-12 at 10.07.06.png
     
  42. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    The version of Surface Waves that is on the asset store is made for Unity 4. I do have a version available now that works for Unity 5 and I should really take the time to update the Asset store, but in the mean time, you can send me an e-mail or DM with your Invoice Number, and I'll send you the unitypackage directly.
     
    HakiZ likes this.
  43. HakiZ

    HakiZ

    Joined:
    Nov 6, 2015
    Posts:
    10
    Thanks you for your response RC-1290.
    Can I send email to purchase email from last time?
     
  44. Nams97

    Nams97

    Joined:
    May 20, 2017
    Posts:
    2
    this asset was working at unity 5.6 just change
    Code (CSharp):
    1. ShaderUtil.ShaderPropertyTexDim texturePropertyType = ShaderUtil.GetTexDim(m_selectedShader, propertyId);
    2.  
    3. ShaderUtil.ShaderPropertyTexDim texturePropertyType = (ShaderUtil.ShaderPropertyTexDim) ShaderUtil.GetTexDim(m_selectedShader, propertyId);
    but.. I cant fix this error in unity 2017.
     
  45. Nams97

    Nams97

    Joined:
    May 20, 2017
    Posts:
    2
    error
    Binary to YAML conversion: type unsigned int is unsupported
     
  46. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    I should really take the time soon to look into how Unity's asset submission system changed since 2014, so I can push out a proper update to everyone.

    In the meantime, you can send me a personal message with your invoice number, so that I can verify it and send you the latest version (which works in 5.5 and 2017, and includes several improvements).
     
  47. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Good news!

    Thanks to a recent contract involving Surface Waves, I have been able to properly update it for use with Unity 5 and Unity 2017. The update should automatically show up once the package has been approved (if you're using Unity 5.6 or above).

    Some of the improvements include:
    • Reflection Probe Support
    • Framerate independent simulation speed.
    • Saving / Loading
    • A basic demo scene
    • Various Fixes

    Hopefully that simplifies things.
     
    Deleted User likes this.
  48. Deleted User

    Deleted User

    Guest

    Great plugin, I really appreciate the updates!

    One thing I can't figure out with my current project though: A mesh I am creating dynamically via script, then modifying in that script every frame, is not being seen by the Terrain Height Renderer. Is there anything fundamentally different about creating raw meshes via script, that would affect the way Surface Waves behaves? I notice in the inspector that the Mesh Filter is unnamed in my dynamic mesh (but not undefined).

    Below is the mesh creation - after creation the mesh is deformed every update:

    Code (CSharp):
    1. private Mesh _Mesh;
    2.  
    3. void CreateMesh(int width, int height)
    4.     {
    5.         _Mesh = new Mesh();
    6.         GetComponent<MeshFilter>().mesh = _Mesh;
    7.  
    8.         _Vertices = new Vector3[width * height];
    9.         _UV = new Vector2[width * height];
    10.         _Triangles = new int[6 * ((width - 1) * (height - 1))];
    11.  
    12.         int triangleIndex = 0;
    13.         for (int y = 0; y < height; y++)
    14.         {
    15.             for (int x = 0; x < width; x++)
    16.             {
    17.                 int index = (y * width) + x;
    18.  
    19.                 _Vertices[index] = new Vector3(x, -y, 0);
    20.                 _UV[index] = new Vector2(((float)x / (float)width), ((float)y / (float)height));
    21.  
    22.                 // Skip the last row/col
    23.                 if (x != (width - 1) && y != (height - 1))
    24.                 {
    25.                     int topLeft = index;
    26.                     int topRight = topLeft + 1;
    27.                     int bottomLeft = topLeft + width;
    28.                     int bottomRight = bottomLeft + 1;
    29.  
    30.                     _Triangles[triangleIndex++] = topLeft;
    31.                     _Triangles[triangleIndex++] = topRight;
    32.                     _Triangles[triangleIndex++] = bottomLeft;
    33.                     _Triangles[triangleIndex++] = bottomLeft;
    34.                     _Triangles[triangleIndex++] = topRight;
    35.                     _Triangles[triangleIndex++] = bottomRight;
    36.                 }
    37.             }
    38.         }
    39.  
    40.         _Mesh.vertices = _Vertices;
    41.         _Mesh.uv = _UV;
    42.         _Mesh.triangles = _Triangles;
    43.         _Mesh.RecalculateNormals();
    44.     }
    45.  
    46.  
     
  49. Deleted User

    Deleted User

    Guest

    Okay, it isn't about the method of creating the mesh, or assignment of the Mesh Filter. Whether I create a mesh in scripting or via the editor it works up until I start altering the vertices in update(). At that point the mesh no longer appears in the Terrain Height Renderer. Below is what I'm doing in update(), passing in depth data from a camera. If I comment out the line where I set the vertices the mesh obviously doesn't change shape, but it does appear in the Terrain Height Renderer.

    Code (CSharp):
    1. private void RefreshData(ushort[] depthData)
    2. {
    3.     var frameDesc = _Sensor.DepthFrameSource.FrameDescription;
    4.  
    5.     for (int y = 0; y < frameDesc.Height; y += _DownsampleSize)
    6.     {
    7.         for (int x = 0; x < frameDesc.Width; x += _DownsampleSize)
    8.         {
    9.             int indexX = x / _DownsampleSize;
    10.             int indexY = y / _DownsampleSize;
    11.             int smallIndex = (indexY * (frameDesc.Width / _DownsampleSize)) + indexX;
    12.  
    13.             double avg = GetAvg(depthData, x, y, frameDesc.Width, frameDesc.Height);
    14.  
    15.             avg = avg * _DepthScale;
    16.  
    17.             _Vertices[smallIndex].z = (float)avg;
    18.         }
    19.     }
    20.  
    21.     _Mesh.vertices = _Vertices;
    22.     _Mesh.uv = _UV;
    23.     _Mesh.triangles = _Triangles;
    24.     _Mesh.RecalculateNormals();
    25. }
     
  50. Deleted User

    Deleted User

    Guest

    I'm ridiculous. A few of the new vertices on the mesh were so distant that they were outside the Surface Waves box collider. Once I corrected to make sure the entire mesh remains inside the Surface Waves while being deformed, that fixed it.
     
    RC-1290 likes this.