Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/skybox/Media/materials/programs/oceanGLSL.frag @ 883

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

added materials

File size: 1.3 KB
Line 
1// oceanGLSL.frag
2// fragment program for Ocean water simulation
3// 05 Aug 2005
4// adapted for Ogre by nfz
5// converted from HLSL to GLSL
6// original shader source from Render Monkey 1.6 Reflections Refractions.rfx
7
8// 06 Aug 2005: moved uvw calculation from fragment program into vertex program
9
10uniform float fadeBias;
11uniform float fadeExp;
12uniform vec4 waterColor;
13uniform sampler3D Noise;
14uniform samplerCube skyBox;
15
16varying vec3 uvw;
17varying vec3 normal;
18varying vec3 vVec;
19
20void main(void)
21{
22   vec3 noisy = texture3D(Noise, uvw).xyz;
23   
24   // convert to signed noise
25   vec3 bump = 2.0 * noisy - 1.0;
26   bump.xz *= 0.15;
27   // Make sure the normal always points upwards
28   // note that Ogres y axis is vertical (RM Z axis is vertical)
29   bump.y = 0.8 * abs(bump.y) + 0.2;
30   // Offset the surface normal with the bump
31   bump = normalize(normal + bump);
32
33   // Find the reflection vector
34   vec3 normView = normalize(vVec);
35   vec3 reflVec = reflect(normView, bump);
36   // Ogre has z flipped for cubemaps
37   reflVec.z = -reflVec.z;
38   vec4 refl = textureCube(skyBox, reflVec);
39
40   // set up for fresnel calc
41   float lrp = 1.0 - dot(-normView, bump);
42   
43   // Interpolate between the water color and reflection for fresnel effect
44   gl_FragColor = mix(waterColor, refl, clamp(fadeBias + pow(lrp, fadeExp), 0.0, 1.0) );
45}
Note: See TracBrowser for help on using the repository browser.