diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/newview/app_settings/shaders | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2 meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz |
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/newview/app_settings/shaders')
10 files changed, 188 insertions, 67 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl b/linden/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl index b2a6d67..c169fce 100644 --- a/linden/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl +++ b/linden/indra/newview/app_settings/shaders/class1/lighting/lightF.glsl | |||
@@ -5,7 +5,7 @@ uniform sampler2D diffuseMap; | |||
5 | void default_lighting() | 5 | void default_lighting() |
6 | { | 6 | { |
7 | vec4 color = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].xy); | 7 | vec4 color = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].xy); |
8 | applyScatter(color.rgb); | 8 | //applyScatter(color.rgb); |
9 | gl_FragColor = color; | 9 | gl_FragColor = color; |
10 | } | 10 | } |
11 | 11 | ||
diff --git a/linden/indra/newview/app_settings/shaders/class1/objects/shinyF.glsl b/linden/indra/newview/app_settings/shaders/class1/objects/shinyF.glsl new file mode 100644 index 0000000..12c99a6 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class1/objects/shinyF.glsl | |||
@@ -0,0 +1,13 @@ | |||
1 | void applyScatter(inout vec3 col); | ||
2 | |||
3 | uniform samplerCube environmentMap; | ||
4 | |||
5 | void main() | ||
6 | { | ||
7 | vec3 ref = textureCube(environmentMap, gl_TexCoord[0].xyz).rgb; | ||
8 | |||
9 | applyScatter(ref); | ||
10 | |||
11 | gl_FragColor.rgb = ref; | ||
12 | gl_FragColor.a = gl_Color.a; | ||
13 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl b/linden/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl new file mode 100644 index 0000000..621ff6b --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class1/objects/shinyV.glsl | |||
@@ -0,0 +1,27 @@ | |||
1 | void default_scatter(vec3 viewVec, vec3 lightDir); | ||
2 | |||
3 | uniform vec4 origin; | ||
4 | |||
5 | void main() | ||
6 | { | ||
7 | //transform vertex | ||
8 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; | ||
9 | |||
10 | vec3 pos = (gl_ModelViewMatrix * gl_Vertex).xyz; | ||
11 | vec3 norm = normalize(gl_NormalMatrix * gl_Normal); | ||
12 | |||
13 | gl_FrontColor = gl_Color; | ||
14 | |||
15 | vec3 ref = reflect(pos, norm); | ||
16 | |||
17 | vec3 d = pos - origin.xyz; | ||
18 | float dist = dot(normalize(d), ref); | ||
19 | vec3 e = d + (ref * max(origin.w-dist, 0.0)); | ||
20 | |||
21 | ref = e - origin.xyz; | ||
22 | |||
23 | gl_TexCoord[0] = gl_TextureMatrix[0]*vec4(ref,1.0); | ||
24 | |||
25 | default_scatter(pos.xyz, gl_LightSource[0].position.xyz); | ||
26 | } | ||
27 | |||
diff --git a/linden/indra/newview/app_settings/shaders/class2/environment/waterV.glsl b/linden/indra/newview/app_settings/shaders/class2/environment/waterV.glsl index 5f06aeb..25309fa 100644 --- a/linden/indra/newview/app_settings/shaders/class2/environment/waterV.glsl +++ b/linden/indra/newview/app_settings/shaders/class2/environment/waterV.glsl | |||
@@ -47,7 +47,7 @@ void main() | |||
47 | gl_TexCoord[0].zw = littleWave1; | 47 | gl_TexCoord[0].zw = littleWave1; |
48 | gl_TexCoord[1].xy = littleWave2; | 48 | gl_TexCoord[1].xy = littleWave2; |
49 | gl_TexCoord[1].zw = bigWave; | 49 | gl_TexCoord[1].zw = bigWave; |
50 | gl_TexCoord[2] = oEyeVec; | 50 | gl_TexCoord[2].xyz = oEyeVec.xyz; |
51 | gl_TexCoord[3].xyz = oRefCoord; | 51 | gl_TexCoord[3].xyz = oRefCoord; |
52 | gl_FrontColor = col; | 52 | gl_FrontColor = col; |
53 | } | 53 | } |
diff --git a/linden/indra/newview/app_settings/shaders/class2/lighting/lightF.glsl b/linden/indra/newview/app_settings/shaders/class2/lighting/lightF.glsl index 0ef1129..6f732ed 100644 --- a/linden/indra/newview/app_settings/shaders/class2/lighting/lightF.glsl +++ b/linden/indra/newview/app_settings/shaders/class2/lighting/lightF.glsl | |||
@@ -5,7 +5,7 @@ uniform sampler2D diffuseMap; | |||
5 | void default_lighting() | 5 | void default_lighting() |
6 | { | 6 | { |
7 | vec4 color = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].xy); | 7 | vec4 color = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].xy); |
8 | applyScatter(color.rgb); | 8 | //applyScatter(color.rgb); |
9 | gl_FragColor = color; | 9 | gl_FragColor = color; |
10 | } | 10 | } |
11 | 11 | ||
diff --git a/linden/indra/newview/app_settings/shaders/class3/environment/groundF.glsl b/linden/indra/newview/app_settings/shaders/class3/environment/groundF.glsl deleted file mode 100644 index 8618dad..0000000 --- a/linden/indra/newview/app_settings/shaders/class3/environment/groundF.glsl +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | vec4 getScatter(vec3 viewVec, vec3 lightDir); | ||
2 | |||
3 | varying vec3 lightd; | ||
4 | varying vec3 viewVec; | ||
5 | |||
6 | void main() | ||
7 | { | ||
8 | vec4 color = gl_Color; | ||
9 | vec4 haze = getScatter(viewVec, lightd) * vec4(gl_Fog.color.rgb, 1.0); | ||
10 | color.rgb = haze.rgb + haze.a * color.rgb; | ||
11 | gl_FragColor = color; | ||
12 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class3/environment/groundV.glsl b/linden/indra/newview/app_settings/shaders/class3/environment/groundV.glsl deleted file mode 100644 index a6f5270..0000000 --- a/linden/indra/newview/app_settings/shaders/class3/environment/groundV.glsl +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | varying vec3 lightd; | ||
2 | varying vec3 viewVec; | ||
3 | |||
4 | void main() | ||
5 | { | ||
6 | gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; | ||
7 | lightd = gl_LightSource[0].position.xyz; | ||
8 | viewVec = (gl_ModelViewMatrix * gl_Vertex).xyz; | ||
9 | |||
10 | gl_FrontColor = gl_Color; | ||
11 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class3/environment/scatterF.glsl b/linden/indra/newview/app_settings/shaders/class3/environment/scatterF.glsl deleted file mode 100644 index 7a9245f..0000000 --- a/linden/indra/newview/app_settings/shaders/class3/environment/scatterF.glsl +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | uniform sampler2D scatterMap; | ||
2 | |||
3 | //for per-pixel scatter | ||
4 | vec4 getScatter(vec3 viewVec, vec3 lightDir) | ||
5 | { | ||
6 | vec2 scatterCoord; | ||
7 | scatterCoord.x = length(viewVec); | ||
8 | vec3 normVec = viewVec / scatterCoord.x; | ||
9 | scatterCoord.y = dot(normVec, lightDir)*0.5 + 0.5; | ||
10 | scatterCoord.x = scatterCoord.x / gl_Fog.end; | ||
11 | scatterCoord.x *= scatterCoord.x; // HACK!! Remove this when we can push the view distance farther out | ||
12 | return texture2D(scatterMap, scatterCoord) * vec4(gl_Fog.color.rgb, 1.0); | ||
13 | } | ||
14 | |||
15 | void applyScatter(inout vec3 color, vec4 haze) | ||
16 | { | ||
17 | color.rgb = haze.rgb + haze.a * color.rgb; | ||
18 | } | ||
19 | |||
20 | //for per-vertex scatter | ||
21 | void applyScatter(inout vec3 color) | ||
22 | { | ||
23 | vec4 haze = texture2D(scatterMap, gl_TexCoord[5].xy) * vec4(gl_Fog.color.rgb, 1.0); | ||
24 | color.rgb = haze.rgb + haze.a * color.rgb; | ||
25 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class3/environment/scatterV.glsl b/linden/indra/newview/app_settings/shaders/class3/environment/scatterV.glsl deleted file mode 100644 index c9ebd9e..0000000 --- a/linden/indra/newview/app_settings/shaders/class3/environment/scatterV.glsl +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | |||
2 | vec2 getScatterCoord(vec3 viewVec, vec3 lightDir) | ||
3 | { | ||
4 | vec2 scatterCoord; | ||
5 | scatterCoord.x = length(viewVec); | ||
6 | vec3 normVec = normalize(viewVec); | ||
7 | scatterCoord.y = dot(normVec, lightDir)*0.5 + 0.5; | ||
8 | scatterCoord.x = scatterCoord.x / gl_Fog.end; | ||
9 | scatterCoord.x *= scatterCoord.x; // HACK!! Remove this when we can push the view distance farther out | ||
10 | return scatterCoord; | ||
11 | } | ||
12 | |||
13 | void default_scatter(vec3 viewVec, vec3 lightDir) | ||
14 | { | ||
15 | gl_TexCoord[5].xy = getScatterCoord(viewVec, lightDir); | ||
16 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/linden/indra/newview/app_settings/shaders/class3/environment/waterF.glsl new file mode 100644 index 0000000..3a117c5 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class3/environment/waterF.glsl | |||
@@ -0,0 +1,145 @@ | |||
1 | void applyScatter(inout vec3 color); | ||
2 | |||
3 | uniform sampler2D diffuseMap; | ||
4 | uniform sampler2D bumpMap; | ||
5 | uniform samplerCube environmentMap; //: TEXUNIT4, // Environment map texture | ||
6 | uniform sampler2D screenTex; // : TEXUNIT5 | ||
7 | |||
8 | uniform vec3 lightDir; | ||
9 | uniform vec3 specular; | ||
10 | uniform float lightExp; | ||
11 | uniform vec2 fbScale; | ||
12 | uniform float refScale; | ||
13 | |||
14 | float msin(float x) { | ||
15 | float k = sin(x)+1.0; | ||
16 | k *= 0.5; | ||
17 | k *= k; | ||
18 | return 2.0 * k; | ||
19 | } | ||
20 | |||
21 | float mcos(float x) { | ||
22 | float k = cos(x)+1.0; | ||
23 | k *= 0.5; | ||
24 | k *= k; | ||
25 | return 2.0 * k; | ||
26 | } | ||
27 | |||
28 | float waveS(vec2 v, float t, float a, float f, vec2 d, float s, sampler1D sinMap) | ||
29 | { | ||
30 | return texture1D(sinMap, (dot(d, v)*f + t*s)*f).r*a; | ||
31 | } | ||
32 | |||
33 | float waveC(vec2 v, float t, float a, float f, vec2 d, float s, sampler1D sinMap) | ||
34 | { | ||
35 | return texture1D(sinMap, (dot(d, v)*f + t*s)*f).g*a*2.0-1.0; | ||
36 | } | ||
37 | |||
38 | float magnitude(vec3 vec) { | ||
39 | return sqrt(dot(vec,vec)); | ||
40 | } | ||
41 | |||
42 | vec3 mreflect(vec3 i, vec3 n) { | ||
43 | return i + n * 2.0 * abs(dot(n,i))+vec3(0.0,0.0,0.5); | ||
44 | } | ||
45 | |||
46 | void main() | ||
47 | { | ||
48 | vec2 texCoord = gl_TexCoord[0].xy; // Texture coordinates | ||
49 | vec2 littleWave1 = gl_TexCoord[0].zw; | ||
50 | vec2 littleWave2 = gl_TexCoord[1].xy; | ||
51 | vec2 bigWave = gl_TexCoord[1].zw; | ||
52 | vec3 viewVec = gl_TexCoord[2].xyz; | ||
53 | vec4 refCoord = gl_TexCoord[3]; | ||
54 | vec4 col = gl_Color; | ||
55 | vec4 color; | ||
56 | |||
57 | //get color from alpha map (alpha denotes water depth), rgb denotes water color | ||
58 | vec4 wcol = texture2D(diffuseMap, texCoord.xy); | ||
59 | |||
60 | float dist = length(viewVec); | ||
61 | |||
62 | //store texture alpha | ||
63 | float da = wcol.a; | ||
64 | |||
65 | //modulate by incoming water color | ||
66 | //wcol.a *= refCoord.w; | ||
67 | |||
68 | //scale wcol.a (water depth) for steep transition | ||
69 | wcol.a *= wcol.a; | ||
70 | |||
71 | //normalize view vector | ||
72 | viewVec = normalize(viewVec); | ||
73 | |||
74 | //get bigwave normal | ||
75 | vec3 wavef = texture2D(bumpMap, bigWave).xyz*2.0; | ||
76 | |||
77 | vec3 view = vec3(viewVec.x, viewVec.y, viewVec.z); | ||
78 | |||
79 | float dx = 1.0-(dot(wavef*2.0-vec3(1.0), view))*da; | ||
80 | dx *= 0.274; | ||
81 | |||
82 | //get detail normals | ||
83 | vec3 dcol = texture2D(bumpMap, littleWave1+dx*view.xy).rgb*0.75; | ||
84 | dcol += texture2D(bumpMap, littleWave2+view.xy*dx*0.1).rgb*1.25; | ||
85 | |||
86 | //interpolate between big waves and little waves (big waves in deep water) | ||
87 | wavef = wavef*wcol.a + dcol*(1.0-wcol.a); | ||
88 | |||
89 | //crunch normal to range [-1,1] | ||
90 | wavef -= vec3(1,1,1); | ||
91 | wavef = normalize(wavef); | ||
92 | //wavef = vec3(0.0, 0.0, 1.0); | ||
93 | |||
94 | //get base fresnel component | ||
95 | float df = dot(viewVec,wavef); | ||
96 | //translate and flip fresnel | ||
97 | df = 1.0-clamp(-df,0.0,1.0); | ||
98 | |||
99 | //set output alpha based on fresnel | ||
100 | color.a = clamp((1.0-df+da)*0.5,0.0,1.0); | ||
101 | |||
102 | //calculate reflection vector | ||
103 | vec3 refnorm = vec3(wavef.x*0.5, wavef.y*0.5, wavef.z*2.0); | ||
104 | |||
105 | //ramp normal towards eye for far view stuff | ||
106 | float ramp = dist/256.0; | ||
107 | refnorm -= viewVec * ramp; | ||
108 | vec3 ref = reflect(viewVec.xyz, normalize(refnorm)); | ||
109 | ref.z /= sqrt(dist); | ||
110 | |||
111 | //get diffuse component | ||
112 | float diff = clamp(dot(ref, wavef),0.0,1.0)*0.9; | ||
113 | |||
114 | //fudge diffuse for extra contrast and ambience | ||
115 | diff *= diff; | ||
116 | diff += 0.4; | ||
117 | |||
118 | vec3 fog = gl_TexCoord[5].rgb*0.5; | ||
119 | |||
120 | //read from reflection map | ||
121 | vec3 refcol = textureCube(environmentMap, ref).rgb; | ||
122 | //tint reflection by fresnal, bias by z component of view vec | ||
123 | color.rgb = refcol*(df*df*dcol.x*dcol.y); | ||
124 | |||
125 | //add diffuse contribution (fake blue water, yay!) | ||
126 | vec3 blue = vec3(0.1, 0.3, 0.6); | ||
127 | color.rgb += (diff/(max(ramp, 1.0)))*vec3(fog.r*blue.r, fog.g*blue.g, fog.b*blue.b); | ||
128 | |||
129 | //figure out distortion vector (ripply) | ||
130 | vec2 distort = clamp(((refCoord.xy/refCoord.z) * 0.5 + 0.5 + wavef.xy*refScale),0.0,0.99); | ||
131 | |||
132 | //read from framebuffer (offset) | ||
133 | vec4 fb = texture2D(screenTex, distort*fbScale); | ||
134 | |||
135 | //tint by framebuffer | ||
136 | color.rgb = da*color.rgb + (1.0-da)*fb.rgb; | ||
137 | |||
138 | //render as solid (previous pixel color already present) | ||
139 | color.a = 1.0; | ||
140 | |||
141 | //apply fog | ||
142 | applyScatter(color.rgb); | ||
143 | |||
144 | gl_FragColor = color; | ||
145 | } | ||