- Home /
Can you make the Simple Water Shader gradient support transparency?
Hello there.
I would just like to know if anyone knows of a way to edit the Simple Water Shader so that it, via the gradient, allows you to change not only color, but transparency as well.
I've seen it here and there edits of it that makes the entire water mesh semi-transparent, but this is not what I want and doesn't seem to work properly anyway, as it only shows shadows underneath and not the actual mesh colors.
Currently, the only thing that happens if you apply transparency to the gradient image, is that it makes the color more white, which would work if I only had a white color underneath, which I do not =)
Basically I'd like it to be more transparent when you look straight down into the water and another color when looking across it.
So yeah, does anyone know of any edit to make this possible?
Answer by Ferb · Sep 30, 2014 at 04:48 PM
First, may I say that being more transparent depending on the view angle sounds like a great idea!
If you look at the source in FX-Water Simple.shader, it already has a value called 'Fresnel' worked out. I'm not sure where the name Fresnel comes from, but apparently that's working out exactly what you want to know - whether you're looking straight at the water or looking across it.
Since it's worked out from a dot product, I'd say the Fresnel is 1 when looking straight at the water, so you probably want the alpha to be something like 1-(0.5*Fresnel). (It's possible it'll be -1 when looking at the water or something though - a bit of trial and error may be necessary.)
Now I've never programmed surface shaders (only vertex/fragment shaders), so I can't say for sure whether it works the same way as the stuff I've done before, but I suspect that you'll set the alpha by setting col.a, and that the alpha value won't have any effect until you add a line like 'Blend SrcAlpha OneMinusSrcAlpha' just underneath the '#CGPROGRAM' line, and change the tags to '"Queue"="Transparent" "RenderType"="Transparent"'.
Your answer
![](https://koobas.hobune.stream/wayback/20220613121719im_/https://answers.unity.com/themes/thub/images/avi.jpg)