From 33a2608da5a85b01acbfcced10128a2c42760928 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Sun, 9 Jun 2013 20:55:02 -0700 Subject: NORSPEC-246 fix issues with normal encoding on precision-deprived hardware and remove haxors --- .../shaders/class1/deferred/blurLightF.glsl | 16 ++++++--------- .../shaders/class1/deferred/materialF.glsl | 23 ++++++---------------- .../shaders/class1/deferred/multiPointLightF.glsl | 16 ++++++--------- .../shaders/class1/deferred/multiSpotLightF.glsl | 16 ++++++--------- .../shaders/class1/deferred/pointLightF.glsl | 16 ++++++--------- .../shaders/class1/deferred/softenLightF.glsl | 18 +++++++++-------- .../shaders/class1/deferred/spotLightF.glsl | 16 ++++++--------- .../shaders/class1/deferred/sunLightSSAOF.glsl | 16 ++++++--------- .../shaders/class2/deferred/multiSpotLightF.glsl | 16 ++++++--------- .../shaders/class2/deferred/softenLightF.glsl | 16 ++++++--------- .../shaders/class2/deferred/spotLightF.glsl | 16 ++++++--------- .../shaders/class2/deferred/sunLightF.glsl | 16 ++++++--------- .../shaders/class2/deferred/sunLightSSAOF.glsl | 16 ++++++--------- 13 files changed, 82 insertions(+), 135 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index e8279241d1..d071801e2d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -67,20 +67,16 @@ vec4 getPosition(vec2 pos_screen) #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 70cc884209..f58c69deaa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -429,20 +429,16 @@ VARYING vec2 vary_texcoord0; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) @@ -692,13 +688,6 @@ void main() #else frag_data[0] = final_color; - -#ifdef SINGLE_FP_ONLY - // "Not so HD" range on older cards; make it fit! - // - final_specular = final_specular * vec4(0.25f); -#endif - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 0d86840c1c..e27250e13e 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -59,20 +59,16 @@ uniform mat4 inv_proj; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index f4d174729d..ca3fcdcadb 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -70,20 +70,16 @@ uniform mat4 inv_proj; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 1313ba582f..850988a604 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -57,20 +57,16 @@ uniform vec4 viewport; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 3e3e0a5a5d..e94201df41 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -79,16 +79,18 @@ uniform mat4 inv_proj; uniform vec2 screen_res; #ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); +} + vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec3 decode_normal (vec2 enc) diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index adfe012e4d..879953b476 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -68,20 +68,16 @@ uniform mat4 inv_proj; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 7fcbb1aa85..6d3b3e23de 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -52,20 +52,16 @@ uniform vec2 screen_res; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index f7023be150..db60c8ea51 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -71,20 +71,16 @@ uniform mat4 inv_proj; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 6e35641277..08b456dd96 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -81,20 +81,16 @@ uniform vec2 screen_res; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 0436c80710..4fc9a6ad87 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -71,20 +71,16 @@ uniform mat4 inv_proj; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 640701572d..c1ed32f7e7 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -68,20 +68,16 @@ uniform float spot_shadow_offset; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 6db26cec4c..8a029109a6 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -69,20 +69,16 @@ uniform float spot_shadow_offset; #ifdef SINGLE_FP_ONLY vec2 encode_normal(vec3 n) { - float f = sqrt(2 * n.z + 2); - return (n.xy / vec2(f)) + vec2(0.5f); + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); } vec3 decode_normal (vec2 enc) { - vec2 fenc = enc - 0.5f; - float f = dot(fenc,fenc); - f = clamp(f,0.0f,1.0f); - float g = sqrt(1-f); - vec3 n; - n.xy = fenc*g; - n.z = 1.0f - (f * 0.5f); - return normalize(n); + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; } #else vec2 encode_normal(vec3 n) -- cgit v1.2.3