Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Surface Waves - Dynamic Rivers, Lakes and Oceans

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

  1. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Adding rivers to your game can be tricky when your scene has a lot of variation in height. And static water can feel a bit lifeless when you try to play with it.

    That's why I've made Surface Waves, a toolset that creates dynamic rivers, lakes and oceans by making waves interact with underlying terrain. It's GPU accelerated by making use of Compute Shaders (when supported), or Fragment shaders.

    1 Surface Waves Main Image.jpg

    Video demonstration and explanation:


    You may have seen an early version of this project last year when I entered the DX11 competition with a Water Simulation. I got a lot of encouragement to turn it into a product. Back then, it was mostly just a tech demo, which wasn't very suitable for anything other than the scene I created. I spent a lot of time trying to make it easier to use, easier to extend and easier maintain. I also made it work across platforms. Although so far I've only been able to test it on Windows and OSX.



    The following will be part of it:
    • GPGPU framework for DirectCompute and vertex/fragment shaders
    • Shallow Water Simulation Shaders
    • Water Shaders:
      • Simple Water Shader
        • Reflection
        • Water Color
        • Transparency
      • Complex Water Shader
        • Reflection
        • Refraction (with adjustable filter color)
        • Depth Based Fog (with adjustable color)
        • Soft Shorelines
        • Light Wrapping
        • Foam (uses simulation data)
      • Opaque Liquid Shader
        • Reflection
        • Color
        • Adjustable Emissive Lighting (Self-illumin)
        • Mix between Diffuse and Emissive
    • Example Materials:
      • Water:
        • Fjord
        • Ocean
        • Muddy
        • Simple
      • Non-Water:
        • Blood (For making blood oceans, like you do)
        • Blue and Green Ink
        • Green Goop
        • Mercury
        • Milk
        • Oil
        • Unidentified Orange Stuff
    • Realtime Texture debugger
    • Custom Reorderable List Property Drawer
    • Experimental Buoyancy (DX11 only)
    • Freeflight Camera with Physics



    You can buy it on the Unity Asset Store, and in the future I also want to make it available through a service like Patreon. I want to make it available in the Unity Asset Store and through Patreon. But I still have to do some work like creating store image, writing descriptions and creating a license for the Patreon version.

    Quick setup guide, and Unity 5 info.


    In the meantime you can play with a demo on my website.

    Please let me know what you think of it so far.

    - RC-1290
     
    Last edited: Nov 17, 2015
    Farelle, Flurgle and marserMD like this.
  2. FBTH

    FBTH

    Joined:
    Jul 25, 2012
    Posts:
    272
    Looks amazing! :D I will definitely get this!
     
    RC-1290 likes this.
  3. IanStanbridge

    IanStanbridge

    Joined:
    Aug 26, 2013
    Posts:
    328
    Looks superb with great performance. How large an area can you cover the water with before performance becomes an issue ? Could you have a large ocean and perhaps have it reduce the quality if you were flying very high above it or perhaps disable an entire section of map if you were very far away from it so you could simulate an entire ocean ? Also how accurate is it's buoyancy simulations ? While you seem to mainly mention that the benefit of your system is that it is easy to setup I think the real benefit is that it is dynamic. having objects physically interact with it during game play is the real strength.
     
    RC-1290 likes this.
  4. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Thanks!
    It depends on a few things. There is the cost of the simulation and there's the cost of rendering.

    The cost of the simulation depends on your hardware and the simulation resolution you choose. In that demo, I'm covering a 2km by 2km terrain with a simulation resolution of 768 by 768 and a mesh tessellation of 1024 by 1024. There tends to be a sharp drop in performance when you use a simulation resolution above a certain level. For my HD5770 the limit is 1024 by 1024.For my HP tx2 laptop (even older hardware) it's 512 by 512.

    It seems like it'll be possible to work around this limitation by tiling the simulation. I've done some early tests of that but it's not really supported yet. Some parts of the simulation still assume there's a single simulation (including the display materials).

    Also, it is possible to change how often simulation steps are performed. For example, if your terrain is static, you don't need to update the heightmap every frame.


    The cost of rendering is relatively easy to change. You can use a simpler shader, or use a mesh with a lower vertex count. In the future I might add a DX11 tessellation shader that dynamically changes the density of the mesh, depending on its distance from the camera.

    Buoyancy is still experimental. Right now I'm calculating forces on the GPU and feeding that back to the CPU. But I'm considering changing that, to make it easier to work with, and to stabilize the performance.
     
  5. ikarth

    ikarth

    Joined:
    Dec 31, 2013
    Posts:
    1
    I've got sketches for a tiled, procedural generation game this would go great with, so I'll be keeping an eye on your progress on that front. Though it strikes me that you could already use this to build something like From Dust. How easy is it to get the water data back, in case you want to see which parts of the terrain got covered? How does it handle something more viscous, like lava?

    The link here on your site doesn't work, by the way.
     
  6. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    I'm doing something similar for Buoyancy right now, but I still need to create a generalized saving system that works without DX11. I have that planned as one of the first major projects after launch. The performance implications are a bit scary in any case, because most(if not all) GPUs need to be idle while copying. Saving data back to system RAM every frame might have quite a performance hit.

    This should get a lot better over time as GPUs start working together more closely with the CPU.
    Actually, fun story, I met the engineer who wrote the simulation for From Dust (Ronan Bel) the day before he was giving his talk about his simulation at GDC Europe, and I was telling him all about this water simulation I wrote in Flash/PixelBender. I saw him smiling, but it wasn't until the next day that I realized just how similar our simulations were. Except for the part where his simulation was written in assembly for CPUs supporting SSE, already worked on several different platforms, and had way fancier stuff, like multiple materials, a plant simulation, etc. That was amusing.


    In any case, yes, it would be possible to include viscosity settings, but right now it's using a fixed value (1). Right now you can influence the apparent viscosity with the timestep setting (which is why that setting isn't suitable for speeding up the simulation).
    I don't have support for interaction between multiple simulations, like Water and Lava yet. It is something I'd like to work on in the long run.
    Ahh, right, yeah, thanks for reminding me. I knew I forgot something.
     
  7. Uberpete

    Uberpete

    Joined:
    Jan 16, 2014
    Posts:
    78
    Ooh. Fancy :3

    If you haven't already done it some sort of occlusion culling may help improve performance (for Unity Indie users)?
     
  8. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Yeah, I haven't done any kind of culling yet, so that might still be an interesting option in the future. Although it's a bit tricky, because you can't easily tell when a piece of the simulation isn't doing anything. When the simulation becomes tiled, it should be possible to freeze any tile, but that will create odd waves when it's re-enabled, because of the changes in the neighbouring tiles.
    Does Unity Indie still exist? I thought it was just Unity (free) and Unity Pro now.
    In any case, Surface Waves makes heavy use of RenderTextures, so it's only for Unity Pro.
     
  9. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    6,824
    Great work

    Will this work well without DX11 ?
     
  10. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Thanks!
    Go ahead and try it for yourself, if you want. But yeah, that's the idea. If compute shaders aren't supported, it uses fragment shaders instead. Which was actually what it used before I entered the DX11 competition.
     
    nasos_333 likes this.
  11. Paddington_Bear

    Paddington_Bear

    Joined:
    Dec 9, 2012
    Posts:
    266
    Looks excellent, any ideas where to go from here? (apart from the edge-blending and so on). Also is there any chance of distance based LOD?
     
  12. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    There are plenty of little things that I want to improve (including some GUI work), but that's not particularly exciting to list here.

    The big stuff on my personal wishlist (subject to change):
    • Cross-platform saving (opens up opportunities for secondary simulations, like vegetation)
    • Framerate independence
    • Top down water displacement (For things like boats)
    • Underwater graphics (fog mainly)
    • Velocity based Flow Mapping
    • Better buoyancy
    • Tiled Simulation
    • Forces (Wind would be cool)
    • Different input/output types (waterfalls and rain would be nice)
    • Realtime Erosion & Multiple surface types.
    • Sound
    But I'm also very curious to hear what kind of things you'd be looking for.

    What do you mean with that? The complex water shader already uses alpha blending in shallow areas, if that's what you mean.

    For the water graphics, yes, that might be interesting. I'm thinking of using DX11 tessellation for the mesh density, and I have some other options in mind. But right now high simulation resolutions dwarf the graphics rendering in terms of cost, so tiling the simulation has a higher priority for me.
     
    Last edited: Jun 8, 2014
  13. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    6,824
    That is great, cant wait for the release :)
     
  14. zRedCode

    zRedCode

    Joined:
    Nov 11, 2013
    Posts:
    130
    A very cool water render, but for my GPU is very heavvy (14FPS if i'm wieving all the world in the demo)
     
  15. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Ahh, so for you it IS dependent on the amount of water on screen? Good to know. Would you mind telling me what GPU you're using?
     
  16. zRedCode

    zRedCode

    Joined:
    Nov 11, 2013
    Posts:
    130
    crossfire software of two AMD ATI Radeon HD 6450 (two low performance GPUs used to make a strange PC, a server pc with 24GB of ram)
     
    RC-1290 likes this.
  17. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    That's indeed a strange setup, I love it ^_^. I'm pretty sure you have enough memory ;). But I can see why it runs so slow. Right now, I've optimized the scene for the HD5770 I'm using, and while the HD6450 is newer, it's not as fast.

    I'm curious how the crossfire setup influences the simulation performance, especially when you start using buoyancy (which moves data back from GPU memory to system RAM). I don't know how Crossfire works, so I'm wondering if it might actually speed up the data transfer.

    I can usually get somewhat interactive framerates on my ancient laptop (with HD3200 integrated graphics), if I reduce the simulation resolution, so perhaps I should upload a version with a lower, or adjustable simulation resolution so you can see if that helps in the short term.
     
  18. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    Amazing! When it's released and I got the $ I'll be very interested in buying (I'm assuming it will be a payed asset).

    Would this kind of water be good for a dynamic map/ocean? Sorta like the bf4 maps and their water. So I could change the wave heights etc.

    Keep it up ;)
     
  19. JscriptFless

    JscriptFless

    Joined:
    Jan 8, 2013
    Posts:
    49
    It looks very good RC-1290, the only problem I saw with it, was the speed of the water when moving around the terrain. (maybe slow it down, or add resistance.) Also it seemed like it just washed down towards the water(or the 'deeper' parts of the terrain.) without a trace. If you can somehow make the water get stuck between high points in the terrain(eg. puddles) I would really appreciate it,(and I'm sure many others would too.) other than that it looks great; keep up the great work RC.
     
  20. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Thanks :), I want to make it available through the Untiy asset store first, and later a cheaper, but subscription based version through Patreon (Where you only pay for one version).

    If you only need it for waves in the background, a classic ocean simulation would be cheaper to render. Surface Waves is most useful when you need the water to be interactive. The waves are all simulated, so to change wave heights, you change the inputs, or apply forces to it.

    In the initial release, there are basic tools for dynamically changing the input amount, and creating waves using a moving mesh, but I would like to be able to add a force like wind in some way.

    Thanks :).

    Maybe you're talking about the problem with the simulation being frame rate dependent, so if you have a really high framerate, the waves seem to move way too fast. But you're not to first to mention it, so there might also be something else going on.

    Unfortunately, increasing ground resistance isn't all that straight forward, because the waves only move vertically, and don't really have a horizontal velocity (it's estimated when calculating foam and buoyancy). You can decrease the timestep, which slows it down and changes the viscosity, but I'm not sure if that would fix the problem for you.

    I removed the timestep setting from the demo at some point, because people were confused about what it did, but I might add it again so you can see if that fixes your problem.

    In the long run, I would like to add different simulation shaders. The current simulation doesn't conserve momentum correctly, and it might be nice to use a more realistic model.

    It does form puddles, in the same way that it forms lakes, the puddles just aren't very visible, because the water doesn't affect the specularity of the terrain yet (doesn't darken it), and the most shallow puddles are hidden because of the depth based soft shores effect.
     
  21. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    I was thinking more waves in your face that is interactive, so things push the water, maybe spaceships/jets displace water when close to it etc. would add more immersion into the game I would think
     
  22. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Yeah, that's one of the things I'm talking about in the video as well. I want to add displacing the water from the top, in stead of from the bottom like the terrain does. The displacing mesh doesn't need to be visible to the regular camera, so if you want a force to extend beyond the object, you could use a separate mesh for the water displacement.
     
  23. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    If your refering to the jets I was thinking maybe to add a collider bellow the jet to interact with the water if it would be possible.

    In addition would it be possible to add smaller waves maybe with normal details etc or using tessellation with vertex displacement based on distance . I dont know if this system would be appropriate for this I would just like the idea of dynamic and interactive water that would work well as a dynamic ocean, i'm looking at Triton but it's a bit on the expensive side and I wont have much money being young and after buying pro
     
  24. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    It works pretty much as you describe, but using regular mesh objects, in stead of PhysX colliders. That is because Surface Waves is completely based on heightmaps.

    It would be possible, and it's on my wishlist. The thing is that I need to implement flow mapping (moving textures in the direction of flow) first, because otherwise the normal mapped waves seem to completely ignore the direction of the simulated waves.

    Triton seems excellent to me when you want to recreate statistically accurate oceans, with correct wave heights for given wind speeds. If you just want an ocean, it'll probably be more realistic than Surface Waves. I just don't see it working for rivers, because their current version seems to completely ignore terrain and other objects.

    Surface waves probably won't look as realistic as Trion for open oceans any time soon, but it reacts to the world, and won't have a military grade price tag.

    Suimono might also be an interesting option for you by the way. It has really nice waves for oceans. It's only partially interactive though, and I think that my depth based fog looks better. The foam looks great in screenshots, but it seems to drift in odd directions in the video, but I'm sure that can be fixed (besides, until I implement flow mapping, the foam in Surface Waves will not have pretty textures, like Suimono). Another advantage of Suimono is that the buoyancy is probably implemented better right now (although that is something I intend to fix).


    *Cough* oh wait, I mean, Surface Waves is totally better than the competition in any situation.
     
  25. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Just fixed a major artifact that caused problems all over the simulation.
    In some places you could see ridges in the water, tat would disappear under high waves, but would show up again if the waves were low enough. There were a few times when I thought this was a problem with the way I generated normals.

    So I thought about the normal map generation again, and realized that I made outdated assumptions about mesh and texture sizes (wave mesh edges have a length of 1 world-unit, and one simulation pixel per wave mesh vertex, but those have been adjustable for a while now.). After I added a setting to the water shader for those things, the look of the reflections improved, but the ridge artifacts remained.

    Persistent Ridges in the waves, and blocky flow texture:
    Then I remembered making notes about blocks in the flow texture of the simulation in areas where the artifact showed up. This wasn't visible in the terrain height input texture. The only other input it could come from was the flow texture from the previous frame, which is used to maintain vertical momentum. And sure enough, when I removed the contribution of the previous flow map texture, the artifact vanished. Of course, it also turned the water into jelly, because it would only try to average all wave heights.

    So I added a multiplier that would dampen the flow input from previous frame slightly, to remove noisy feedback loops (0.99 by default). That did not only fix the problem, but also resulted in much more pronounced wave bounces off of shorelines, and smoother waves in general.
    Waves after fix:
    So I had originally made quite a stupid mistake. If I had studied other simulations better I would've probably seen a similar damping factor, in a different place than the timestep setting. And even in the comments above it comes up in the form of:
    But I just dismissed the idea that damping was anything more than a bonus, because I thought: the timestep already dampens stuff.

    But you know, the more obviously stupid the mistake, the more likely it is that I'll learn from it ;).


    So, I'm really happy with how the waves deflect off of shores now, creating more interference patterns with following waves than before.

    Hopefully it also helps to solve the problem JscriptFless was having. I'll update the demo so you can see for yourself. (I've left the damping setting unlimited, so you can break the demo pretty spectacularly if you want - which is always fun - by setting values higher than 1, or lower than 0.88.)


    Finally, here's a video showing the flow texture now that the problem has been solved.


    Hopefully that was interesting to someone.

    - RC-1290
     
  26. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    Oh wow, the water looks soo much better with all the smaller waves in the centre of the lake, just what I want :D.
    Is this caused from your latest update or just a good screen shot. (Compare first post pics with this one)
     
  27. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    It's the latest update, after adding some big waves :D. You should be able to get a similar effect in the demo.

    I'm so glad I finally got that fixed, it felt like it was completely broken before ^_^. If only I had managed to fix it before the video.
     
    Last edited: Jun 10, 2014
  28. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    This looks really great for rivers and other bodies of water whose dynamics depend much on differing elevations. I've been hacking away at suimono 2's betas for ages, i really like the artistic control and that with some mixing and matching with another ocean i hacked up into my own use i was intending that to be my general ocean taken care of when needed.

    It's not, however, currently suitable for rivers and such without a bunch of hard work so this is a great kind of thing to fill this specific need - I had a few ideas for rivers figured out, using a premade mesh that was tessellated and displaced along with flowmapping to show directionality and waves/ripples as well as nice texture based foam (Maybe even provide info as to placing particle effects like splashes in sharp changes in water velocity. Thats actually a lot of messing around and hassle however and still wouldn't look right or react with objects in the water properly.

    The oceans ive been used to messing with other than suimono have used a frustrum based culling or a weighted disc with vertices biased towards area of choice (The camera usually, naturally) so that was one way of doing LOD without tessellation and I got very nice performance in the ocean i got together using work on http://scrawkblog.com/ which itself was based on Eric Bruneton's ocean shaders using a compute shader for FFT waves

    Looking at your video, would it be possible to have the resolution of the water fixed along the general length of a river, hence flowing into an existing ocean setup? Then the river be able to respond nicely to fairly small details, like rocks and other objects in the river? Flowmapping would naturally be expected here but the dynamics of your system make for very nice surface waves and following contours, i'm mainly interested how the effect might look close up and it reacting to bodies usually found scattered about in rivers and particularly shallow but wide streams. The physical appearance in terms of shape of this looks great, i'm just curious as to the applicability and appearance of finer detailed texture-based surface appearance

    Great work anyways, and I hope my questions made sense, i can post a video i did if needed to illustrate the kind of/appearance of foam and similar visuals
     
  29. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    I kind of broke the standard CPU based culling because meshes should not be hidden when they're displaced. The CPU doesn't know the location of any of the vertices, because the height is determined by a GPU-side texture, so only GPU based LOD and culling really works. And what you're talking about sounds like a CPU-based system, is that correct?

    I've been thinking about ways to handle it, and so far the only thing I've come up with that I think might work, is using a custom mesh that has the most dense tessellation near the center, and is placed in your point of interest (I guess the system you mentioned might help with that!). The water shader should then be able to sample the heightmaps of several of the nearest (4 at minimum) simulation tiles. Not something I can do really easily yet though.

    I'd love to see a hybrid solution like that. I have implemented controls for positioning the simulation wherever you want, but it doesn't support rotation well yet, and I currently don't have a test scene for non-square simulations yet, but I believe I got that working.

    The detail of the simulation depends mostly on the density of the simulation you use. The demo I have right now spreads its 768 by 768 resolution over a 2k by 2km terrain, so it's not going to react very accurately to the small details you mention.

    So the way I had planned to implement flow mapping so far, would also ignore most of those rocks. But it would be nice if it could react to smaller details. I don't have any plans for that yet, so let me know if you have suggestions.

    One thing that might work is using a high detail simulation to set up the flow map once, and using the results of the simulation in a static way. (Only flow mapping, no dynamic simulation at runtime)

    Thanks! I think I understood most of your questions, but let me know if I misinterpreted them.
     
  30. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I think that was fine! This is a post on scrawks blog regarding how to render the water http://scrawkblog.com/2013/02/24/ocean-renderer-for-unity/ - he links to two projects that use the projected grid method, which relies on the view frustrum, and shows he used the radial grid approach himself, all the source is there, im not sure how much of it is on the gpu or can be moved to the gpu but it might help , i was using the disc idea for most of my forays, you created a radial mesh at start and specify how bunched near the camera the vertices would be by some parameter. I did personally find it very effective and presumably could be further refined with tesselation

    This is a vid i did of one of scrawks later ports (code is on his blog), mixed with a little bit of suimono's shading, it'll give an idea of the kind of foam i mention: h ttps://www.youtube.com/watch?v=vmwdP4OFgtI (I bodged the link to avoid the youtube embedded thing popping in)

    Alot of the visual effect comes from Eric Brunetons BRDF for oceans work which relies a lot on the atmosphere model, but its nice
     
  31. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    if you could somehow add in scrawk's ocean with this dynamic water you would be my god :D and a definite future buy.
     
  32. BeyondReality

    BeyondReality

    Joined:
    Mar 25, 2013
    Posts:
    7
    I see in your video you use CubeMaps for reflections.
    Do you have plans for some sort of option to use 'realtime' reflections?
    I'd love to see my objects that are floating in the water getting reflected as well :)

    The flipped camera method will probably not look very nice with the dynamic heights of the geometry, so raytracing would be realy cool:
     
  33. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    787
    There's a lot of science here that's beyond me, but the end result is really great looking dynamic water. this reminds me of something i'd see at Siggraph, a technical achievement that then gets spread into new games. Great work!
     
  34. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Ah yes, that looks like a mesh at the camera position. Interesting option, but it does require some quite significant changes to how the water is rendered. If I want to support a tiled simulation, I need to finish that first, and then see if sampling multiple tiles from one mesh actually improves performance.
    Textured foam is definitely something I want to do, but I've tried it before, and without flow mapping it looks like it's pasted on. And in that video the foam just seems to be everywhere, while if I look at real world examples, you only really see it in transition areas.

    I'm currently testing out a simpler foam simulation, which seems to work better so far. In stead of using the acceleration of the water, it combines the velocity with a value that represents in the missmatch between input and output of a tile (I call it 'shock' in the shader). Previously the foam mostly appeared on shorelines, but now it also shows up much more on rapids/waterfalls and on choppy waves (Depending on the foam display settings you choose).

    It might be interesting to generate a single displacement texture that samples two different water systems, so that a single mesh can transition from one to the next, but I'm not sure what you want me to do exactly. I'm not just going to copy scrawk's code.

    I'm indeed using cubemap reflections, but like you mention, the dynamic water height makes using a second camera a bit tricky, because that only captures the reflection on a single plane, it might still look passable, so I might give it a try at some point.
    Raytracing would be cool, but I figure that ray tracing engines are going to be built anyway, and I might as well make use of a generalized solution when it becomes available.

    Perhaps rendering cubemaps at a point of interest would be close enough for distant terrain, but there are bound to be mismatches between the cubemap reflection and the nearby objects. I don't think a solution like the parallax corrected cubemaps presented by Sébastian Legarde would work very well for dynamic objects. I should probably try to figure out how his image proxies work and if it could be adapted for non-planar surfaces.
     
  35. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    Well what I was trying to say was is it possible to also generate all those ripple waves, normal etc so it looks like (or is similar to) scrawks thx
     
  36. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    You could replace the two step simulation in Surface Waves, with a single step that sets the heights with scrawk's FFT approach instead.

    But I would rather try to find a way to apply forces to the simulation that create ocean-size waves, in stead of removing the interactivity. In my wishlist above, I simply call it wind ^_^.
     
    Tiny-Man likes this.
  37. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    Yeah that would be great looking forward to it (wasn't attempting to ask to redo simulation just the look if it were possible, but I'll let you do your magic ;) )
     
  38. zRedCode

    zRedCode

    Joined:
    Nov 11, 2013
    Posts:
    130
    Usually the crossfired video cards have the same memory in the same time (using a crossfire you not have an ram aument, but a calculation power aument), The my GPU setup uses alternate frame rendering, so i get an average doubled frame rate (wich is the double of the result of the software, so is 31 FPS and not 15.
     
  39. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    That's exactly why I wondered how it would affect the performance of moving data to the CPU, because the memory transfer could be done while the other GPU is busy.

    I also wondered if having the memory twice might increase the bandwidth, but I guess they're still both using the same bus.
     
  40. zRedCode

    zRedCode

    Joined:
    Nov 11, 2013
    Posts:
    130
    esactly, they use a duplicatede Bus (and this increase the CPU load because it have to send the sama datas twice.
     
  41. entro_p

    entro_p

    Joined:
    Mar 9, 2014
    Posts:
    36
    Would this also work on non-terrain meshes?
    For example rasterized voxel terrains?

    Cheers,
    Entro-P
     
  42. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    It should work, but it doesn't support overhang, because it's essentially a 2.5D simulation. It uses a depth camera to create a heightmap of the scene, so you can put any mesh you want in the layer it renders.

    If you want it to run into a cave, you need to make the roof of that cave invisible to the depth camera. And when you do that, the water won't run on top of the terrain that the cave is under.
     
  43. entro_p

    entro_p

    Joined:
    Mar 9, 2014
    Posts:
    36
    Very interesting!
    Thank you for clearing that up!
     
  44. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    In my video using scrawks code (which in itself is based on Eric Brunettons code) the foam is somewhat emphasised but in its implementation depends much on the choppiness of the waves, with choppier waves causing the sort of energetic water collision that causes foam generation, so you pretty much have the right idea, it comes from a mix of this choppiness being present in the first place, relation to the angle of the water surface (steeper being more likely to produce foam) and just a general parameter to affect coverage, which i pushed quite far - in a 'realistic' setting the foam would only occur in spots. What can be said however is that FFT waves can look very nice but they don't suit dynamic water simulation very well, certainly at 'local' distances to anything affecting the simulation and from above the foam clearly evidences the FFT being a very large scale but identifiable repeating pattern. In a truly realtime simulation it would be much as you say, with wind and its turbulence causing the most intrinsic wave creation with this further affected by water depth and surface collisions (And i guess if you want to get super accurate, other factors like tides and streams in ocean bodies but this kind of thing be quite unnecessary to simulate in this case)
     
  45. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Surface Waves has been submitted to the Asset Store, and is now awaiting review! :)

    (this is scary!)

    So in the meantime, let's get back to development.


    I've switched to using the difference between input and output of a cell (I call it the 'shock' value, because its an estimate of how much the water is either compressed or 'pulled apart') combined with its estimated velocity, in stead of acceleration, to determine where foam is supposed to be. Which turns out to be a lot more like the foam I'd expect to see, especially on waterfalls, etc. I tried using some other factors, like the local angle of the waves, but so far most of the approaches I tried added way too much foam in unexpected areas, so I decided to keep it simple for now.

    While I was studying some more reference material for foam in water, I noticed that a big part of the effect was that there are a lot of water bubbles under the surface, which blend much more non-linearly with the fog color of the water (just like refractions). So I decided to try to simulate that, which turned out to also make the shader settings a bit simpler. I also made the foam ignore light wrapping, which also turned out to emphasize the lightwrapping of the water fog.

    The foam is obviously still very blurry, so I probably really do need some kind of detail textures, once I've implemented flow mapping. But I think it at least looks a bit better than before. As usual, I've updated the demo, so you can judge for yourself.


    It has become very clear to me that the number of draw calls required by the current system is way too high, and it's causing quite some overhead (way more than the cost of the pixel shader itself). So I'm considering using a single camera aligned mesh, as suggested above, in stead of the grouped square grid meshes I'm now using. The tricky part is going to be adjusting the normal calculation to the uneven mesh, and resampling the simulation data to match the mesh.

    Thanks for the suggestions!
     
  46. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    Awesome! I hope to get it after I get some money off clients and have enough $ for a unite ticket when it arrives in Australia.
    Now what's the price?
     
  47. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    I'm glad to hear you would like to help fund the project! I can sure use it! Just please only pay if you can handle it financially ;).

    Actually, if you live near Melbourne, you might see Surface Waves in use at some upcoming events in August. I'll post more details when that is confirmed.

    I set the initial price at $80, but it's not final yet, because the asset is still going through approval.
     
  48. dallasxiong

    dallasxiong

    Joined:
    Feb 7, 2013
    Posts:
    7
    Take my Money!!!!!
     
    RC-1290 likes this.
  49. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Looking forwards to approval and a demo! Would you be able to make the resolution of the simulation mesh alterable in a demo?
     
  50. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Demo is already out, I've linked it above, and again here. But unfortunately I can't easily expose the mesh resolution settings, because they require a rebuild of the mesh, which isn't possible at runtime in this version. And even if I fix that, I would still have to make a custom GUI for it, because the Editor GUI can't be used at runtime. (I'm looking forward to the new GUI. When it's out, I think I'll try to make a GUI to expose the material settings in the demo.)

    So I think it's a better idea if I work on trying to to fix the drawcall problem in stead. Especially because it's also linked to some other issues, such as supporting a tiled simulation, and removing or simplifying some confusing settings from the water shader, related to vertex normal calculation.