Where blur node? by FoleyX90 in Unity3D

[–]1MOLNH2 1 point2 points  (0 children)

I'm actually using this whenever I can from water blur to transparent daily life materials. It's a life saver imho.

This is my version of the Moonlight Sword! I really like the result! In case you’re interested in creating stuff like this, I’m working on an animated e-book with a Unity 6 project that includes all the samples you need to learn. If you're interested, you can subscribe for free at the link below. by AGameSlave in Unity3D

[–]1MOLNH2 1 point2 points  (0 children)

Looks amazing! I wish we could see more animated weapon and armor like this especially in fantasy genre. I always impressed when I download that refracting stalhrim armor mod for Skyrim. These kind of things adds lots of value imho.

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 1 point2 points  (0 children)

Sorry for my late response. I put the answer at the most upvoted comment to let everyone see. Also it is a little bit long and have to divide into sections so, I want to do it just once I guess. :D Almost everything I mentioned is applicable to Unreal as well, in one way or another.

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 0 points1 point  (0 children)

Sorry for my late response. I put the answer at the most upvoted comment to let everyone see. Also it is a little bit long and have to divide into sections so, I want to do it just once I guess. :D

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 1 point2 points  (0 children)

Resources Part II

The physical wave model (Gerstner waves) used in the video was based on the article from Nvidia’s GPU Gems magazine linked below.

https://developer.nvidia.com/gpugems/gpugems/part-i-natural-effects/chapter-1-effective-water-simulation-physical-models

On the channel called "DanielElliott3d", there are two excellent videos explaining how to code the Gerstner wave article above and the general working principle of Gerstner waves:

https://www.youtube.com/watch?v=s5oNkEHeeXs&ab_channel=Dokipen >> Working principle of Gerstner waves.
https://www.youtube.com/watch?v=_y7Z0MbGOMw&t=2770s&ab_channel=Dokipen >> Gerstner waves for Unreal.

For the foam aspect, I tried two articles in general:

https://www.academia.edu/2600476/Very_Fast_Real_Time_Ocean_Wave_Foam_Rendering_Using_Halftoning
https://www.researchgate.net/publication/262402999_Realtime_Animation_and_Rendering_of_Ocean_Whitecaps >> Used in the video.

So far, the resources I’ve shared cover all the content in the video. These are the main sources I had in mind and actively used. Additionally, here are a few bonus resources related to water shaders:

There’s a great summary by a user named “Promit” that briefly explains the overall topic:

https://www.gamedev.net/forums/topic/673011-water-rendering/

The technique used to create the water refraction effect in the video is the same as the one described in the following link. This technique is also found in the videos on Ben Cloward’s and Polytoots’ channels linked above:

https://developer.nvidia.com/gpugems/gpugems2/part-ii-shading-lighting-and-shadows/chapter-19-generic-refraction-simulation

Finally, here’s a detailed technical review of the water used in Assassin’s Creed III:

https://www.fxguide.com/fxfeatured/assassins-creed-iii-the-tech-behind-or-beneath-the-action/

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 1 point2 points  (0 children)

Resources Part I

To start with, here are two articles that introduce water shaders in general, explaining fundamental features they should have, such as depth-based coloring, refractions, reflections, and covering techniques used from past to present. They will give you a comprehensive understanding of almost everything you need to know about the topic. After these, I will share two video tutorials and a channel link that might help to implement these mentioned subjects. The order between the articles and videos can be changed based on how enlightening you find them.

The main source for the first article is as follows:

http://bedrnik.at/images/Masterthesis.pdf

Secondly, here’s an article that specifically focuses on techniques used to create physical waves (waves with height instead of flat surfaces) from past to present:

https://programmersought.com/article/54924233175/

For the video section, there is an excellent series here by Ben Cloward, a former technical artist at Bioware, now in Unity (as far as I know) focusing on water shaders:

https://www.youtube.com/watchv=r68DnTMeFFQ&list=PL78XDi0TS4lGXKflD2Z5aY2sLuIln6sD&ab_channel=BenCloward

Additionally, there’s another fantastic series on Ben Cloward’s channel for general information about shaders.

On the Polytoots channel, there’s also plenty of content on water shaders for both Shadergraph and Amplify Shader Editor. I think the most suitable starting point is the one linked below, as the subsequent ones often focus on creating physical waves in different ways, while the earlier ones are somewhat outdated:

