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,14 @@
/**
* @file avatarF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void default_lighting();
void main()
{
default_lighting();
}

View File

@@ -0,0 +1,24 @@
/**
* @file avatarSkinV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
attribute vec4 weight; //1
uniform vec4 matrixPalette[45];
mat4 getSkinnedTransform()
{
mat4 ret;
int i = int(floor(weight.x));
float x = fract(weight.x);
ret[0] = mix(matrixPalette[i+0], matrixPalette[i+1], x);
ret[1] = mix(matrixPalette[i+15],matrixPalette[i+16], x);
ret[2] = mix(matrixPalette[i+30],matrixPalette[i+31], x);
ret[3] = vec4(0,0,0,1);
return ret;
}

View File

@@ -0,0 +1,43 @@
/**
* @file avatarV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
mat4 getSkinnedTransform();
void calcAtmospherics(vec3 inPositionEye);
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
vec4 pos;
vec3 norm;
mat4 trans = getSkinnedTransform();
pos.x = dot(trans[0], gl_Vertex);
pos.y = dot(trans[1], gl_Vertex);
pos.z = dot(trans[2], gl_Vertex);
pos.w = 1.0;
norm.x = dot(trans[0].xyz, gl_Normal);
norm.y = dot(trans[1].xyz, gl_Normal);
norm.z = dot(trans[2].xyz, gl_Normal);
norm = normalize(norm);
gl_Position = gl_ProjectionMatrix * pos;
//gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_FogFragCoord = length(pos.xyz);
calcAtmospherics(pos.xyz);
vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0,0,0,0));
gl_FrontColor = color;
}

View File

@@ -0,0 +1,14 @@
/**
* @file eyeballF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void default_lighting();
void main()
{
default_lighting();
}

View File

@@ -0,0 +1,27 @@
/**
* @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 = vec4(1.0);
vec4 color = calcLightingSpecular(pos, norm, gl_Color, specular, vec4(0.0));
gl_FrontColor = color;
}

View File

@@ -0,0 +1,13 @@
/**
* @file pickAvatarF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
void main()
{
gl_FragColor = vec4(gl_Color.rgb, texture2D(diffuseMap, gl_TexCoord[0].xy).a);
}

View File

@@ -0,0 +1,23 @@
/**
* @file pickAvatarV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
mat4 getSkinnedTransform();
void main()
{
vec4 pos;
mat4 trans = getSkinnedTransform();
pos.x = dot(trans[0], gl_Vertex);
pos.y = dot(trans[1], gl_Vertex);
pos.z = dot(trans[2], gl_Vertex);
pos.w = 1.0;
gl_FrontColor = gl_Color;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ProjectionMatrix * pos;
}

View File

@@ -0,0 +1,88 @@
/**
* @file alphaF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#extension GL_ARB_texture_rectangle : enable
uniform sampler2D diffuseMap;
uniform sampler2DShadow shadowMap0;
uniform sampler2DShadow shadowMap1;
uniform sampler2DShadow shadowMap2;
uniform sampler2DShadow shadowMap3;
uniform sampler2D noiseMap;
uniform sampler2DRect positionMap;
uniform mat4 shadow_matrix[4];
uniform vec4 shadow_clip;
uniform vec2 screen_res;
vec3 atmosLighting(vec3 light);
vec3 scaleSoftClip(vec3 light);
varying vec3 vary_ambient;
varying vec3 vary_directional;
varying vec3 vary_fragcoord;
varying vec3 vary_position;
uniform float alpha_soften;
void main()
{
vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
frag *= screen_res;
vec3 samp_pos = texture2DRect(positionMap, frag).xyz;
float shadow = 1.0;
vec4 pos = vec4(vary_position, 1.0);
if (pos.z > -shadow_clip.w)
{
if (pos.z < -shadow_clip.z)
{
vec4 lpos = shadow_matrix[3]*pos;
shadow = shadow2DProj(shadowMap3, lpos).x;
shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);
}
else if (pos.z < -shadow_clip.y)
{
vec4 lpos = shadow_matrix[2]*pos;
shadow = shadow2DProj(shadowMap2, lpos).x;
}
else if (pos.z < -shadow_clip.x)
{
vec4 lpos = shadow_matrix[1]*pos;
shadow = shadow2DProj(shadowMap1, lpos).x;
}
else
{
vec4 lpos = shadow_matrix[0]*pos;
shadow = shadow2DProj(shadowMap0, lpos).x;
}
}
vec4 col = vec4(vary_ambient + vary_directional.rgb*shadow, gl_Color.a);
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy) * col;
color.rgb = atmosLighting(color.rgb);
color.rgb = scaleSoftClip(color.rgb);
if (samp_pos.z != 0.0)
{
float dist_factor = alpha_soften;
float a = gl_Color.a;
a *= a;
dist_factor *= 1.0/(1.0-a);
color.a *= min((pos.z-samp_pos.z)*dist_factor, 1.0);
}
//gl_FragColor = gl_Color;
gl_FragColor = color;
//gl_FragColor = vec4(1,0,1,1);
}

View File

@@ -0,0 +1,69 @@
/**
* @file alphaV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
void calcAtmospherics(vec3 inPositionEye);
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);
vec3 scaleUpLight(vec3 light);
varying vec3 vary_ambient;
varying vec3 vary_directional;
varying vec3 vary_fragcoord;
varying vec3 vary_position;
uniform float near_clip;
void main()
{
//transform vertex
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vec4 pos = (gl_ModelViewMatrix * gl_Vertex);
vec3 norm = normalize(gl_NormalMatrix * gl_Normal);
vary_position = pos.xyz;
calcAtmospherics(pos.xyz);
//vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0.));
vec4 col;
col.a = gl_Color.a;
// Add windlight lights
col.rgb = atmosAmbient(vec3(0.));
col.rgb = scaleUpLight(col.rgb);
// Collect normal lights (need to be divided by two, as we later multiply by 2)
col.rgb += gl_LightSource[2].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation);
col.rgb += gl_LightSource[3].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation);
col.rgb += gl_LightSource[4].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation);
col.rgb += gl_LightSource[5].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[5].position, gl_LightSource[5].linearAttenuation);
col.rgb += gl_LightSource[6].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[6].position, gl_LightSource[6].linearAttenuation);
col.rgb += gl_LightSource[7].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[7].position, gl_LightSource[7].linearAttenuation);
col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
col.rgb = scaleDownLight(col.rgb);
vary_ambient = col.rgb*gl_Color.rgb;
vary_directional.rgb = gl_Color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, gl_LightSource[0].position.xyz), (1.0-gl_Color.a)*(1.0-gl_Color.a)));
col.rgb = min(col.rgb*gl_Color.rgb, 1.0);
gl_FrontColor = col;
gl_FogFragCoord = pos.z;
pos = gl_ModelViewProjectionMatrix * gl_Vertex;
vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
}

View File

@@ -0,0 +1,68 @@
/**
* @file avatarAlphaF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform sampler2DShadow shadowMap0;
uniform sampler2DShadow shadowMap1;
uniform sampler2DShadow shadowMap2;
uniform sampler2DShadow shadowMap3;
uniform sampler2D noiseMap;
uniform mat4 shadow_matrix[4];
uniform vec4 shadow_clip;
vec3 atmosLighting(vec3 light);
vec3 scaleSoftClip(vec3 light);
varying vec3 vary_ambient;
varying vec3 vary_directional;
varying vec4 vary_position;
varying vec3 vary_normal;
void main()
{
float shadow = 1.0;
vec4 pos = vary_position;
vec3 norm = normalize(vary_normal);
vec3 nz = texture2D(noiseMap, gl_FragCoord.xy/128.0).xyz;
if (pos.z > -shadow_clip.w)
{
if (pos.z < -shadow_clip.z)
{
vec4 lpos = shadow_matrix[3]*pos;
shadow = shadow2DProj(shadowMap3, lpos).x;
}
else if (pos.z < -shadow_clip.y)
{
vec4 lpos = shadow_matrix[2]*pos;
shadow = shadow2DProj(shadowMap2, lpos).x;
}
else if (pos.z < -shadow_clip.x)
{
vec4 lpos = shadow_matrix[1]*pos;
shadow = shadow2DProj(shadowMap1, lpos).x;
}
else
{
vec4 lpos = shadow_matrix[0]*pos;
shadow = shadow2DProj(shadowMap0, lpos).x;
}
}
vec4 col = vec4(vary_ambient + vary_directional*shadow, gl_Color.a);
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy) * col;
color.rgb = atmosLighting(color.rgb);
color.rgb = scaleSoftClip(color.rgb);
gl_FragColor = color;
}

View File

@@ -0,0 +1,78 @@
/**
* @file avatarAlphaV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
mat4 getSkinnedTransform();
void calcAtmospherics(vec3 inPositionEye);
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);
vec3 scaleUpLight(vec3 light);
varying vec4 vary_position;
varying vec3 vary_ambient;
varying vec3 vary_directional;
varying vec3 vary_normal;
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
vec4 pos;
vec3 norm;
mat4 trans = getSkinnedTransform();
pos.x = dot(trans[0], gl_Vertex);
pos.y = dot(trans[1], gl_Vertex);
pos.z = dot(trans[2], gl_Vertex);
pos.w = 1.0;
norm.x = dot(trans[0].xyz, gl_Normal);
norm.y = dot(trans[1].xyz, gl_Normal);
norm.z = dot(trans[2].xyz, gl_Normal);
norm = normalize(norm);
gl_Position = gl_ProjectionMatrix * pos;
vary_position = pos;
vary_normal = norm;
calcAtmospherics(pos.xyz);
//vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0.));
vec4 col;
col.a = gl_Color.a;
// Add windlight lights
col.rgb = atmosAmbient(vec3(0.));
col.rgb = scaleUpLight(col.rgb);
// Collect normal lights (need to be divided by two, as we later multiply by 2)
col.rgb += gl_LightSource[2].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation);
col.rgb += gl_LightSource[3].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation);
col.rgb += gl_LightSource[4].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation);
col.rgb += gl_LightSource[5].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[5].position, gl_LightSource[5].linearAttenuation);
col.rgb += gl_LightSource[6].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[6].position, gl_LightSource[6].linearAttenuation);
col.rgb += gl_LightSource[7].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[7].position, gl_LightSource[7].linearAttenuation);
col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
col.rgb = scaleDownLight(col.rgb);
vary_ambient = col.rgb*gl_Color.rgb;
vary_directional = gl_Color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, gl_LightSource[0].position.xyz), (1.0-gl_Color.a)*(1.0-gl_Color.a)));
col.rgb = min(col.rgb*gl_Color.rgb, 1.0);
gl_FrontColor = col;
gl_FogFragCoord = pos.z;
}

View File

@@ -0,0 +1,20 @@
/**
* @file avatarF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
varying vec3 vary_normal;
varying vec4 vary_position;
void main()
{
gl_FragData[0] = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].xy);
gl_FragData[1] = vec4(0,0,0,0);
gl_FragData[2] = vec4(normalize(vary_normal), 0.0);
gl_FragData[3] = vary_position;
}

View File

@@ -0,0 +1,15 @@
/**
* @file avatarShadowF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
void main()
{
gl_FragColor = vec4(1,1,1,gl_Color.a * texture2D(diffuseMap, gl_TexCoord[0].xy));
}

View File

@@ -0,0 +1,38 @@
/**
* @file avatarShadowV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
mat4 getSkinnedTransform();
attribute vec4 weight;
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
vec4 pos;
vec3 norm;
mat4 trans = getSkinnedTransform();
pos.x = dot(trans[0], gl_Vertex);
pos.y = dot(trans[1], gl_Vertex);
pos.z = dot(trans[2], gl_Vertex);
pos.w = 1.0;
norm.x = dot(trans[0].xyz, gl_Normal);
norm.y = dot(trans[1].xyz, gl_Normal);
norm.z = dot(trans[2].xyz, gl_Normal);
norm = normalize(norm);
pos = gl_ProjectionMatrix * pos;
//smash geometry against near clip plane
pos.z = max(pos.z, -1.0);
gl_Position = pos;
gl_FrontColor = gl_Color;
}

View File

@@ -0,0 +1,42 @@
/**
* @file avatarV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
mat4 getSkinnedTransform();
attribute vec4 weight;
varying vec3 vary_normal;
varying vec4 vary_position;
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
vec4 pos;
vec3 norm;
mat4 trans = getSkinnedTransform();
pos.x = dot(trans[0], gl_Vertex);
pos.y = dot(trans[1], gl_Vertex);
pos.z = dot(trans[2], gl_Vertex);
pos.w = 1.0;
norm.x = dot(trans[0].xyz, gl_Normal);
norm.y = dot(trans[1].xyz, gl_Normal);
norm.z = dot(trans[2].xyz, gl_Normal);
norm = normalize(norm);
vary_position = pos;
vary_normal = norm;
gl_Position = gl_ProjectionMatrix * pos;
//gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_FrontColor = gl_Color;
}

View File

@@ -0,0 +1,48 @@
/**
* @file blurLightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect positionMap;
uniform sampler2DRect normalMap;
uniform sampler2DRect lightMap;
uniform float blur_size;
uniform vec2 delta;
uniform vec3 kern[32];
uniform int kern_length;
uniform float kern_scale;
varying vec2 vary_fragcoord;
void main()
{
vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz;
vec3 pos = texture2DRect(positionMap, vary_fragcoord.xy).xyz;
vec2 ccol = texture2DRect(lightMap, vary_fragcoord.xy).rg;
vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy);
vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free'
vec2 col = defined_weight * ccol;
for (int i = 1; i < kern_length; i++)
{
vec2 tc = vary_fragcoord.xy + kern[i].z*dlt;
vec3 samppos = texture2DRect(positionMap, tc).xyz;
float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane
if (d*d <= 0.003)
{
col += texture2DRect(lightMap, tc).rg*kern[i].xy;
defined_weight += kern[i].xy;
}
}
col /= defined_weight;
gl_FragColor = vec4(col.r, col.g, 0.0, 1.0);
}

View File

@@ -0,0 +1,17 @@
/**
* @file blurLightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec2 vary_fragcoord;
uniform vec2 screen_res;
void main()
{
//transform vertex
gl_Position = ftransform();
vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;
vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
}

View File

@@ -0,0 +1,29 @@
/**
* @file bumpF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform sampler2D bumpMap;
varying vec3 vary_mat0;
varying vec3 vary_mat1;
varying vec3 vary_mat2;
varying vec4 vary_position;
void main()
{
vec3 col = texture2D(diffuseMap, gl_TexCoord[0].xy).rgb;
vec3 norm = texture2D(bumpMap, gl_TexCoord[0].xy).rgb * 2.0 - 1.0;
vec3 tnorm = vec3(dot(norm,vary_mat0),
dot(norm,vary_mat1),
dot(norm,vary_mat2));
gl_FragData[0].rgb = gl_Color.rgb*col;
gl_FragData[1] = vec4(col*(gl_Color.a*1.5), gl_Color.a);
gl_FragData[2] = vec4(normalize(tnorm), 0.0);
gl_FragData[3] = vary_position;
}

View File

@@ -0,0 +1,30 @@
/**
* @file bumpV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec3 vary_mat0;
varying vec3 vary_mat1;
varying vec3 vary_mat2;
varying vec4 vary_position;
void main()
{
//transform vertex
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vary_position = gl_ModelViewMatrix * gl_Vertex;
vec3 n = normalize(gl_NormalMatrix * gl_Normal);
vec3 b = normalize(gl_NormalMatrix * gl_MultiTexCoord2.xyz);
vec3 t = cross(b, n);
vary_mat0 = vec3(t.x, b.x, n.x);
vary_mat1 = vec3(t.y, b.y, n.y);
vary_mat2 = vec3(t.z, b.z, n.z);
gl_FrontColor = gl_Color;
}

View File

@@ -0,0 +1,20 @@
/**
* @file diffuseF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
varying vec3 vary_normal;
varying vec4 vary_position;
void main()
{
vec3 col = texture2D(diffuseMap, gl_TexCoord[0].xy).rgb;
gl_FragData[0] = vec4(gl_Color.rgb*col, 1.0);
gl_FragData[1] = vec4(col*(gl_Color.a*1.5), gl_Color.a);
gl_FragData[2] = vec4(normalize(vary_normal), 0.0);
gl_FragData[3] = vary_position;
}

View File

@@ -0,0 +1,22 @@
/**
* @file diffuseV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec3 vary_normal;
varying vec4 vary_position;
void main()
{
//transform vertex
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vary_position = gl_ModelViewMatrix * gl_Vertex;
vary_normal = normalize(gl_NormalMatrix * gl_Normal);
gl_FrontColor = gl_Color;
}

View File

@@ -0,0 +1,63 @@
/**
* @file fullbrightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#extension GL_ARB_texture_rectangle : enable
uniform sampler2D diffuseMap;
uniform sampler2DShadow shadowMap0;
uniform sampler2DShadow shadowMap1;
uniform sampler2DShadow shadowMap2;
uniform sampler2DShadow shadowMap3;
uniform sampler2D noiseMap;
uniform sampler2DRect positionMap;
uniform mat4 shadow_matrix[4];
uniform vec4 shadow_clip;
uniform vec2 screen_res;
vec3 fullbrightAtmosTransport(vec3 light);
vec3 fullbrightScaleSoftClip(vec3 light);
varying vec3 vary_ambient;
varying vec3 vary_directional;
varying vec4 vary_position;
varying vec3 vary_normal;
varying vec3 vary_fragcoord;
uniform float alpha_soften;
void main()
{
vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
frag *= screen_res;
vec3 samp_pos = texture2DRect(positionMap, frag).xyz;
float shadow = 1.0;
vec4 pos = vary_position;
vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy)*gl_Color;
color.rgb = fullbrightAtmosTransport(color.rgb);
color.rgb = fullbrightScaleSoftClip(color.rgb);
if (samp_pos.z != 0.0)
{
float dist_factor = alpha_soften;
float a = gl_Color.a;
a *= a;
dist_factor *= 1.0/(1.0-a);
color.a *= min((pos.z-samp_pos.z)*dist_factor, 1.0);
}
//gl_FragColor = gl_Color;
gl_FragColor = color;
//gl_FragColor = vec4(1,0,1,1);
}

View File

@@ -0,0 +1,41 @@
/**
* @file fullbrightV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void calcAtmospherics(vec3 inPositionEye);
vec3 atmosAmbient(vec3 light);
vec3 atmosAffectDirectionalLight(float lightIntensity);
vec3 scaleDownLight(vec3 light);
vec3 scaleUpLight(vec3 light);
varying vec4 vary_position;
varying vec3 vary_ambient;
varying vec3 vary_directional;
varying vec3 vary_normal;
varying vec3 vary_fragcoord;
uniform float near_clip;
void main()
{
//transform vertex
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vec4 pos = (gl_ModelViewMatrix * gl_Vertex);
vary_position = pos;
calcAtmospherics(pos.xyz);
gl_FrontColor = gl_Color;
gl_FogFragCoord = pos.z;
pos = gl_ModelViewProjectionMatrix * gl_Vertex;
vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
}

View File

@@ -0,0 +1,20 @@
/**
* @file impostorF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform sampler2D normalMap;
uniform sampler2D specularMap;
varying vec4 vary_position;
void main()
{
gl_FragData[0] = texture2D(diffuseMap, gl_TexCoord[0].xy);
gl_FragData[1] = texture2D(specularMap, gl_TexCoord[0].xy);
gl_FragData[2] = vec4(texture2D(normalMap, gl_TexCoord[0].xy).xyz, vary_position.z);
gl_FragData[3] = vary_position;
}

View File

@@ -0,0 +1,19 @@
/**
* @file impostorV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec4 vary_position;
void main()
{
//transform vertex
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vary_position = gl_ModelViewMatrix * gl_Vertex;
gl_FrontColor = gl_Color;
}

View File

@@ -0,0 +1,83 @@
/**
* @file multiPointLightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect diffuseRect;
uniform sampler2DRect specularRect;
uniform sampler2DRect positionMap;
uniform sampler2DRect normalMap;
uniform samplerCube environmentMap;
uniform sampler2DRect lightMap;
uniform sampler2D noiseMap;
uniform vec3 env_mat[3];
uniform float sun_wash;
uniform int light_count;
uniform vec4 light[16];
uniform vec4 light_col[16];
varying vec3 vary_fragcoord;
uniform vec2 screen_res;
void main()
{
vec2 frag = (vary_fragcoord.xy*0.5+0.5)*screen_res;
vec3 pos = texture2DRect(positionMap, frag.xy).xyz;
vec3 norm = normalize(texture2DRect(normalMap, frag.xy).xyz);
vec4 spec = texture2DRect(specularRect, frag.xy);
vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb;
float noise = texture2D(noiseMap, frag.xy/128.0).b;
vec3 out_col = vec3(0,0,0);
for (int i = 0; i < light_count; ++i)
{
vec3 lv = light[i].xyz-pos;
float dist2 = dot(lv,lv);
if (dist2 > light[i].w)
{
continue;
}
float da = dot(norm, lv);
if (da < 0.0)
{
continue;
}
lv = normalize(lv);
da = dot(norm, lv);
float fa = light_col[i].a+1.0;
float dist_atten = clamp(1.0-(dist2-light[i].w*(1.0-fa))/(light[i].w*fa), 0.0, 1.0);
dist_atten *= noise;
float lit = da * dist_atten;
vec3 col = light_col[i].rgb*lit*diff;
if (spec.a > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);
float sa = dot(ref,lv);
sa = max(sa, 0.0);
sa = pow(sa, 128.0 * spec.a*spec.a/dist_atten)*min(dist_atten*4.0, 1.0);
sa *= noise;
col += da*sa*light_col[i].rgb*spec.rgb;
}
out_col += col;
}
//attenuate point light contribution by SSAO component
out_col *= texture2DRect(lightMap, frag.xy).g;
gl_FragColor.rgb = out_col;
gl_FragColor.a = 0.0;
}

View File

@@ -0,0 +1,75 @@
/**
* @file pointLightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect diffuseRect;
uniform sampler2DRect specularRect;
uniform sampler2DRect positionMap;
uniform sampler2DRect normalMap;
uniform samplerCube environmentMap;
uniform sampler2DRect lightMap;
uniform sampler2D noiseMap;
uniform vec3 env_mat[3];
uniform float sun_wash;
varying vec4 vary_light;
varying vec3 vary_fragcoord;
uniform vec2 screen_res;
void main()
{
vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
frag *= screen_res;
vec3 pos = texture2DRect(positionMap, frag).xyz;
vec3 lv = vary_light.xyz-pos;
float dist2 = dot(lv,lv);
if (dist2 > vary_light.w)
{
discard;
}
vec3 norm = texture2DRect(normalMap, frag).xyz;
float da = dot(norm, lv);
if (da < 0.0)
{
discard;
}
norm = normalize(norm);
lv = normalize(lv);
da = dot(norm, lv);
float noise = texture2D(noiseMap, frag/128.0).b;
vec3 col = texture2DRect(diffuseRect, frag).rgb;
float fa = gl_Color.a+1.0;
float dist_atten = clamp(1.0-(dist2-vary_light.w*(1.0-fa))/(vary_light.w*fa), 0.0, 1.0);
float lit = da * dist_atten * noise;
col = gl_Color.rgb*lit*col;
vec4 spec = texture2DRect(specularRect, frag);
if (spec.a > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);
float sa = dot(ref,lv);
sa = max(sa, 0.0);
sa = pow(sa, 128.0 * spec.a*spec.a/dist_atten)*min(dist_atten*4.0, 1.0);
sa *= noise;
col += da*sa*gl_Color.rgb*spec.rgb;
}
//attenuate point light contribution by SSAO component
col *= texture2DRect(lightMap, frag.xy).g;
gl_FragColor.rgb = col;
gl_FragColor.a = 0.0;
}

View File

@@ -0,0 +1,28 @@
/**
* @file pointLightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec4 vary_light;
varying vec3 vary_fragcoord;
uniform vec2 screen_res;
uniform float near_clip;
void main()
{
//transform vertex
gl_Position = ftransform();
vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;
vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip);
vec4 tex = gl_MultiTexCoord0;
tex.w = 1.0;
vary_light = gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
}

View File

@@ -0,0 +1,14 @@
/**
* @file shadowF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
void main()
{
gl_FragColor = vec4(1,1,1,texture2D(diffuseMap, gl_TexCoord[0].xy).a * gl_Color.a);
}

View File

@@ -0,0 +1,17 @@
/**
* @file shadowV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void main()
{
//transform vertex
vec4 pos = gl_ModelViewProjectionMatrix*gl_Vertex;
//smash geometry against the near clip plane (great for ortho projections)
pos.z = max(pos.z, -1.0);
gl_Position = pos;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
}

View File

@@ -0,0 +1,279 @@
/**
* @file softenLightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect diffuseRect;
uniform sampler2DRect specularRect;
uniform sampler2DRect positionMap;
uniform sampler2DRect normalMap;
uniform sampler2DRect depthMap;
uniform sampler2DRect lightMap;
uniform sampler2D noiseMap;
uniform samplerCube environmentMap;
uniform float blur_size;
uniform float blur_fidelity;
// Inputs
uniform vec4 morphFactor;
uniform vec3 camPosLocal;
//uniform vec4 camPosWorld;
uniform vec4 gamma;
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;
uniform float scene_light_strength;
uniform vec3 env_mat[3];
uniform mat4 shadow_matrix[3];
uniform vec4 shadow_clip;
uniform mat3 ssao_effect_mat;
varying vec4 vary_light;
varying vec2 vary_fragcoord;
vec3 vary_PositionEye;
vec3 vary_SunlitColor;
vec3 vary_AmblitColor;
vec3 vary_AdditiveColor;
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;
}
void calcAtmospherics(vec3 inPositionEye, float ambFactor) {
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);
//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;
/* decrease value and saturation (that in HSV, not HSL) for occluded areas
* // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html
* // The following line of code performs the equivalent of:
* float ambAlpha = tmpAmbient.a;
* float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis
* vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue);
* tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha);
*/
tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a);
//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));
}
vec3 atmosLighting(vec3 light)
{
light *= getAtmosAttenuation().r;
light += getAdditiveColor();
return (2.0 * light);
}
vec3 atmosTransport(vec3 light) {
light *= getAtmosAttenuation().r;
light += getAdditiveColor() * 2.0;
return light;
}
vec3 atmosGetDiffuseSunlightColor()
{
return getSunlitColor();
}
vec3 scaleDownLight(vec3 light)
{
return (light / scene_light_strength );
}
vec3 scaleUpLight(vec3 light)
{
return (light * scene_light_strength);
}
vec3 atmosAmbient(vec3 light)
{
return getAmblitColor() + light / 2.0;
}
vec3 atmosAffectDirectionalLight(float lightIntensity)
{
return getSunlitColor() * lightIntensity;
}
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()
{
vec2 tc = vary_fragcoord.xy;
vec3 pos = texture2DRect(positionMap, tc).xyz;
vec3 norm = texture2DRect(normalMap, tc).xyz;
vec3 nz = texture2D(noiseMap, vary_fragcoord.xy/128.0).xyz;
float da = max(dot(norm.xyz, vary_light.xyz), 0.0);
vec4 diffuse = vec4(texture2DRect(diffuseRect, tc).rgb, 1.0);
vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg;
float scol = scol_ambocc.r;
float ambocc = scol_ambocc.g;
calcAtmospherics(pos.xyz, ambocc);
vec3 col = atmosAmbient(vec3(0));
col += atmosAffectDirectionalLight(min(da, scol));
col *= diffuse.rgb;
if (spec.a > 0.2)
{
vec3 ref = reflect(pos.xyz, norm.xyz);
vec3 rc;
rc.x = dot(ref, env_mat[0]);
rc.y = dot(ref, env_mat[1]);
rc.z = dot(ref, env_mat[2]);
vec3 refcol = textureCube(environmentMap, rc).rgb;
col.rgb += refcol * spec.rgb;
}
col = atmosLighting(col);
col = scaleSoftClip(col);
gl_FragColor.rgb = col;
gl_FragColor.a = 0.0;
//gl_FragColor.rg = scol_ambocc.rg;
//gl_FragColor.rgb = norm.rgb*0.5+0.5;
//gl_FragColor.rgb = vec3(ambocc);
//gl_FragColor.rgb = vec3(scol);
}

