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,30 @@
/**
* @file eyeballV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol);
void calcAtmospherics(vec3 inPositionEye);
void main()
{
//transform vertex
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vec3 pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
vec3 norm = normalize(gl_NormalMatrix * gl_Normal);
calcAtmospherics(pos.xyz);
// vec4 specular = specularColor;
vec4 specular = vec4(1.0);
vec4 color = calcLightingSpecular(pos, norm, gl_Color, specular, vec4(0.0));
gl_FrontColor = color;
gl_FogFragCoord = pos.z;
}

View File

@@ -0,0 +1,31 @@
/**
* @file blurf.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2DRect RenderTexture;
uniform float bloomStrength;
varying vec4 gl_TexCoord[gl_MaxTextureCoords];
void main(void)
{
float blurWeights[7];
blurWeights[0] = 0.05;
blurWeights[1] = 0.1;
blurWeights[2] = 0.2;
blurWeights[3] = 0.3;
blurWeights[4] = 0.2;
blurWeights[5] = 0.1;
blurWeights[6] = 0.05;
vec3 color = vec3(0,0,0);
for (int i = 0; i < 7; i++){
color += vec3(texture2DRect(RenderTexture, gl_TexCoord[i].st)) * blurWeights[i];
}
color *= bloomStrength;
gl_FragColor = vec4(color, 1.0);
}

View File

@@ -0,0 +1,35 @@
/**
* @file blurV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform vec2 texelSize;
uniform vec2 blurDirection;
uniform float blurWidth;
void main(void)
{
// Transform vertex
gl_Position = ftransform();
vec2 blurDelta = texelSize * blurDirection * vec2(blurWidth, blurWidth);
vec2 s = gl_MultiTexCoord0.st - (blurDelta * 3.0);
// for (int i = 0; i < 7; i++) {
// gl_TexCoord[i].st = s + (i * blurDelta);
// }
// MANUALLY UNROLL
gl_TexCoord[0].st = s;
gl_TexCoord[1].st = s + blurDelta;
gl_TexCoord[2].st = s + (2. * blurDelta);
gl_TexCoord[3].st = s + (3. * blurDelta);
gl_TexCoord[4].st = s + (4. * blurDelta);
gl_TexCoord[5].st = s + (5. * blurDelta);
gl_TexCoord[6].st = s + (6. * blurDelta);
// gl_TexCoord[0].st = s;
// gl_TexCoord[1].st = blurDelta;
}

View File

@@ -0,0 +1,31 @@
/**
* @file colorFilterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2DRect RenderTexture;
uniform float brightness;
uniform float contrast;
uniform vec3 contrastBase;
uniform float saturation;
uniform vec3 lumWeights;
const float gamma = 2.0;
void main(void)
{
vec3 color = vec3(texture2DRect(RenderTexture, gl_TexCoord[0].st));
/// Modulate brightness
color *= brightness;
/// Modulate contrast
color = mix(contrastBase, color, contrast);
/// Modulate saturation
color = mix(vec3(dot(color, lumWeights)), color, saturation);
gl_FragColor = vec4(color, 1.0);
}

View File

@@ -0,0 +1,14 @@
/**
* @file drawQuadV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void main(void)
{
//transform vertex
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
}

View File

@@ -0,0 +1,22 @@
/**
* @file extractF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2DRect RenderTexture;
uniform float extractLow;
uniform float extractHigh;
uniform vec3 lumWeights;
void main(void)
{
/// Get scene color
vec3 color = vec3(texture2DRect(RenderTexture, gl_TexCoord[0].st));
/// Extract luminance and scale up by night vision brightness
float lum = smoothstep(extractLow, extractHigh, dot(color, lumWeights));
gl_FragColor = vec4(vec3(lum), 1.0);
}

View File

@@ -0,0 +1,42 @@
/**
* @file nightVisionF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2DRect RenderTexture;
uniform sampler2D NoiseTexture;
uniform float brightMult;
uniform float noiseStrength;
float luminance(vec3 color)
{
/// CALCULATING LUMINANCE (Using NTSC lum weights)
/// http://en.wikipedia.org/wiki/Luma_%28video%29
return dot(color, vec3(0.299, 0.587, 0.114));
}
void main(void)
{
/// Get scene color
vec3 color = vec3(texture2DRect(RenderTexture, gl_TexCoord[0].st));
/// Extract luminance and scale up by night vision brightness
float lum = luminance(color) * brightMult;
/// Convert into night vision color space
/// Newer NVG colors (crisper and more saturated)
vec3 outColor = (lum * vec3(0.91, 1.21, 0.9)) + vec3(-0.07, 0.1, -0.12);
/// Add noise
float noiseValue = texture2D(NoiseTexture, gl_TexCoord[1].st).r;
noiseValue = (noiseValue - 0.5) * noiseStrength;
/// Older NVG colors (more muted)
// vec3 outColor = (lum * vec3(0.82, 0.75, 0.83)) + vec3(0.05, 0.32, -0.11);
outColor += noiseValue;
gl_FragColor = vec4(outColor, 1.0);
}

View File

@@ -0,0 +1,14 @@
/**
* @file simpleF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2DRect RenderTexture;
void main(void)
{
vec3 color = vec3(texture2DRect(RenderTexture, gl_TexCoord[0].st));
gl_FragColor = vec4(1.0 - color, 1.0);
}

View File

@@ -0,0 +1,38 @@
/**
* @file terrainF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D detail_0;
uniform sampler2D detail_1;
uniform sampler2D detail_2;
uniform sampler2D detail_3;
uniform sampler2D alpha_ramp;
vec3 atmosLighting(vec3 light);
vec3 scaleSoftClip(vec3 color);
void main()
{
/// Note: This should duplicate the blending functionality currently used for the terrain rendering.
/// TODO Confirm tex coords and bind them appropriately in vert shader.
vec4 color0 = texture2D(detail_0, gl_TexCoord[0].xy);
vec4 color1 = texture2D(detail_1, gl_TexCoord[0].xy);
vec4 color2 = texture2D(detail_2, gl_TexCoord[0].xy);
vec4 color3 = texture2D(detail_3, gl_TexCoord[0].xy);
float alpha1 = texture2D(alpha_ramp, gl_TexCoord[0].zw).a;
float alpha2 = texture2D(alpha_ramp,gl_TexCoord[1].xy).a;
float alphaFinal = texture2D(alpha_ramp, gl_TexCoord[1].zw).a;
vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal );
/// Add WL Components
outColor.rgb = atmosLighting(outColor.rgb * gl_Color.rgb);
gl_FragColor = vec4(scaleSoftClip(outColor.rgb), 1.0);
}

View File

@@ -0,0 +1,52 @@
/**
* @file terrainV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void calcAtmospherics(vec3 inPositionEye);
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 = ftransform();
vec4 pos = gl_ModelViewMatrix * gl_Vertex;
vec3 norm = normalize(gl_NormalMatrix * gl_Normal);
/// Potentially better without it for water.
pos /= pos.w;
calcAtmospherics((gl_ModelViewMatrix * gl_Vertex).xyz);
vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0));
gl_FrontColor = color;
// Transform and pass tex coords
gl_TexCoord[0].xy = texgen_object(gl_Vertex, gl_MultiTexCoord0, gl_TextureMatrix[0], gl_ObjectPlaneS[0], gl_ObjectPlaneT[0]).xy;
vec4 t = gl_MultiTexCoord1;
gl_TexCoord[0].zw = t.xy;
gl_TexCoord[1].xy = t.xy-vec2(2.0, 0.0);
gl_TexCoord[1].zw = t.xy-vec2(1.0, 0.0);
}

View File

@@ -0,0 +1,39 @@
/**
* @file terrainWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D detail_0;
uniform sampler2D detail_1;
uniform sampler2D detail_2;
uniform sampler2D detail_3;
uniform sampler2D alpha_ramp;
vec3 atmosLighting(vec3 light);
vec4 applyWaterFog(vec4 color);
void main()
{
/// Note: This should duplicate the blending functionality currently used for the terrain rendering.
/// TODO Confirm tex coords and bind them appropriately in vert shader.
vec4 color0 = texture2D(detail_0, gl_TexCoord[0].xy);
vec4 color1 = texture2D(detail_1, gl_TexCoord[0].xy);
vec4 color2 = texture2D(detail_2, gl_TexCoord[0].xy);
vec4 color3 = texture2D(detail_3, gl_TexCoord[0].xy);
float alpha1 = texture2D(alpha_ramp, gl_TexCoord[0].zw).a;
float alpha2 = texture2D(alpha_ramp,gl_TexCoord[1].xy).a;
float alphaFinal = texture2D(alpha_ramp, gl_TexCoord[1].zw).a;
vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal );
/// Add WL Components
outColor.rgb = atmosLighting(outColor.rgb * gl_Color.rgb);
outColor = applyWaterFog(outColor);
gl_FragColor = outColor;
}

View File

@@ -0,0 +1,88 @@
/**
* @file underWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform sampler2D bumpMap;
uniform sampler2D screenTex;
uniform sampler2D refTex;
uniform sampler2D screenDepth;
uniform vec4 fogCol;
uniform vec3 lightDir;
uniform vec3 specular;
uniform float lightExp;
uniform vec2 fbScale;
uniform float refScale;
uniform float znear;
uniform float zfar;
uniform float kd;
uniform vec4 waterPlane;
uniform vec3 eyeVec;
uniform vec4 waterFogColor;
uniform float waterFogDensity;
uniform float waterFogKS;
uniform vec2 screenRes;
//bigWave is (refCoord.w, view.w);
varying vec4 refCoord;
varying vec4 littleWave;
varying vec4 view;
vec4 applyWaterFog(vec4 color, vec3 viewVec)
{
//normalize view vector
vec3 view = normalize(viewVec);
float es = -view.z;
//find intersection point with water plane and eye vector
//get eye depth
float e0 = max(-waterPlane.w, 0.0);
//get object depth
float depth = length(viewVec);
//get "thickness" of water
float l = max(depth, 0.1);
float kd = waterFogDensity;
float ks = waterFogKS;
vec4 kc = waterFogColor;
float F = 0.98;
float t1 = -kd * pow(F, ks * e0);
float t2 = kd + ks * es;
float t3 = pow(F, t2*l) - 1.0;
float L = min(t1/t2*t3, 1.0);
float D = pow(0.98, l*kd);
//return vec4(1.0, 0.0, 1.0, 1.0);
return color * D + kc * L;
//depth /= 10.0;
//return vec4(depth,depth,depth,0.0);
}
void main()
{
vec4 color;
//get detail normals
vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0;
vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0;
vec3 wavef = normalize(wave1+wave2+wave3);
//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 = applyWaterFog(fb,view.xyz);
}

View File

@@ -0,0 +1,117 @@
/**
* @file waterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec3 scaleSoftClip(vec3 inColor);
vec3 atmosTransport(vec3 inColor);
uniform sampler2D bumpMap;
uniform sampler2D screenTex;
uniform sampler2D refTex;
uniform float sunAngle;
uniform float sunAngle2;
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;
//bigWave is (refCoord.w, view.w);
varying vec4 refCoord;
varying vec4 littleWave;
varying vec4 view;
void main()
{
vec4 color;
float dist = length(view.xy);
//normalize view vector
vec3 viewVec = normalize(view.xyz);
//get wave normals
vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0;
vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0;
//get base fresnel components
vec3 df = vec3(
dot(viewVec, wave1),
dot(viewVec, (wave2 + wave3) * 0.5),
dot(viewVec, wave3)
) * fresnelScale + fresnelOffset;
df *= df;
vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
float dist2 = dist;
dist = max(dist, 5.0);
float dmod = sqrt(dist);
vec2 dmod_scale = vec2(dmod*dmod, dmod);
//get reflected color
vec2 refdistort1 = wave1.xy*normScale.x;
vec2 refvec1 = distort+refdistort1/dmod_scale;
vec4 refcol1 = texture2D(refTex, refvec1);
vec2 refdistort2 = wave2.xy*normScale.y;
vec2 refvec2 = distort+refdistort2/dmod_scale;
vec4 refcol2 = texture2D(refTex, refvec2);
vec2 refdistort3 = wave3.xy*normScale.z;
vec2 refvec3 = distort+refdistort3/dmod_scale;
vec4 refcol3 = texture2D(refTex, refvec3);
vec4 refcol = refcol1 + refcol2 + refcol3;
float df1 = df.x + df.y + df.z;
refcol *= df1 * 0.333;
vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5;
wavef.z *= max(-viewVec.z, 0.1);
wavef = normalize(wavef);
float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset;
vec2 refdistort4 = wavef.xy*0.125;
refdistort4.y -= abs(refdistort4.y);
vec2 refvec4 = distort+refdistort4/dmod;
float dweight = min(dist2*blurMultiplier, 1.0);
vec4 baseCol = texture2D(refTex, refvec4);
refcol = mix(baseCol*df2, refcol, dweight);
//get specular component
float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0);
//harden specular
spec = pow(spec, 128.0);
//figure out distortion vector (ripply)
vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0);
vec4 fb = texture2D(screenTex, distort2);
//mix with reflection
// Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug
color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999);
color.rgb += spec * specular;
color.rgb = atmosTransport(color.rgb);
color.rgb = scaleSoftClip(color.rgb);
color.a = spec * sunAngle2;
gl_FragColor = color;
}

View File

@@ -0,0 +1,54 @@
/**
* @file waterFogF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform vec4 lightnorm;
uniform vec4 waterPlane;
uniform vec4 waterFogColor;
uniform float waterFogDensity;
uniform float waterFogKS;
vec3 getPositionEye();
vec4 applyWaterFog(vec4 color)
{
//normalize view vector
vec3 view = normalize(getPositionEye());
float es = -(dot(view, waterPlane.xyz));
//find intersection point with water plane and eye vector
//get eye depth
float e0 = max(-waterPlane.w, 0.0);
vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0);
//get object depth
float depth = length(getPositionEye() - int_v);
//get "thickness" of water
float l = max(depth, 0.1);
float kd = waterFogDensity;
float ks = waterFogKS;
vec4 kc = waterFogColor;
float F = 0.98;
float t1 = -kd * pow(F, ks * e0);
float t2 = kd + ks * es;
float t3 = pow(F, t2*l) - 1.0;
float L = min(t1/t2*t3, 1.0);
float D = pow(0.98, l*kd);
color.rgb = color.rgb * D + kc.rgb * L;
color.a = kc.a + color.a;
return color;
}

View File

@@ -0,0 +1,23 @@
/**
* @file lightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
vec3 atmosLighting(vec3 light);
vec3 scaleSoftClip(vec3 light);
void default_lighting()
{
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy) * gl_Color;
color.rgb = atmosLighting(color.rgb);
color.rgb = scaleSoftClip(color.rgb);
gl_FragColor = color;
}

View File

@@ -0,0 +1,23 @@
/**
* @file lightFullbrightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
vec3 fullbrightAtmosTransport(vec3 light);
vec3 fullbrightScaleSoftClip(vec3 light);
void fullbright_lighting()
{
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy) * gl_Color;
color.rgb = fullbrightAtmosTransport(color.rgb);
color.rgb = fullbrightScaleSoftClip(color.rgb);
gl_FragColor = color;
}

View File

@@ -0,0 +1,30 @@
/**
* @file lightFullbrightShinyF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform samplerCube environmentMap;
vec3 fullbrightShinyAtmosTransport(vec3 light);
vec3 fullbrightScaleSoftClip(vec3 light);
void fullbright_shiny_lighting()
{
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy);
color.rgb *= gl_Color.rgb;
vec3 envColor = textureCube(environmentMap, gl_TexCoord[1].xyz).rgb;
color.rgb = mix(color.rgb, envColor.rgb, gl_Color.a);
color.rgb = fullbrightShinyAtmosTransport(color.rgb);
color.rgb = fullbrightScaleSoftClip(color.rgb);
color.a = max(color.a, gl_Color.a);
gl_FragColor = color;
}

View File

@@ -0,0 +1,21 @@
/**
* @file lightFullbrightWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
vec3 fullbrightAtmosTransport(vec3 light);
vec4 applyWaterFog(vec4 color);
void fullbright_lighting_water()
{
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy) * gl_Color;
color.rgb = fullbrightAtmosTransport(color.rgb);
gl_FragColor = applyWaterFog(color);
}

View File

@@ -0,0 +1,29 @@
/**
* @file lightShinyF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform samplerCube environmentMap;
vec3 scaleSoftClip(vec3 light);
vec3 atmosLighting(vec3 light);
vec4 applyWaterFog(vec4 color);
void shiny_lighting()
{
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy);
color.rgb *= gl_Color.rgb;
vec3 envColor = textureCube(environmentMap, gl_TexCoord[1].xyz).rgb;
color.rgb = mix(color.rgb, envColor.rgb, gl_Color.a);
color.rgb = atmosLighting(color.rgb);
color.rgb = scaleSoftClip(color.rgb);
color.a = max(color.a, gl_Color.a);
gl_FragColor = color;
}

View File

@@ -0,0 +1,27 @@
/**
* @file lightShinyWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform samplerCube environmentMap;
vec3 atmosLighting(vec3 light);
vec4 applyWaterFog(vec4 color);
void shiny_lighting_water()
{
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy);
color.rgb *= gl_Color.rgb;
vec3 envColor = textureCube(environmentMap, gl_TexCoord[1].xyz).rgb;
color.rgb = mix(color.rgb, envColor.rgb, gl_Color.a);
color.rgb = atmosLighting(color.rgb);
color.a = max(color.a, gl_Color.a);
gl_FragColor = applyWaterFog(color);
}

View File

@@ -0,0 +1,16 @@
/**
* @file lightSpecularV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
// All lights, no specular highlights
vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol);
vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol)
{
return sumLightsSpecular(pos, norm, color, specularColor, baseCol);
}

View File

@@ -0,0 +1,16 @@
/**
* @file lightV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
// All lights, no specular highlights
vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight);
vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
{
return sumLights(pos, norm, color, baseLight);
}

View File

@@ -0,0 +1,21 @@
/**
* @file lightWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
vec3 atmosLighting(vec3 light);
vec4 applyWaterFog(vec4 color);
void default_lighting_water()
{
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy) * gl_Color;
color.rgb = atmosLighting(color.rgb);
gl_FragColor = applyWaterFog(color);
}

View File

@@ -0,0 +1,41 @@
/**
* @file sumLightsV.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da);
vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol);
vec3 atmosAmbient(vec3 light);
vec3 atmosAffectDirectionalLight(float lightIntensity);
vec3 atmosGetDiffuseSunlightColor();
vec3 scaleDownLight(vec3 light);
vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol)
{
vec4 col = vec4(0.0, 0.0, 0.0, color.a);
vec3 view = normalize(pos);
/// collect all the specular values from each calcXXXLightSpecular() function
vec4 specularSum = vec4(0.0);
// Collect normal lights (need to be divided by two, as we later multiply by 2)
col.rgb += gl_LightSource[1].diffuse.rgb * calcDirectionalLightSpecular(specularColor, view, norm, gl_LightSource[1].position.xyz, gl_LightSource[1].diffuse.rgb, 1.0);
col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, gl_LightSource[2].position.xyz, gl_LightSource[2].linearAttenuation, gl_LightSource[2].quadraticAttenuation, gl_LightSource[2].diffuse.rgb);
col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, gl_LightSource[3].position.xyz, gl_LightSource[3].linearAttenuation, gl_LightSource[3].quadraticAttenuation, gl_LightSource[3].diffuse.rgb);
//col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, gl_LightSource[4].position.xyz, gl_LightSource[4].linearAttenuation, gl_LightSource[4].quadraticAttenuation, gl_LightSource[4].diffuse.rgb);
col.rgb = scaleDownLight(col.rgb);
// Add windlight lights
col.rgb += atmosAmbient(baseCol.rgb);
col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, gl_LightSource[0].position.xyz, atmosGetDiffuseSunlightColor()*baseCol.a, 1.0));
col.rgb = min(col.rgb*color.rgb, 1.0);
specularColor.rgb = min(specularColor.rgb*specularSum.rgb, 1.0);
col.rgb += specularColor.rgb;
return col;
}

View File

@@ -0,0 +1,34 @@
/**
* @file sumLightsV.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
float calcDirectionalLight(vec3 n, vec3 l);
float calcPointLight(vec3 v, vec3 n, vec4 lp, float la);
vec3 atmosAmbient(vec3 light);
vec3 atmosAffectDirectionalLight(float lightIntensity);
vec3 scaleDownLight(vec3 light);
vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
{
vec4 col = vec4(0.0, 0.0, 0.0, color.a);
// Collect normal lights (need to be divided by two, as we later multiply by 2)
col.rgb += gl_LightSource[1].diffuse.rgb * calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
col.rgb += gl_LightSource[2].diffuse.rgb * calcPointLight(pos, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation);
col.rgb += gl_LightSource[3].diffuse.rgb * calcPointLight(pos, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation);
//col.rgb += gl_LightSource[4].diffuse.rgb * calcPointLight(pos, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation);
col.rgb = scaleDownLight(col.rgb);
// Add windlight lights
col.rgb += atmosAmbient(baseLight.rgb);
col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, gl_LightSource[0].position.xyz));
col.rgb = min(col.rgb*color.rgb, 1.0);
return col;
}

View File

@@ -0,0 +1,31 @@
/**
* @file shinyV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
void calcAtmospherics(vec3 inPositionEye);
uniform vec4 origin;
void main()
{
//transform vertex
gl_Position = ftransform();
vec4 pos = (gl_ModelViewMatrix * gl_Vertex);
vec3 norm = normalize(gl_NormalMatrix * gl_Normal);
vec3 ref = reflect(pos.xyz, -norm);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_TexCoord[1] = gl_TextureMatrix[1]*vec4(ref,1.0);
calcAtmospherics(pos.xyz);
gl_FrontColor = calcLighting(pos.xyz, norm, gl_Color, vec4(0.0));
gl_FogFragCoord = pos.z;
}

View File

@@ -0,0 +1,24 @@
/**
* @file atmosphericsF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
//////////////////////////////////////////////////////////
// The fragment shader for the terrain atmospherics
//////////////////////////////////////////////////////////
vec3 getAdditiveColor();
vec3 getAtmosAttenuation();
uniform sampler2D cloudMap;
uniform vec4 cloud_pos_density1;
vec3 atmosLighting(vec3 light)
{
light *= getAtmosAttenuation().r;
light += getAdditiveColor();
return (2.0 * light);
}

View File

@@ -0,0 +1,41 @@
/**
* @file atmosphericsHelpersV.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
// Output variables
vec3 getSunlitColor();
vec3 getAmblitColor();
vec3 getAdditiveColor();
vec3 getAtmosAttenuation();
vec3 getPositionEye();
uniform float scene_light_strength;
vec3 atmosAmbient(vec3 light)
{
return getAmblitColor() + light / 2.0;
}
vec3 atmosAffectDirectionalLight(float lightIntensity)
{
return getSunlitColor() * lightIntensity;
}
vec3 atmosGetDiffuseSunlightColor()
{
return getSunlitColor();
}
vec3 scaleDownLight(vec3 light)
{
return (light / scene_light_strength );
}
vec3 scaleUpLight(vec3 light)
{
return (light * scene_light_strength);
}

View File

@@ -0,0 +1,137 @@
/**
* @file atmosphericsV.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
// varying param funcs
void setSunlitColor(vec3 v);
void setAmblitColor(vec3 v);
void setAdditiveColor(vec3 v);
void setAtmosAttenuation(vec3 v);
void setPositionEye(vec3 v);
vec3 getAdditiveColor();
//varying vec4 vary_CloudUVs;
//varying float vary_CloudDensity;
// Inputs
uniform vec4 morphFactor;
uniform vec3 camPosLocal;
//uniform vec4 camPosWorld;
uniform vec4 lightnorm;
uniform vec4 sunlight_color;
uniform vec4 ambient;
uniform vec4 blue_horizon;
uniform vec4 blue_density;
uniform vec4 haze_horizon;
uniform vec4 haze_density;
uniform vec4 cloud_shadow;
uniform vec4 density_multiplier;
uniform vec4 distance_multiplier;
uniform vec4 max_y;
uniform vec4 glow;
void calcAtmospherics(vec3 inPositionEye) {
vec3 P = inPositionEye;
setPositionEye(P);
//(TERRAIN) limit altitude
if (P.y > max_y.x) P *= (max_y.x / P.y);
if (P.y < -max_y.x) P *= (-max_y.x / P.y);
vec3 tmpLightnorm = lightnorm.xyz;
vec3 Pn = normalize(P);
float Plen = length(P);
vec4 temp1 = vec4(0);
vec3 temp2 = vec3(0);
vec4 blue_weight;
vec4 haze_weight;
vec4 sunlight = sunlight_color;
vec4 light_atten;
//sunlight attenuation effect (hue and brightness) due to atmosphere
//this is used later for sunlight modulation at various altitudes
light_atten = (blue_density * 1.0 + vec4(haze_density.r) * 0.25) * (density_multiplier.x * max_y.x);
//I had thought blue_density and haze_density should have equal weighting,
//but attenuation due to haze_density tends to seem too strong
temp1 = blue_density + vec4(haze_density.r);
blue_weight = blue_density / temp1;
haze_weight = vec4(haze_density.r) / temp1;
//(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain)
temp2.y = max(0.0, tmpLightnorm.y);
temp2.y = 1. / temp2.y;
sunlight *= exp( - light_atten * temp2.y);
// main atmospheric scattering line integral
temp2.z = Plen * density_multiplier.x;
// Transparency (-> temp1)
// ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier.x in a variable because the ati
// compiler gets confused.
temp1 = exp(-temp1 * temp2.z * distance_multiplier.x);
//final atmosphere attenuation factor
setAtmosAttenuation(temp1.rgb);
//vary_AtmosAttenuation = distance_multiplier / 10000.;
//vary_AtmosAttenuation = density_multiplier * 100.;
//vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.);
//compute haze glow
//(can use temp2.x as temp because we haven't used it yet)
temp2.x = dot(Pn, tmpLightnorm.xyz);
temp2.x = 1. - temp2.x;
//temp2.x is 0 at the sun and increases away from sun
temp2.x = max(temp2.x, .03); //was glow.y
//set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
temp2.x *= glow.x;
//higher glow.x gives dimmer glow (because next step is 1 / "angle")
temp2.x = pow(temp2.x, glow.z);
//glow.z should be negative, so we're doing a sort of (1 / "angle") function
//add "minimum anti-solar illumination"
temp2.x += .25;
//increase ambient when there are more clouds
vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow.x * 0.5;
//haze color
setAdditiveColor(
vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow.x) + tmpAmbient)
+ (haze_horizon.r * haze_weight) * (sunlight*(1.-cloud_shadow.x) * temp2.x
+ tmpAmbient)));
//brightness of surface both sunlight and ambient
setSunlitColor(vec3(sunlight * .5));
setAmblitColor(vec3(tmpAmbient * .25));
setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1));
// vary_SunlitColor = vec3(0);
// vary_AmblitColor = vec3(0);
// vary_AdditiveColor = vec4(Pn, 1.0);
/*
const float cloudShadowScale = 100.;
// Get cloud uvs for shadowing
vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.;
vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale;
// We can take uv1 and multiply it by (TerrainSpan / CloudSpan)
// cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.);
vary_CloudUVs *= (10000./40000.);
// Offset by sun vector * (CloudAltitude / CloudSpan)
vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.);
vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.);
*/
}

