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