I’m trying to get some foam at the shoreline on my water, but i cant get it to work.
I’ve tried water4 advanced, but i dont like the look of it.
Now I’m using the WaterProDaytime.
I’ve never made a shader, so I have no idea where to start.
Does anyone have tips or something that could help me?
All I’m looking for is a white foam edge of the water where the water collides with the terrain.
I’ve modified the WaterProDaytime shader to include the foam you wanted along the shorelines. Check the attached image and the new shader. A sample project using a terrain and the new water shader is also linked. I’ve added some new parameters to the WaterProDaytime material: a foam texture(found in standard assets), a gradient texture and a parameter to control the foam strength(or length).
The most important changes are in the vertex shader and pixel shader. You can look after the HAS_FOAM define. It also uses _CameraDepthTexture to get the depth of the geometry behind the water plane.
The project is made with Unity 5.1.2.
Yes, use a bigger texture if you want more detail.
Right now there’s not too much variation and the foam looks like a continuous strip. But if you want more variation you can modify the shader and use a 2D noise texture and modulate it with the final foam intensity. You should use something similar to the attached image that will cover the entire map. If you need help let me know.
@INedelcu Hi thanks much for shader,does it optimized for mobile devices?? Also could you guide me on how to make river water for river racing game like Shine runner and Ripitude GP ?
Hello INedelcu & Everyone,
I’m new to Unity although I’ve fair amount of experience with C# and WPF. Right now I’m working on a project where foam and water interaction with game objects happen to be the trickiest part. I’ve made my water and waves tweaking codes from Scrawk blog. But left absolutely clueless about the foam and wave interaction with the game object. I’m uploading a few images where both what I’ve achieved and what is my target is portrayed (images with Reference at the end are my target). Any help, clue, comment on how to achieve it in Unity or if at all feasible in Unity, would be more than helpful for me. Since these posts are related to foam and water interaction, I thought of posting it here. If I made a mistake, my apology in advance.
We don’t have that level of detail in Unity. That’s clearly a water rendering that uses fluid simulation with all complex mathematical stuff or maybe it’s even real :). You could use my project above to generate some foam near geometries but other than this there’s no water interaction, just a flat plane.
I’m really grateful to hear from you. I almost understood that such fluid simulation with complicated foams is near impossible in Unity, still I was looking for a confirmation from someone much experienced. Many thanks once again. I hope if I bother for some suggestions sometimes you won’t mind right?
@INedelcu It works great using unity 5.2.1f1, or 5.2 in general, but not working in 5.3, the foam appears everywhere… anybody knows why? :S checked the code but can’t find the problem…
Thank you!
PS: What sould I do to to make it mobile friendly? (Is working though, just trying to make it better), should I make it working with rendering path of forward? how?
Thanks again!
I tried your shader, and it looks amazing! However, I need to change my camera’s clipping plane from the default 0.3-1000 to something like 10-10000. Unfortunately, this makes the foam disappear entirely as it seems dependant on a low clipping plane. Is there an easy way to fix this, or do I need to take another approach?
Thanks for providing this, I think your shader should be included as the default water shader.
Yes, this shader might not work for the mobile platform, because it uses the CameraDepthTexture. Some platform like mobile have the depth texture mode off by default to reduce the memory footprint.
So to use this shader on mobile, you need to specifically mention Unity to enable the depth texture mode for your main Camera.
I’m really struggling with water. I’ve downloaded your project and it looks great. But when I create the same component in another project it just doesn’t seem to do the trick. I’m creating a shoreline and I’ve tried with Basic Water, Water4 and WaterPro but none look anywhere close to realistic for a shoreline.
Maybe it’s totally unrelated but my problem is that even though I’m using your same values, my water just vaguely moves and hence it doesn’t create any foam. It should still create foam when it collides with terrain, but it’s not meant to work that way. I’m sort of new to Unity so I do not know what else am I missing to have a wave of foam like in your example.
Nice Shader, I test it in Unity 5.3.3 it works well, but in Unity 5.5.0, there is no foam effect, no error information with the shader, I don’t know why? How to fix it?
@INedelcu I notice that when update to 5.5, these values changed
is this the reason this water shader is not working on 5.5? Could you please modify a new version to 5.5?
Thanks
Shaders: Z-buffer float inverted
The Z-buffer (depth buffer) direction has been inverted and this means the Z-buffer will now contain 1.0 at the near plane, 0.0 at the far plane. This, combined with the floating point depth buffer significantly increases the depth buffer precision resulting in less Z-fighting and better shadows, especially when using small near planes and large far planes.
Graphics API changes:
Clip space range is [near, 0] instead of [0, far]
_CameraDepthTexture texture range is [1,0] instead of [0,1]
Z-bias is negated before being applied
24 bit depth buffers are switched to 32 bit float format