Stylized Water Shader - Desktop/Mobile/VR [Built-in RP]

Hi where I can get your water shader?

You find it on the asset store :wink: http://u3d.as/A2R

I’m seeing this effect when trying to use the material on a “waterfall” mesh (just a curved plane really). The darker blue hourglass appears to follow the focus point of the camera, and it’s translucent for what it’s worth. Modifying the Transparency value just increases/decreases the effect of this as well.

2019.3.11 + SRP + Deferred, think those are the only things I’ve got going on

EDIT: Seems to be an Editor Scene only thing, in Playmode + build I’m not actually seeing it.

I’m having an issue with the brightness of the Water (using the mobile version). The scene’s lighting is for nighttime, and there’s a tinted directional light in my scene. It seems to be making the water brighter than the land surrounding. I’ve tried setting the Lighting to Unlit, then Basic, and then tried setting the Shallow Color to black.

I attached a screenshot showing the issue.

I’m having to use just the shallow color because the icebergs and glaciers were creating squares of “shallow” water around them. My solution was to add a plane slightly under the water plane.

Any way for me to make the water a darker shade while keeping my lighting setup?

Hi, is there a alternative way for the DepthBuffer Script on the camera ? I notice some major performance issues on some mobile devices. (especially Huawei)
So far this Shader is a bliss to work with.

The water uses the depth buffer to measure how far away objects underneath it are, so it’s required for the depth and intersection effects to render correctly. On some devices, without it, the water would turn invisible. So I’m afraid it’s a requirement.

The performance drawback in this case is that Unity does another pass on all objects, to get their depth. In Deferred rendering this is “free”, but Forward rendering is better suited for mobile.

I’m using a trimmed down version of the water shader, but some players are reporting that it’s drawing before the fog. On my machine it renders after the fog so this is only on certain platforms.

Tried changing the render queue of the water shader to be 3000+ and no effect. Do you have any suggestions?

I assume this is using a fog post processing effect? Transparent materials such as water do not contribute to the depth buffer, as such any depth-based effects like fog can’t tell how far away the surface is and appear to ignore it. In this case, the fog effect should execute before transparant materials are rendered, and it will fog transparant materials purely on what’s behind them. Still not ideal, but avoids them not being affected at all.

Just circling back on this in case you missed it. It might be something simple but I haven’t coded many shaders so I’m not sure where to look.

I have, apologies! Since the water is flat, it will be shaded uniformly. In your screenshot, some of the terrain surface is facing away from the light direction, so they are a darker shade.

Setting the Deep/Shallow colors to black, will in any case make the water black regardless of any direct or ambient light. So setting these colors to a darker tint will decrease the brightness of the water. If you’re using a fixed lighting setup, then using the Unlit lighting mode is viable, and you can tweak the colors to the point where you’re satisfied.

Hope that clarifies it!

That’s what I had tried, but this time I set Intersection to black as well and that did it (along with rotating the direction light a little bit). Icy water looks dark and imposing now. :slight_smile:

Interestingly, I still found that directional lights (not moving) still affect the water shader’s tint even when set to Unlit. That might be different from the fixed lighting you mentioned though.

Yes it’s deferred fog with the v2 postprocessing.
I can’t find any way to customize the fog draw order. It’s frustrating because it renders properly on most machines. I guess we just have to live with it?

I see, the built-in fog effect cannot be modified in this way. It’s possible this behaviour is deferent between DirectX and OpenGL/Metal. Do you happen to know if this occurs only on Windows or Mac?

Seeing as the deferred fog and “normal fog” use pretty much the same technique. It may be possible to enable the normal fog anway. Transparent materials (such as water) render in Forward rendering. So this may be a way to still apply fog to them. I’m not sure if the post processing stack forces fog to disable, if it’s using deferred fog. But worth a shot!

When running android build with forward rendering water is not rendering at all if depth buffer is not enabled. Tested with several devices. It renders fine in editor.
I can live without intersactions and depth and understand that these cannot work without depth buffer. But water should be rendering, just without these.

The depth buffer is also used to drive the water’s transparency, without this it is perceived as infinitely shallow and thus becomes completely transparent. Because of this, it is required. There are few slight manual modifications you can make to the mobile shader file, that will convert it to an opaque material:

Replace line 44 with:

Tags{ "RenderType" = "Opaque"  "Queue" = "Geometry+0" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True" }

57 with:

#pragma surface surf StandardCustomLighting keepalpha noshadow nolightmap  nodynlightmap nodirlightmap nometa noforwardadd vertex:vertexDataFunc

155 with:

float DepthTexture494 = 1;

You can remove the entire block of code above line 155 surrounded by “Stylized Water custom depth” comments at this point. After which you’ll have to turn the intersection and depth effect parameters all the way down, or they’ll span over the water entirely.

Thanks! That made it work on mobile without depth buffer.

1 Like

Is it possible to reflect the Skybox? This is especially viislbe in the Pond demo scene, where the mountains are not visible in the reflection.

Are there any workarounds?

When Planar Reflections are enabled, the skybox is always reflected (Even if “Reflect Layers” is set to ‘Nothing’).
6135980--669263--upload_2020-7-27_9-51-32.png

An alternative means is to set the Lighting mode to “Advanced” and create a Reflection Probe that encompasses the water. The Glossiness and Metalicness parameters have to be turned way up before the water starts taking on reflective properties in this case.
6135980--669260--upload_2020-7-27_9-50-36.png

@StaggartCreations Thank-you, that helps a lot!

I noticed that the Colors > Use Gradient checkbox does not work.

1 Like

Me too, this has meanwhile been fixed in an upcoming update. By the looks of it, this was broken for a long time, but nobody including myself noticed :stuck_out_tongue: