PageRenderTime 16ms CodeModel.GetById 7ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 4ms

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

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