View File

@@ -0,0 +1,24 @@
/**
* @file softenLightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform vec2 screen_res;
varying vec4 vary_light;
varying vec2 vary_fragcoord;
void main()
{
//transform vertex
gl_Position = ftransform();
vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;
vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
vec4 tex = gl_MultiTexCoord0;
tex.w = 1.0;
vary_light = gl_MultiTexCoord0;
}

View File

@@ -0,0 +1,139 @@
/**
* @file sunLightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect positionMap;
uniform sampler2DRect normalMap;
uniform sampler2DRect depthMap;
uniform sampler2DShadow shadowMap0;
uniform sampler2DShadow shadowMap1;
uniform sampler2DShadow shadowMap2;
uniform sampler2DShadow shadowMap3;
uniform sampler2D noiseMap;
// Inputs
uniform mat4 shadow_matrix[4];
uniform vec4 shadow_clip;
uniform float ssao_radius;
uniform float ssao_max_radius;
uniform float ssao_factor;
uniform float ssao_factor_inv;
varying vec2 vary_fragcoord;
varying vec4 vary_light;
//calculate decreases in ambient lighting when crowded out (SSAO)
float calcAmbientOcclusion(vec4 pos, vec3 norm)
{
vec2 kern[8];
// exponentially (^2) distant occlusion samples spread around origin
kern[0] = vec2(-1.0, 0.0) * 0.125*0.125;
kern[1] = vec2(1.0, 0.0) * 0.250*0.250;
kern[2] = vec2(0.0, 1.0) * 0.375*0.375;
kern[3] = vec2(0.0, -1.0) * 0.500*0.500;
kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625;
kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750;
kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875;
kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000;
vec2 pos_screen = vary_fragcoord.xy;
vec3 pos_world = pos.xyz;
vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy;
float angle_hidden = 0.0;
int points = 0;
float scale = min(ssao_radius / -pos_world.z, ssao_max_radius);
// it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?)
for (int i = 0; i < 8; i++)
{
vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect);
vec3 samppos_world = texture2DRect(positionMap, samppos_screen).xyz;
vec3 diff = pos_world - samppos_world;
float dist2 = dot(diff, diff);
// assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area
// --> solid angle shrinking by the square of distance
//radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2
//(k should vary inversely with # of samples, but this is taken care of later)
//if (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) // -0.05*norm to shift sample point back slightly for flat surfaces
// angle_hidden += min(1.0/dist2, ssao_factor_inv); // dist != 0 follows from conditional. max of 1.0 (= ssao_factor_inv * ssao_factor)
angle_hidden = angle_hidden + float(dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) * min(1.0/dist2, ssao_factor_inv);
// 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion"
points = points + int(diff.z > -1.0);
}
angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0);
return 1.0 - (float(points != 0) * angle_hidden);
}
void main()
{
vec2 pos_screen = vary_fragcoord.xy;
vec4 pos = vec4(texture2DRect(positionMap, pos_screen).xyz, 1.0);
vec3 norm = texture2DRect(normalMap, pos_screen).xyz;
/*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL
{
gl_FragColor = vec4(0.0); // doesn't matter
return;
}*/
float shadow = 1.0;
float dp_directional_light = max(0.0, dot(norm, vary_light.xyz));
if (dp_directional_light == 0.0)
{
// if we know this point is facing away from the sun then we know it's in shadow without having to do a squirrelly shadow-map lookup
shadow = 0.0;
}
else if (pos.z > -shadow_clip.w)
{
if (pos.z < -shadow_clip.z)
{
vec4 lpos = shadow_matrix[3]*pos;
shadow = shadow2DProj(shadowMap3, lpos).x;
shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);
}
else if (pos.z < -shadow_clip.y)
{
vec4 lpos = shadow_matrix[2]*pos;
shadow = shadow2DProj(shadowMap2, lpos).x;
}
else if (pos.z < -shadow_clip.x)
{
vec4 lpos = shadow_matrix[1]*pos;
shadow = shadow2DProj(shadowMap1, lpos).x;
}
else
{
vec4 lpos = shadow_matrix[0]*pos;
shadow = shadow2DProj(shadowMap0, lpos).x;
}
// take the most-shadowed value out of these two:
// * the blurred sun shadow in the light (shadow) map
// * an unblurred dot product between the sun and this norm
// the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting
shadow = min(shadow, dp_directional_light);
}
else
{
// more distant than the shadow map covers - just use directional shading as shadow
shadow = dp_directional_light;
}
gl_FragColor[0] = shadow;
gl_FragColor[1] = calcAmbientOcclusion(pos, norm);
//gl_FragColor[2] is unused as of August 2008, may be used for debugging
}

