diff options
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl')
-rw-r--r-- | linden/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl b/linden/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl new file mode 100644 index 0000000..bea1515 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl | |||
@@ -0,0 +1,139 @@ | |||
1 | /** | ||
2 | * @file waterF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | vec3 scaleSoftClip(vec3 inColor); | ||
9 | vec3 atmosTransport(vec3 inColor); | ||
10 | |||
11 | uniform sampler2D bumpMap; | ||
12 | uniform sampler2D screenTex; | ||
13 | uniform sampler2D refTex; | ||
14 | uniform sampler2DRectShadow shadowMap0; | ||
15 | uniform sampler2DRectShadow shadowMap1; | ||
16 | uniform sampler2DRectShadow shadowMap2; | ||
17 | uniform sampler2DRectShadow shadowMap3; | ||
18 | uniform sampler2D noiseMap; | ||
19 | |||
20 | uniform mat4 shadow_matrix[6]; | ||
21 | uniform vec4 shadow_clip; | ||
22 | |||
23 | uniform float sunAngle; | ||
24 | uniform float sunAngle2; | ||
25 | uniform vec3 lightDir; | ||
26 | uniform vec3 specular; | ||
27 | uniform float lightExp; | ||
28 | uniform float refScale; | ||
29 | uniform float kd; | ||
30 | uniform vec2 screenRes; | ||
31 | uniform vec3 normScale; | ||
32 | uniform float fresnelScale; | ||
33 | uniform float fresnelOffset; | ||
34 | uniform float blurMultiplier; | ||
35 | uniform vec2 screen_res; | ||
36 | uniform mat4 norm_mat; //region space to screen space | ||
37 | |||
38 | //bigWave is (refCoord.w, view.w); | ||
39 | varying vec4 refCoord; | ||
40 | varying vec4 littleWave; | ||
41 | varying vec4 view; | ||
42 | varying vec4 vary_position; | ||
43 | |||
44 | void main() | ||
45 | { | ||
46 | vec4 color; | ||
47 | float dist = length(view.xy); | ||
48 | |||
49 | //normalize view vector | ||
50 | vec3 viewVec = normalize(view.xyz); | ||
51 | |||
52 | //get wave normals | ||
53 | vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; | ||
54 | vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; | ||
55 | vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; | ||
56 | //get base fresnel components | ||
57 | |||
58 | vec3 df = vec3( | ||
59 | dot(viewVec, wave1), | ||
60 | dot(viewVec, (wave2 + wave3) * 0.5), | ||
61 | dot(viewVec, wave3) | ||
62 | ) * fresnelScale + fresnelOffset; | ||
63 | df *= df; | ||
64 | |||
65 | vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; | ||
66 | |||
67 | float dist2 = dist; | ||
68 | dist = max(dist, 5.0); | ||
69 | |||
70 | float dmod = sqrt(dist); | ||
71 | |||
72 | vec2 dmod_scale = vec2(dmod*dmod, dmod); | ||
73 | |||
74 | //get reflected color | ||
75 | vec2 refdistort1 = wave1.xy*normScale.x; | ||
76 | vec2 refvec1 = distort+refdistort1/dmod_scale; | ||
77 | vec4 refcol1 = texture2D(refTex, refvec1); | ||
78 | |||
79 | vec2 refdistort2 = wave2.xy*normScale.y; | ||
80 | vec2 refvec2 = distort+refdistort2/dmod_scale; | ||
81 | vec4 refcol2 = texture2D(refTex, refvec2); | ||
82 | |||
83 | vec2 refdistort3 = wave3.xy*normScale.z; | ||
84 | vec2 refvec3 = distort+refdistort3/dmod_scale; | ||
85 | vec4 refcol3 = texture2D(refTex, refvec3); | ||
86 | |||
87 | vec4 refcol = refcol1 + refcol2 + refcol3; | ||
88 | float df1 = df.x + df.y + df.z; | ||
89 | refcol *= df1 * 0.333; | ||
90 | |||
91 | vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; | ||
92 | //wavef.z *= max(-viewVec.z, 0.1); | ||
93 | wavef = normalize(wavef); | ||
94 | |||
95 | float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; | ||
96 | |||
97 | vec2 refdistort4 = wavef.xy*0.125; | ||
98 | refdistort4.y -= abs(refdistort4.y); | ||
99 | vec2 refvec4 = distort+refdistort4/dmod; | ||
100 | float dweight = min(dist2*blurMultiplier, 1.0); | ||
101 | vec4 baseCol = texture2D(refTex, refvec4); | ||
102 | refcol = mix(baseCol*df2, refcol, dweight); | ||
103 | |||
104 | //get specular component | ||
105 | //float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); | ||
106 | |||
107 | //harden specular | ||
108 | //spec = pow(spec, 128.0); | ||
109 | |||
110 | //figure out distortion vector (ripply) | ||
111 | vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); | ||
112 | |||
113 | vec4 fb = texture2D(screenTex, distort2); | ||
114 | |||
115 | //mix with reflection | ||
116 | // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug | ||
117 | color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); | ||
118 | |||
119 | float shadow = 1.0; | ||
120 | vec4 pos = vary_position; | ||
121 | |||
122 | vec3 nz = texture2D(noiseMap, gl_FragCoord.xy/128.0).xyz; | ||
123 | vec4 spos = pos; | ||
124 | |||
125 | //spec *= shadow; | ||
126 | //color.rgb += spec * specular; | ||
127 | |||
128 | //color.rgb = atmosTransport(color.rgb); | ||
129 | //color.rgb = scaleSoftClip(color.rgb); | ||
130 | //color.a = spec * sunAngle2; | ||
131 | |||
132 | //wavef.z *= 0.1f; | ||
133 | wavef = normalize(wavef); | ||
134 | wavef = (norm_mat*vec4(wavef, 1.0)).xyz; | ||
135 | |||
136 | gl_FragData[0] = vec4(color.rgb, 0.5); | ||
137 | gl_FragData[1] = vec4(0.5,0.5,0.5, 0.95); | ||
138 | gl_FragData[2] = vec4(wavef*0.5+0.5, 0.f); | ||
139 | } | ||