Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Stylized Water 2 [URP] ☑️ Desktop/Mobile/Consoles/VR

Discussion in 'Assets and Asset Store' started by StaggartCreations, Nov 3, 2020.

  1. Diego_Graphics

    Diego_Graphics

    Joined:
    Nov 3, 2014
    Posts:
    120
    Is there any way to prohibit the FloatingTransform component from overwriting the Y axis? the floating system is really helpful and simple for some things. For more complex things I use DWP, but now I have objects where DWP would be too complex and there the FloatingTransform component would be ideal, if it left the Y axis untouched.

    Code (CSharp):
    1. private void ApplyTransform()
    2.         {
    3.             //this.transform.up = normal;
    4.             this.transform.position = new Vector3(this.transform.position.x, height, this.transform.position.z);
    5.         }
    6.  
    Of course this is successful, but then no rotation is applied to X and Z, which is a pity and makes the buoyancy effect look less beautiful.
     
  2. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    27
    Hi, I have been having some issues with the water reflections.
    Normally all seems good in the scene view, but the problems are in the game view (and also builds).

    For example:

    scene view.png
    Versus:

    game view.png

    Basically some objects are rendered in the incorrect order, and others seems to render the back faces. The big blue and green "floors" are not reflected in either view, but that is because I forgot to add the custom layer to the culling mask in the reflection renderer.

    Another example, scene:

    scene view2.png

    Versus game:

    game view2.png

    Two simple boxes with simple materials.

    I tested with most of the options of the water shader, with different materials and setting up my scene with only one camera, but the problems persist.

    Regards.
     
    Last edited: Dec 31, 2020
  3. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    92
    Hello! I am facing a strange issue with the asset when built to my android device. In editor, it works splendidly. However, when running the water in my android device, I notice that the surface foam starts out okay, but very quickly start to slow down. I have attached a GIF showing this issue:



    So here you can see that the fps isn't tanking, the waves are operating normally as well. It is just the surface foam that seems to be incredibly laggy and jittery?

    I have also attached my water's material settings below. Reflection, underwater, and normal settings have been disabled. Would you be able to help me with this surface foam issue? Have I missed setting up the water correctly? Thank you for your help!

    SurfaceFoamSetting.png AdvancedSetting.png LightingSetting.png WavesSetting.png IntersectionFoamSetting.png
     
  4. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    This is unfortunately inherent to how transforms work. Setting the orientation of a transform involves modifying the XYZ axis. If the Y-axis would be left untouched the object would exhibit unwanted behaviour and would appear to wobble around, rather than aligning to the wave surface. Though I can simply add a toggle to disable setting the orientation.
    The faces will appear inverted if the camera goes below the virtual reflection plane. Normally this isn't noticeable, because the camera would already be underwater.

    With the Planar Reflection Renderer component selected, you'll notice a white box around the affected water objects. This box should appear as a flat rectangle, rather than a cube, meaning all the water objects must have the same height on the Y-axis.

    If you've moved the water up or down, you can press the "Recalculate bounds" button to update the bounds around all the water, which under the hood determines the height of the reflection plane. After which, the you shouldn't be seeing any incorrect culling on the reflected objects.
    upload_2020-12-31_11-8-4.png

    Thanks for taking the time to record a video, shows it clearly! Off the bat the cause doesn't seem apparent to me, all the animations use the same time index, so if something is wrong there, in theory everything should appear moving in a stepped fashion.

    Do you have the possibility to test on another device? Mobile can be particularly finicky, where specific devices have specific issues, with no indication as to why (could be hardware, or the graphics driver)
     
  5. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    27
    Ok, I tried a lot of things but couldn't make the reflections work correctly.

    I then went and created a new template URP project with Unity 2019.4.
    I installed the stylized water asset and URP was upgraded to 7.5.2.
    Then I added a water object, the plane reflection renderer, reused the StylizedWater2_Lowpoly material (I added shadows and increased the reflection strength to see it more clearly), and added two scaled cubes with simple materials.

    test.png
    And the game view seems to be wrong (with the correct bounds).
    So any hint would be appreciated :)

    test2.png

    test3.png
     
  6. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    92

    Hello! I have managed to test on another device (a really old Samsung tablet) and it was running fine, and yet a newer device wasn't. I suspected that it might have something to do with the graphics API being vulkan causing this issue, and it appears I might be right.

    So I have decided to test both Vulkan and OpenGLES3 on the same device. Here is the gif for vulkan, showing the lag on surface foam:




    And here is the same device running on opengles3:




    So it appears there is something weird going on with Vulkan?
     
  7. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    A little puzzling, since the reflected objects appear to be rendered with incorrect sorting. Bounds do seem to check out! I can't reproduce the same result, unless I bring the "Offset" value on the Planar Reflections script way down.

    What works for there is replacing line 322 in the PlanarReflectionRenderer script from
    Code (CSharp):
    1. oldCamPos = source.transform.position - new Vector3(0, position.y * 2f, 0);
    to
    Code (CSharp):
    1. oldCamPos = source.transform.position - new Vector3(0, position.y, 0);
    Would you mind checking if this works for you as well?

    Yes, it certainly seems like an idiosyncrasy related to a specific device, at least with the Vulkan API. On a OnePlus One and Galaxy S10 using Vulkan the issue doesn't seem to appear. The related shader code is pretty straightforward and doesn't do anything that need platform or API specific treatment, so I don't think it's anything I can fix.
     
    Klausology likes this.
  8. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    5,509
    These types of issues often occur when using fixed/half data-types in my experience. Desktop uses float always, that's probably why it works in the editor. You could test if that's the case if you change everything to float instead.
     
    Klausology likes this.
  9. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    Good point, that may be the case! I'll have to check if I'm using half precision on any time related.
     
  10. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    92

    Hey hey! I just made another discovery! It appears if I disable the wave module, the surface foam jitter disappears. Also, I don't think I mentioned this earlier, but the surface foam jitter issue takes about 1 minute or 2 before it appears on my HTC 10. Mayhaps you would be able to take a look into this. :)
     
  11. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    27
    Puzzling indeed..

    Changing that line didn't correct the issue for me.
    I went and recreated the test scene again, and the result is still the same.

    My current steps:
    - create URP template with Unity
    - erase all sample and tutorial assets from the project
    - update URP to 7.5.2 (later I downgraded it to 7.5.1 but with no effect)
    - activated "Depth texture" and "Opaque texture" in the URP high quality asset (also in the other lower quality assets)
    - imported last Stylized Water 2 asset
    - moved low poly water prefab to scene
    - created cube with scale (4, 0.25, 4), created sphere with default scale
    - added gameobject with Planar Reflection Renderer with default values
    - moved the camera and the objects a little around, to get this:

    reflect1.png
    What exactly is the game camera missing then?

    One thing that I noticed this time is that I don't see the white bounds when selecting the reflection renderer object (even after doing the Recalculate Bounds). Don't know if because this prefab is bigger.

    Other interesting thing is that when I move the sphere a little up, it start appearing:

    reflect2.png
    Is like there is no depth test/buffer/texture used for the game camera objects..

    I think I will try with Unity 2020.2 now.. at some point we will solve this :)
    (I hope is not some strange graphic driver issue..)
     
    Last edited: Jan 4, 2021
  12. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    27
    Well, no luck with 2020.2 either..

    reflect3.png
    I tried with more materials and different water prefabs.
    Changing things from the camera and the water and objects materials, but nothing.

    Only thing I can say is that Unity 2020.2 seems more consistent in the rendering order. It seems the objects are always rendered (in the game camera reflection) in the order that I added them to the scene (cube, sphere, capsule in this case), and this doesn't change if I move them around, like with Unity 2019.
     
  13. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    27
    I changed line 238 in the PlanarReflectionRenderer.cs from "data.requiresDepthTexture = false;"
    to "data.requiresDepthTexture = true;"
    And it seems to solve the issue..
    But I'm going to do more tests tomorrow to confirm.
     
  14. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    Thanks for the information. If it takes some time before the animations becomes stepped, it indicates precision issues are occurring. I'll be able to make some changes, and send you a potential fix later today.

    That actually makes a lot of sense! So far, on any devices and project I tested, this wasn't necessary. My guess is that's it's potentially a quirk related to W7, but I can't be sure. This only adds one drawcall, for copying the depth information, so I'll be sure to include this change in next update. Apologies for the hassle, and thanks for the effort!
     
    Klausology likes this.
  15. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    27
    Yeah, windows7 is also my main suspect at this point. If not I don't understand how more people is not reporting this.
    Sure, not everyone use reflections, and the waves or using only single objects in the water (far apart from each other) can hide the issue, but still..

    Anyway I think you could add it as a "quality" option in the reflection component. That and others, like "refection shadows" maybe, so people could choose.

    I think I also had problems with objects using multiple materials before, but all is good now.

    This for the future: I'm also using another asset for planar reflections (PIDI planar reflections 3) and they support rendering to a texture. Could it be possible that you add support to use an external render texture for the reflections in the water?
    For me it would be useful, because I could reuse the same texture for other reflections in the scene.

    Also I already did the integration of those reflections with a volumetric shader and it was pretty easy.
    So I offer my time to test anything you need about this :)

    Regards.
     
  16. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    I think if you're already using PIDI you could simply continue to use it for specific planar reflections. The reflections rendered for the water would only work for more water, specifically planes with the same orientation and height. Plus the reflections aren't rendered unless the water is visible on screen, so couldn't really be used for anything else ;)
     
  17. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    Preview of a "river mode" feature being adding in the next update.



    This changes the behavior of all animations so they flow in a single direction, based on the mesh's UV. For spline meshes this automatically means everything flows along the direction of the spline (R.A.M. for example).

    The surface foam for the material also becomes more visible on slopes, and gradually tapers off as the water flattens out. An option to control the amount of stretching on slopes, and a speed multiplier is exposed when it is enabled. The particle effects are a new additional, specifically for water falls.
     
    Acissathar, LogaNRV and Klausology like this.
  18. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    27
    That river looks amazing, nice work :D

    About the reflections I think you misunderstood me (if not just ignore me), I want to use the PDI reflections to replace the one in the water, because I already have ones at the same orientation/height. But don't worry anyway, this is very low "priority".

    Regards.
     
  19. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    Submitted v.1.0.6, changelog:
    Oh I see, the other way around.

    If you replace every occurrence of "
    _PlanarReflectionLeft" in the Lighting.hlsl and Input.hlsl file with "_ReflectionTexture" (assuming that's what PIDI calls it). The in the "StylizedWater2.shader" file remove the one line that reads
    _PlanarReflectionLeft("Planar Reflections", 2D) = "" {}

    With these changes, the shader will use a global _ReflectionTexture instead of one assigned to the individual water objects.
     
    LogaNRV likes this.
  20. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    Version 1.0.6 is now available, changelog:

    Added:
    - River mode, forces animations to flow in the vertical UV direction and draws surface foam on slopes (with configurable stretching and speed). Documentation has been extended
    - Waterfall splash particle effect
    - Data provider script for Dynamic Water Physics 2 is now part of the package (can be unlocked through the Help window if installed)
    - Curvature mask parameter for environment reflections, allows for more true-to-nature reflections

    Changed:
    - Water hole shader can now also be used with Curved World 2020

    Fixed:
    - Planar reflections, reflected objects being sorting in reverse in some cases
    - Mobile, animations appearing stepped on some devices when using Vulkan rendering
    - (Preliminary) Error in URP 11, due to changes in shader code

    Upgrade discount has been set to 20% now, I'll leave this up until barely anyone makes use of it.
     
    Last edited: Jan 8, 2021
    LogaNRV and Acissathar like this.
  21. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    27
    Hi.

    Some more feedback about reflections :)

    - From what I can see the planar reflections don't use the skybox color. Normally if I set the reflection strength to max, the water color changes to black. If this the intended behavior?

    - After the last update, I need to increase a lot the reflection strength (and decrease the curvature mask), to get something similar to the previous strength/behavior. Also objects that are over the water at a far distance, no longer could be reflected easily.
    I was looking at the code and did a little change to the curvature mask (_ReflectionFresnel) range to allow values from 0 to 20 (instead of 1 to 20), so the ReflectionFresnel() function can return 1 in that case. With that I can configure my scene to something similar than before.
    So it would be nice if you could add that change later, if possible of course.

    - I tried to integrate the PDI reflections but failed to get any visible reflection.
    I did the changes that you told me (using _ReflectionTex instead of _PlanarReflectionLeft), but also had to change the references to sampler_PlanarReflectionLeft, to be sampler_ReflectionTex.

    Apart from that I had to change a little the screen coord passed to SAMPLE_TEX() (coord X is flipped) and added a "PDI reflection caster" component to the water object (the same things that I did before for another shader).
    But everything failed, so any idea of what could be missing would be helpful.

    I have one gameobject with a PlanarReflectionRenderer.cs in the scene, but is disabled, so I assume is not causing any problem.
    Do you expect the reflection texture in a specific format or resolution? (this can be setup in the PDI reflection renderer).

    Regards.
     
  22. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    Delved back into underwater rendering and finally had a breakthrough with rendering a partially submerged camera. Can now reliably determine what's above and under water, next to rendering a meniscus/waterline on the camera "lens".



    Still plenty of legwork on some specific issues (hopefully entirely avoidable) and features (waving, blurring and sunshafts) but at least the biggest challenge is out of the way!
     
  23. JoshWB

    JoshWB

    Joined:
    Aug 4, 2019
    Posts:
    13
    Question ~

    Is there a way to include the Skybox with planar reflections in SW2?

    With SW1 I was always able to reflect the clouds/Skybox by turning the Fresnel effect to 0 in the Planar Reflections properties.


    By the way, thank you for your hard work!
     
    Last edited: Jan 22, 2021
  24. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    For reflections, the skybox is sourced from a Reflection Probe, which is then composited with the planar reflection, containing any sort of scene geometry.

    Unity always generates a global reflection probe, with just the skybox rendered into it. For a new scene, you'd have to tick the "Auto generate" option in the Lighting window once in order to initialize it:
    upload_2021-1-21_12-30-24.png

    Alternatively, you can create a Reflection Probe object and set it's culling mask to "Nothing". Just have to make sure the probe's bounding box touches the water plane.
     
  25. JoshWB

    JoshWB

    Joined:
    Aug 4, 2019
    Posts:
    13
    Hm. I can get it to work with URP 2020.1 with waves turned off, but with URP 2019.4 and PPv2 enabled it doesn't seem to work at all.

    I'll keep messing around with it.

    Thanks!
     
  26. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    I think it's because PPSv2 clears the depth texture, which is what's used to mask which pixels belong to the skybox and/or scene geometry. URP's post processing doesn't do this.

    I've meanwhile added an option to include the skybox in the planar reflection, so I'll DM you the modified script ;)
     
    JoshWB likes this.
  27. LogaNRV

    LogaNRV

    Joined:
    Jun 3, 2017
    Posts:
    27
    I just noticed an issue while editing a material with your custom water shader.
    If you have any tab open (try it with "Color" for example) and you select more than one water material, then all values in those tabs are overwritten with the values from one of the materials selected.

    This is kind of dangerous if you are not aware of the issue. At some point I lost some materials that I had, because I selected all of them, with the intention of moving them to a new folder, and later I noticed that the definitions were wrong, when I could no longer "undo" the damage. But I recovered most of them from a backup.

    I'm still in Unity 2019.4 with Windows 7, so I don't know if this happens everywhere, but I know it can also happen with your grass asset (maybe there is a little more severe, because you can have multiple tabs open in the material at the same time, while with the water material if you open one tab, then the others close).
     
  28. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    Thanks for the heads up! I have an idea why this may be the case, I can most likely make it work for multi-selecteded materials.
     
  29. esmundoz

    esmundoz

    Joined:
    Sep 18, 2013
    Posts:
    1
    Hi, and thank you for your great asset :) This works perfectly when building for iOS, but for Android there is no depth to the water showing what is underneath. Do you know why this happens, maybe something I've missed in the settings for Unity?
     
  30. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    1,355
    If the transparency isn't working, this means the URP isn't rendering a depth texture. You can find this option in the pipeline settings:
    upload_2021-2-10_17-55-14.png

    Note that it's also possible to use different pipeline assets, per quality level:
    upload_2021-2-10_17-56-9.png
    So it's possible on Android one is used where this option is disabled
     
unityunity