View File

@@ -0,0 +1,34 @@
/**
* @file atmosphericVars.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec3 vary_PositionEye;
varying vec3 vary_SunlitColor;
varying vec3 vary_AmblitColor;
varying vec3 vary_AdditiveColor;
varying vec3 vary_AtmosAttenuation;
vec3 getPositionEye()
{
return vary_PositionEye;
}
vec3 getSunlitColor()
{
return vary_SunlitColor;
}
vec3 getAmblitColor()
{
return vary_AmblitColor;
}
vec3 getAdditiveColor()
{
return vary_AdditiveColor;
}
vec3 getAtmosAttenuation()
{
return vary_AtmosAttenuation;
}

View File

@@ -0,0 +1,60 @@
/**
* @file atmosphericVars.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec3 vary_PositionEye;
varying vec3 vary_SunlitColor;
varying vec3 vary_AmblitColor;
varying vec3 vary_AdditiveColor;
varying vec3 vary_AtmosAttenuation;
vec3 getPositionEye()
{
return vary_PositionEye;
}
vec3 getSunlitColor()
{
return vary_SunlitColor;
}
vec3 getAmblitColor()
{
return vary_AmblitColor;
}
vec3 getAdditiveColor()
{
return vary_AdditiveColor;
}
vec3 getAtmosAttenuation()
{
return vary_AtmosAttenuation;
}
void setPositionEye(vec3 v)
{
vary_PositionEye = v;
}
void setSunlitColor(vec3 v)
{
vary_SunlitColor = v;
}
void setAmblitColor(vec3 v)
{
vary_AmblitColor = v;
}
void setAdditiveColor(vec3 v)
{
vary_AdditiveColor = v;
}
void setAtmosAttenuation(vec3 v)
{
vary_AtmosAttenuation = v;
}

View File

@@ -0,0 +1,76 @@
/**
* @file WLCloudsF.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
/////////////////////////////////////////////////////////////////////////
// The fragment shader for the sky
/////////////////////////////////////////////////////////////////////////
varying vec4 vary_CloudColorSun;
varying vec4 vary_CloudColorAmbient;
varying float vary_CloudDensity;
uniform sampler2D cloud_noise_texture;
uniform vec4 cloud_pos_density1;
uniform vec4 cloud_pos_density2;
uniform vec4 gamma;
/// Soft clips the light with a gamma correction
vec3 scaleSoftClip(vec3 light) {
//soft clip effect:
light = 1. - clamp(light, vec3(0.), vec3(1.));
light = 1. - pow(light, gamma.xxx);
return light;
}
void main()
{
// Set variables
vec2 uv1 = gl_TexCoord[0].xy;
vec2 uv2 = gl_TexCoord[1].xy;
vec4 cloudColorSun = vary_CloudColorSun;
vec4 cloudColorAmbient = vary_CloudColorAmbient;
float cloudDensity = vary_CloudDensity;
vec2 uv3 = gl_TexCoord[2].xy;
vec2 uv4 = gl_TexCoord[3].xy;
// Offset texture coords
uv1 += cloud_pos_density1.xy; //large texture, visible density
uv2 += cloud_pos_density1.xy; //large texture, self shadow
uv3 += cloud_pos_density2.xy; //small texture, visible density
uv4 += cloud_pos_density2.xy; //small texture, self shadow
// Compute alpha1, the main cloud opacity
float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z;
alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.);
// And smooth
alpha1 = 1. - alpha1 * alpha1;
alpha1 = 1. - alpha1 * alpha1;
// Compute alpha2, for self shadowing effect
// (1 - alpha2) will later be used as percentage of incoming sunlight
float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5);
alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.);
// And smooth
alpha2 = 1. - alpha2;
alpha2 = 1. - alpha2 * alpha2;
// Combine
vec4 color;
color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient);
color *= 2.;
/// Gamma correct for WL (soft clip effect).
gl_FragColor.rgb = scaleSoftClip(color.rgb);
gl_FragColor.a = alpha1;
}

View File

@@ -0,0 +1,163 @@
/**
* @file WLCloudsV.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
//////////////////////////////////////////////////////////////////////////
// The vertex shader for creating the atmospheric sky
///////////////////////////////////////////////////////////////////////////////
// Output parameters
varying vec4 vary_CloudColorSun;
varying vec4 vary_CloudColorAmbient;
varying float vary_CloudDensity;
// Inputs
uniform vec3 camPosLocal;
uniform vec4 lightnorm;
uniform vec4 sunlight_color;
uniform vec4 ambient;
uniform vec4 blue_horizon;
uniform vec4 blue_density;
uniform vec4 haze_horizon;
uniform vec4 haze_density;
uniform vec4 cloud_shadow;
uniform vec4 density_multiplier;
uniform vec4 max_y;
uniform vec4 glow;
uniform vec4 cloud_color;
uniform vec4 cloud_scale;
void main()
{
// World / view / projection
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
// Get relative position
vec3 P = gl_Vertex.xyz - camPosLocal.xyz + vec3(0,50,0);
// Set altitude
if (P.y > 0.)
{
P *= (max_y.x / P.y);
}
else
{
P *= (-32000. / P.y);
}
// Can normalize then
vec3 Pn = normalize(P);
float Plen = length(P);
// Initialize temp variables
vec4 temp1 = vec4(0.);
vec4 temp2 = vec4(0.);
vec4 blue_weight;
vec4 haze_weight;
vec4 sunlight = sunlight_color;
vec4 light_atten;
// Sunlight attenuation effect (hue and brightness) due to atmosphere
// this is used later for sunlight modulation at various altitudes
light_atten = (blue_density * 1.0 + haze_density.x * 0.25) * (density_multiplier.x * max_y.x);
// Calculate relative weights
temp1 = blue_density + haze_density.x;
blue_weight = blue_density / temp1;
haze_weight = haze_density.x / temp1;
// Compute sunlight from P & lightnorm (for long rays like sky)
temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y );
temp2.y = 1. / temp2.y;
sunlight *= exp( - light_atten * temp2.y);
// Distance
temp2.z = Plen * density_multiplier.x;
// Transparency (-> temp1)
// ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati
// compiler gets confused.
temp1 = exp(-temp1 * temp2.z);
// Compute haze glow
temp2.x = dot(Pn, lightnorm.xyz);
temp2.x = 1. - temp2.x;
// temp2.x is 0 at the sun and increases away from sun
temp2.x = max(temp2.x, .001);
// Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
temp2.x *= glow.x;
// Higher glow.x gives dimmer glow (because next step is 1 / "angle")
temp2.x = pow(temp2.x, glow.z);
// glow.z should be negative, so we're doing a sort of (1 / "angle") function
// Add "minimum anti-solar illumination"
temp2.x += .25;
// Increase ambient when there are more clouds
vec4 tmpAmbient = ambient;
tmpAmbient += (1. - tmpAmbient) * cloud_shadow.x * 0.5;
// Dim sunlight by cloud shadow percentage
sunlight *= (1. - cloud_shadow.x);
// Haze color below cloud
vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient)
+ (haze_horizon.r * haze_weight) * (sunlight * temp2.x + tmpAmbient)
);
// CLOUDS
sunlight = sunlight_color;
temp2.y = max(0., lightnorm.y * 2.);
temp2.y = 1. / temp2.y;
sunlight *= exp( - light_atten * temp2.y);
// Cloud color out
vary_CloudColorSun = (sunlight * temp2.x) * cloud_color;
vary_CloudColorAmbient = tmpAmbient * cloud_color;
// Attenuate cloud color by atmosphere
temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds
vary_CloudColorSun *= temp1;
vary_CloudColorAmbient *= temp1;
vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1);
// Make a nice cloud density based on the cloud_shadow value that was passed in.
vary_CloudDensity = 2. * (cloud_shadow.x - 0.25);
// Texture coords
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[0].xy -= 0.5;
gl_TexCoord[0].xy /= cloud_scale.x;
gl_TexCoord[0].xy += 0.5;
gl_TexCoord[1] = gl_TexCoord[0];
gl_TexCoord[1].x += lightnorm.x * 0.0125;
gl_TexCoord[1].y += lightnorm.z * 0.0125;
gl_TexCoord[2] = gl_TexCoord[0] * 16.;
gl_TexCoord[3] = gl_TexCoord[1] * 16.;
// Combine these to minimize register use
vary_CloudColorAmbient += oHazeColorBelowCloud;
// needs this to compile on mac
//vary_AtmosAttenuation = vec3(0.0,0.0,0.0);
// END CLOUDS
}

View File

@@ -0,0 +1,24 @@
/**
* @file gammaF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform vec4 gamma;
vec3 getAtmosAttenuation();
/// Soft clips the light with a gamma correction
vec3 scaleSoftClip(vec3 light) {
//soft clip effect:
light = 1. - clamp(light, vec3(0.), vec3(1.));
light = 1. - pow(light, gamma.xxx);
return light;
}
vec3 fullbrightScaleSoftClip(vec3 light) {
return mix(scaleSoftClip(light.rgb), light.rgb, getAtmosAttenuation());
}

View File

@@ -0,0 +1,41 @@
/**
* @file WLSkyF.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
/////////////////////////////////////////////////////////////////////////
// The fragment shader for the sky
/////////////////////////////////////////////////////////////////////////
varying vec4 vary_HazeColor;
uniform sampler2D cloud_noise_texture;
uniform vec4 gamma;
/// Soft clips the light with a gamma correction
vec3 scaleSoftClip(vec3 light) {
//soft clip effect:
light = 1. - clamp(light, vec3(0.), vec3(1.));
light = 1. - pow(light, gamma.xxx);
return light;
}
void main()
{
// Potential Fill-rate optimization. Add cloud calculation
// back in and output alpha of 0 (so that alpha culling kills
// the fragment) if the sky wouldn't show up because the clouds
// are fully opaque.
vec4 color;
color = vary_HazeColor;
color *= 2.;
/// Gamma correct for WL (soft clip effect).
gl_FragColor.rgb = scaleSoftClip(color.rgb);
gl_FragColor.a = 1.0;
}

View File

@@ -0,0 +1,138 @@
/**
* @file WLSkyV.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
// SKY ////////////////////////////////////////////////////////////////////////
// The vertex shader for creating the atmospheric sky
///////////////////////////////////////////////////////////////////////////////
// Output parameters
varying vec4 vary_HazeColor;
// Inputs
uniform vec3 camPosLocal;
uniform vec4 lightnorm;
uniform vec4 sunlight_color;
uniform vec4 ambient;
uniform vec4 blue_horizon;
uniform vec4 blue_density;
uniform vec4 haze_horizon;
uniform vec4 haze_density;
uniform vec4 cloud_shadow;
uniform vec4 density_multiplier;
uniform vec4 max_y;
uniform vec4 glow;
uniform vec4 cloud_color;
uniform vec4 cloud_scale;
void main()
{
// World / view / projection
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
// Get relative position
vec3 P = gl_Vertex.xyz - camPosLocal.xyz + vec3(0,50,0);
//vec3 P = gl_Vertex.xyz + vec3(0,50,0);
// Set altitude
if (P.y > 0.)
{
P *= (max_y.x / P.y);
}
else
{
P *= (-32000. / P.y);
}
// Can normalize then
vec3 Pn = normalize(P);
float Plen = length(P);
// Initialize temp variables
vec4 temp1 = vec4(0.);
vec4 temp2 = vec4(0.);
vec4 blue_weight;
vec4 haze_weight;
vec4 sunlight = sunlight_color;
vec4 light_atten;
// Sunlight attenuation effect (hue and brightness) due to atmosphere
// this is used later for sunlight modulation at various altitudes
light_atten = (blue_density * 1.0 + haze_density.x * 0.25) * (density_multiplier.x * max_y.x);
// Calculate relative weights
temp1 = blue_density + haze_density.x;
blue_weight = blue_density / temp1;
haze_weight = haze_density.x / temp1;
// Compute sunlight from P & lightnorm (for long rays like sky)
temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y );
temp2.y = 1. / temp2.y;
sunlight *= exp( - light_atten * temp2.y);
// Distance
temp2.z = Plen * density_multiplier.x;
// Transparency (-> temp1)
// ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati
// compiler gets confused.
temp1 = exp(-temp1 * temp2.z);
// Compute haze glow
temp2.x = dot(Pn, lightnorm.xyz);
temp2.x = 1. - temp2.x;
// temp2.x is 0 at the sun and increases away from sun
temp2.x = max(temp2.x, .001);
// Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
temp2.x *= glow.x;
// Higher glow.x gives dimmer glow (because next step is 1 / "angle")
temp2.x = pow(temp2.x, glow.z);
// glow.z should be negative, so we're doing a sort of (1 / "angle") function
// Add "minimum anti-solar illumination"
temp2.x += .25;
// Haze color above cloud
vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient)
+ (haze_horizon.r * haze_weight) * (sunlight * temp2.x + ambient)
);
// Increase ambient when there are more clouds
vec4 tmpAmbient = ambient;
tmpAmbient += (1. - tmpAmbient) * cloud_shadow.x * 0.5;
// Dim sunlight by cloud shadow percentage
sunlight *= (1. - cloud_shadow.x);
// Haze color below cloud
vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient)
+ (haze_horizon.r * haze_weight) * (sunlight * temp2.x + tmpAmbient)
);
// Final atmosphere additive
vary_HazeColor *= (1. - temp1);
// Attenuate cloud color by atmosphere
temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds
// At horizon, blend high altitude sky color towards the darker color below the clouds
vary_HazeColor += (additiveColorBelowCloud - vary_HazeColor) * (1. - sqrt(temp1));
// won't compile on mac without this being set
//vary_AtmosAttenuation = vec3(0.0,0.0,0.0);
}

View File

@@ -0,0 +1,35 @@
/**
* @file transportF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
//////////////////////////////////////////////////////////
// The fragment shader for the terrain atmospherics
//////////////////////////////////////////////////////////
vec3 getAdditiveColor();
vec3 getAtmosAttenuation();
uniform sampler2D cloudMap;
uniform vec4 cloud_pos_density1;
vec3 atmosTransport(vec3 light) {
light *= getAtmosAttenuation().r;
light += getAdditiveColor() * 2.0;
return light;
}
vec3 fullbrightAtmosTransport(vec3 light) {
float brightness = dot(light.rgb, vec3(0.33333));
return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness);
}
vec3 fullbrightShinyAtmosTransport(vec3 light) {
float brightness = dot(light.rgb, vec3(0.33333));
return mix(atmosTransport(light.rgb), (light.rgb + getAdditiveColor().rgb) * (2.0 - brightness), brightness * brightness);
}