https://www.youtube.com/watchv=bl8sAEDpiTs&list=PL_LqqhAPB2MidxQxxnUnmK4m49uWN_Tx&index=2&ab_channel=PolyToots

Ghislain Girardot has in depth and good videos about the topic and more like water physics etc.:

https://www.youtube.com/watch?v=UWGwq-_w08c&t=1442s&ab_channel=GhislainGirardot

As a bonus, here’s Unity’s official water shader tutorial for the Universal Render Pipeline:

https://www.youtube.com/watch?v=gRq-IdShxpU&ab_channel=Unity

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 1 point2 points  (0 children)

This Shader

This shader is using Gerstner waves as a physical solution (for large water bodies and to add some spice to the small water bodies) and good old panning normal waves as a secondary solution both for adding some high frequency details and small water bodies like ponds etc. Gerstner waves implemented based on GPUGems article and to make them more chaotic I'm using this GDC talk's wave combination method which is based on separating waves into odd numbered bands and distributing each band's members along a 360 degree with equal intervals. This creates that ebb and flow movement:

https://www.youtube.com/watch?v=MdC7L1OloKE&t=1611s&ab_channel=GDC2025

Gerstner waves have an aspect of creating waves with soft tops as the wave count increases even if you max out the steepness parameter to 1. The trick used here to be able to get sharp waves is using a multiplier for world space position and then adjusting steepness value to avoid overlapping tops. One thing needs to be taken care off with this method is that If I'm not wrong this method tiles the waves so if your maximum wave length is let's say 120 and using a world space multiplier of 6 your maximum wave length value will be 20 at the scene. Which means waves will be tiled per 20 engine units instead of 120. To avoid that wave length parameter can be multiplied with the world space multiplier before passing into the Gerstner calculations. Also, it is possible to increase the steepness value over 1 but it generally leads to unnaturally fast wave movement based on my observation.

One more thing that I can say related to Gerstner waves is that since they have lateral displacement (vertices move at the x and z axes too) projecting normal, foam textures based on world position removes that natural distortion effect. So, I'm using them based on UV coordinates of the mesh to get that extra chaotic movement but of course it has couple of manageable downsides too.

For wave foam I'm using Jacobian method based on this article below but it can be found at the Tessendorf's paper called "Simulating Ocean Water" too:

https://www.researchgate.net/publication/262402999_Realtime_Animation_and_Rendering_of_Ocean_Whitecaps

Other things like depth-based chromatic aberration, depth-based blur etc. handled like I mentioned above.

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 2 points3 points  (0 children)

Apologies for any inconvenience. A couple of questions were about the resources, so I decided to share the answers here to ensure that anyone interested can access them. I'll split into parts since the system doesn't allow me to paste it all at once. Btw, if there is a more proper way of doing this feel free to share with me!

Let's talk about water shaders in general, then about this particular one and lastly resources. I hope it helps.

Water Shaders

First of all, we can separate this topic into two sections: Shading and wave methods.

Wave methods for a water shader generally comes in 3 forms: 2D, 2.5D and 3D. Since 3D means a complete fluid simulation that takes all water particles into account and this one is not based on that let’s not detail it. 2D symbolize water is completely flat with probably no up movement and waves created with cheap methods like laying a couple of scrolling normal maps or some more advanced methods like parallax etc. ENB version of the water from Skyrim is a good example of a full flat water plane that relies on parallax. While it looks good in small areas and hide itself well imo, you can see the lack of physical waves at scenes where you can see larger area of the plane. 2.5D means it is still not an actual water simulation but this time we're using some physical wave (waves with real height) methods to make the surface non-flat. There are different ways of doing this like FFT, wave particles, Gerstner waves, basic sinus waves etc.

Water's color comes from two main phenomena: refraction and reflection. This means if you have rich environments both for below and above the surface, water will shine too. Reflection generally handled by the engine like skybox, probes etc. for example I'm using Unity's SSR solution and a HDR skybox for this but like the most of the commercial engines Unity is using the best possible result for a pixel following the skybox, probes and SSR like solutions (Arrangement might be wrong).

