I saw an older post about this that didn't have a solution, but I thought I'd ask now and see if anyone's figured out a way to put a good looking water shader behind glass, with caustics and some light rays. I'm fairly new to Unity and shaders but this seems like something that should be solvable. Any ideas?
If you give the glass material a frag shader that measures the depth of the back of the aquarium glass or the aquarium floor or ceiling somehow (use stencil perhaps), then you know the depth difference between the front of the aquarium and the back/floor. This lets you change the colour by an amount proportional to that depth, which you could either fake using a texture lookup ramp, a function, or by doing some more correct solution like rayleigh scattering to remove reds and greens proportional to distance. If you want the water to refract properly, you'll need to do something like set up render textures for each pane and use a separate camera to get the right projection. Not a trivial problem to solve. A ray tracing solution might be better but that's a whole other ball game. There are some good shader examples out there showing ray tracing in isolated water volumes, but I'm not sue how they'll deal with regular meshes/shaders within that volume.
If you want light rays then you could ray march through the volume over the given distance, sampling and accumulating light at each position against a caustics cookie on a directional light with a falloff based on distance to the water surface. This could also be used for fogging as you look through greater depths of water. Caustics can be achieved with an animated texture as a cookie on the directional light. An easier approach to the light rays of course would be to use a particle system
yeah i was thinking about particles for rays, which seemed obvious but then again i still can't wrap my head around why a shader won't work for a volume i'm not inside of. your suggestions are more advanced than my skill level (at the moment) so i'll need to find someone to help out. fyi the aquarium is 500m x 2.5 km x 5 km, and is filled with alien sea creatures. it's for a social vr environment and i can't use any custom scripts.
There are some excellent examples on raymarching to achieve things similar to what you are after here. https://www.shadertoy.com/results?query=water&sort=popular&from=12&num=12 Crazy cool stuff.
shadertoy is awesome, but from what little i know it's seemed like something that takes too much processing for vr. not sure if the raymarching is also resource intensive. those examples look great though.
always outside. so the components of realistic water are: - a dark blue colour that has a gradient. i have this already with a skybox, even just that alone with creatures swimming around in it doesn't look half bad. - light rays. this can probably be done via particle effects. - random particles, bubbles. more particle effects. - caustics. so these can't be done unless we're in the volume? we won't see the ground, it's just open water and the creatures.
assetstore has underwater and volumetric effect packages, have you tested some? from those caustics some seem to mention custom shader and scrolling uv, animated texture, or could be projector.. then can add fog, or depth fog. light rays could be volumetric light effects (see asset store again, one mentioned vr support too)
the problem is that every volumetric light effect i've seen is using custom scripts, which aren't an option for building worlds in vrchat. at least not yet, although soon they're implementing Playmaker but i don't know visual scripting yet so not sure what can be done exactly. i haven't bought and tried different quality water unity packages because even when i asked the developer of one of these, he said he didn't know of a way to replicate an aquarium. i'm still not entirely sure what the difficulty is.
I don't think you need volumetric fog for this. Regular fog will do. Assuming the back of the aquarium is not transparent, and can only be viewed from one side you can: - define the front aquarium plane as a constant (can do some of the work in the vertex shader) - work out the distance from the glass to the fragment along the view direction of that fragment to the camera, and derive how much fog and rayleigh scattering you want to add from that - do light rays as a particle system No custom scripts should be necessary for this.
Actually I'd been playing around with regular fog, with a blue sphere surrounding the scene, it's looking quite good. Tried some light ray particles so far that don't really work well so need to keep looking on that front. I thought I needed caustics, but looking at photos and video from deeper underwater, I'm not seeing any.
You mean something like this? https://forum.unity3d.com/threads/aubergines-water-shaders.160965/page-3#post-2124716