PageRenderTime 464ms CodeModel.GetById 205ms app.highlight 1ms RepoModel.GetById 95ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 110 lines | 91 code | 19 blank | 0 comment | 0 complexity | a7b1c19e84ed5bcfc917b1ffb88105e2 MD5 | raw file
  1/**
  2 * @file underWaterF.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#ifdef DEFINE_GL_FRAGCOLOR
 27out vec4 gl_FragColor;
 28#endif
 29
 30uniform sampler2D diffuseMap;
 31uniform sampler2D bumpMap;   
 32uniform sampler2D screenTex;
 33uniform sampler2D refTex;
 34uniform sampler2D screenDepth;
 35
 36uniform vec4 fogCol;
 37uniform vec3 lightDir;
 38uniform vec3 specular;
 39uniform float lightExp;
 40uniform vec2 fbScale;
 41uniform float refScale;
 42uniform float znear;
 43uniform float zfar;
 44uniform float kd;
 45uniform vec4 waterPlane;
 46uniform vec3 eyeVec;
 47uniform vec4 waterFogColor;
 48uniform float waterFogDensity;
 49uniform float waterFogKS;
 50uniform vec2 screenRes;
 51
 52//bigWave is (refCoord.w, view.w);
 53VARYING vec4 refCoord;
 54VARYING vec4 littleWave;
 55VARYING vec4 view;
 56
 57vec4 applyWaterFog(vec4 color, vec3 viewVec)
 58{
 59	//normalize view vector
 60	vec3 view = normalize(viewVec);
 61	float es = -view.z;
 62
 63	//find intersection point with water plane and eye vector
 64	
 65	//get eye depth
 66	float e0 = max(-waterPlane.w, 0.0);
 67	
 68	//get object depth
 69	float depth = length(viewVec);
 70		
 71	//get "thickness" of water
 72	float l = max(depth, 0.1);
 73
 74	float kd = waterFogDensity;
 75	float ks = waterFogKS;
 76	vec4 kc = waterFogColor;
 77	
 78	float F = 0.98;
 79	
 80	float t1 = -kd * pow(F, ks * e0);
 81	float t2 = kd + ks * es;
 82	float t3 = pow(F, t2*l) - 1.0;
 83	
 84	float L = min(t1/t2*t3, 1.0);
 85	
 86	float D = pow(0.98, l*kd);
 87	//return vec4(1.0, 0.0, 1.0, 1.0);
 88	return color * D + kc * L;
 89	//depth /= 10.0;
 90	//return vec4(depth,depth,depth,0.0);
 91}
 92
 93void main() 
 94{
 95	vec4 color;
 96	    
 97	//get detail normals
 98	vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
 99	vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0;
100	vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0;    
101	vec3 wavef = normalize(wave1+wave2+wave3);
102	
103	//figure out distortion vector (ripply)   
104	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
105	distort = distort+wavef.xy*refScale;
106		
107	vec4 fb = texture2D(screenTex, distort);
108	
109	gl_FragColor = applyWaterFog(fb,view.xyz);
110}