Is there any possibility of having the strength of the reflection and refraction on the water shader be based on the camera’s angle to the surface? It would make the reflective/refractive water look really good, and you could simplify it by dropping the refraction value for the reflect only water, and of course drop them alltogether for the simple water. You could use the following equations to do it:
cos(angle*pi/180)=reflection value
1-cos(angle*pi/180)=refraction value
Notes:
Angle is always a float value between 0-90 and is the angle between the surface and the camera.
Reflection and refraction value are always a float value between 0-1, and when added together, must always equal 1 (which they will with the above equations). These values would be used to determine the ‘strength’ of the reflection and refraction.
So, for example:
Angle=26.5 degrees
cos(26.5pi/180)=0.8949 or ~0.89
1-cos(26.5pi/180)=0.1050 or ~0.11
To check, 0.89+0.11=1
This would make it so when perfectly parallel to the surface, it would be 100% reflective and 0% refractive, and when perfectly perpendicular to the surface, 0% reflective and 100% refractive. If you wanted, you could calculate it on a per surface basis to make it less expensive but still good, and per pixel to make it more realistic and true to life (this would look especially good if you had a normal map for the water…damn near photoreal)…this could further give you a few more choices in the appearance of water in Unity, and would look damn cool…
*Sidebar- I am aware this would make water more expensive, but to that I say this: that is why I would suggest making this an option that could be enabled/disabled in the editor and also in the options dialog for projects that have been built (eg. an ‘enable high quality reflection/refraction’ checkbox and an ‘enable per pixel reflection/refraction’ checkbox that is greyed out if the former is not enabled. As for the expense, well, video hardware is getting to be very powerful and I don’t see why we couldn’t use some of that power
I think the water already does this or something like it, no ? Have you actually tried a test scene with obvious colors above and below the water to see how it works ?
At least as far as I have seen, it does not. If it did, the reflection would increase into the distance along the z axis away from the player view (and decrease towards the player view), and the refraction would increase along the z axis toward the player view (and decrease away from the player view) if you were looking horizontally across the plane. Imagine instead of a water surface, you have it shift between two different colors (red and blue) based on the angle you are looking at the surface. With these calculations, looking across the surface, the surface would appear as a red to blue gradient, and wether it was more red or blue would change based on your angle to each pixel on the surface; if you were perfectly parallel it would be 100% red, and if you were perfectly perpendicular, it would be 100% blue. Anything in between would produce a varying gradient of the two colors based on your angle. Apply this theory to the reflection and refraction values of the water, and you will get what I am going for here.
As an adjunct, the previous calculations assume radians; if the measurements were to be in degrees, the calculations are simpler:
1-cos(angle)=refractive index
cos(angle)=reflective index
Well, this looks exactly like what I was talking about. Thanks for the clarification, I guess I thought the effect should be more obvious, but it would appear I am wrong.
Thank you, I guess I should have read the documentation a bit more.
On a similar note, is there a way to fade the edge transparency of the water to smoothly blend its edges where it collides with other polys (such as the ground)? IIRC, HL2 does this.
The built-in water does not do this, but of course it’s possible somehow. Either you could calculate additional “fadeout” texture that is mapped onto water from the top, where it would fade out at the edges. Or if the water mesh is finely tesselated, calculate fadeout factor in vertex colors, and so on.
…or do scrolling shorelines like in the Island demo example project (the one that ships with Unity).
…or do what I do:
I have a few different flat objects onto which I map semi-transparent textures to simulate shorelines. I place these just above the water, and it works pretty well.
However, I’d kill…er…no, but quite likely pay, for a more advanced water system that would take coasts/islands into account. Also, I would love a component that modifies the actual water mesh (=“real” waves) with some form of LOD control incase there’s a huge mass of water.
I imagine none of the above is very hard to do, but I seriously lack the time to do it…
Can you provide an example of the technique you mentioned? I would imagine this works well for irregular coast lines, and it would be flexible in that coasts would be smoothly faded, while objects in the water would have an (appropriately) hard edge.
Well, the same, except that for now mine is a lazy approach. It doesn’t wave and does nothing script-wise to follow the actual shorelines. It’s basically just a fading texture on a large flat object. I use it to achieve the fading near the shore seen around tropical islands. So, basically, I’m more interested in changing the color of the water near the shore than achieving the waves.
Again, it’s pretty temporary but works. When/if I get the time I’ll try to combine the Island demo techinque with what I want to achieve colorwise and hopefully make it fully automatic. Manually placing the wave polys around the terrain (as done in the terrain demo) works and looks nice, but is pretty ineffective for projects with more terrain assets. It would be nice to be able to just plop in a wave object and link the terrain and have it generate the waves and color fading automagically.
However, it would be cool if someone with more time on their hands did it for me/us.