View File

@@ -0,0 +1,25 @@
/**
* @file sunLightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec4 vary_light;
varying vec2 vary_fragcoord;
uniform vec2 screen_res;
void main()
{
//transform vertex
gl_Position = ftransform();
vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;
vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;
vec4 tex = gl_MultiTexCoord0;
tex.w = 1.0;
vary_light = gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
}

View File

@@ -0,0 +1,36 @@
/**
* @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;
varying vec3 vary_normal;
varying vec4 vary_position;
void main()
{
/// Note: This should duplicate the blending functionality currently used for the terrain rendering.
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 );
gl_FragData[0] = vec4(outColor.rgb, 1.0);
gl_FragData[1] = vec4(outColor.rgb*0.2, 0.2);
gl_FragData[2] = vec4(normalize(vary_normal), 0.0);
gl_FragData[3] = vary_position;
}

View File

@@ -0,0 +1,41 @@
/**
* @file terrainV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec3 vary_normal;
varying vec4 vary_position;
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;
vary_position = gl_ModelViewMatrix * gl_Vertex;
vary_normal = normalize(gl_NormalMatrix * gl_Normal);
// 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,20 @@
/**
* @file treeF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
varying vec3 vary_normal;
varying vec4 vary_position;
void main()
{
vec4 col = texture2D(diffuseMap, gl_TexCoord[0].xy);
gl_FragData[0] = gl_Color*col;
gl_FragData[1] = vec4(0,0,0,0);
gl_FragData[2] = vec4(normalize(vary_normal), 0.0);
gl_FragData[3] = vary_position;
}

View File

@@ -0,0 +1,22 @@
/**
* @file treeV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec3 vary_normal;
varying vec4 vary_position;
void main()
{
//transform vertex
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vary_position = gl_ModelViewMatrix * gl_Vertex;
vary_normal = normalize(gl_NormalMatrix * gl_Normal);
gl_FrontColor = gl_Color;
}

View File

@@ -0,0 +1,157 @@
/**
* @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 sampler2DShadow shadowMap0;
uniform sampler2DShadow shadowMap1;
uniform sampler2DShadow shadowMap2;
uniform sampler2DShadow shadowMap3;
uniform sampler2D noiseMap;
uniform mat4 shadow_matrix[4];
uniform vec4 shadow_clip;
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;
varying vec4 vary_position;
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);
float shadow = 1.0;
vec4 pos = vary_position;
vec3 nz = texture2D(noiseMap, gl_FragCoord.xy/128.0).xyz;
if (pos.z > -shadow_clip.w)
{
vec4 spos = pos;
if (pos.z < -shadow_clip.z)
{
vec4 lpos = (shadow_matrix[3]*spos);
shadow = shadow2DProj(shadowMap3, lpos).x;
}
else if (pos.z < -shadow_clip.y)
{
vec4 lpos = (shadow_matrix[2]*spos);
shadow = shadow2DProj(shadowMap2, lpos).x;
}
else if (pos.z < -shadow_clip.x)
{
vec4 lpos = (shadow_matrix[1]*spos);
shadow = shadow2DProj(shadowMap1, lpos).x;
}
else
{
vec4 lpos = (shadow_matrix[0]*spos);
shadow = shadow2DProj(shadowMap0, lpos).x;
}
}
spec *= shadow;
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,76 @@
/**
* @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;
varying vec4 vary_position;
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);
vary_position = gl_ModelViewMatrix * oPosition;
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;
}

View File

@@ -0,0 +1,28 @@
/**
* @file glowExtractF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect diffuseMap;
uniform float minLuminance;
uniform float maxExtractAlpha;
uniform vec3 lumWeights;
uniform vec3 warmthWeights;
uniform float warmthAmount;
void main()
{
vec4 col = texture2DRect(diffuseMap, gl_TexCoord[0].xy);
/// CALCULATING LUMINANCE (Using NTSC lum weights)
/// http://en.wikipedia.org/wiki/Luma_%28video%29
float lum = smoothstep(minLuminance, minLuminance+1.0, dot(col.rgb, lumWeights ) );
float warmth = smoothstep(minLuminance, minLuminance+1.0, max(col.r * warmthWeights.r, max(col.g * warmthWeights.g, col.b * warmthWeights.b)) );
gl_FragColor.rgb = col.rgb;
gl_FragColor.a = max(col.a, mix(lum, warmth, warmthAmount) * maxExtractAlpha);
}

View File

@@ -0,0 +1,14 @@
/**
* @file glowExtractV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
}

View File

@@ -0,0 +1,31 @@
/**
* @file glowF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform float glowStrength;
void main()
{
vec4 col = vec4(0.0, 0.0, 0.0, 0.0);
// ATI compiler falls down on array initialization.
float kern[8];
kern[0] = 0.25; kern[1] = 0.5; kern[2] = 0.8; kern[3] = 1.0;
kern[4] = 1.0; kern[5] = 0.8; kern[6] = 0.5; kern[7] = 0.25;
col += kern[0] * texture2D(diffuseMap, gl_TexCoord[0].xy);
col += kern[1] * texture2D(diffuseMap, gl_TexCoord[1].xy);
col += kern[2] * texture2D(diffuseMap, gl_TexCoord[2].xy);
col += kern[3] * texture2D(diffuseMap, gl_TexCoord[3].xy);
col += kern[4] * texture2D(diffuseMap, gl_TexCoord[0].zw);
col += kern[5] * texture2D(diffuseMap, gl_TexCoord[1].zw);
col += kern[6] * texture2D(diffuseMap, gl_TexCoord[2].zw);
col += kern[7] * texture2D(diffuseMap, gl_TexCoord[3].zw);
gl_FragColor = vec4(col.rgb * glowStrength, col.a);
}

View File

@@ -0,0 +1,22 @@
/**
* @file glowV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform vec2 glowDelta;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0].xy = gl_MultiTexCoord0.xy + glowDelta*(-3.5);
gl_TexCoord[1].xy = gl_MultiTexCoord0.xy + glowDelta*(-2.5);
gl_TexCoord[2].xy = gl_MultiTexCoord0.xy + glowDelta*(-1.5);
gl_TexCoord[3].xy = gl_MultiTexCoord0.xy + glowDelta*(-0.5);
gl_TexCoord[0].zw = gl_MultiTexCoord0.xy + glowDelta*(0.5);
gl_TexCoord[1].zw = gl_MultiTexCoord0.xy + glowDelta*(1.5);
gl_TexCoord[2].zw = gl_MultiTexCoord0.xy + glowDelta*(2.5);
gl_TexCoord[3].zw = gl_MultiTexCoord0.xy + glowDelta*(3.5);
}

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;
}

View File

@@ -0,0 +1,13 @@
/**
* @file highlightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
void main()
{
gl_FragColor = gl_Color*texture2D(diffuseMap, gl_TexCoord[0].xy);
}

View File

@@ -0,0 +1,25 @@
/**
* @file highlightV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void main()
{
//transform vertex
gl_Position = ftransform();
vec3 pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
pos = normalize(pos);
float d = dot(pos, normalize(gl_NormalMatrix * gl_Normal));
d *= d;
d = 1.0 - d;
d *= d;
d = min(d, gl_Color.a*2.0);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_FrontColor.rgb = gl_Color.rgb;
gl_FrontColor.a = max(d, gl_Color.a);
}

View File

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

View File

@@ -0,0 +1,15 @@
/**
* @file lightFullbrightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
void fullbright_lighting()
{
gl_FragColor = texture2D(diffuseMap, gl_TexCoord[0].xy);
}

View File

@@ -0,0 +1,15 @@
/**
* @file lightFullbrightShinyF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform samplerCube environmentMap;
void fullbright_shiny_lighting()
{
gl_FragColor = texture2D(diffuseMap, gl_TexCoord[0].xy);
}

View File

@@ -0,0 +1,15 @@
/**
* @file lightFullbrightWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
void fullbright_lighting_water()
{
gl_FragColor = texture2D(diffuseMap, gl_TexCoord[0].xy);
}

View File

@@ -0,0 +1,46 @@
/**
* @file lightFuncSpecularV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
float calcDirectionalLight(vec3 n, vec3 l)
{
float a = max(dot(n,l),0.0);
return a;
}
float calcDirectionalSpecular(vec3 view, vec3 n, vec3 l)
{
return pow(max(dot(reflect(view, n),l), 0.0),8.0);
}
float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da)
{
specular.rgb += calcDirectionalSpecular(view,n,l)*lightCol*da;
return max(dot(n,l),0.0);
}
vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol)
{
//get light vector
vec3 lv = l-v;
//get distance
float d = length(lv);
//normalize light vector
lv *= 1.0/d;
//distance attenuation
float da = clamp(1.0/(r * d), 0.0, 1.0);
//angular attenuation
da *= calcDirectionalLightSpecular(specular, view, n, lv, lightCol, da);
return da*lightCol;
}

View File

@@ -0,0 +1,34 @@
/**
* @file lightFuncV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
float calcDirectionalLight(vec3 n, vec3 l)
{
float a = max(dot(n,l),0.0);
return a;
}
float calcPointLight(vec3 v, vec3 n, vec4 lp, float la)
{
//get light vector
vec3 lv = lp.xyz-v;
//get distance
float d = length(lv);
//normalize light vector
lv *= 1.0/d;
//distance attenuation
float da = clamp(1.0/(la * d), 0.0, 1.0);
//angular attenuation
da *= calcDirectionalLight(n, lv);
return da;
}

View File

@@ -0,0 +1,17 @@
/**
* @file lightShinyF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform samplerCube environmentMap;
void shiny_lighting()
{
vec4 color = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].xy);
gl_FragColor = color;
}

View File

@@ -0,0 +1,17 @@
/**
* @file lightShinyWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform sampler2D diffuseMap;
uniform samplerCube environmentMap;
void shiny_lighting_water()
{
vec4 color = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].xy);
gl_FragColor = color;
}

View File

@@ -0,0 +1,26 @@
/**
* @file lightV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
float calcDirectionalLight(vec3 n, vec3 l);
// Same as non-specular lighting in lightV.glsl
vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol)
{
specularColor.rgb = vec3(0.0, 0.0, 0.0);
vec4 col;
col.a = color.a;
col.rgb = gl_LightModel.ambient.rgb + baseCol.rgb;
col.rgb += gl_LightSource[0].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[0].position.xyz);
col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
col.rgb = min(col.rgb*color.rgb, 1.0);
return col;
}

View File

@@ -0,0 +1,24 @@
/**
* @file lightV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
float calcDirectionalLight(vec3 n, vec3 l);
vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
{
vec4 col;
col.a = color.a;
col.rgb = gl_LightModel.ambient.rgb + baseLight.rgb;
col.rgb += gl_LightSource[0].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[0].position.xyz);
col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
col.rgb = min(col.rgb*color.rgb, 1.0);
return col;
}

View File

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

View File

@@ -0,0 +1,35 @@
/**
* @file sumLightsSpecularV.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 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;
col.a = color.a;
vec3 view = normalize(pos);
/// collect all the specular values from each calcXXXLightSpecular() function
vec4 specularSum = vec4(0.0);
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 = scaleDownLight(col.rgb);
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,29 @@
/**
* @file sumLightsV.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
float calcDirectionalLight(vec3 n, vec3 l);
vec3 atmosAmbient(vec3 light);
vec3 atmosAffectDirectionalLight(float lightIntensity);
vec3 scaleDownLight(vec3 light);
vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight)
{
vec4 col;
col.a = color.a;
col.rgb = gl_LightSource[1].diffuse.rgb * calcDirectionalLight(norm, gl_LightSource[1].position.xyz);
col.rgb = scaleDownLight(col.rgb);
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,13 @@
/**
* @file fullbrightF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void fullbright_lighting();
void main()
{
fullbright_lighting();
}

View File

@@ -0,0 +1,13 @@
/**
* @file fullbrightShinyF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void fullbright_shiny_lighting();
void main()
{
fullbright_shiny_lighting();
}

View File

@@ -0,0 +1,29 @@
/**
* @file fullbrightShinyV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
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 = gl_Color;
gl_FogFragCoord = pos.z;
}

View File

@@ -0,0 +1,23 @@
/**
* @file fullbrightV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void calcAtmospherics(vec3 inPositionEye);
void main()
{
//transform vertex
gl_Position = ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
vec4 pos = (gl_ModelViewMatrix * gl_Vertex);
calcAtmospherics(pos.xyz);
gl_FrontColor = gl_Color;
gl_FogFragCoord = pos.z;
}

View File

@@ -0,0 +1,13 @@
/**
* @file fullbrightWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void fullbright_lighting_water();
void main()
{
fullbright_lighting_water();
}

View File

@@ -0,0 +1,13 @@
/**
* @file shinyF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void shiny_lighting();
void main()
{
shiny_lighting();
}

View File

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

View File

@@ -0,0 +1,13 @@
/**
* @file shinyWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void shiny_lighting_water();
void main()
{
shiny_lighting_water();
}

View File

@@ -0,0 +1,13 @@
/**
* @file simpleF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void default_lighting();
void main()
{
default_lighting();
}

View File

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

View File

@@ -0,0 +1,13 @@
/**
* @file simpleWaterF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void default_lighting_water();
void main()
{
default_lighting_water();
}

View File

@@ -0,0 +1,13 @@
/**
* @file atmosphericsF.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec3 atmosLighting(vec3 light)
{
/* stub function for fallback compatibility on class1 hardware */
return light;
}

