source: OGRE/trunk/ogrenew/Samples/Media/materials/programs/oceanGLSL.frag @ 692

Revision 692, 1.7 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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   // in OpenGL Ogre uses Devil 1.6.7 for loading dds textures.
23   // But Devil buggers up the green and blue channels of the 3D
24   // texture by setting them to zero so only the red channel has good data
25   // Dx9 loads the texture properly but if we want things to look the same
26   // between Dx9 and GL we only use the red channel for now until Devil dds issues are fixed
27   vec3 noisy = texture3D(Noise, uvw).xxx;
28   
29   // convert to signed noise
30   vec3 bump = 2.0 * noisy - 1.0;
31   bump.xz *= 0.15;
32   // Make sure the normal always points upwards
33   // note that Ogres y axis is vertical (RM Z axis is vertical)
34   bump.y = 0.8 * abs(bump.y) + 0.2;
35   // Offset the surface normal with the bump
36   bump = normalize(normal + bump);
37
38   // Find the reflection vector
39   vec3 normView = normalize(vVec);
40   vec3 reflVec = reflect(normView, bump);
41   // Ogre has z flipped for cubemaps
42   reflVec.z = -reflVec.z;
43   vec4 refl = textureCube(skyBox, reflVec);
44
45   // set up for fresnel calc
46   float lrp = 1.0 - dot(-normView, bump);
47   
48   // Interpolate between the water color and reflection for fresnel effect
49   gl_FragColor = mix(waterColor, refl, clamp(fadeBias + pow(lrp, fadeExp), 0.0, 1.0) );
50}
Note: See TracBrowser for help on using the repository browser.