PageRenderTime 16ms CodeModel.GetById 9ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 96 lines | 77 code | 19 blank | 0 comment | 0 complexity | d0ac84c7215b0afb2959346be87bbe81 MD5 | raw file
 1/** 
 2 * @file waterV.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
26uniform mat4 modelview_matrix;
27uniform mat4 modelview_projection_matrix;
28
29ATTRIBUTE vec3 position;
30
31void calcAtmospherics(vec3 inPositionEye);
32
33uniform vec2 d1;
34uniform vec2 d2;
35uniform float time;
36uniform vec3 eyeVec;
37uniform float waterHeight;
38
39VARYING vec4 refCoord;
40VARYING vec4 littleWave;
41VARYING vec4 view;
42
43float wave(vec2 v, float t, float f, vec2 d, float s) 
44{
45   return (dot(d, v)*f + t*s)*f;
46}
47
48void main()
49{
50	//transform vertex
51	mat4 modelViewProj = modelview_projection_matrix;
52	
53	vec4 oPosition;
54		    
55	//get view vector
56	vec3 oEyeVec;
57	oEyeVec.xyz = position.xyz-eyeVec;
58		
59	float d = length(oEyeVec.xy);
60	float ld = min(d, 2560.0);
61	
62	vec3 lpos = position;
63	lpos.xy = eyeVec.xy + oEyeVec.xy/d*ld;
64	view.xyz = oEyeVec;
65		
66	d = clamp(ld/1536.0-0.5, 0.0, 1.0);	
67	d *= d;
68		
69	oPosition = vec4(lpos, 1.0);
70	oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d);
71	oPosition = modelViewProj * oPosition;
72	refCoord.xyz = oPosition.xyz + vec3(0,0,0.2);
73	
74	//get wave position parameter (create sweeping horizontal waves)
75	vec3 v = lpos;
76	v.x += (cos(v.x*0.08/*+time*0.01*/)+sin(v.y*0.02))*6.0;
77	    
78	//push position for further horizon effect.
79	vec4 pos;
80	pos.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z);
81	pos.w = 1.0;
82	pos = modelview_matrix*pos;
83	
84	calcAtmospherics(pos.xyz);
85	
86	
87	//pass wave parameters to pixel shader
88	vec2 bigWave =  (v.xy) * vec2(0.04,0.04)  + d1 * time * 0.055;
89	//get two normal map (detail map) texture coordinates
90	littleWave.xy = (v.xy) * vec2(0.45, 0.9)   + d2 * time * 0.13;
91	littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1;
92	view.w = bigWave.y;
93	refCoord.w = bigWave.x;
94	
95	gl_Position = oPosition;
96}