Imported existing code

This commit is contained in:
Hazim Gazov
2010-04-02 02:48:44 -03:00
parent 48fbc5ae91
commit 7a86d01598
13996 changed files with 2468699 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
/**
* @file terrainF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D detail0;
uniform sampler2D detail1;
uniform sampler2D alphaRamp;
void main()
{
float a = texture2D(alphaRamp, gl_TexCoord[1].xy).a;
vec3 color = mix(texture2D(detail1, gl_TexCoord[2].xy).rgb,
texture2D(detail0, gl_TexCoord[0].xy).rgb,
a);
gl_FragColor.rgb = color;
gl_FragColor.a = texture2D(alphaRamp, gl_TexCoord[3].xy).a;
}

View File

@@ -0,0 +1,40 @@
/**
* @file terrainV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)
{
vec4 tcoord;
tcoord.x = dot(vpos, tp0);
tcoord.y = dot(vpos, tp1);
tcoord.z = tc.z;
tcoord.w = tc.w;
tcoord = mat * tcoord;
return tcoord;
}
void main()
{
//transform vertex
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 pos = gl_ModelViewMatrix * gl_Vertex;
vec3 norm = normalize(gl_NormalMatrix * gl_Normal);
vec4 color = calcLighting(pos.xyz, norm, vec4(1,1,1,1), gl_Color);
gl_FrontColor = color;
gl_TexCoord[0] = texgen_object(gl_Vertex,gl_MultiTexCoord0,gl_TextureMatrix[0],gl_ObjectPlaneS[0],gl_ObjectPlaneT[0]);
gl_TexCoord[1] = gl_TextureMatrix[1]*gl_MultiTexCoord1;
gl_TexCoord[2] = texgen_object(gl_Vertex,gl_MultiTexCoord2,gl_TextureMatrix[2],gl_ObjectPlaneS[2],gl_ObjectPlaneT[2]);
gl_TexCoord[3] = gl_TextureMatrix[3]*gl_MultiTexCoord3;
}

View File

@@ -0,0 +1,23 @@
/**
* @file terrainWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
// this class1 shader is just a copy of terrainF
uniform sampler2D detail0;
uniform sampler2D detail1;
uniform sampler2D alphaRamp;
void main()
{
float a = texture2D(alphaRamp, gl_TexCoord[1].xy).a;
vec3 color = mix(texture2D(detail1, gl_TexCoord[2].xy).rgb,
texture2D(detail0, gl_TexCoord[0].xy).rgb,
a);
gl_FragColor.rgb = color;
gl_FragColor.a = texture2D(alphaRamp, gl_TexCoord[3].xy).a;
}

View File

@@ -0,0 +1,45 @@
/**
* @file underWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform sampler2D bumpMap;
uniform sampler2D screenTex;
uniform float refScale;
uniform vec4 waterFogColor;
//bigWave is (refCoord.w, view.w);
varying vec4 refCoord;
varying vec4 littleWave;
varying vec4 view;
void main()
{
vec4 color;
//get bigwave normal
vec3 wavef = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0;
//get detail normals
vec3 dcol = texture2D(bumpMap, littleWave.xy).rgb*0.75;
dcol += texture2D(bumpMap, littleWave.zw).rgb*1.25;
//interpolate between big waves and little waves (big waves in deep water)
wavef = (wavef+dcol)*0.5;
//crunch normal to range [-1,1]
wavef -= vec3(1,1,1);
//figure out distortion vector (ripply)
vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
distort = distort+wavef.xy*refScale;
vec4 fb = texture2D(screenTex, distort);
gl_FragColor.rgb = mix(waterFogColor.rgb, fb.rgb, waterFogColor.a * 0.001 + 0.999);
gl_FragColor.a = fb.a;
}

View File

@@ -0,0 +1,95 @@
/**
* @file waterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec3 scaleSoftClip(vec3 inColor);
vec3 atmosTransport(vec3 inColor);
vec3 applyWaterFog(vec4 inColor);
uniform sampler2D diffuseMap;
uniform sampler2D bumpMap;
uniform sampler2D screenTex;
uniform sampler2D refTex;
uniform float sunAngle;
uniform float sunAngle2;
uniform float scaledAngle;
uniform vec3 lightDir;
uniform vec3 specular;
uniform float lightExp;
uniform float refScale;
uniform float kd;
uniform vec2 screenRes;
uniform vec3 normScale;
uniform float fresnelScale;
uniform float fresnelOffset;
uniform float blurMultiplier;
uniform vec4 fogCol;
//bigWave is (refCoord.w, view.w);
varying vec4 refCoord;
varying vec4 littleWave;
varying vec4 view;
void main()
{
vec3 viewVec = view.xyz;
vec4 color;
float dist = length(viewVec.xy);
//normalize view vector
viewVec = normalize(viewVec);
//get wave normals
vec3 wavef = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0;
//get detail normals
vec3 dcol = texture2D(bumpMap, littleWave.xy).rgb*0.75;
dcol += texture2D(bumpMap, littleWave.zw).rgb*1.25;
//interpolate between big waves and little waves (big waves in deep water)
wavef = (wavef + dcol) * 0.5;
//crunch normal to range [-1,1]
wavef -= vec3(1,1,1);
wavef = normalize(wavef);
//get base fresnel components
float df = dot(viewVec,wavef) * fresnelScale + fresnelOffset;
vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
float dist2 = dist;
dist = max(dist, 5.0);
//get reflected color
vec2 refdistort = wavef.xy*dot(normScale, vec3(0.333));
vec2 refvec = distort+refdistort/dist;
vec4 refcol = texture2D(refTex, refvec);
//get specular component
float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0);
//harden specular
spec = pow(spec, lightExp);
//figure out distortion vector (ripply)
vec2 distort2 = distort+wavef.xy*refScale/max(dist*df, 1.0);
vec4 fb = texture2D(screenTex, distort2);
//mix with reflection
color.rgb = mix(mix(fogCol.rgb, fb.rgb, fogCol.a), refcol.rgb, df);
color.rgb += spec * specular;
//color.rgb = applyWaterFog(color);//atmosTransport(color.rgb);
color.rgb = scaleSoftClip(color.rgb);
color.a = spec * sunAngle2;
gl_FragColor = color;
}

View File

@@ -0,0 +1,20 @@
/**
* @file waterFogF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec4 applyWaterFog(vec4 color)
{
// GL_EXP2 Fog
//float fog = exp(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord);
// GL_EXP Fog
// float fog = exp(-gl_Fog.density * gl_FogFragCoord);
// GL_LINEAR Fog
float fog = (gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale;
fog = clamp(fog, 0.0, 1.0);
color.rgb = mix(gl_Fog.color.rgb, color.rgb, fog);
return color;
}

View File

@@ -0,0 +1,72 @@
/**
* @file waterV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void calcAtmospherics(vec3 inPositionEye);
uniform vec2 d1;
uniform vec2 d2;
uniform float time;
uniform vec3 eyeVec;
uniform float waterHeight;
varying vec4 refCoord;
varying vec4 littleWave;
varying vec4 view;
float wave(vec2 v, float t, float f, vec2 d, float s)
{
return (dot(d, v)*f + t*s)*f;
}
void main()
{
//transform vertex
vec4 position = gl_Vertex;
mat4 modelViewProj = gl_ModelViewProjectionMatrix;
vec4 oPosition;
//get view vector
vec3 oEyeVec;
oEyeVec.xyz = position.xyz-eyeVec;
float d = length(oEyeVec.xy);
float ld = min(d, 2560.0);
position.xy = eyeVec.xy + oEyeVec.xy/d*ld;
view.xyz = oEyeVec;
d = clamp(ld/1536.0-0.5, 0.0, 1.0);
d *= d;
oPosition = position;
oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d);
oPosition = modelViewProj * oPosition;
refCoord.xyz = oPosition.xyz + vec3(0,0,0.2);
//get wave position parameter (create sweeping horizontal waves)
vec3 v = position.xyz;
v.x += (cos(v.x*0.08/*+time*0.01*/)+sin(v.y*0.02))*6.0;
//push position for further horizon effect.
position.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z);
position.w = 1.0;
position = position*gl_ModelViewMatrix;
calcAtmospherics((gl_ModelViewMatrix * gl_Vertex).xyz);
//pass wave parameters to pixel shader
vec2 bigWave = (v.xy) * vec2(0.04,0.04) + d1 * time * 0.055;
//get two normal map (detail map) texture coordinates
littleWave.xy = (v.xy) * vec2(0.45, 0.9) + d2 * time * 0.13;
littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1;
view.w = bigWave.y;
refCoord.w = bigWave.x;
gl_Position = oPosition;
}