Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4065 was 3939, checked in by bensch, 19 years ago

data/trunk: merged the data from the atmos branche back

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