aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/app_settings/shaders/class1/environment/waterF.glsl
blob: 7e1788678da59d1ec8ec1df8fdb369bbfccb143e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/** 
 * @file waterF.glsl
 *
 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

vec3 scaleSoftClip(vec3 inColor);
vec3 atmosTransport(vec3 inColor);
vec3 applyWaterFog(vec4 inColor);

uniform sampler2D diffuseMap;
uniform sampler2D bumpMap;   
uniform sampler2D screenTex;
uniform sampler2D refTex;

uniform float sunAngle;
uniform float sunAngle2;
uniform float scaledAngle;
uniform vec3 lightDir;
uniform vec3 specular;
uniform float lightExp;
uniform float refScale;
uniform float kd;
uniform vec2 screenRes;
uniform vec3 normScale;
uniform float fresnelScale;
uniform float fresnelOffset;
uniform float blurMultiplier;
uniform vec4 fogCol;

//bigWave is (refCoord.w, view.w);
varying vec4 refCoord;
varying vec4 littleWave;
varying vec4 view;

void main() 
{
	vec3 viewVec = view.xyz;
	vec4 color;
	
	float dist = length(viewVec.xy);
	
	//normalize view vector
	viewVec = normalize(viewVec);
	
	//get wave normals
	vec3 wavef = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0;

	//get detail normals
	vec3 dcol = texture2D(bumpMap, littleWave.xy).rgb*0.75;
	dcol += texture2D(bumpMap, littleWave.zw).rgb*1.25;

	//interpolate between big waves and little waves (big waves in deep water)
	wavef = (wavef + dcol) * 0.5;
	
	//crunch normal to range [-1,1]
	wavef -= vec3(1,1,1);
	wavef = normalize(wavef);
   
	//get base fresnel components	
	
	float df = dot(viewVec,wavef) * fresnelScale + fresnelOffset;
		    
	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
	
	float dist2 = dist;
	dist = max(dist, 5.0);
	
	//get reflected color
	vec2 refdistort = wavef.xy*dot(normScale, vec3(0.333));
	vec2 refvec = distort+refdistort/dist;
	vec4 refcol = texture2D(refTex, refvec);

	//get specular component
	float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0);
	
	//harden specular
	spec = pow(spec, lightExp);

	//figure out distortion vector (ripply)   
	vec2 distort2 = distort+wavef.xy*refScale/max(dist*df, 1.0);
		
	vec4 fb = texture2D(screenTex, distort2);
	
	//mix with reflection
	color.rgb = mix(mix(fogCol.rgb, fb.rgb, fogCol.a), refcol.rgb, df);
	color.rgb += spec * specular;
	
	//color.rgb = applyWaterFog(color);//atmosTransport(color.rgb);
	color.rgb = scaleSoftClip(color.rgb);
	color.a = spec * sunAngle2;

	gl_FragColor = color;
}