PageRenderTime 14ms CodeModel.GetById 10ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl

https://bitbucket.org/lindenlab/viewer-beta/
text | 74 lines | 56 code | 18 blank | 0 comment | 0 complexity | 1463bb0a2d7ae0e1d0ca11e1b8020994 MD5 | raw file
 1/**
 2 * @file waterFogF.glsl
 3 *
 4 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
 5 * Second Life Viewer Source Code
 6 * Copyright (C) 2007, Linden Research, Inc.
 7 * 
 8 * This library is free software; you can redistribute it and/or
 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation;
11 * version 2.1 of the License only.
12 * 
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 * 
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 * 
22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
23 * $/LicenseInfo$
24 */
25 
26
27
28uniform vec4 lightnorm;
29uniform vec4 waterPlane;
30uniform vec4 waterFogColor;
31uniform float waterFogDensity;
32uniform float waterFogKS;
33
34vec3 getPositionEye();
35
36vec4 applyWaterFog(vec4 color)
37{
38	//normalize view vector
39	vec3 view = normalize(getPositionEye());
40	float es = -(dot(view, waterPlane.xyz));
41
42	//find intersection point with water plane and eye vector
43	
44	//get eye depth
45	float e0 = max(-waterPlane.w, 0.0);
46	
47	vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0);
48	
49	//get object depth
50	float depth = length(getPositionEye() - int_v);
51		
52	//get "thickness" of water
53	float l = max(depth, 0.1);
54
55	float kd = waterFogDensity;
56	float ks = waterFogKS;
57	vec4 kc = waterFogColor;
58	
59	float F = 0.98;
60	
61	float t1 = -kd * pow(F, ks * e0);
62	float t2 = kd + ks * es;
63	float t3 = pow(F, t2*l) - 1.0;
64	
65	float L = min(t1/t2*t3, 1.0);
66	
67	float D = pow(0.98, l*kd);
68	
69	color.rgb = color.rgb * D + kc.rgb * L;
70	color.a = kc.a + color.a;
71	
72	return color;
73}
74