summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class2
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/app_settings/shaders/class2')
-rw-r--r--indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl23
-rw-r--r--indra/newview/app_settings/shaders/class2/environment/waterF.glsl136
-rw-r--r--indra/newview/app_settings/shaders/class2/lighting/lightF.glsl36
-rw-r--r--indra/newview/app_settings/shaders/class2/lighting/lightV.glsl126
4 files changed, 321 insertions, 0 deletions
diff --git a/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl b/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl
new file mode 100644
index 0000000000..7957eddb31
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class2/avatar/eyeballV.glsl
@@ -0,0 +1,23 @@
+vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec3 baseCol);
+void default_scatter(vec3 viewVec, vec3 lightDir);
+
+attribute vec4 materialColor;
+attribute vec4 specularColor;
+
+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);
+
+ default_scatter(pos.xyz, gl_LightSource[0].position.xyz);
+ vec4 specular = specularColor;
+ vec4 color = calcLightingSpecular(pos, norm, materialColor, specular, gl_Color.rgb);
+
+ gl_FrontColor = color;
+ gl_FogFragCoord = pos.z;
+}
+
diff --git a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl
new file mode 100644
index 0000000000..e0e79e95ba
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl
@@ -0,0 +1,136 @@
+void applyScatter(inout vec3 color);
+
+uniform sampler2D diffuseMap;
+uniform sampler2D bumpMap;
+uniform samplerCube environmentMap; //: TEXUNIT4, // Environment map texture
+uniform sampler2D screenTex; // : TEXUNIT5
+
+uniform vec3 lightDir;
+uniform vec3 specular;
+uniform float lightExp;
+uniform vec2 fbScale;
+uniform float refScale;
+
+float msin(float x) {
+ float k = sin(x)+1.0;
+ k *= 0.5;
+ k *= k;
+ return 2.0 * k;
+}
+
+float mcos(float x) {
+ float k = cos(x)+1.0;
+ k *= 0.5;
+ k *= k;
+ return 2.0 * k;
+}
+
+float waveS(vec2 v, float t, float a, float f, vec2 d, float s, sampler1D sinMap)
+{
+ return texture1D(sinMap, (dot(d, v)*f + t*s)*f).r*a;
+}
+
+float waveC(vec2 v, float t, float a, float f, vec2 d, float s, sampler1D sinMap)
+{
+ return texture1D(sinMap, (dot(d, v)*f + t*s)*f).g*a*2.0-1.0;
+}
+
+float magnitude(vec3 vec) {
+ return sqrt(dot(vec,vec));
+}
+
+vec3 mreflect(vec3 i, vec3 n) {
+ return i + n * 2.0 * abs(dot(n,i))+vec3(0.0,0.0,0.5);
+}
+
+void main()
+{
+ vec2 texCoord = gl_TexCoord[0].xy; // Texture coordinates
+ vec2 littleWave1 = gl_TexCoord[0].zw;
+ vec2 littleWave2 = gl_TexCoord[1].xy;
+ vec2 bigWave = gl_TexCoord[1].zw;
+ vec3 viewVec = gl_TexCoord[2].xyz;
+ vec4 refCoord = gl_TexCoord[3];
+ vec4 col = gl_Color;
+ vec4 color;
+
+ //get color from alpha map (alpha denotes water depth), rgb denotes water color
+ vec4 wcol = texture2D(diffuseMap, texCoord.xy);
+
+ //store texture alpha
+ float da = wcol.a;
+
+ //modulate by incoming water color
+ //wcol.a *= refCoord.w;
+
+ //scale wcol.a (water depth) for steep transition
+ wcol.a *= wcol.a;
+
+ //normalize view vector
+ viewVec = normalize(viewVec);
+
+ //get bigwave normal
+ vec3 wavef = texture2D(bumpMap, bigWave).xyz*2.0;
+
+ vec3 view = vec3(viewVec.x, viewVec.y, viewVec.z);
+
+ float dx = 1.0-(dot(wavef*2.0-vec3(1.0), view))*da;
+ dx *= 0.274;
+
+ //get detail normals
+ vec3 dcol = texture2D(bumpMap, littleWave1+dx*view.xy).rgb*0.75;
+ dcol += texture2D(bumpMap, littleWave2+view.xy*dx*0.1).rgb*1.25;
+
+ //interpolate between big waves and little waves (big waves in deep water)
+ wavef = wavef*wcol.a + dcol*(1.0-wcol.a);
+
+ //crunch normal to range [-1,1]
+ wavef -= vec3(1,1,1);
+
+ //get base fresnel component
+ float df = dot(viewVec,wavef);
+ //reposition fresnel to latter half of [0,1]
+ df = 1.0-clamp(df,0.0,1.0);
+
+ //set output alpha based on fresnel
+ color.a = clamp((df+da)*0.5,0.0,1.0);
+
+ //calculate reflection vector
+ vec3 ref = reflect(viewVec.xyz, wavef);
+
+ //get specular component
+ float spec = clamp(dot(lightDir, normalize(ref)),0.0,1.0);
+
+ //fudge reflection to be more noisy at good angles
+ ref.z = ref.z*ref.z+df*df*0.5;
+
+ //get diffuse component
+ float diff = clamp((abs(dot(ref, wavef))),0.0,1.0)*0.9;
+
+ //fudge diffuse for extra contrast and ambience
+ diff *= diff;
+ diff += 0.4;
+
+ //set diffuse color contribution
+ color.rgb = textureCube(environmentMap, ref).rgb*diff;
+
+ //harden specular
+ spec = pow(spec, lightExp);
+
+ //add specular color contribution
+ color.rgb += spec * specular;
+
+ //figure out distortion vector (ripply)
+ vec2 distort = clamp(((refCoord.xy/refCoord.z) * 0.5 + 0.5 + wavef.xy*refScale),0.0,0.99);
+
+ //read from framebuffer (offset)
+ vec4 fb = texture2D(screenTex, distort*fbScale);
+
+ //tint by framebuffer
+ color.rgb = color.a*color.rgb + (1.0-color.a)*fb.rgb;
+
+ //apply fog
+ applyScatter(color.rgb);
+
+ gl_FragColor = color;
+}
diff --git a/indra/newview/app_settings/shaders/class2/lighting/lightF.glsl b/indra/newview/app_settings/shaders/class2/lighting/lightF.glsl
new file mode 100644
index 0000000000..0ef1129253
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class2/lighting/lightF.glsl
@@ -0,0 +1,36 @@
+void applyScatter(inout vec3 color);
+
+uniform sampler2D diffuseMap;
+
+void default_lighting()
+{
+ vec4 color = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].xy);
+ applyScatter(color.rgb);
+ gl_FragColor = color;
+}
+
+void alpha_lighting()
+{
+ vec4 diff = texture2D(diffuseMap, gl_TexCoord[0].xy);
+ vec3 color = gl_Color.rgb * diff.rgb;
+ applyScatter(color);
+ gl_FragColor.rgb = color;
+ gl_FragColor.a = diff.a * gl_Color.a;
+}
+
+void water_lighting(inout vec3 diff)
+{
+ diff = (diff*0.9 + gl_Color.rgb*0.1);
+ applyScatter(diff);
+}
+
+void terrain_lighting(inout vec3 color)
+{
+ color.rgb *= gl_Color.rgb;
+ applyScatter(color);
+}
+
+vec4 getLightColor()
+{
+ return gl_Color;
+} \ No newline at end of file
diff --git a/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl
new file mode 100644
index 0000000000..b15960dea2
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class2/lighting/lightV.glsl
@@ -0,0 +1,126 @@
+// All lights, no specular highlights
+
+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;
+}
+
+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 calcDirectionalLight(n,l);
+}
+
+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;
+}
+
+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 += 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 += gl_LightSource[5].diffuse.rgb*calcPointLight(pos, norm, gl_LightSource[5].position, gl_LightSource[5].linearAttenuation);
+ col.rgb += gl_LightSource[6].diffuse.rgb*calcPointLight(pos, norm, gl_LightSource[6].position, gl_LightSource[6].linearAttenuation);
+ col.rgb += gl_LightSource[7].diffuse.rgb*calcPointLight(pos, norm, gl_LightSource[7].position, gl_LightSource[7].linearAttenuation);
+
+ col.rgb = min(col.rgb*color.rgb, 1.0);
+
+ gl_FrontColor = vec4(col.rgb, col.a);
+ return col;
+}
+
+vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec3 baseLight)
+{
+ return calcLighting(pos, norm, color, vec4(baseLight, 1.0));
+}
+
+vec4 calcLighting(vec3 pos, vec3 norm, vec4 color)
+{
+ return calcLighting(pos, norm, color, vec3(0.0,0.0,0.0));
+}
+
+vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol)
+{
+ vec4 col;
+ col.a = color.a;
+
+ col.rgb = gl_LightModel.ambient.rgb;
+
+ vec3 view = normalize(pos);
+
+ vec4 specular = specularColor;
+ specularColor.rgb = vec3(0.0, 0.0, 0.0);
+
+ col.rgb += baseCol.a*gl_LightSource[0].diffuse.rgb*calcDirectionalLightSpecular(specularColor, view, norm, gl_LightSource[0].position.xyz,gl_LightSource[0].diffuse.rgb*baseCol.a, 1.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 += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[2].position.xyz, gl_LightSource[2].linearAttenuation, gl_LightSource[2].quadraticAttenuation,gl_LightSource[2].diffuse.rgb);
+ col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[3].position.xyz, gl_LightSource[3].linearAttenuation, gl_LightSource[3].quadraticAttenuation,gl_LightSource[3].diffuse.rgb);
+ col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[4].position.xyz, gl_LightSource[4].linearAttenuation, gl_LightSource[4].quadraticAttenuation,gl_LightSource[4].diffuse.rgb);
+ col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[5].position.xyz, gl_LightSource[5].linearAttenuation, gl_LightSource[5].quadraticAttenuation,gl_LightSource[5].diffuse.rgb);
+ //col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[6].position.xyz, gl_LightSource[6].linearAttenuation, gl_LightSource[6].quadraticAttenuation,gl_LightSource[6].diffuse.rgb);
+ //col.rgb += calcPointLightSpecular(specularColor, view, pos, norm, gl_LightSource[7].position.xyz, gl_LightSource[7].linearAttenuation, gl_LightSource[7].quadraticAttenuation,gl_LightSource[7].diffuse.rgb);
+ col.rgb += baseCol.rgb;
+
+ col.rgb = min(col.rgb*color.rgb, 1.0);
+ specularColor.rgb = min(specularColor.rgb*specular.rgb, 1.0);
+
+ gl_FrontColor = vec4(col.rgb+specularColor.rgb,col.a);
+ return col;
+}
+
+vec4 calcLightingSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec3 baseCol)
+{
+ return calcLightingSpecular(pos, norm, color, specularColor, vec4(baseCol, 1.0));
+}