Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GPU Water ripple effect - Desktop and iOS source code available

Discussion in 'Made With Unity' started by brianasu, May 15, 2013.

  1. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369

    Attached Files:

    Last edited: Apr 3, 2016
    JosephHK, John3D, MiniMe_ and 4 others like this.
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    That is pretty awesome! Thanks for sharing!
     
  3. Unity Games

    Unity Games

    Joined:
    Jul 13, 2012
    Posts:
    55
    This effect is amazing! Thanks for sharing it.
     
  4. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Hi,

    Nice job. Much appreciated. Thanks for the share.
     
  5. Breyer

    Breyer

    Joined:
    Nov 10, 2012
    Posts:
    412
    very nice job absolutely

    is there any chance porting to unity free? (with smaller quality of course)
     
    Last edited: May 15, 2013
  6. Max70

    Max70

    Joined:
    Jul 30, 2011
    Posts:
    27
    Good effect, and very very interesting job ;)
     
  7. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Thanks for the comments. Yeah I think I'll give the unity free version a try. I'm just scared of using Get and SetPixels since it is pretty slow but I might be able to compute it per vertex rather than per pixel. Glad you guys enjoyed it I thought it might be useful in games. I'll be coming out with some more iOS friendly shader stuff next week.
     
    XCO likes this.
  8. DaneC020

    DaneC020

    Joined:
    Mar 19, 2010
    Posts:
    191
    **EDITED**

    Thanks ZJP, it works on Safari for me but for some reason my Chrome wasn't. I guess I need to go check some of my user preferences... It was just opening up a tab with the link but nothing was being downloaded... First time I had that issue on these forums.

    Thanks for sharing brianasu! This is going to be helpful.
    -Dane
     
    Last edited: May 17, 2013
  9. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    The link is fine with Firefox and Chrome for me. Doesn't works with IE10
     
  10. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
  11. DaneC020

    DaneC020

    Joined:
    Mar 19, 2010
    Posts:
    191
    Thanks so much brianasu! I am going to play around with it some today, looks really interesting.

    -Dane
     
  12. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    It's interesting that the author of that article you mentioned claims that the water ripples need to lose energy. In a force based simulation, the waves eventually cancel each other out automatically anyway. It's probably losing some energy automatically, due to precision errors, but there's no need to actually apply an extra dampening force, because that happens automatically due to pressure. The waves get shallower over distance anyway, due to the force being applied to more and more pixels, resulting in less displacement per pixel.

    Anyway, still a nice demo. What kind of precision textures does it require? If it only requires standard ARGB32 RenderTextures, that would definitely be an advantage over a more complex simulation.
     
    Last edited: Jun 13, 2013
  13. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Yeah you are correct RC-1290. You lose a lot of precision. I'm using just the red channel so 8-bit precision since I can't seem to get depth or any floating point textures working on iOS. I haven't tried it yet but it's possible to pack float into the 32-bit argb but it requires like something like 4-5 multiplications * 4 texture samples to get the surrounding energy
     
  14. Nimerion

    Nimerion

    Joined:
    Apr 20, 2014
    Posts:
    42
    Good job!
    It's very amazing! :)
    But why is the water surface shader not loading after I restart unity?
     
  15. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Haven't tried it in a while. May have to update it for unity 4.5
     
    Nimerion likes this.
  16. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    ... and not working in Unity 5.0.2f1 ;)
     
  17. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Time to fix it:) I'll release the code on github after I update it.
     
    Yippie likes this.
  18. Yippie

    Yippie

    Joined:
    May 4, 2009
    Posts:
    227
    thanks for sharing it dude it's amazing, please make it working in Unity 5 :)
     
  19. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    XCO likes this.
  20. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    I've started porting it over to Unity 5. You can access it at https://github.com/brianasu/water-ripple

    I've only tested it on mac unity 5.0.2f so be warned. I'll port over the mobile shaders later.

    Enjoy!
     
  21. XCO

    XCO

    Joined:
    Nov 17, 2012
    Posts:
    379
    Very cool, I will be followin you kind sir! :)
     
  22. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    Thanks a lot ^_^

    Edit : got an error in "Water Desktop.shader" on windows, unity 5.0.2f1

    Shader error in 'Custom/Water Ripple/Desktop': 'tex2Dlod': no matching 2 parameter intrinsic function; Possible intrinsic functions are: tex2Dlod(sampler2D, float4|half4|min10float4|min16float4) at line 64 (on d3d11)


    Had to replace stuff like:
    tex2Dlod(_MainTex, uv + texSize.xz * 1).r;

    by :
    tex2Dlod(_MainTex, float4(uv + texSize.xz * 1,0,0)).r;

    Then the shader can compile... but the result is still wrong : I get flickering polygons far from the expected result ;)
     
    Last edited: Jun 3, 2015
  23. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    I haven't tested on windows yet. I'll do that soon. Tex2dlod is always an issue across platforms.
     
  24. IronDuke

    IronDuke

    Joined:
    May 13, 2014
    Posts:
    132
    I suggest putting the latest link on the original post. It's much easier to find that way.

    --IronDuke
     
  25. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    I've uploaded some fixes for windows machines. Give it a go and see if it works. Thanks IronDuke just did it.
     
  26. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    Hi,

    Still not working for me... No more flickering, but I can only see a perfect flat water :/
    Win7 64bits, Unity 5.0.2f1, Geforce GTX 660 Ti - drivers 352.86
     
  27. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Can you try switching to linear / gamma lighting? I think it has something to do with the srgb encoding.
     
  28. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    It looks like a dx11 problem. Have to investigate.
     
  29. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    I tried to switch bewteen Linear or Gamma -> except the lighting, no changes :/
     
  30. frostdani

    frostdani

    Joined:
    Aug 14, 2015
    Posts:
    7
    This is a great looking tool to make those water ripples. But when i try to use it in Unity 5.2 nothing happens, just a flat transparent plane. Can you please make some fixex for it?
     
  31. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    When I get some time later this week I'll throw it into U5.2 and see if I can sort out everything
     
    frostdani likes this.
  32. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Finally pushed a fix for Dx11
     
  33. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    OOOO.... Could I put realtime reflection there, I wonder... ;)

    EDIT: OOH BABY IT'S RIPPLE!
    Screenshot from 2016-04-05 21-17-11.png
    And YES, that's gnome shell... XD
     
    Last edited: Apr 5, 2016
    GibTreaty likes this.
  34. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    Hey,

    i'm really interessed about making some water ripples.

    I would like to know if it's possible to generate ripples normal maps with this?

    it's for a mobile project.

    Thanks a lot! :)
     
    GibTreaty likes this.
  35. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Not the project owner, but from what I make of it, no.
    Saying that though, a shader that outputs the normals in tangent space + some scripting magic could work. :)
     
    GibTreaty likes this.