Search Unity

Graphics Hydroform Ocean Renderer [RELEASED]

Discussion in 'Tools In Progress' started by Xix-Interactive, Feb 11, 2016.

  1. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    Does this water receive any kind of lighting other than the specular? I'm trying to make it play nicely in a scene with a day-night cycle.

    My day/night is from trueSKY, and as far as depth/mist/clouds are concerned the two seem to play quite nicely. Right now my ocean doesn't go dark with the rest of my scene, though.
     
  2. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    That is on my list of things to add. You can do it yourself relatively easily though. Do a dot product between vector( 0, 1, 0) and the negative vector of the light direction. Then multiply that by the water color, which can be set from script.
     
    angrypenguin likes this.
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    Ok, cheers, from a quick test it's already working in principle. Will need to apply the same to other color values as well, but I'll get it where I want it.
     
    Xix-Interactive likes this.
  4. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Awesome, glad to hear it!
     
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    I'm away from my dev PC for a bit. I noticed that when I set surfaceFX.waterColor (or whatever it is) there's a delay before it's applied to the material. This is going to be an issue during sunrise and sunset where the lighting changes pretty quickly, as you can see the color "stepping" from value to value.

    I can't look at the moment, but I'm guessing that there's somewhere I can change the script so that it updates the material more often? If so, are there likely to be any unforseen issues if I mess with that, and/or would you recommend going about it differently?
     
  6. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Yes exactly - most of the parameters are constant so it's inefficient to send that data to the shader constantly, so I only update it periodically. Look in PeriodUpdate() for where it updates the colors. You could just change the delay to get it working quickly, or you could add a function that instantly writes the color values to the shader.
     
    angrypenguin likes this.
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    Ok, I've got that working well enough for now. :)

    While testing other stuff, though, I've noticed this:
    HydroformProjectorGeometry.JPG
    That's a few bits of geometry that show up in front of the camera when they happen to line up with a Projector. Each of them correspond to parts of the ocean - turning the Hydroform GameObjects on and off makes pieces of that appear and disappear.

    I suspect I can set up the layer masks on the Projectors to avoid it, but I thought it worth pointing out. Certainly if I wanted to project onto stuff in the Water layer it'd be an issue.

    For clarity, they aren't directly being rendered, they're just being picked up by the Projector.
     
  8. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Yeah unfortunately that will happen anytime the water is rendered with a replacement shader. Also note that Hydroform does not render to the depth texture, so projectors don't work on the water surface. See posts from a few days ago for that discussion.
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Out of curiosity what is the order of rendering for hydroform? I thought it was: render geo of game, get render texture then render hydroform as another opaque object before transparent pass? if it does not write to depth then it can't support a transparent object halfway inside of it? or am I mistaken? Sorry was confused.
     
    Xix-Interactive likes this.
  10. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Yes that is correct, it does render opaque to the depth BUFFER, but not to the depth TEXTURE. So it will render and intersect properly with transparent objects. The depth texture is used by Unity to draw shadows and projectors and used by Hydroform to control the transparency of the water and calc the underwater fog. However to render the ocean to the depth texture requires an extra draw pass (bad for performance), and I cannot control when that pass happens. If I add in the shadowcaster pass, then the shoreline transparency no longer works because it thinks the depth is 0 everywhere on the ocean surface since it always renders to the depth texture before the regular rendering pass. In addition, it draws the shadows during the shadowcaster pass, but doesn't draw them to the depth buffer, so they immediately get overwritten by the regular rendering pass. I think I can get around all that by sampling the shadow texture in the shader (maybe), but projectors are still a problem. They should draw after the ocean, so they wouldn't get overwritten, but there was some other problem that I cannot recall, maybe I didn't have time to hunt it down 100%. Anyway, welcome to my pain! ;)
     
    hippocoder likes this.
  11. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So I get artifacts when moving meshes intersect with the water like the boat below. They disappear after some short time. FYI particle systems intersecting water show the same artifacts.

    upload_2017-7-19_12-38-3.png
     
  12. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Hey here are a couple of classes that make it easy to use the community buoyancy script out there. If you want to include them in your asset.

    I also added an additional boolean (default true) to GetHeightAtPoint in HydroFormComponent.cs, since adjusting the cam like that messes with some camera setups.
     

    Attached Files:

    Mark_01 and Xix-Interactive like this.
  13. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Awesome, thank you! Could you clarify about adding the boolean and the camera? How is it messing with your setup?
     
  14. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Yes, so that is caused by the Height Cam rendering the boat into the height buffer which is used to generate the foam. It's easily resolved by setting a culling mask for the Height Cam (located under the ocean prefab).
     
  15. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Actually I can't remember now and can't replicate the issue either, so who knows could have been something I did.
     
  16. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Ok I remember what it is now. It doesn't work correctly in the editor. Probably an easy way to get the editor camera position, haven't had a reason to do so myself but just guessing.
     
  17. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I'm also seeing the black artifacts as posted earlier. Some testing and I can verify that it kicks in when the camera hits the terrain edge. If I put in a plane for the ocean floor so there is never that drop into nothing, the issue goes away. Also seems to be related to wave settings, since this only cropped up after my last iteration with changing wave settings to larger waves.

    upload_2017-7-19_14-58-10.png
     
  18. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    I'm also noticing that even though I can't see it, any time I click in the center of my Scene window it selects my water, presumably because it's hitting that geometry.
     
  19. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Hmm, what do I need to do to reproduce that? I'm not seeing any black when the camera reaches the terrain edge.
     
  20. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I'm using 2017.1.0f3 for one. Now it looks like it's not the terrain. One thing is when I have an mesh intersecting with the water I see flickers, and it seems to possibly trigger the black stuff, either that or having the mesh selected. Hard to tell I just took a new scene dragged the Ocean prefab in, drug in a cube and scaled Y to 20, then sat for a couple of minutes.

    upload_2017-7-20_1-39-59.png
     
  21. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    OK thanks I'll take a look at it.


    EDIT:
    Sorry, I am not able to reproduce following your steps
     
    Last edited: Jul 20, 2017
  22. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
    I just bought this package for a prototype.

    I'm using Time Of Day from Mod Monkeys for my day night cycle.

    Could you please include a script to easily modify the ocean color depending on the lighting with an example please?
     
  23. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Yeah I'll try and add that in the next update.
     
  24. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So two people have reported this now. I just created a brand new project, HydroForm the only asset imported. Was able to repro it with nothing but your water in the scene. So I don't think your test copied what I did. Did you set the camera to a similar angle? That seems to matter, at a lower angle I have only seen it once or twice.
     
  25. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    FYI that camera angle is 40 X, 150 Y
     
  26. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So some more digging around and testing. Disabling HDR makes it go away. So does settings the clear flags on the camera to solid color. I'm guessing something is writing Nan pixels somewhere.
     
  27. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    I still can't reproduce - are you in deferred or forward? Is this happening in editor mode, game mode, or both? Have you tried disabling features like ShoreFX, and reflections? Is this only occurring in that beta version of Unity? Could you put together a demo that I could download?
     
  28. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    That's not a beta version it's a release version.

    The scene setup is exactly like I said it was, nothing more nothing less. New project, import HydroForm, drag ocean into scene. That's it. Did you actually test it in the same unity version?
     
  29. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    It only shows in game mode. Also after installing the patch release put out today, cannot repro in the new project as of yet. I'll try reproducing it in the game project where it was easier to repro.
     
  30. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Can't repro it anymore in the game either, although the lighting since last attempt changed significantly as switched to linear. But I'm guessing this is a bug in 2017 that was fixed in the patch release.
     
  31. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Well that's good. Thanks for trying out the patch, that saved me a bunch of time!
     
  32. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    it's cropping up again. Disabling HDR seems to be the one thing that guarantees it goes away. Digging around I found a couple of other times where shader bugs with HDR caused just this, black artifacts. Due to Nan pixels usually.

    Unfortunate because it makes this asset not usable with linear lighting until it's fixed. Possible it's a unity bug, but even in that case it should be worked around.
     
  33. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Well there's an easy way to determine if it's definitely an issue on the Unity end. At the top of calcPixel(), put return float4( 1, 0,0, 1 ). If there are still black areas, then it's a Unity issue.
     
  34. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I bought this asset today, and been playing with it. And I can add to the issues above.

    The black artifacts happens with HDR and refractions enabled. Not sure if linear mode affects it.

    if you edit the shader and saturate the end pixel result, it fixes the issue. But i am not sure if this fix is just a work around for the Unity issue or not.

    Another thing. Well, should have asked this before I bought the asset, but ...

    1. Water doesn't receive any shadows.
    2. It doesn't react to any other lights than a single directional light.

    Well, I realised that all of above features weren't exactly advertised on the store front page before so I am not saying xix has done anything wrong, but alas me the same. :(

    So I was wondering if any of above features can be implemented in the future version?

    I also realized after looking at the shader, that the system basically renders in forward mode only, even in deferred camera setting for obvious reason being that it only has vertex,pixel shader variant version. And Unity's standard deferred mode is probably unsuitable or difficult to be utilized as water shader, but I did have hope.

    After some search, play way water system "seems" to be based on the Unity's standard shader, so it might do what I need so I think I may have to look into that one instead...

    So I was just hoping and wanted to ask about the above feature? :D

    Thanks.
     
  35. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    You are using Unity 2017? OK, saturating seems like a very easy fix, I'll check it out.

    As far as I can tell, no water assets in the store accept shadows. If you look at Playaway's screenshots, the ship has no shadow, which also means that they are not using a standard shader and it also probably means that water doesn't react to multiple point lights, etc. These are not trivial issues to resolve given that we cannot control when the shadowcaster pass occurs or when/how the depth texture is written to.

    There is a chance that I could get it to accept shadows by reading the shadow buffer from the shader directly rather than relying on a shadowcaster pass. This may only work in forward rendering, or not at all, I'm not sure yet.

    I've looked at rendering directly to the gbuffers in deferred mode and there are several problems with it. I've forgotten the details, but just the fact that you'd lose control over the lighting would mean it would be very difficult to look good.
     
  36. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I am using 5.6 but saturate is indeed easy way to fix the problem. Not sure exactly why it fixes the problem, because the shader is using fixed4 so it should be limited by that?
     
  37. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Also play way water system doc does indeed mention about shadow receiver. I am going to check it out..
     
  38. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    4 days left on the SALE!

    I've made some improvements that will fix this issue that sometimes comes up when interacting with other assets:


    I should have that and the 2017 fixes up in a few days. Progress is being made on underwater
     
    angrypenguin likes this.
  39. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Confirmed saturate() fixes the black pixels in the 2017 build. Thanks so much for your help on that guys!
     
  40. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Not a problem.

    Do you have any idea why this actually happens? My guess is that the value may go wrap around the limit of the precision but not 100 sure.
     
  41. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,619
    Possibly related, but untested, I've also noticed issues when looking almost directly away from the water (straight up) that are new - wavy patches appearing on transparent objects. However, we made a raft of our own changes over the period where the water went in.
     
  42. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Why is playway deleting all shader variants every time ANY asset is saved?????
     
  43. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    I'm not sure either, I didn't mess around with it too much to try and find out. Could be an internal Unity thing.
     
  44. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Let me know if you can reproduce and I'll take a look at it.
     
  45. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    I don't know, ask the playway guy?
     
  46. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    duh sorry about that, wrong forum. Late night:)
     
  47. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    Last day for the sale!

    The new update with misc fixes should go up tomorrow.
     
  48. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Just wondering if that patch includes any performance improvements or experimental features to watch out for?
     
  49. Xix-Interactive

    Xix-Interactive

    Joined:
    Aug 26, 2015
    Posts:
    442
    No performance tweaks, but the new draw method should make it play nice with more 3rd party assets.
     
    OdderOtter likes this.
  50. franky_li

    franky_li

    Joined:
    Aug 8, 2016
    Posts:
    163
    I have problems after the update, the ocean works fine in editor, but in play mode it's disappearing under certain viewing angles. With the previous version I didn't had that issue.

    Unity 2017.1.0f3, Windows 10, 64bit

    Regards

    Frank