Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/skybox/Media/materials/programs/Ocean2GLSL.frag @ 2274

Last change on this file since 2274 was 390, checked in by landauf, 17 years ago

added materials

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