Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/trunk/shaders/mapped_water.frag @ 3864

Last change on this file since 3864 was 3824, checked in by patrick, 19 years ago

sharers moved again

File size: 1.7 KB
Line 
1varying vec4 refrCoords;
2varying vec4 normCoords;
3varying vec4 viewCoords;
4varying vec4 viewTangetSpace;
5varying vec4 lightTangetSpace;
6
7uniform sampler2D reflection;
8uniform sampler2D refraction;
9uniform sampler2D normalMap;
10uniform sampler2D dudvMap;
11uniform sampler2D depthMap;
12uniform vec4 waterColor;
13
14void main()
15{
16        const float kShine = 128.0;
17        const float kDistortion = 0.015;
18        const float kRefraction = 0.009;
19
20        vec4 distOffset = texture2D(dudvMap, normCoords.xy) * kDistortion;
21        vec4 dudvColor = texture2D(dudvMap, vec2(refrCoords + distOffset));
22        dudvColor = normalize(dudvColor * 2.0 - 1.0) * kRefraction;
23
24        vec4 normalVector = texture2D(normalMap, vec2(refrCoords + distOffset));
25        normalVector = normalVector * 2.0 - 1.0;
26        normalVector.a = 0.0;
27
28        vec4 lightReflection = normalize( reflect(-lightTangetSpace, normalVector) );
29
30        vec4 invertedFresnel = vec4( dot(normalVector, lightReflection ) );
31        vec4 fresnelTerm = 1.0 - invertedFresnel;
32
33        vec4 projCoord = viewCoords / viewCoords.q;
34        projCoord = (projCoord + 1.0) * 0.5;
35        projCoord += dudvColor;
36        projCoord = clamp(projCoord, 0.001, 0.999);
37       
38        vec4 reflectionColor  = texture2D(reflection, projCoord.xy);
39        vec4 refractionColor  = texture2D(refraction, projCoord.xy);
40        vec4 depthValue = texture2D(depthMap, projCoord.xy);
41               
42        vec4 invDepth = 1.0 - depthValue;
43        refractionColor *= invertedFresnel * invDepth;
44        refractionColor +=  waterColor * depthValue * invertedFresnel;
45
46        reflectionColor *= fresnelTerm;
47
48        vec4 localView = normalize(viewTangetSpace);           
49        float intensity = max(0.0, dot(lightReflection, localView) );
50        vec4 specular = vec4(pow(intensity, kShine));
51
52        gl_FragColor = refractionColor + reflectionColor + specular;
53}
Note: See TracBrowser for help on using the repository browser.