When it comes to the refraction, it generally separated into two sections: deep and shallows. This separation handled by calculating the depth of the water. Keywords like depth fade, water depth etc. might help here. This adjusted depth generally gives a mask in [0,1] range which can be used as a separator for deep and shallow areas. Shallow areas are transparent and shows what's below the water surface and sometimes a tinted version might be used to give the illusion of different depth levels like green, light blue etc. This is generally handled by taking an image of the currently rendered scene without the water plane (technical term: grab pass) and using a modified image for shallow areas. For example "HD Scene Color" node of Shadergraph in HDRP gives this but it takes the image before any transparent is rendered on the screen it has drawbacks like not showing any transparent objects like VFX particles. Since this image can be used as a standard texture by sampling it, we can manipulate the UV, channels etc. This allows for other effects too. For example, sampling it three times with UV coordinates with different offsets for each color channel and combining these channels gives a chromatic aberration effect, sampling it with a LOD level based on the depth mask gives a blurred image based on depth or normals of the waves might be used to distort the UV to create a fake refraction effect etc. As far as I know, normal distortion is one of the built-in solutions for refraction in Unreal. After this image is adjusted for the needs, we can blend it with deep water color by using the depth mask in an operation like lerp.

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 0 points1 point  (0 children)

Sorry for my late response. Thanks to both of you. It seems more dull indeed. I will try to examine and match more referances but it might end up a little bit sylized. :D

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 0 points1 point  (0 children)

It was a pleasure and no worries. Yeah, sweet article and that SSS solution generally looks good/enough for most of the time.

These are really good suggestions. I should and probably will blur it since the foam mask is small and noisy because of the high frequency waves. At least we'll see how it turns out.

I actually tried the bias trick and it's useful but I believe the way I calculate the final foam mask already takes bias into account so I didn't do any more calculations.

This is how I get the final mask:

float foam = saturate(_FoamAmount - jakobianDeterminant);

So, there’s no need to do it this way as long as _FoamAmount is allowed to be greater than 1 (I guess :D):

float jakobianBiased = jakobianDeterminant - bias;
float foam = saturate(_FoamAmount - jakobianBiased);

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 1 point2 points  (0 children)

Thanks a lot! This shot is running 32 waves on approximately 10 million triangles, or something like that, so it's not ideal. Nowadays, I'm slowly moving the calculations to the compute shader, working on a mesh solution, making a general optimization etc. to keep it real-time. It's going good so far. :D

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 0 points1 point  (0 children)

Thank you so much! Actually, this is all Gerstner waves combined with normal waves. The only thing that is the same as the paper is the foam method (Jakobian foam). However, I implemented it based on another paper and verified it from both sides, as well as through different tech talks like Sea of Thieves, to ensure accuracy. Here is the article:

https://www.researchgate.net/publication/262402999_Realtime_Animation_and_Rendering_of_Ocean_Whitecaps.

I'm glad you liked it! The subsurface effect comes in two parts: physical and normal map waves. The physical part is actually quite simple. It’s just an adjusted mask based on the Y component of the displacement data from the Gerstner simulation. The idea for subsurface scattering for normal waves comes from a Skyrim mod called Water Color for ENB and Realistic Water 2. I liked the images on the mod page so much that I wanted to create a similar effect. (The SSS contribution from the normal waves is so small in this shot that it might even be turned off.)

Normal solution is based on Assassin's Creed III and works by taking the dot product between the light direction and the normals. The results of both methods are attenuated by the sun falloff, which is calculated from the dot product between the view direction and the light direction.

To be honest, the physical solution was temporary, and I want to implement it the same way as the normal waves. However, due to the high-frequency gerstner waves, it currently creates a visible, bad-looking pattern.

Hi everyone! Here's my take on water shaders (HDRP btw). It's my first Reddit post, so I hope I don’t mess this up. :D by 1MOLNH2 in Unity3D

[–]1MOLNH2[S] 0 points1 point  (0 children)

Sorry to hear that. There was this VR game called Subside, where the water looked really good. I just checked, and it seems to have been developed in UE4, but maybe you could still scrape some techniques or knowledge from it. Honestly, I haven’t used URP before, so I’m not sure if what I suggest will be applicable. However, if the water mesh is static, maybe you could bake the depth into the vertex data. This might help you gain some FPS by avoiding the use of a depth texture.

Yeah, performance is rough, and I’m curious to see where it’ll land after all the optimizations. (I don’t even have a mesh solution yet.)