1 | /*********************************************************************NVMH3**** |
---|
2 | Copyright NVIDIA Corporation 2003 |
---|
3 | TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED |
---|
4 | *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS |
---|
5 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY |
---|
6 | AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS |
---|
7 | BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES |
---|
8 | WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, |
---|
9 | BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) |
---|
10 | ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS |
---|
11 | BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
---|
12 | |
---|
13 | |
---|
14 | Comments: |
---|
15 | Simple ocean shader with animated bump map and geometric waves |
---|
16 | Based partly on "Effective Water Simulation From Physical Models", GPU Gems |
---|
17 | |
---|
18 | 11 Aug 05: converted from HLSL to GLSL by Jeff Doyle (nfz) to work in Ogre |
---|
19 | |
---|
20 | ******************************************************************************/ |
---|
21 | |
---|
22 | |
---|
23 | uniform sampler2D NormalMap; |
---|
24 | uniform samplerCube EnvironmentMap; |
---|
25 | uniform vec4 deepColor; |
---|
26 | uniform vec4 shallowColor; |
---|
27 | uniform vec4 reflectionColor; |
---|
28 | uniform float reflectionAmount; |
---|
29 | uniform float waterAmount; |
---|
30 | uniform float fresnelPower; |
---|
31 | uniform float fresnelBias; |
---|
32 | uniform float hdrMultiplier; |
---|
33 | |
---|
34 | varying mat3 rotMatrix; // first row of the 3x3 transform from tangent to cube space |
---|
35 | varying vec2 bumpCoord0; |
---|
36 | varying vec2 bumpCoord1; |
---|
37 | varying vec2 bumpCoord2; |
---|
38 | varying vec3 eyeVector; |
---|
39 | |
---|
40 | |
---|
41 | void main(void) |
---|
42 | { |
---|
43 | // sum normal maps |
---|
44 | // sample from 3 different points so no texture repetition is noticeable |
---|
45 | vec4 t0 = texture2D(NormalMap, bumpCoord0) * 2.0 - 1.0; |
---|
46 | vec4 t1 = texture2D(NormalMap, bumpCoord1) * 2.0 - 1.0; |
---|
47 | vec4 t2 = texture2D(NormalMap, bumpCoord2) * 2.0 - 1.0; |
---|
48 | vec3 N = t0.xyz + t1.xyz + t2.xyz; |
---|
49 | |
---|
50 | N = normalize(rotMatrix * N); |
---|
51 | |
---|
52 | // reflection |
---|
53 | vec3 E = normalize(eyeVector); |
---|
54 | vec3 R = reflect(E, N); |
---|
55 | // Ogre conversion for cube map lookup |
---|
56 | R.z = -R.z; |
---|
57 | |
---|
58 | vec4 reflection = textureCube(EnvironmentMap, R); |
---|
59 | // cheap hdr effect |
---|
60 | reflection.rgb *= (reflection.r + reflection.g + reflection.b) * hdrMultiplier; |
---|
61 | |
---|
62 | // fresnel |
---|
63 | float facing = 1.0 - dot(-E, N); |
---|
64 | float fresnel = clamp(fresnelBias + pow(facing, fresnelPower), 0.0, 1.0); |
---|
65 | |
---|
66 | vec4 waterColor = mix(shallowColor, deepColor, facing) * waterAmount; |
---|
67 | |
---|
68 | reflection = mix(waterColor, reflection * reflectionColor, fresnel) * reflectionAmount; |
---|
69 | gl_FragColor = waterColor + reflection; |
---|
70 | } |
---|