diff options
author | Armin Weatherwax | 2010-09-07 13:41:02 +0200 |
---|---|---|
committer | Armin Weatherwax | 2010-09-23 15:42:40 +0200 |
commit | 087e15e89930d51c3964329befb273ae3b2d330d (patch) | |
tree | 684c49a772b0097ed88a25660e1fd3dd10b264cc /linden/indra/newview/app_settings/shaders/class2/deferred | |
parent | Robin Cornelius: fixes for building plugins on Linux 64bit (diff) | |
download | meta-impy-087e15e89930d51c3964329befb273ae3b2d330d.zip meta-impy-087e15e89930d51c3964329befb273ae3b2d330d.tar.gz meta-impy-087e15e89930d51c3964329befb273ae3b2d330d.tar.bz2 meta-impy-087e15e89930d51c3964329befb273ae3b2d330d.tar.xz |
port of LL renderpipeline/Kirstens S19 pipeline for bridging to Viewer 2 texture system
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class2/deferred')
16 files changed, 1654 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl new file mode 100644 index 0000000..0055a73 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl | |||
@@ -0,0 +1,112 @@ | |||
1 | /** | ||
2 | * @file alphaF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | #extension GL_ARB_texture_rectangle : enable | ||
9 | |||
10 | uniform sampler2D diffuseMap; | ||
11 | uniform sampler2DRectShadow shadowMap0; | ||
12 | uniform sampler2DRectShadow shadowMap1; | ||
13 | uniform sampler2DRectShadow shadowMap2; | ||
14 | uniform sampler2DRectShadow shadowMap3; | ||
15 | uniform sampler2D noiseMap; | ||
16 | uniform sampler2DRect depthMap; | ||
17 | |||
18 | uniform mat4 shadow_matrix[6]; | ||
19 | uniform vec4 shadow_clip; | ||
20 | uniform vec2 screen_res; | ||
21 | |||
22 | vec3 atmosLighting(vec3 light); | ||
23 | vec3 scaleSoftClip(vec3 light); | ||
24 | |||
25 | varying vec3 vary_ambient; | ||
26 | varying vec3 vary_directional; | ||
27 | varying vec3 vary_fragcoord; | ||
28 | varying vec3 vary_position; | ||
29 | varying vec3 vary_light; | ||
30 | |||
31 | uniform float alpha_soften; | ||
32 | |||
33 | uniform mat4 inv_proj; | ||
34 | |||
35 | vec4 getPosition(vec2 pos_screen) | ||
36 | { | ||
37 | float depth = texture2DRect(depthMap, pos_screen.xy).a; | ||
38 | vec2 sc = pos_screen.xy*2.0; | ||
39 | sc /= screen_res; | ||
40 | sc -= vec2(1.0,1.0); | ||
41 | vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); | ||
42 | vec4 pos = inv_proj * ndc; | ||
43 | pos /= pos.w; | ||
44 | pos.w = 1.0; | ||
45 | return pos; | ||
46 | } | ||
47 | |||
48 | void main() | ||
49 | { | ||
50 | vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; | ||
51 | frag *= screen_res; | ||
52 | |||
53 | vec3 samp_pos = getPosition(frag).xyz; | ||
54 | |||
55 | float shadow = 1.0; | ||
56 | vec4 pos = vec4(vary_position, 1.0); | ||
57 | |||
58 | vec4 spos = pos; | ||
59 | |||
60 | if (spos.z > -shadow_clip.w) | ||
61 | { | ||
62 | vec4 lpos; | ||
63 | |||
64 | if (spos.z < -shadow_clip.z) | ||
65 | { | ||
66 | lpos = shadow_matrix[3]*spos; | ||
67 | lpos.xy *= screen_res; | ||
68 | shadow = shadow2DRectProj(shadowMap3, lpos).x; | ||
69 | shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); | ||
70 | } | ||
71 | else if (spos.z < -shadow_clip.y) | ||
72 | { | ||
73 | lpos = shadow_matrix[2]*spos; | ||
74 | lpos.xy *= screen_res; | ||
75 | shadow = shadow2DRectProj(shadowMap2, lpos).x; | ||
76 | } | ||
77 | else if (spos.z < -shadow_clip.x) | ||
78 | { | ||
79 | lpos = shadow_matrix[1]*spos; | ||
80 | lpos.xy *= screen_res; | ||
81 | shadow = shadow2DRectProj(shadowMap1, lpos).x; | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | lpos = shadow_matrix[0]*spos; | ||
86 | lpos.xy *= screen_res; | ||
87 | shadow = shadow2DRectProj(shadowMap0, lpos).x; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | vec4 col = vec4(vary_ambient + vary_directional.rgb*shadow, gl_Color.a); | ||
92 | vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy) * col; | ||
93 | |||
94 | color.rgb = atmosLighting(color.rgb); | ||
95 | |||
96 | color.rgb = scaleSoftClip(color.rgb); | ||
97 | |||
98 | if (samp_pos.z != 0.0) | ||
99 | { | ||
100 | float dist_factor = alpha_soften; | ||
101 | float a = gl_Color.a; | ||
102 | a *= a; | ||
103 | dist_factor *= 1.0/(1.0-a); | ||
104 | color.a *= min((pos.z-samp_pos.z)*dist_factor, 1.0); | ||
105 | } | ||
106 | |||
107 | //gl_FragColor = gl_Color; | ||
108 | gl_FragColor = color; | ||
109 | //gl_FragColor = vec4(1,0,1,1)*shadow; | ||
110 | |||
111 | } | ||
112 | |||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl new file mode 100644 index 0000000..ab60b65 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl | |||
@@ -0,0 +1,75 @@ | |||
1 | /** | ||
2 | * @file alphaV.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); | ||
9 | void calcAtmospherics(vec3 inPositionEye); | ||
10 | |||
11 | float calcDirectionalLight(vec3 n, vec3 l); | ||
12 | float calcPointLight(vec3 v, vec3 n, vec4 lp, float la); | ||
13 | |||
14 | vec3 atmosAmbient(vec3 light); | ||
15 | vec3 atmosAffectDirectionalLight(float lightIntensity); | ||
16 | vec3 scaleDownLight(vec3 light); | ||
17 | vec3 scaleUpLight(vec3 light); | ||
18 | |||
19 | varying vec3 vary_ambient; | ||
20 | varying vec3 vary_directional; | ||
21 | varying vec3 vary_fragcoord; | ||
22 | varying vec3 vary_position; | ||
23 | varying vec3 vary_light; | ||
24 | |||
25 | uniform float near_clip; | ||
26 | uniform float shadow_offset; | ||
27 | uniform float shadow_bias; | ||
28 | |||
29 | void main() | ||
30 | { | ||
31 | //transform vertex | ||
32 | gl_Position = ftransform(); | ||
33 | |||
34 | gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; | ||
35 | |||
36 | vec4 pos = (gl_ModelViewMatrix * gl_Vertex); | ||
37 | vec3 norm = normalize(gl_NormalMatrix * gl_Normal); | ||
38 | |||
39 | vary_position = vec4(pos.xyz + norm.xyz * (-pos.z/64.0*shadow_offset+shadow_bias), 1.0); | ||
40 | |||
41 | calcAtmospherics(pos.xyz); | ||
42 | |||
43 | //vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0.)); | ||
44 | vec4 col; | ||
45 | col.a = gl_Color.a; | ||
46 | |||
47 | // Add windlight lights | ||
48 | col.rgb = atmosAmbient(vec3(0.)); | ||
49 | col.rgb = scaleUpLight(col.rgb); | ||
50 | |||
51 | // Collect normal lights (need to be divided by two, as we later multiply by 2) | ||
52 | col.rgb += gl_LightSource[2].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation); | ||
53 | col.rgb += gl_LightSource[3].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation); | ||
54 | col.rgb += gl_LightSource[4].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation); | ||
55 | col.rgb += gl_LightSource[5].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[5].position, gl_LightSource[5].linearAttenuation); | ||
56 | col.rgb += gl_LightSource[6].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[6].position, gl_LightSource[6].linearAttenuation); | ||
57 | col.rgb += gl_LightSource[7].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[7].position, gl_LightSource[7].linearAttenuation); | ||
58 | col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz); | ||
59 | col.rgb = scaleDownLight(col.rgb); | ||
60 | |||
61 | vary_light = gl_LightSource[0].position.xyz; | ||
62 | |||
63 | vary_ambient = col.rgb*gl_Color.rgb; | ||
64 | 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))); | ||
65 | |||
66 | col.rgb = min(col.rgb*gl_Color.rgb, 1.0); | ||
67 | |||
68 | gl_FrontColor = col; | ||
69 | |||
70 | gl_FogFragCoord = pos.z; | ||
71 | |||
72 | pos = gl_ModelViewProjectionMatrix * gl_Vertex; | ||
73 | vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); | ||
74 | |||
75 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaF.glsl new file mode 100644 index 0000000..fe83c3c --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaF.glsl | |||
@@ -0,0 +1,77 @@ | |||
1 | /** | ||
2 | * @file avatarAlphaF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | uniform sampler2D diffuseMap; | ||
9 | uniform sampler2DRectShadow shadowMap0; | ||
10 | uniform sampler2DRectShadow shadowMap1; | ||
11 | uniform sampler2DRectShadow shadowMap2; | ||
12 | uniform sampler2DRectShadow shadowMap3; | ||
13 | uniform sampler2D noiseMap; | ||
14 | |||
15 | uniform mat4 shadow_matrix[6]; | ||
16 | uniform vec4 shadow_clip; | ||
17 | uniform vec2 screen_res; | ||
18 | |||
19 | vec3 atmosLighting(vec3 light); | ||
20 | vec3 scaleSoftClip(vec3 light); | ||
21 | |||
22 | varying vec3 vary_ambient; | ||
23 | varying vec3 vary_directional; | ||
24 | varying vec4 vary_position; | ||
25 | varying vec3 vary_normal; | ||
26 | |||
27 | void main() | ||
28 | { | ||
29 | float shadow = 1.0; | ||
30 | vec4 pos = vary_position; | ||
31 | vec3 norm = normalize(vary_normal); | ||
32 | |||
33 | vec3 nz = texture2D(noiseMap, gl_FragCoord.xy/128.0).xyz; | ||
34 | |||
35 | vec4 spos = pos; | ||
36 | |||
37 | if (spos.z > -shadow_clip.w) | ||
38 | { | ||
39 | vec4 lpos; | ||
40 | |||
41 | if (spos.z < -shadow_clip.z) | ||
42 | { | ||
43 | lpos = shadow_matrix[3]*spos; | ||
44 | lpos.xy *= screen_res; | ||
45 | shadow = shadow2DRectProj(shadowMap3, lpos).x; | ||
46 | shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); | ||
47 | } | ||
48 | else if (spos.z < -shadow_clip.y) | ||
49 | { | ||
50 | lpos = shadow_matrix[2]*spos; | ||
51 | lpos.xy *= screen_res; | ||
52 | shadow = shadow2DRectProj(shadowMap2, lpos).x; | ||
53 | } | ||
54 | else if (spos.z < -shadow_clip.x) | ||
55 | { | ||
56 | lpos = shadow_matrix[1]*spos; | ||
57 | lpos.xy *= screen_res; | ||
58 | shadow = shadow2DRectProj(shadowMap1, lpos).x; | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | lpos = shadow_matrix[0]*spos; | ||
63 | lpos.xy *= screen_res; | ||
64 | shadow = shadow2DRectProj(shadowMap0, lpos).x; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | |||
69 | vec4 col = vec4(vary_ambient + vary_directional*shadow, gl_Color.a); | ||
70 | vec4 color = texture2D(diffuseMap, gl_TexCoord[0].xy) * col; | ||
71 | |||
72 | color.rgb = atmosLighting(color.rgb); | ||
73 | |||
74 | color.rgb = scaleSoftClip(color.rgb); | ||
75 | |||
76 | gl_FragColor = color; | ||
77 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl new file mode 100644 index 0000000..c1988d3 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl | |||
@@ -0,0 +1,78 @@ | |||
1 | /** | ||
2 | * @file avatarAlphaV.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); | ||
9 | mat4 getSkinnedTransform(); | ||
10 | void calcAtmospherics(vec3 inPositionEye); | ||
11 | |||
12 | float calcDirectionalLight(vec3 n, vec3 l); | ||
13 | float calcPointLight(vec3 v, vec3 n, vec4 lp, float la); | ||
14 | |||
15 | vec3 atmosAmbient(vec3 light); | ||
16 | vec3 atmosAffectDirectionalLight(float lightIntensity); | ||
17 | vec3 scaleDownLight(vec3 light); | ||
18 | vec3 scaleUpLight(vec3 light); | ||
19 | |||
20 | varying vec4 vary_position; | ||
21 | varying vec3 vary_ambient; | ||
22 | varying vec3 vary_directional; | ||
23 | varying vec3 vary_normal; | ||
24 | |||
25 | void main() | ||
26 | { | ||
27 | gl_TexCoord[0] = gl_MultiTexCoord0; | ||
28 | |||
29 | vec4 pos; | ||
30 | vec3 norm; | ||
31 | |||
32 | mat4 trans = getSkinnedTransform(); | ||
33 | pos.x = dot(trans[0], gl_Vertex); | ||
34 | pos.y = dot(trans[1], gl_Vertex); | ||
35 | pos.z = dot(trans[2], gl_Vertex); | ||
36 | pos.w = 1.0; | ||
37 | |||
38 | norm.x = dot(trans[0].xyz, gl_Normal); | ||
39 | norm.y = dot(trans[1].xyz, gl_Normal); | ||
40 | norm.z = dot(trans[2].xyz, gl_Normal); | ||
41 | norm = normalize(norm); | ||
42 | |||
43 | gl_Position = gl_ProjectionMatrix * pos; | ||
44 | vary_position = pos; | ||
45 | vary_normal = norm; | ||
46 | |||
47 | calcAtmospherics(pos.xyz); | ||
48 | |||
49 | //vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0.)); | ||
50 | vec4 col; | ||
51 | col.a = gl_Color.a; | ||
52 | |||
53 | // Add windlight lights | ||
54 | col.rgb = atmosAmbient(vec3(0.)); | ||
55 | col.rgb = scaleUpLight(col.rgb); | ||
56 | |||
57 | // Collect normal lights (need to be divided by two, as we later multiply by 2) | ||
58 | col.rgb += gl_LightSource[2].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[2].position, gl_LightSource[2].linearAttenuation); | ||
59 | col.rgb += gl_LightSource[3].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[3].position, gl_LightSource[3].linearAttenuation); | ||
60 | col.rgb += gl_LightSource[4].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[4].position, gl_LightSource[4].linearAttenuation); | ||
61 | col.rgb += gl_LightSource[5].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[5].position, gl_LightSource[5].linearAttenuation); | ||
62 | col.rgb += gl_LightSource[6].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[6].position, gl_LightSource[6].linearAttenuation); | ||
63 | col.rgb += gl_LightSource[7].diffuse.rgb*calcPointLight(pos.xyz, norm, gl_LightSource[7].position, gl_LightSource[7].linearAttenuation); | ||
64 | col.rgb += gl_LightSource[1].diffuse.rgb*calcDirectionalLight(norm, gl_LightSource[1].position.xyz); | ||
65 | col.rgb = scaleDownLight(col.rgb); | ||
66 | |||
67 | vary_ambient = col.rgb*gl_Color.rgb; | ||
68 | vary_directional = gl_Color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, gl_LightSource[0].position.xyz), (1.0-gl_Color.a)*(1.0-gl_Color.a))); | ||
69 | |||
70 | col.rgb = min(col.rgb*gl_Color.rgb, 1.0); | ||
71 | |||
72 | gl_FrontColor = col; | ||
73 | |||
74 | gl_FogFragCoord = pos.z; | ||
75 | |||
76 | } | ||
77 | |||
78 | |||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/blurLightF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/blurLightF.glsl new file mode 100644 index 0000000..1713fe9 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/blurLightF.glsl | |||
@@ -0,0 +1,71 @@ | |||
1 | /** | ||
2 | * @file blurLightF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | #extension GL_ARB_texture_rectangle : enable | ||
9 | |||
10 | uniform sampler2DRect depthMap; | ||
11 | uniform sampler2DRect normalMap; | ||
12 | uniform sampler2DRect lightMap; | ||
13 | |||
14 | uniform float dist_factor; | ||
15 | uniform float blur_size; | ||
16 | uniform vec2 delta; | ||
17 | uniform vec3 kern[32]; | ||
18 | uniform int kern_length; | ||
19 | uniform float kern_scale; | ||
20 | |||
21 | varying vec2 vary_fragcoord; | ||
22 | |||
23 | uniform mat4 inv_proj; | ||
24 | uniform vec2 screen_res; | ||
25 | |||
26 | vec4 getPosition(vec2 pos_screen) | ||
27 | { | ||
28 | float depth = texture2DRect(depthMap, pos_screen.xy).a; | ||
29 | vec2 sc = pos_screen.xy*2.0; | ||
30 | sc /= screen_res; | ||
31 | sc -= vec2(1.0,1.0); | ||
32 | vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); | ||
33 | vec4 pos = inv_proj * ndc; | ||
34 | pos /= pos.w; | ||
35 | pos.w = 1.0; | ||
36 | return pos; | ||
37 | } | ||
38 | |||
39 | void main() | ||
40 | { | ||
41 | vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz*2.0-1.0; | ||
42 | vec3 pos = getPosition(vary_fragcoord.xy).xyz; | ||
43 | vec4 ccol = texture2DRect(lightMap, vary_fragcoord.xy).rgba; | ||
44 | |||
45 | vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); | ||
46 | |||
47 | dlt /= max(-pos.z*dist_factor, 1.0); | ||
48 | |||
49 | 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' | ||
50 | vec4 col = defined_weight.xyxx * ccol; | ||
51 | |||
52 | for (int i = 1; i < kern_length; i++) | ||
53 | { | ||
54 | vec2 tc = vary_fragcoord.xy + kern[i].z*dlt; | ||
55 | vec3 samppos = getPosition(tc).xyz; | ||
56 | float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane | ||
57 | if (d*d <= 0.003) | ||
58 | { | ||
59 | col += texture2DRect(lightMap, tc)*kern[i].xyxx; | ||
60 | defined_weight += kern[i].xy; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | |||
65 | |||
66 | col /= defined_weight.xyxx; | ||
67 | |||
68 | gl_FragColor = col; | ||
69 | |||
70 | //gl_FragColor = ccol; | ||
71 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/blurLightV.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/blurLightV.glsl new file mode 100644 index 0000000..b7f07e5 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/blurLightV.glsl | |||
@@ -0,0 +1,17 @@ | |||
1 | /** | ||
2 | * @file blurLightF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | varying vec2 vary_fragcoord; | ||
9 | uniform vec2 screen_res; | ||
10 | |||
11 | void main() | ||
12 | { | ||
13 | //transform vertex | ||
14 | gl_Position = ftransform(); | ||
15 | vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex; | ||
16 | vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; | ||
17 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl new file mode 100644 index 0000000..6519594 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl | |||
@@ -0,0 +1,188 @@ | |||
1 | /** | ||
2 | * @file multiSpotLightF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | #version 120 | ||
9 | |||
10 | #extension GL_ARB_texture_rectangle : enable | ||
11 | |||
12 | uniform sampler2DRect diffuseRect; | ||
13 | uniform sampler2DRect specularRect; | ||
14 | uniform sampler2DRect depthMap; | ||
15 | uniform sampler2DRect normalMap; | ||
16 | uniform samplerCube environmentMap; | ||
17 | uniform sampler2DRect lightMap; | ||
18 | uniform sampler2D noiseMap; | ||
19 | uniform sampler2D lightFunc; | ||
20 | uniform sampler2D projectionMap; | ||
21 | |||
22 | uniform mat4 proj_mat; //screen space to light space | ||
23 | uniform float proj_near; //near clip for projection | ||
24 | uniform vec3 proj_p; //plane projection is emitting from (in screen space) | ||
25 | uniform vec3 proj_n; | ||
26 | uniform float proj_focus; //distance from plane to begin blurring | ||
27 | uniform float proj_lod; //(number of mips in proj map) | ||
28 | uniform float proj_range; //range between near clip and far clip plane of projection | ||
29 | uniform float proj_ambient_lod; | ||
30 | uniform float proj_ambiance; | ||
31 | uniform float near_clip; | ||
32 | uniform float far_clip; | ||
33 | |||
34 | uniform vec3 proj_origin; //origin of projection to be used for angular attenuation | ||
35 | uniform float sun_wash; | ||
36 | uniform int proj_shadow_idx; | ||
37 | uniform float shadow_fade; | ||
38 | |||
39 | varying vec4 vary_light; | ||
40 | |||
41 | varying vec4 vary_fragcoord; | ||
42 | uniform vec2 screen_res; | ||
43 | |||
44 | uniform mat4 inv_proj; | ||
45 | |||
46 | vec4 getPosition(vec2 pos_screen) | ||
47 | { | ||
48 | float depth = texture2DRect(depthMap, pos_screen.xy).a; | ||
49 | vec2 sc = pos_screen.xy*2.0; | ||
50 | sc /= screen_res; | ||
51 | sc -= vec2(1.0,1.0); | ||
52 | vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); | ||
53 | vec4 pos = inv_proj * ndc; | ||
54 | pos /= pos.w; | ||
55 | pos.w = 1.0; | ||
56 | return pos; | ||
57 | } | ||
58 | |||
59 | void main() | ||
60 | { | ||
61 | vec4 frag = vary_fragcoord; | ||
62 | frag.xyz /= frag.w; | ||
63 | frag.xyz = frag.xyz*0.5+0.5; | ||
64 | frag.xy *= screen_res; | ||
65 | |||
66 | vec3 pos = getPosition(frag.xy).xyz; | ||
67 | vec3 lv = vary_light.xyz-pos.xyz; | ||
68 | float dist2 = dot(lv,lv); | ||
69 | dist2 /= vary_light.w; | ||
70 | if (dist2 > 1.0) | ||
71 | { | ||
72 | discard; | ||
73 | } | ||
74 | |||
75 | float shadow = 1.0; | ||
76 | |||
77 | if (proj_shadow_idx >= 0) | ||
78 | { | ||
79 | vec4 shd = texture2DRect(lightMap, frag.xy); | ||
80 | float sh[2]; | ||
81 | sh[0] = shd.b; | ||
82 | sh[1] = shd.a; | ||
83 | shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); | ||
84 | } | ||
85 | |||
86 | vec3 norm = texture2DRect(normalMap, frag.xy).xyz*2.0-1.0; | ||
87 | |||
88 | norm = normalize(norm); | ||
89 | float l_dist = -dot(lv, proj_n); | ||
90 | |||
91 | vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); | ||
92 | if (proj_tc.z < 0.0) | ||
93 | { | ||
94 | discard; | ||
95 | } | ||
96 | |||
97 | proj_tc.xyz /= proj_tc.w; | ||
98 | |||
99 | float fa = gl_Color.a+1.0; | ||
100 | float dist_atten = min(1.0-(dist2-1.0*(1.0-fa))/fa, 1.0); | ||
101 | if (dist_atten <= 0.0) | ||
102 | { | ||
103 | discard; | ||
104 | } | ||
105 | |||
106 | lv = proj_origin-pos.xyz; | ||
107 | lv = normalize(lv); | ||
108 | float da = dot(norm, lv); | ||
109 | |||
110 | vec3 col = vec3(0,0,0); | ||
111 | |||
112 | vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; | ||
113 | |||
114 | float noise = texture2D(noiseMap, frag.xy/128.0).b; | ||
115 | if (proj_tc.z > 0.0 && | ||
116 | proj_tc.x < 1.0 && | ||
117 | proj_tc.y < 1.0 && | ||
118 | proj_tc.x > 0.0 && | ||
119 | proj_tc.y > 0.0) | ||
120 | { | ||
121 | float lit = 0.0; | ||
122 | float amb_da = proj_ambiance; | ||
123 | |||
124 | if (da > 0.0) | ||
125 | { | ||
126 | float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); | ||
127 | float lod = diff * proj_lod; | ||
128 | |||
129 | vec4 plcol = texture2DLod(projectionMap, proj_tc.xy, lod); | ||
130 | |||
131 | vec3 lcol = gl_Color.rgb * plcol.rgb * plcol.a; | ||
132 | |||
133 | lit = da * dist_atten * noise; | ||
134 | |||
135 | col = lcol*lit*diff_tex*shadow; | ||
136 | amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; | ||
137 | } | ||
138 | |||
139 | //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); | ||
140 | vec4 amb_plcol = texture2DLod(projectionMap, proj_tc.xy, proj_ambient_lod); | ||
141 | |||
142 | amb_da += (da*da*0.5+0.5)*proj_ambiance; | ||
143 | |||
144 | amb_da *= dist_atten * noise; | ||
145 | |||
146 | amb_da = min(amb_da, 1.0-lit); | ||
147 | |||
148 | col += amb_da*gl_Color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; | ||
149 | } | ||
150 | |||
151 | |||
152 | vec4 spec = texture2DRect(specularRect, frag.xy); | ||
153 | if (spec.a > 0.0) | ||
154 | { | ||
155 | vec3 ref = reflect(normalize(pos), norm); | ||
156 | |||
157 | //project from point pos in direction ref to plane proj_p, proj_n | ||
158 | vec3 pdelta = proj_p-pos; | ||
159 | float ds = dot(ref, proj_n); | ||
160 | |||
161 | if (ds < 0.0) | ||
162 | { | ||
163 | vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; | ||
164 | |||
165 | vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); | ||
166 | |||
167 | if (stc.z > 0.0) | ||
168 | { | ||
169 | stc.xy /= stc.w; | ||
170 | |||
171 | if (stc.x < 1.0 && | ||
172 | stc.y < 1.0 && | ||
173 | stc.x > 0.0 && | ||
174 | stc.y > 0.0) | ||
175 | { | ||
176 | vec4 scol = texture2DLod(projectionMap, stc.xy, proj_lod-spec.a*proj_lod); | ||
177 | col += dist_atten*scol.rgb*gl_Color.rgb*scol.a*spec.rgb*shadow; | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | |||
183 | //attenuate point light contribution by SSAO component | ||
184 | col *= texture2DRect(lightMap, frag.xy).g; | ||
185 | |||
186 | gl_FragColor.rgb = col; | ||
187 | gl_FragColor.a = 0.0; | ||
188 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/postDeferredF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/postDeferredF.glsl new file mode 100644 index 0000000..ee0e9d6 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/postDeferredF.glsl | |||
@@ -0,0 +1,59 @@ | |||
1 | /** | ||
2 | * @file postDeferredF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | uniform sampler2DRect diffuseRect; | ||
9 | uniform sampler2DRect localLightMap; | ||
10 | uniform sampler2DRect sunLightMap; | ||
11 | uniform sampler2DRect giLightMap; | ||
12 | uniform sampler2D luminanceMap; | ||
13 | uniform sampler2DRect lightMap; | ||
14 | |||
15 | uniform vec3 gi_lum_quad; | ||
16 | uniform vec3 sun_lum_quad; | ||
17 | uniform vec3 lum_quad; | ||
18 | uniform float lum_lod; | ||
19 | uniform vec4 ambient; | ||
20 | |||
21 | uniform vec3 gi_quad; | ||
22 | |||
23 | uniform vec2 screen_res; | ||
24 | varying vec2 vary_fragcoord; | ||
25 | |||
26 | void main() | ||
27 | { | ||
28 | vec2 tc = vary_fragcoord.xy; | ||
29 | vec3 lcol = texture2DLod(luminanceMap, tc/screen_res, lum_lod).rgb; | ||
30 | |||
31 | float lum = sqrt(lcol.r)*lum_quad.x+lcol.r*lcol.r*lum_quad.y+lcol.r*lum_quad.z; | ||
32 | |||
33 | vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); | ||
34 | |||
35 | float ambocc = texture2DRect(lightMap, vary_fragcoord.xy).g; | ||
36 | |||
37 | vec3 gi_col = texture2DRect(giLightMap, vary_fragcoord.xy).rgb; | ||
38 | gi_col = gi_col*gi_col*gi_quad.x + gi_col*gi_quad.y+gi_quad.z*ambocc*ambient.rgb; | ||
39 | gi_col *= diff; | ||
40 | |||
41 | vec4 sun_col = texture2DRect(sunLightMap, vary_fragcoord.xy); | ||
42 | |||
43 | vec3 local_col = texture2DRect(localLightMap, vary_fragcoord.xy).rgb; | ||
44 | |||
45 | |||
46 | float sun_lum = 1.0-lum; | ||
47 | sun_lum = sun_lum*sun_lum*sun_lum_quad.x + sun_lum*sun_lum_quad.y+sun_lum_quad.z; | ||
48 | |||
49 | float gi_lum = lum; | ||
50 | gi_lum = gi_lum*gi_lum*gi_lum_quad.x+gi_lum*gi_lum_quad.y+gi_lum_quad.z; | ||
51 | gi_col *= 1.0/gi_lum; | ||
52 | |||
53 | vec3 col = sun_col.rgb*(1.0+max(sun_lum,0.0))+gi_col+local_col; | ||
54 | |||
55 | gl_FragColor.rgb = col.rgb; | ||
56 | gl_FragColor.a = max(sun_lum*min(sun_col.r+sun_col.g+sun_col.b, 1.0), sun_col.a); | ||
57 | |||
58 | //gl_FragColor.rgb = texture2DRect(giLightMap, vary_fragcoord.xy).rgb; | ||
59 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/postDeferredV.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/postDeferredV.glsl new file mode 100644 index 0000000..9819232 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/postDeferredV.glsl | |||
@@ -0,0 +1,17 @@ | |||
1 | /** | ||
2 | * @file postDeferredV.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | varying vec2 vary_fragcoord; | ||
9 | uniform vec2 screen_res; | ||
10 | |||
11 | void main() | ||
12 | { | ||
13 | //transform vertex | ||
14 | gl_Position = ftransform(); | ||
15 | vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex; | ||
16 | vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; | ||
17 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl new file mode 100644 index 0000000..52b79e3 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl | |||
@@ -0,0 +1,294 @@ | |||
1 | /** | ||
2 | * @file softenLightF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | #extension GL_ARB_texture_rectangle : enable | ||
9 | |||
10 | uniform sampler2DRect diffuseRect; | ||
11 | uniform sampler2DRect specularRect; | ||
12 | uniform sampler2DRect normalMap; | ||
13 | uniform sampler2DRect lightMap; | ||
14 | uniform sampler2D noiseMap; | ||
15 | uniform samplerCube environmentMap; | ||
16 | uniform sampler2D lightFunc; | ||
17 | uniform vec3 gi_quad; | ||
18 | |||
19 | uniform float blur_size; | ||
20 | uniform float blur_fidelity; | ||
21 | |||
22 | // Inputs | ||
23 | uniform vec4 morphFactor; | ||
24 | uniform vec3 camPosLocal; | ||
25 | //uniform vec4 camPosWorld; | ||
26 | uniform vec4 gamma; | ||
27 | uniform vec4 lightnorm; | ||
28 | uniform vec4 sunlight_color; | ||
29 | uniform vec4 ambient; | ||
30 | uniform vec4 blue_horizon; | ||
31 | uniform vec4 blue_density; | ||
32 | uniform vec4 haze_horizon; | ||
33 | uniform vec4 haze_density; | ||
34 | uniform vec4 cloud_shadow; | ||
35 | uniform vec4 density_multiplier; | ||
36 | uniform vec4 distance_multiplier; | ||
37 | uniform vec4 max_y; | ||
38 | uniform vec4 glow; | ||
39 | uniform float scene_light_strength; | ||
40 | uniform vec3 env_mat[3]; | ||
41 | uniform vec4 shadow_clip; | ||
42 | uniform mat3 ssao_effect_mat; | ||
43 | |||
44 | uniform sampler2DRect depthMap; | ||
45 | uniform mat4 inv_proj; | ||
46 | uniform vec2 screen_res; | ||
47 | |||
48 | varying vec4 vary_light; | ||
49 | varying vec2 vary_fragcoord; | ||
50 | |||
51 | vec3 vary_PositionEye; | ||
52 | |||
53 | vec3 vary_SunlitColor; | ||
54 | vec3 vary_AmblitColor; | ||
55 | vec3 vary_AdditiveColor; | ||
56 | vec3 vary_AtmosAttenuation; | ||
57 | |||
58 | vec4 getPosition(vec2 pos_screen) | ||
59 | { //get position in screen space (world units) given window coordinate and depth map | ||
60 | float depth = texture2DRect(depthMap, pos_screen.xy).a; | ||
61 | vec2 sc = pos_screen.xy*2.0; | ||
62 | sc /= screen_res; | ||
63 | sc -= vec2(1.0,1.0); | ||
64 | vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); | ||
65 | vec4 pos = inv_proj * ndc; | ||
66 | pos /= pos.w; | ||
67 | pos.w = 1.0; | ||
68 | return pos; | ||
69 | } | ||
70 | |||
71 | vec3 getPositionEye() | ||
72 | { | ||
73 | return vary_PositionEye; | ||
74 | } | ||
75 | vec3 getSunlitColor() | ||
76 | { | ||
77 | return vary_SunlitColor; | ||
78 | } | ||
79 | vec3 getAmblitColor() | ||
80 | { | ||
81 | return vary_AmblitColor; | ||
82 | } | ||
83 | vec3 getAdditiveColor() | ||
84 | { | ||
85 | return vary_AdditiveColor; | ||
86 | } | ||
87 | vec3 getAtmosAttenuation() | ||
88 | { | ||
89 | return vary_AtmosAttenuation; | ||
90 | } | ||
91 | |||
92 | |||
93 | void setPositionEye(vec3 v) | ||
94 | { | ||
95 | vary_PositionEye = v; | ||
96 | } | ||
97 | |||
98 | void setSunlitColor(vec3 v) | ||
99 | { | ||
100 | vary_SunlitColor = v; | ||
101 | } | ||
102 | |||
103 | void setAmblitColor(vec3 v) | ||
104 | { | ||
105 | vary_AmblitColor = v; | ||
106 | } | ||
107 | |||
108 | void setAdditiveColor(vec3 v) | ||
109 | { | ||
110 | vary_AdditiveColor = v; | ||
111 | } | ||
112 | |||
113 | void setAtmosAttenuation(vec3 v) | ||
114 | { | ||
115 | vary_AtmosAttenuation = v; | ||
116 | } | ||
117 | |||
118 | void calcAtmospherics(vec3 inPositionEye, float ambFactor) { | ||
119 | |||
120 | vec3 P = inPositionEye; | ||
121 | setPositionEye(P); | ||
122 | |||
123 | //(TERRAIN) limit altitude | ||
124 | if (P.y > max_y.x) P *= (max_y.x / P.y); | ||
125 | if (P.y < -max_y.x) P *= (-max_y.x / P.y); | ||
126 | |||
127 | vec3 tmpLightnorm = lightnorm.xyz; | ||
128 | |||
129 | vec3 Pn = normalize(P); | ||
130 | float Plen = length(P); | ||
131 | |||
132 | vec4 temp1 = vec4(0); | ||
133 | vec3 temp2 = vec3(0); | ||
134 | vec4 blue_weight; | ||
135 | vec4 haze_weight; | ||
136 | vec4 sunlight = sunlight_color; | ||
137 | vec4 light_atten; | ||
138 | |||
139 | //sunlight attenuation effect (hue and brightness) due to atmosphere | ||
140 | //this is used later for sunlight modulation at various altitudes | ||
141 | light_atten = (blue_density * 1.0 + vec4(haze_density.r) * 0.25) * (density_multiplier.x * max_y.x); | ||
142 | //I had thought blue_density and haze_density should have equal weighting, | ||
143 | //but attenuation due to haze_density tends to seem too strong | ||
144 | |||
145 | temp1 = blue_density + vec4(haze_density.r); | ||
146 | blue_weight = blue_density / temp1; | ||
147 | haze_weight = vec4(haze_density.r) / temp1; | ||
148 | |||
149 | //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) | ||
150 | temp2.y = max(0.0, tmpLightnorm.y); | ||
151 | temp2.y = 1. / temp2.y; | ||
152 | sunlight *= exp( - light_atten * temp2.y); | ||
153 | |||
154 | // main atmospheric scattering line integral | ||
155 | temp2.z = Plen * density_multiplier.x; | ||
156 | |||
157 | // Transparency (-> temp1) | ||
158 | // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier.x in a variable because the ati | ||
159 | // compiler gets confused. | ||
160 | temp1 = exp(-temp1 * temp2.z * distance_multiplier.x); | ||
161 | |||
162 | //final atmosphere attenuation factor | ||
163 | setAtmosAttenuation(temp1.rgb); | ||
164 | |||
165 | //compute haze glow | ||
166 | //(can use temp2.x as temp because we haven't used it yet) | ||
167 | temp2.x = dot(Pn, tmpLightnorm.xyz); | ||
168 | temp2.x = 1. - temp2.x; | ||
169 | //temp2.x is 0 at the sun and increases away from sun | ||
170 | temp2.x = max(temp2.x, .03); //was glow.y | ||
171 | //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) | ||
172 | temp2.x *= glow.x; | ||
173 | //higher glow.x gives dimmer glow (because next step is 1 / "angle") | ||
174 | temp2.x = pow(temp2.x, glow.z); | ||
175 | //glow.z should be negative, so we're doing a sort of (1 / "angle") function | ||
176 | |||
177 | //add "minimum anti-solar illumination" | ||
178 | temp2.x += .25; | ||
179 | |||
180 | //increase ambient when there are more clouds | ||
181 | vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow.x * 0.5; | ||
182 | |||
183 | /* decrease value and saturation (that in HSV, not HSL) for occluded areas | ||
184 | * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html | ||
185 | * // The following line of code performs the equivalent of: | ||
186 | * float ambAlpha = tmpAmbient.a; | ||
187 | * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis | ||
188 | * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); | ||
189 | * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); | ||
190 | */ | ||
191 | tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); | ||
192 | |||
193 | //haze color | ||
194 | setAdditiveColor( | ||
195 | vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow.x) + tmpAmbient) | ||
196 | + (haze_horizon.r * haze_weight) * (sunlight*(1.-cloud_shadow.x) * temp2.x | ||
197 | + tmpAmbient))); | ||
198 | |||
199 | //brightness of surface both sunlight and ambient | ||
200 | setSunlitColor(vec3(sunlight * .5)); | ||
201 | setAmblitColor(vec3(tmpAmbient * .25)); | ||
202 | setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); | ||
203 | } | ||
204 | |||
205 | vec3 atmosLighting(vec3 light) | ||
206 | { | ||
207 | light *= getAtmosAttenuation().r; | ||
208 | light += getAdditiveColor(); | ||
209 | return (2.0 * light); | ||
210 | } | ||
211 | |||
212 | vec3 atmosTransport(vec3 light) { | ||
213 | light *= getAtmosAttenuation().r; | ||
214 | light += getAdditiveColor() * 2.0; | ||
215 | return light; | ||
216 | } | ||
217 | vec3 atmosGetDiffuseSunlightColor() | ||
218 | { | ||
219 | return getSunlitColor(); | ||
220 | } | ||
221 | |||
222 | vec3 scaleDownLight(vec3 light) | ||
223 | { | ||
224 | return (light / scene_light_strength ); | ||
225 | } | ||
226 | |||
227 | vec3 scaleUpLight(vec3 light) | ||
228 | { | ||
229 | return (light * scene_light_strength); | ||
230 | } | ||
231 | |||
232 | vec3 atmosAmbient(vec3 light) | ||
233 | { | ||
234 | return getAmblitColor() + light / 2.0; | ||
235 | } | ||
236 | |||
237 | vec3 atmosAffectDirectionalLight(float lightIntensity) | ||
238 | { | ||
239 | return getSunlitColor() * lightIntensity; | ||
240 | } | ||
241 | |||
242 | vec3 scaleSoftClip(vec3 light) | ||
243 | { | ||
244 | //soft clip effect: | ||
245 | light = 1. - clamp(light, vec3(0.), vec3(1.)); | ||
246 | light = 1. - pow(light, gamma.xxx); | ||
247 | |||
248 | return light; | ||
249 | } | ||
250 | |||
251 | void main() | ||
252 | { | ||
253 | vec2 tc = vary_fragcoord.xy; | ||
254 | vec3 pos = getPosition(tc).xyz; | ||
255 | vec3 norm = texture2DRect(normalMap, tc).xyz*2.0-1.0; | ||
256 | vec3 nz = texture2D(noiseMap, vary_fragcoord.xy/128.0).xyz; | ||
257 | |||
258 | float da = max(dot(norm.xyz, vary_light.xyz), 0.0); | ||
259 | |||
260 | vec4 diffuse = texture2DRect(diffuseRect, tc); | ||
261 | vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); | ||
262 | |||
263 | vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; | ||
264 | float scol = max(scol_ambocc.r, diffuse.a); | ||
265 | float ambocc = scol_ambocc.g; | ||
266 | |||
267 | calcAtmospherics(pos.xyz, ambocc); | ||
268 | |||
269 | vec3 col = atmosAmbient(vec3(0)); | ||
270 | col += atmosAffectDirectionalLight(max(min(da, scol), diffuse.a)); | ||
271 | |||
272 | col *= diffuse.rgb; | ||
273 | |||
274 | if (spec.a > 0.0) | ||
275 | { | ||
276 | vec3 ref = normalize(reflect(pos.xyz, norm.xyz)); | ||
277 | float sa = dot(ref, vary_light.xyz); | ||
278 | col.rgb += vary_SunlitColor*scol*spec.rgb*texture2D(lightFunc, vec2(sa, spec.a)).a; | ||
279 | } | ||
280 | |||
281 | col = atmosLighting(col); | ||
282 | col = scaleSoftClip(col); | ||
283 | |||
284 | gl_FragColor.rgb = col; | ||
285 | |||
286 | //gl_FragColor.rgb = gi_col.rgb; | ||
287 | gl_FragColor.a = 0.0; | ||
288 | |||
289 | //gl_FragColor.rg = scol_ambocc.rg; | ||
290 | //gl_FragColor.rgb = texture2DRect(lightMap, vary_fragcoord.xy).rgb; | ||
291 | //gl_FragColor.rgb = norm.rgb*0.5+0.5; | ||
292 | //gl_FragColor.rgb = vec3(ambocc); | ||
293 | //gl_FragColor.rgb = vec3(scol); | ||
294 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl new file mode 100644 index 0000000..ad8af47 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/softenLightV.glsl | |||
@@ -0,0 +1,24 @@ | |||
1 | /** | ||
2 | * @file softenLightF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | uniform vec2 screen_res; | ||
9 | |||
10 | varying vec4 vary_light; | ||
11 | varying vec2 vary_fragcoord; | ||
12 | void main() | ||
13 | { | ||
14 | //transform vertex | ||
15 | gl_Position = ftransform(); | ||
16 | |||
17 | vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex; | ||
18 | vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; | ||
19 | |||
20 | vec4 tex = gl_MultiTexCoord0; | ||
21 | tex.w = 1.0; | ||
22 | |||
23 | vary_light = gl_MultiTexCoord0; | ||
24 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl new file mode 100644 index 0000000..d653408 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl | |||
@@ -0,0 +1,199 @@ | |||
1 | /** | ||
2 | * @file spotLightF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | #version 120 | ||
9 | |||
10 | #extension GL_ARB_texture_rectangle : enable | ||
11 | |||
12 | uniform sampler2DRect diffuseRect; | ||
13 | uniform sampler2DRect specularRect; | ||
14 | uniform sampler2DRect depthMap; | ||
15 | uniform sampler2DRect normalMap; | ||
16 | uniform samplerCube environmentMap; | ||
17 | uniform sampler2DRect lightMap; | ||
18 | uniform sampler2D noiseMap; | ||
19 | uniform sampler2D lightFunc; | ||
20 | uniform sampler2D projectionMap; | ||
21 | |||
22 | uniform mat4 proj_mat; //screen space to light space | ||
23 | uniform float proj_near; //near clip for projection | ||
24 | uniform vec3 proj_p; //plane projection is emitting from (in screen space) | ||
25 | uniform vec3 proj_n; | ||
26 | uniform float proj_focus; //distance from plane to begin blurring | ||
27 | uniform float proj_lod; //(number of mips in proj map) | ||
28 | uniform float proj_range; //range between near clip and far clip plane of projection | ||
29 | uniform float proj_ambiance; | ||
30 | uniform float near_clip; | ||
31 | uniform float far_clip; | ||
32 | |||
33 | uniform vec3 proj_origin; //origin of projection to be used for angular attenuation | ||
34 | uniform float sun_wash; | ||
35 | uniform int proj_shadow_idx; | ||
36 | uniform float shadow_fade; | ||
37 | |||
38 | varying vec4 vary_light; | ||
39 | |||
40 | varying vec4 vary_fragcoord; | ||
41 | uniform vec2 screen_res; | ||
42 | |||
43 | uniform mat4 inv_proj; | ||
44 | |||
45 | vec4 getPosition(vec2 pos_screen) | ||
46 | { | ||
47 | float depth = texture2DRect(depthMap, pos_screen.xy).a; | ||
48 | vec2 sc = pos_screen.xy*2.0; | ||
49 | sc /= screen_res; | ||
50 | sc -= vec2(1.0,1.0); | ||
51 | vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); | ||
52 | vec4 pos = inv_proj * ndc; | ||
53 | pos /= pos.w; | ||
54 | pos.w = 1.0; | ||
55 | return pos; | ||
56 | } | ||
57 | |||
58 | void main() | ||
59 | { | ||
60 | vec4 frag = vary_fragcoord; | ||
61 | frag.xyz /= frag.w; | ||
62 | frag.xyz = frag.xyz*0.5+0.5; | ||
63 | frag.xy *= screen_res; | ||
64 | |||
65 | float shadow = 1.0; | ||
66 | |||
67 | if (proj_shadow_idx >= 0) | ||
68 | { | ||
69 | vec4 shd = texture2DRect(lightMap, frag.xy); | ||
70 | float sh[2]; | ||
71 | sh[0] = shd.b; | ||
72 | sh[1] = shd.a; | ||
73 | shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0); | ||
74 | } | ||
75 | |||
76 | vec3 pos = getPosition(frag.xy).xyz; | ||
77 | vec3 lv = vary_light.xyz-pos.xyz; | ||
78 | float dist2 = dot(lv,lv); | ||
79 | dist2 /= vary_light.w; | ||
80 | if (dist2 > 1.0) | ||
81 | { | ||
82 | discard; | ||
83 | } | ||
84 | |||
85 | vec3 norm = texture2DRect(normalMap, frag.xy).xyz*2.0-1.0; | ||
86 | |||
87 | norm = normalize(norm); | ||
88 | float l_dist = -dot(lv, proj_n); | ||
89 | |||
90 | vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); | ||
91 | if (proj_tc.z < 0.0) | ||
92 | { | ||
93 | discard; | ||
94 | } | ||
95 | |||
96 | proj_tc.xyz /= proj_tc.w; | ||
97 | |||
98 | float fa = gl_Color.a+1.0; | ||
99 | float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); | ||
100 | |||
101 | lv = proj_origin-pos.xyz; | ||
102 | lv = normalize(lv); | ||
103 | float da = dot(norm, lv); | ||
104 | |||
105 | vec3 col = vec3(0,0,0); | ||
106 | |||
107 | vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; | ||
108 | |||
109 | float noise = texture2D(noiseMap, frag.xy/128.0).b; | ||
110 | if (proj_tc.z > 0.0 && | ||
111 | proj_tc.x < 1.0 && | ||
112 | proj_tc.y < 1.0 && | ||
113 | proj_tc.x > 0.0 && | ||
114 | proj_tc.y > 0.0) | ||
115 | { | ||
116 | float lit = 0.0; | ||
117 | if (da > 0.0) | ||
118 | { | ||
119 | float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); | ||
120 | float lod = diff * proj_lod; | ||
121 | |||
122 | vec4 plcol = texture2DLod(projectionMap, proj_tc.xy, lod); | ||
123 | |||
124 | vec3 lcol = gl_Color.rgb * plcol.rgb * plcol.a; | ||
125 | |||
126 | lit = da * dist_atten * noise; | ||
127 | |||
128 | col = lcol*lit*diff_tex*shadow; | ||
129 | } | ||
130 | |||
131 | float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); | ||
132 | float lod = diff * proj_lod; | ||
133 | vec4 amb_plcol = texture2DLod(projectionMap, proj_tc.xy, lod); | ||
134 | //float amb_da = mix(proj_ambiance, proj_ambiance*max(-da, 0.0), max(da, 0.0)); | ||
135 | float amb_da = proj_ambiance; | ||
136 | if (da > 0.0) | ||
137 | { | ||
138 | amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; | ||
139 | } | ||
140 | |||
141 | amb_da += (da*da*0.5+0.5)*proj_ambiance; | ||
142 | |||
143 | amb_da *= dist_atten * noise; | ||
144 | |||
145 | amb_da = min(amb_da, 1.0-lit); | ||
146 | |||
147 | col += amb_da*gl_Color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; | ||
148 | } | ||
149 | |||
150 | |||
151 | vec4 spec = texture2DRect(specularRect, frag.xy); | ||
152 | if (spec.a > 0.0) | ||
153 | { | ||
154 | vec3 ref = reflect(normalize(pos), norm); | ||
155 | |||
156 | //project from point pos in direction ref to plane proj_p, proj_n | ||
157 | vec3 pdelta = proj_p-pos; | ||
158 | float ds = dot(ref, proj_n); | ||
159 | |||
160 | if (ds < 0.0) | ||
161 | { | ||
162 | vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; | ||
163 | |||
164 | vec3 stc = (proj_mat * vec4(pfinal.xyz, 1.0)).xyz; | ||
165 | |||
166 | if (stc.z > 0.0) | ||
167 | { | ||
168 | stc.xy /= stc.z+proj_near; | ||
169 | |||
170 | if (stc.x < 1.0 && | ||
171 | stc.y < 1.0 && | ||
172 | stc.x > 0.0 && | ||
173 | stc.y > 0.0) | ||
174 | { | ||
175 | vec4 scol = texture2DLod(projectionMap, stc.xy, proj_lod-spec.a*proj_lod); | ||
176 | col += dist_atten*scol.rgb*gl_Color.rgb*scol.a*spec.rgb*shadow; | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 | /*if (spec.a > 0.0) | ||
183 | { | ||
184 | //vec3 ref = reflect(normalize(pos), norm); | ||
185 | float sa = dot(normalize(lv-normalize(pos)),norm);; | ||
186 | //sa = max(sa, 0.0); | ||
187 | //sa = pow(sa, 128.0 * spec.a*spec.a/dist_atten)*min(dist_atten*4.0, 1.0); | ||
188 | sa = texture2D(lightFunc, vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0); | ||
189 | sa *= noise; | ||
190 | col += da*sa*lcol*spec.rgb; | ||
191 | }*/ | ||
192 | |||
193 | //attenuate point light contribution by SSAO component | ||
194 | col *= texture2DRect(lightMap, frag.xy).g; | ||
195 | |||
196 | |||
197 | gl_FragColor.rgb = col; | ||
198 | gl_FragColor.a = 0.0; | ||
199 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl new file mode 100644 index 0000000..8ced94e --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl | |||
@@ -0,0 +1,203 @@ | |||
1 | /** | ||
2 | * @file sunLightF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | #extension GL_ARB_texture_rectangle : enable | ||
9 | |||
10 | uniform sampler2DRect depthMap; | ||
11 | uniform sampler2DRect normalMap; | ||
12 | uniform sampler2DRectShadow shadowMap0; | ||
13 | uniform sampler2DRectShadow shadowMap1; | ||
14 | uniform sampler2DRectShadow shadowMap2; | ||
15 | uniform sampler2DRectShadow shadowMap3; | ||
16 | uniform sampler2DRectShadow shadowMap4; | ||
17 | uniform sampler2DRectShadow shadowMap5; | ||
18 | uniform sampler2D noiseMap; | ||
19 | |||
20 | uniform sampler2D lightFunc; | ||
21 | |||
22 | |||
23 | // Inputs | ||
24 | uniform mat4 shadow_matrix[6]; | ||
25 | uniform vec4 shadow_clip; | ||
26 | uniform float ssao_radius; | ||
27 | uniform float ssao_max_radius; | ||
28 | uniform float ssao_factor; | ||
29 | uniform float ssao_factor_inv; | ||
30 | |||
31 | varying vec2 vary_fragcoord; | ||
32 | varying vec4 vary_light; | ||
33 | |||
34 | uniform mat4 inv_proj; | ||
35 | uniform vec2 screen_res; | ||
36 | |||
37 | uniform float shadow_bias; | ||
38 | uniform float shadow_offset; | ||
39 | |||
40 | vec4 getPosition(vec2 pos_screen) | ||
41 | { | ||
42 | float depth = texture2DRect(depthMap, pos_screen.xy).a; | ||
43 | vec2 sc = pos_screen.xy*2.0; | ||
44 | sc /= screen_res; | ||
45 | sc -= vec2(1.0,1.0); | ||
46 | vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); | ||
47 | vec4 pos = inv_proj * ndc; | ||
48 | pos /= pos.w; | ||
49 | pos.w = 1.0; | ||
50 | return pos; | ||
51 | } | ||
52 | |||
53 | //calculate decreases in ambient lighting when crowded out (SSAO) | ||
54 | float calcAmbientOcclusion(vec4 pos, vec3 norm) | ||
55 | { | ||
56 | vec2 kern[8]; | ||
57 | // exponentially (^2) distant occlusion samples spread around origin | ||
58 | kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; | ||
59 | kern[1] = vec2(1.0, 0.0) * 0.250*0.250; | ||
60 | kern[2] = vec2(0.0, 1.0) * 0.375*0.375; | ||
61 | kern[3] = vec2(0.0, -1.0) * 0.500*0.500; | ||
62 | kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; | ||
63 | kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; | ||
64 | kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; | ||
65 | kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; | ||
66 | |||
67 | vec2 pos_screen = vary_fragcoord.xy; | ||
68 | vec3 pos_world = pos.xyz; | ||
69 | vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; | ||
70 | |||
71 | float angle_hidden = 0.0; | ||
72 | int points = 0; | ||
73 | |||
74 | float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); | ||
75 | |||
76 | // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) | ||
77 | for (int i = 0; i < 8; i++) | ||
78 | { | ||
79 | vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect); | ||
80 | vec3 samppos_world = getPosition(samppos_screen).xyz; | ||
81 | |||
82 | vec3 diff = pos_world - samppos_world; | ||
83 | float dist2 = dot(diff, diff); | ||
84 | |||
85 | // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area | ||
86 | // --> solid angle shrinking by the square of distance | ||
87 | //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 | ||
88 | //(k should vary inversely with # of samples, but this is taken care of later) | ||
89 | |||
90 | //if (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) // -0.05*norm to shift sample point back slightly for flat surfaces | ||
91 | // angle_hidden += min(1.0/dist2, ssao_factor_inv); // dist != 0 follows from conditional. max of 1.0 (= ssao_factor_inv * ssao_factor) | ||
92 | angle_hidden = angle_hidden + float(dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) * min(1.0/dist2, ssao_factor_inv); | ||
93 | |||
94 | // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion" | ||
95 | points = points + int(diff.z > -1.0); | ||
96 | } | ||
97 | |||
98 | angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0); | ||
99 | |||
100 | return (1.0 - (float(points != 0) * angle_hidden)); | ||
101 | } | ||
102 | |||
103 | void main() | ||
104 | { | ||
105 | vec2 pos_screen = vary_fragcoord.xy; | ||
106 | |||
107 | //try doing an unproject here | ||
108 | |||
109 | vec4 pos = getPosition(pos_screen); | ||
110 | |||
111 | vec3 norm = texture2DRect(normalMap, pos_screen).xyz*2.0-1.0; | ||
112 | |||
113 | /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL | ||
114 | { | ||
115 | gl_FragColor = vec4(0.0); // doesn't matter | ||
116 | return; | ||
117 | }*/ | ||
118 | |||
119 | float shadow = 1.0; | ||
120 | float dp_directional_light = max(0.0, dot(norm, vary_light.xyz)); | ||
121 | |||
122 | vec4 spos = vec4(pos.xyz + norm.xyz * (-pos.z/64.0*shadow_offset+shadow_bias), 1.0); | ||
123 | |||
124 | //vec3 debug = vec3(0,0,0); | ||
125 | |||
126 | if (spos.z > -shadow_clip.w) | ||
127 | { | ||
128 | if (dp_directional_light == 0.0) | ||
129 | { | ||
130 | // 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 | ||
131 | shadow = 0.0; | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | vec4 lpos; | ||
136 | |||
137 | if (spos.z < -shadow_clip.z) | ||
138 | { | ||
139 | lpos = shadow_matrix[3]*spos; | ||
140 | lpos.xy *= screen_res; | ||
141 | shadow = shadow2DRectProj(shadowMap3, lpos).x; | ||
142 | shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); | ||
143 | } | ||
144 | else if (spos.z < -shadow_clip.y) | ||
145 | { | ||
146 | lpos = shadow_matrix[2]*spos; | ||
147 | lpos.xy *= screen_res; | ||
148 | shadow = shadow2DRectProj(shadowMap2, lpos).x; | ||
149 | } | ||
150 | else if (spos.z < -shadow_clip.x) | ||
151 | { | ||
152 | lpos = shadow_matrix[1]*spos; | ||
153 | lpos.xy *= screen_res; | ||
154 | shadow = shadow2DRectProj(shadowMap1, lpos).x; | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | lpos = shadow_matrix[0]*spos; | ||
159 | lpos.xy *= screen_res; | ||
160 | shadow = shadow2DRectProj(shadowMap0, lpos).x; | ||
161 | } | ||
162 | |||
163 | // take the most-shadowed value out of these two: | ||
164 | // * the blurred sun shadow in the light (shadow) map | ||
165 | // * an unblurred dot product between the sun and this norm | ||
166 | // the goal is to err on the side of most-shadow to fill-in shadow holes and reduce artifacting | ||
167 | shadow = min(shadow, dp_directional_light); | ||
168 | } | ||
169 | |||
170 | /*debug.r = lpos.y / (lpos.w*screen_res.y); | ||
171 | |||
172 | lpos.xy /= lpos.w*32.0; | ||
173 | if (fract(lpos.x) < 0.1 || fract(lpos.y) < 0.1) | ||
174 | { | ||
175 | debug.gb = vec2(0.5, 0.5); | ||
176 | } | ||
177 | |||
178 | debug += (1.0-shadow)*0.5;*/ | ||
179 | |||
180 | } | ||
181 | else | ||
182 | { | ||
183 | // more distant than the shadow map covers | ||
184 | shadow = 1.0; | ||
185 | } | ||
186 | |||
187 | gl_FragColor[0] = shadow; | ||
188 | gl_FragColor[1] = calcAmbientOcclusion(pos, norm); | ||
189 | |||
190 | //spotlight shadow 1 | ||
191 | vec4 lpos = shadow_matrix[4]*spos; | ||
192 | lpos.xy *= screen_res; | ||
193 | gl_FragColor[2] = shadow2DRectProj(shadowMap4, lpos).x; | ||
194 | |||
195 | //spotlight shadow 2 | ||
196 | lpos = shadow_matrix[5]*spos; | ||
197 | lpos.xy *= screen_res; | ||
198 | gl_FragColor[3] = shadow2DRectProj(shadowMap5, lpos).x; | ||
199 | |||
200 | //gl_FragColor.rgb = pos.xyz; | ||
201 | //gl_FragColor.b = shadow; | ||
202 | //gl_FragColor.rgb = debug; | ||
203 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl new file mode 100644 index 0000000..5081485 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/sunLightV.glsl | |||
@@ -0,0 +1,25 @@ | |||
1 | /** | ||
2 | * @file sunLightF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | varying vec4 vary_light; | ||
9 | varying vec2 vary_fragcoord; | ||
10 | |||
11 | uniform vec2 screen_res; | ||
12 | |||
13 | void main() | ||
14 | { | ||
15 | //transform vertex | ||
16 | gl_Position = ftransform(); | ||
17 | vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex; | ||
18 | vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res; | ||
19 | vec4 tex = gl_MultiTexCoord0; | ||
20 | tex.w = 1.0; | ||
21 | |||
22 | vary_light = gl_MultiTexCoord0; | ||
23 | |||
24 | gl_FrontColor = gl_Color; | ||
25 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl new file mode 100644 index 0000000..7342186 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl | |||
@@ -0,0 +1,139 @@ | |||
1 | /** | ||
2 | * @file waterF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | vec3 scaleSoftClip(vec3 inColor); | ||
9 | vec3 atmosTransport(vec3 inColor); | ||
10 | |||
11 | uniform sampler2D bumpMap; | ||
12 | uniform sampler2D screenTex; | ||
13 | uniform sampler2D refTex; | ||
14 | uniform sampler2DRectShadow shadowMap0; | ||
15 | uniform sampler2DRectShadow shadowMap1; | ||
16 | uniform sampler2DRectShadow shadowMap2; | ||
17 | uniform sampler2DRectShadow shadowMap3; | ||
18 | uniform sampler2D noiseMap; | ||
19 | |||
20 | uniform mat4 shadow_matrix[6]; | ||
21 | uniform vec4 shadow_clip; | ||
22 | |||
23 | uniform float sunAngle; | ||
24 | uniform float sunAngle2; | ||
25 | uniform vec3 lightDir; | ||
26 | uniform vec3 specular; | ||
27 | uniform float lightExp; | ||
28 | uniform float refScale; | ||
29 | uniform float kd; | ||
30 | uniform vec2 screenRes; | ||
31 | uniform vec3 normScale; | ||
32 | uniform float fresnelScale; | ||
33 | uniform float fresnelOffset; | ||
34 | uniform float blurMultiplier; | ||
35 | uniform vec2 screen_res; | ||
36 | uniform mat4 norm_mat; //region space to screen space | ||
37 | |||
38 | //bigWave is (refCoord.w, view.w); | ||
39 | varying vec4 refCoord; | ||
40 | varying vec4 littleWave; | ||
41 | varying vec4 view; | ||
42 | varying vec4 vary_position; | ||
43 | |||
44 | void main() | ||
45 | { | ||
46 | vec4 color; | ||
47 | float dist = length(view.xy); | ||
48 | |||
49 | //normalize view vector | ||
50 | vec3 viewVec = normalize(view.xyz); | ||
51 | |||
52 | //get wave normals | ||
53 | vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; | ||
54 | vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; | ||
55 | vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; | ||
56 | //get base fresnel components | ||
57 | |||
58 | vec3 df = vec3( | ||
59 | dot(viewVec, wave1), | ||
60 | dot(viewVec, (wave2 + wave3) * 0.5), | ||
61 | dot(viewVec, wave3) | ||
62 | ) * fresnelScale + fresnelOffset; | ||
63 | df *= df; | ||
64 | |||
65 | vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; | ||
66 | |||
67 | float dist2 = dist; | ||
68 | dist = max(dist, 5.0); | ||
69 | |||
70 | float dmod = sqrt(dist); | ||
71 | |||
72 | vec2 dmod_scale = vec2(dmod*dmod, dmod); | ||
73 | |||
74 | //get reflected color | ||
75 | vec2 refdistort1 = wave1.xy*normScale.x; | ||
76 | vec2 refvec1 = distort+refdistort1/dmod_scale; | ||
77 | vec4 refcol1 = texture2D(refTex, refvec1); | ||
78 | |||
79 | vec2 refdistort2 = wave2.xy*normScale.y; | ||
80 | vec2 refvec2 = distort+refdistort2/dmod_scale; | ||
81 | vec4 refcol2 = texture2D(refTex, refvec2); | ||
82 | |||
83 | vec2 refdistort3 = wave3.xy*normScale.z; | ||
84 | vec2 refvec3 = distort+refdistort3/dmod_scale; | ||
85 | vec4 refcol3 = texture2D(refTex, refvec3); | ||
86 | |||
87 | vec4 refcol = refcol1 + refcol2 + refcol3; | ||
88 | float df1 = df.x + df.y + df.z; | ||
89 | refcol *= df1 * 0.333; | ||
90 | |||
91 | vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; | ||
92 | //wavef.z *= max(-viewVec.z, 0.1); | ||
93 | wavef = normalize(wavef); | ||
94 | |||
95 | float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; | ||
96 | |||
97 | vec2 refdistort4 = wavef.xy*0.125; | ||
98 | refdistort4.y -= abs(refdistort4.y); | ||
99 | vec2 refvec4 = distort+refdistort4/dmod; | ||
100 | float dweight = min(dist2*blurMultiplier, 1.0); | ||
101 | vec4 baseCol = texture2D(refTex, refvec4); | ||
102 | refcol = mix(baseCol*df2, refcol, dweight); | ||
103 | |||
104 | //get specular component | ||
105 | //float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); | ||
106 | |||
107 | //harden specular | ||
108 | //spec = pow(spec, 128.0); | ||
109 | |||
110 | //figure out distortion vector (ripply) | ||
111 | vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); | ||
112 | |||
113 | vec4 fb = texture2D(screenTex, distort2); | ||
114 | |||
115 | //mix with reflection | ||
116 | // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug | ||
117 | color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); | ||
118 | |||
119 | float shadow = 1.0; | ||
120 | vec4 pos = vary_position; | ||
121 | |||
122 | vec3 nz = texture2D(noiseMap, gl_FragCoord.xy/128.0).xyz; | ||
123 | vec4 spos = pos; | ||
124 | |||
125 | //spec *= shadow; | ||
126 | //color.rgb += spec * specular; | ||
127 | |||
128 | //color.rgb = atmosTransport(color.rgb); | ||
129 | //color.rgb = scaleSoftClip(color.rgb); | ||
130 | //color.a = spec * sunAngle2; | ||
131 | |||
132 | //wavef.z *= 0.1f; | ||
133 | wavef = normalize(wavef); | ||
134 | wavef = (norm_mat*vec4(wavef, 1.0)).xyz; | ||
135 | |||
136 | gl_FragData[0] = vec4(color.rgb, 0.75); | ||
137 | gl_FragData[1] = vec4(1,1,1, 0.8); | ||
138 | gl_FragData[2] = vec4(wavef*0.5+0.5, 0.f); | ||
139 | } | ||
diff --git a/linden/indra/newview/app_settings/shaders/class2/deferred/waterV.glsl b/linden/indra/newview/app_settings/shaders/class2/deferred/waterV.glsl new file mode 100644 index 0000000..b45e5c5 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/deferred/waterV.glsl | |||
@@ -0,0 +1,76 @@ | |||
1 | /** | ||
2 | * @file waterV.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | void calcAtmospherics(vec3 inPositionEye); | ||
9 | |||
10 | uniform vec2 d1; | ||
11 | uniform vec2 d2; | ||
12 | uniform float time; | ||
13 | uniform vec3 eyeVec; | ||
14 | uniform float waterHeight; | ||
15 | |||
16 | varying vec4 refCoord; | ||
17 | varying vec4 littleWave; | ||
18 | varying vec4 view; | ||
19 | |||
20 | varying vec4 vary_position; | ||
21 | |||
22 | float wave(vec2 v, float t, float f, vec2 d, float s) | ||
23 | { | ||
24 | return (dot(d, v)*f + t*s)*f; | ||
25 | } | ||
26 | |||
27 | void main() | ||
28 | { | ||
29 | //transform vertex | ||
30 | vec4 position = gl_Vertex; | ||
31 | mat4 modelViewProj = gl_ModelViewProjectionMatrix; | ||
32 | |||
33 | vec4 oPosition; | ||
34 | |||
35 | //get view vector | ||
36 | vec3 oEyeVec; | ||
37 | oEyeVec.xyz = position.xyz-eyeVec; | ||
38 | |||
39 | float d = length(oEyeVec.xy); | ||
40 | float ld = min(d, 2560.0); | ||
41 | |||
42 | position.xy = eyeVec.xy + oEyeVec.xy/d*ld; | ||
43 | view.xyz = oEyeVec; | ||
44 | |||
45 | d = clamp(ld/1536.0-0.5, 0.0, 1.0); | ||
46 | d *= d; | ||
47 | |||
48 | oPosition = position; | ||
49 | oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); | ||
50 | vary_position = gl_ModelViewMatrix * oPosition; | ||
51 | oPosition = modelViewProj * oPosition; | ||
52 | |||
53 | refCoord.xyz = oPosition.xyz + vec3(0,0,0.2); | ||
54 | |||
55 | //get wave position parameter (create sweeping horizontal waves) | ||
56 | vec3 v = position.xyz; | ||
57 | v.x += (cos(v.x*0.08/*+time*0.01*/)+sin(v.y*0.02))*6.0; | ||
58 | |||
59 | //push position for further horizon effect. | ||
60 | position.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z); | ||
61 | position.w = 1.0; | ||
62 | position = position*gl_ModelViewMatrix; | ||
63 | |||
64 | calcAtmospherics((gl_ModelViewMatrix * gl_Vertex).xyz); | ||
65 | |||
66 | |||
67 | //pass wave parameters to pixel shader | ||
68 | vec2 bigWave = (v.xy) * vec2(0.04,0.04) + d1 * time * 0.055; | ||
69 | //get two normal map (detail map) texture coordinates | ||
70 | littleWave.xy = (v.xy) * vec2(0.45, 0.9) + d2 * time * 0.13; | ||
71 | littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1; | ||
72 | view.w = bigWave.y; | ||
73 | refCoord.w = bigWave.x; | ||
74 | |||
75 | gl_Position = oPosition; | ||
76 | } | ||