From c2df68743d53a9525f67cbec14637db9d56dd9fe Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 8 Apr 2013 23:02:57 -0400 Subject: First pass of per-pixel lit alpha blended objects. --- .../shaders/class1/deferred/alphaNonIndexedF.glsl | 54 +++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl index beb3290187..a0a79bada6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl @@ -47,9 +47,51 @@ VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; VARYING vec4 vertex_color; +VARYING vec3 vary_norm; uniform mat4 inv_proj; +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec3 light_attenuation[8]; +uniform vec3 light_diffuse[8]; + +float calcDirectionalLight(vec3 n, vec3 l) +{ + float a = pow(max(dot(n,l),0.0), 0.6); + return a; +} + +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) +{ + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float d = dot(lv,lv); + + float da = 0.0; + + if (d > 0.0 && la > 0.0 && fa > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist2 = d/la; + da = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); + + // spotlight coefficient. + float spot = max(dot(-ln, lv), is_pointlight); + da *= spot*spot; // GL_SPOT_EXPONENT=2 + + //angular attenuation + da *= max(pow(dot(n, lv), 0.6), 0.0); + } + + return da; +} + vec4 getPosition(vec2 pos_screen) { float depth = texture2DRect(depthMap, pos_screen.xy).a; @@ -72,14 +114,22 @@ void main() vec4 diff= texture2D(diffuseMap,vary_texcoord0.xy); - vec4 col = vec4(vary_ambient + vary_directional.rgb, vertex_color.a); + vec3 dlight = calcDirectionalLight(vary_norm, light_position[0].xyz) * vary_directional.rgb * vary_pointlight_col; + + vec4 col = vec4(vary_ambient + dlight, vertex_color.a); vec4 color = diff * col; color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); + vec3 light_col = vec3(0,0,0); - color.rgb += diff.rgb * vary_pointlight_col.rgb; + for (int i = 2; i < 8; i++) + { + light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, vary_norm, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + } + + color.rgb += vary_pointlight_col * light_col; frag_color = color; //frag_color = vec4(1,0,1,1); -- cgit v1.2.3 From 27fbf5efc9192813e5109443c60bfc26f99716ee Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 9 Apr 2013 11:46:52 -0400 Subject: Re-added RGB10_A2 normal buffer, this time encoded with a sphere map transform so we can store the environment intensity in the blue channel. --- .../app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl index a0a79bada6..10e9670894 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl @@ -58,7 +58,7 @@ uniform vec3 light_diffuse[8]; float calcDirectionalLight(vec3 n, vec3 l) { - float a = pow(max(dot(n,l),0.0), 0.6); + float a = pow(max(dot(n,l),0.0), 0.7); return a; } @@ -86,7 +86,7 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= max(pow(dot(n, lv), 0.6), 0.0); + da *= max(pow(dot(n, lv), 0.7), 0.0); } return da; @@ -129,7 +129,7 @@ void main() light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, vary_norm, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); } - color.rgb += vary_pointlight_col * light_col; + color.rgb += diff.rgb * vary_pointlight_col * light_col; frag_color = color; //frag_color = vec4(1,0,1,1); -- cgit v1.2.3 From 9e9e0f3ea6dad9d0f553aaeb0819e660e248ad9f Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 10 Apr 2013 10:31:51 -0700 Subject: NORSPEC-98 side-step nV compiler fail-o-rama --- .../shaders/class1/deferred/alphaNonIndexedF.glsl | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl index 10e9670894..07a7ee4e1a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl @@ -55,6 +55,12 @@ uniform vec4 light_position[8]; uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +#if 0 +uniform vec4 light_position[1]; +uniform vec3 light_direction[1]; +uniform vec3 light_attenuation[1]; +uniform vec3 light_diffuse[1]; +#endif float calcDirectionalLight(vec3 n, vec3 l) { @@ -124,11 +130,17 @@ void main() color.rgb = scaleSoftClip(color.rgb); vec3 light_col = vec3(0,0,0); - for (int i = 2; i < 8; i++) - { - light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, vary_norm, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); - } - +#define LIGHT_LOOP(i) \ + light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, vary_norm, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + color.rgb += diff.rgb * vary_pointlight_col * light_col; frag_color = color; -- cgit v1.2.3 From 19430bfce05748c363bb83c7e78e605ee6af3b14 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Thu, 11 Apr 2013 11:57:50 -0700 Subject: NORSPEC-98 fix? for mac shader compiler crasher --- .../shaders/class1/deferred/alphaNonIndexedF.glsl | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl index 07a7ee4e1a..eff7b91a88 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl @@ -55,12 +55,6 @@ uniform vec4 light_position[8]; uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -#if 0 -uniform vec4 light_position[1]; -uniform vec3 light_direction[1]; -uniform vec3 light_attenuation[1]; -uniform vec3 light_diffuse[1]; -#endif float calcDirectionalLight(vec3 n, vec3 l) { @@ -120,7 +114,10 @@ void main() vec4 diff= texture2D(diffuseMap,vary_texcoord0.xy); - vec3 dlight = calcDirectionalLight(vary_norm, light_position[0].xyz) * vary_directional.rgb * vary_pointlight_col; + vec3 n = vary_norm; + vec3 l = light_position[0].xyz; + vec3 dlight = calcDirectionalLight(n, l); + dlight = dlight * vary_directional.rgb * vary_pointlight_col; vec4 col = vec4(vary_ambient + dlight, vertex_color.a); vec4 color = diff * col; -- cgit v1.2.3 From 7d623abfc3c7f6ef99ae3189a592211f4bf696db Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Thu, 11 Apr 2013 20:16:11 -0700 Subject: NORSPEC-98 redux...hopefully fix mac AND linux at the same time --- .../shaders/class1/deferred/alphaNonIndexedF.glsl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl index eff7b91a88..e872dadcc1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl @@ -126,8 +126,8 @@ void main() color.rgb = scaleSoftClip(color.rgb); vec3 light_col = vec3(0,0,0); - -#define LIGHT_LOOP(i) \ +#if MAC_GEFORCE_HACK + #define LIGHT_LOOP(i) \ light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, vary_norm, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) @@ -137,7 +137,12 @@ void main() LIGHT_LOOP(5) LIGHT_LOOP(6) LIGHT_LOOP(7) - +#else + for (int i = 2; i < 8; i++) + { + light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, vary_norm, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + } +#endif color.rgb += diff.rgb * vary_pointlight_col * light_col; frag_color = color; -- cgit v1.2.3 From a9f3e6d95c03a469ac6b88e8d0ed4034cb978d88 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Tue, 16 Apr 2013 12:50:45 -0700 Subject: See if we can run with no ifdefs in alpha shaders on all platforms --- .../shaders/class1/deferred/alphaNonIndexedF.glsl | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl index e872dadcc1..cccc7275ab 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl @@ -56,13 +56,13 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -float calcDirectionalLight(vec3 n, vec3 l) +vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = pow(max(dot(n,l),0.0), 0.7); - return a; + return vec3(a,a,a); } -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) +vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { //get light vector vec3 lv = lp.xyz-v; @@ -89,7 +89,7 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa da *= max(pow(dot(n, lv), 0.7), 0.0); } - return da; + return vec3(da,da,da); } vec4 getPosition(vec2 pos_screen) @@ -126,7 +126,7 @@ void main() color.rgb = scaleSoftClip(color.rgb); vec3 light_col = vec3(0,0,0); -#if MAC_GEFORCE_HACK + #define LIGHT_LOOP(i) \ light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, vary_norm, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); @@ -137,12 +137,7 @@ void main() LIGHT_LOOP(5) LIGHT_LOOP(6) LIGHT_LOOP(7) -#else - for (int i = 2; i < 8; i++) - { - light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, vary_norm, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); - } -#endif + color.rgb += diff.rgb * vary_pointlight_col * light_col; frag_color = color; -- cgit v1.2.3 From f3036451564a00da5af4935ca59d22103ba46066 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 3 Jun 2013 17:10:37 -0500 Subject: NORSPEC-195 Fix for incorrect alpha blending with deferred rendering enabled. --- .../newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl index cccc7275ab..2ce44d599f 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl @@ -140,6 +140,8 @@ void main() color.rgb += diff.rgb * vary_pointlight_col * light_col; + color.rgb = pow(color.rgb, vec3(1.0/2.2)); + frag_color = color; //frag_color = vec4(1,0,1,1); //frag_color = vec4(1,0,1,1)*shadow; -- cgit v1.2.3