View File

@@ -0,0 +1,34 @@
/**
* @file atmosphericsHelpersV.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec3 atmosAmbient(vec3 light)
{
return gl_LightModel.ambient.rgb + light;
}
vec3 atmosAffectDirectionalLight(float lightIntensity)
{
return gl_LightSource[0].diffuse.rgb * lightIntensity;
}
vec3 atmosGetDiffuseSunlightColor()
{
return gl_LightSource[0].diffuse.rgb;
}
vec3 scaleDownLight(vec3 light)
{
/* stub function for fallback compatibility on class1 hardware */
return light;
}
vec3 scaleUpLight(vec3 light)
{
/* stub function for fallback compatibility on class1 hardware */
return light;
}

View File

@@ -0,0 +1,15 @@
/**
* @file atmosphericsV.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
void setPositionEye(vec3 v);
void calcAtmospherics(vec3 inPositionEye)
{
/* stub function for fallback compatibility on class1 hardware */
setPositionEye(inPositionEye);
}

View File

@@ -0,0 +1,13 @@
/**
* @file atmosphericVarsF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec3 vary_PositionEye;
vec3 getPositionEye()
{
return vary_PositionEye;
}

View File

@@ -0,0 +1,19 @@
/**
* @file atmosphericVarsV.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
varying vec3 vary_PositionEye;
vec3 getPositionEye()
{
return vary_PositionEye;
}
void setPositionEye(vec3 v)
{
vary_PositionEye = v;
}

View File

@@ -0,0 +1,19 @@
/**
* @file gammaF.glsl
*
* Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
* $License$
*/
uniform vec4 gamma;
/// Soft clips the light with a gamma correction
vec3 scaleSoftClip(vec3 light) {
// For compatibility with lower cards. Do nothing.
return light;
}
vec3 fullbrightScaleSoftClip(vec3 light) {
return scaleSoftClip(light);
}

View File

@@ -0,0 +1,26 @@
/**
* @file transportF.glsl
*
* Copyright (c) 2005-$CurrentYear$, Linden Research, Inc.
* $License$
*/
vec3 atmosTransport(vec3 light)
{
/* stub function for fallback compatibility on class1 hardware */
return light;
}
vec3 fullbrightAtmosTransport(vec3 light)
{
/* stub function for fallback compatibility on class1 hardware */
return light;
}
vec3 fullbrightShinyAtmosTransport(vec3 light)
{
/* stub function for fallback compatibility on class1 hardware */
return light;
}

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;
}

Some files were not shown because too many files have changed in this diff Show More