I’m currently in the process of developing a water shader that detects objects and creates a sort of “foam” edging around said objects that the water intersects with. What would the code look like to implement this?
There is 4 ways to do it:
- The easy way with quad animated at the surface of water at the point of impacts
- the sloppy way, using a shader that compare depth of water with depth of scene, everything in a range between surface and a given distance is a proportional gradient to that distance, then use that as a mask for a foam texture.
- The hard way, you project the objects shape as a mesh (like doom3 shadow) and extrude it, then use that as a mask for a foam texture.
- The old way, render a quad at the point of impacts, render the object as a silouhette from the point of view of the impact, scale a bit, use that as a mask to a foam texture.
Have fun
I was thinking more of integrating the method as a shader feature for the water shader, I guess I’ll take the sloppy way.
Is there any way I could get some code on that, then? I’m afraid I’m still a bit new with shaders.
You can do it with shader forge and probably amplify shader stuff.
Also, problem with that method is you will only get foam where the water actually overlaps the object, so while this can work alright for a shoreline, a floating object will have the foam be cut-off at the sides of the object since the depth value there will be whatever is far in the background.