Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/oceanGLSL.frag @ 12083

Last change on this file since 12083 was 12083, checked in by wiesep, 6 years ago

Reorganised shader programs

File size: 1.4 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
10#version 150
11
12uniform float fadeBias;
13uniform float fadeExp;
14uniform vec4 waterColor;
15uniform sampler3D Noise;
16uniform samplerCube skyBox;
17
18in vec3 uvw;
19in vec4 oNormal;
20in vec3 vVec;
21out vec4 fragColour;
22
23void main(void)
24{
25   vec3 noisy = texture(Noise, uvw).xyz;
26   
27   // convert to signed noise
28   vec3 bump = 2.0 * noisy - 1.0;
29   bump.xz *= 0.15;
30   // Make sure the normal always points upwards
31   // note that Ogres y axis is vertical (RM Z axis is vertical)
32   bump.y = 0.8 * abs(bump.y) + 0.2;
33   // Offset the surface normal with the bump
34   bump = normalize(oNormal.xyz + bump);
35
36   // Find the reflection vector
37   vec3 normView = normalize(vVec);
38   vec3 reflVec = reflect(normView, bump);
39   // Ogre has z flipped for cubemaps
40   reflVec.z = -reflVec.z;
41   vec4 refl = texture(skyBox, reflVec);
42
43   // set up for fresnel calc
44   float lrp = 1.0 - dot(-normView, bump);
45   
46   // Interpolate between the water color and reflection for fresnel effect
47   fragColour = mix(waterColor, refl, clamp(fadeBias + pow(lrp, fadeExp), 0.0, 1.0) );
48}
Note: See TracBrowser for help on using the repository browser.