From 9593e85e144e2141c92abe597653851852501060 Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Sun, 9 Sep 2012 21:01:24 -0400 Subject: Use a customized normalized gaussian specular term. --- .../newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 7e79317543..9e194cdcd1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -128,8 +128,7 @@ void main() if (sa > 0.0) { - sa = 6 * texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0); - sa *= noise; + sa = texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0); col += da*sa*light_col[i].rgb*spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 75757b26c8..6e5ac8317b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -110,8 +110,7 @@ void main() float sa = dot(normalize(lv-normalize(pos)),norm); if (sa > 0.0) { - sa = 6 * texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0); - sa *= noise; + sa = texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0); col += da*sa*color.rgb*spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 89448e2167..14eaafeb68 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -301,7 +301,7 @@ void main() // vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*(6 * texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; -- cgit v1.2.3 From eda11a25a465dd87b187f63da661f2ce02925deb Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 11 Jan 2013 06:37:21 -0500 Subject: Initial (largely complete) gamma correct rendering implementation. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 1 + .../app_settings/shaders/class1/deferred/fullbrightF.glsl | 1 + .../app_settings/shaders/class1/deferred/pointLightF.glsl | 1 + .../shaders/class1/deferred/postDeferredF.glsl | 3 ++- .../shaders/class1/deferred/postDeferredNoDoFF.glsl | 3 ++- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 14 +++++++++----- .../shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl | 4 +++- 7 files changed, 19 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index dd87ddb330..ef04ef5ce6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -59,6 +59,7 @@ void main() vec4 pos = vec4(vary_position, 1.0); vec4 diff= diffuseLookup(vary_texcoord0.xy); + diff.rgb = pow(diff.rgb, vec3(2.2)); vec4 col = vec4(vary_ambient + vary_directional.rgb, vertex_color.a); vec4 color = diff * col; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 36433a5827..b6a9417fe7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -43,6 +43,7 @@ void main() float shadow = 1.0; vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; + color.rgb = pow(color.rgb, vec3(2.2)); color.rgb = fullbrightAtmosTransport(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 6e5ac8317b..fa1572e692 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -108,6 +108,7 @@ void main() if (spec.a > 0.0) { float sa = dot(normalize(lv-normalize(pos)),norm); + spec.rgb += pow(1 - dot(-normalize(pos), norm), 2) * da * 3; if (sa > 0.0) { sa = texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl index bf362e21a4..3f57b006cd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl @@ -37,6 +37,7 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform float max_cof; uniform float res_scale; +uniform float global_gamma; VARYING vec2 vary_fragcoord; @@ -123,6 +124,6 @@ void main() diff /= w; } - + diff.rgb = pow(diff.rgb, vec3(1.0/global_gamma)); frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl index eb5beeef39..c891c4e445 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl @@ -35,12 +35,13 @@ uniform sampler2DRect diffuseRect; uniform sampler2D bloomMap; uniform vec2 screen_res; +uniform float global_gamma; VARYING vec2 vary_fragcoord; void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); - + diff.rgb = pow(diff.rgb, vec3(1.0/global_gamma)); vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res); frag_color = diff + bloom; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 14eaafeb68..87cdf1026f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -77,6 +77,11 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; +vec3 samplesRGB(vec3 color) +{ + return pow(color, vec3(2.2)); +} + vec4 getPosition_d(vec2 pos_screen, float depth) { vec2 sc = pos_screen.xy*2.0; @@ -101,22 +106,21 @@ vec3 getPositionEye() } vec3 getSunlitColor() { - return vary_SunlitColor; + return samplesRGB(vary_SunlitColor) * 4.4; } vec3 getAmblitColor() { - return vary_AmblitColor; + return samplesRGB((vary_AmblitColor)) * 2.2; } vec3 getAdditiveColor() { - return vary_AdditiveColor; + return samplesRGB(vary_AdditiveColor) * 2.2; } vec3 getAtmosAttenuation() { return vary_AtmosAttenuation; } - void setPositionEye(vec3 v) { vary_PositionEye = v; @@ -310,7 +314,7 @@ void main() //add environmentmap vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, + col = mix(col.rgb, samplesRGB(textureCube(environmentMap, env_vec).rgb) * 2.2, max(spec.a-diffuse.a*2.0, 0.0)); } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl index 6c34643aab..9543be562b 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl @@ -37,6 +37,8 @@ vec3 fullbrightScaleSoftClip(vec3 light); VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +uniform float texture_gamma; + void fullbright_lighting() { vec4 color = diffuseLookup(vary_texcoord0.xy) * vertex_color; @@ -45,7 +47,7 @@ void fullbright_lighting() { discard; } - + color.rgb = pow(color.rgb, vec3(texture_gamma)); color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); -- cgit v1.2.3 From de0863ed6e91fda0c1b5342b9fecf07c4af47d63 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 11 Jan 2013 07:19:27 -0500 Subject: Linearize spotlight textures. --- .../app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 6 ++++++ indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index bff87cb6aa..53e5a228fa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -70,6 +70,8 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = pow(ret.rgb, vec3(2.2)); + vec2 dist = tc-vec2(0.5); float det = max(1.0-lod/(proj_lod*0.5), 0.0); @@ -85,6 +87,8 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = pow(ret.rgb, vec3(2.2)); + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -102,6 +106,8 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = pow(ret.rgb, vec3(2.2)); + vec2 dist = tc-vec2(0.5); float d = dot(dist,dist); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index cca63872de..9bdf87678f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -72,6 +72,8 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = pow(ret.rgb, vec3(2.2)); + vec2 dist = tc-vec2(0.5); float det = max(1.0-lod/(proj_lod*0.5), 0.0); @@ -87,6 +89,8 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = pow(ret.rgb, vec3(2.2)); + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -104,6 +108,8 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = pow(ret.rgb, vec3(2.2)); + vec2 dist = tc-vec2(0.5); float d = dot(dist,dist); -- cgit v1.2.3 From cc7ae8fbd1fc249f77ced95171e5c22e48adedb6 Mon Sep 17 00:00:00 2001 From: Geenz Date: Fri, 25 Jan 2013 17:53:43 -0500 Subject: Linearize light source colors, and a bit of cook torrance fanciness. --- .../shaders/class1/deferred/multiPointLightF.glsl | 13 ++++++++++--- .../shaders/class1/deferred/pointLightF.glsl | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 9e194cdcd1..ad50690c02 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -123,13 +123,20 @@ void main() if (spec.a > 0.0) { //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + vec3 fres = spec.rgb + pow(1 - dot(h, npos), 5) * (1 - spec.rgb); + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - float sa = dot(normalize(lv+npos),norm); if (sa > 0.0) { - sa = texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0); - col += da*sa*light_col[i].rgb*spec.rgb; + vec3 scol = (fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt) / (nh * da); + col += lit*scol*light_col[i].rgb; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index fa1572e692..03b036375b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -107,12 +107,20 @@ void main() vec4 spec = texture2DRect(specularRect, frag.xy); if (spec.a > 0.0) { - float sa = dot(normalize(lv-normalize(pos)),norm); - spec.rgb += pow(1 - dot(-normalize(pos), norm), 2) * da * 3; + vec3 npos = -normalize(pos); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + vec3 fres = spec.rgb + pow(1 - dot(h, npos), 5) * (1 - spec.rgb); + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); + if (sa > 0.0) { - sa = texture2D(lightFunc, vec2(sa, spec.a)).r * min(dist_atten*4.0, 1.0); - col += da*sa*color.rgb*spec.rgb; + vec3 scol = (fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt) / (nh * da); + col += lit*scol*color.rgb; } } -- cgit v1.2.3 From aa1befd689703d9fea50399201911e0f8fca6ac6 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 30 Jan 2013 12:17:04 -0500 Subject: Specular map support. This is the vast majority of the material parameters implemented at this point for opaque geometry. --- .../app_settings/shaders/class1/deferred/bumpF.glsl | 21 +++++++++++++-------- .../shaders/class1/deferred/softenLightF.glsl | 6 +++--- 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 23c4ea2fff..6e5cc69e39 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -31,6 +31,9 @@ out vec4 frag_data[3]; uniform sampler2D diffuseMap; uniform sampler2D bumpMap; +uniform sampler2D specularMap; +uniform float env_intensity; +uniform vec4 specular_color; VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; @@ -42,15 +45,17 @@ VARYING vec2 vary_texcoord0; void main() { vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb; - vec3 norm = texture2D(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0; + vec4 spec = texture2D(specularMap, vary_texcoord0.xy); + vec4 norm = texture2D(bumpMap, vary_texcoord0.xy); + norm.xyz = norm.xyz * 2 - 1; - vec3 tnorm = vec3(dot(norm,vary_mat0), - dot(norm,vary_mat1), - dot(norm,vary_mat2)); - - frag_data[0] = vec4(col, 0.0); - frag_data[1] = vertex_color.aaaa; // spec + vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); + + frag_data[0] = vec4(col * (1 - spec.a * env_intensity), 0); + frag_data[1] = vec4(spec.xyz * specular_color.xyz, specular_color.a * norm.a); // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(tnorm); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); + frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, spec.a * env_intensity); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 87cdf1026f..2ec3fe4a52 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -280,8 +280,8 @@ void main() vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; vec3 pos = getPosition_d(tc, depth).xyz; - vec3 norm = texture2DRect(normalMap, tc).xyz; - norm = (norm.xyz-0.5)*2.0; // unpack norm + vec4 norm = texture2DRect(normalMap, tc); + norm.xyz = (norm.xyz-0.5)*2.0; // unpack norm float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); @@ -315,7 +315,7 @@ void main() //add environmentmap vec3 env_vec = env_mat * refnormpersp; col = mix(col.rgb, samplesRGB(textureCube(environmentMap, env_vec).rgb) * 2.2, - max(spec.a-diffuse.a*2.0, 0.0)); + max(norm.a-diffuse.a*2.0, 0.0)); } col = atmosLighting(col); -- cgit v1.2.3 From 2ae4b6976baf0556066d5a3b43b8f6148f18c1d8 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 4 Feb 2013 11:32:05 -0500 Subject: Added a new draw pool specifically for faces with materials applied to them. Removed materials rendering from the bump draw pool, and reverted it to its previous state. --- .../shaders/class1/deferred/bumpF.glsl | 21 ++--- .../shaders/class1/deferred/materialF.glsl | 89 ++++++++++++++++++++++ .../shaders/class1/deferred/materialV.glsl | 57 ++++++++++++++ 3 files changed, 154 insertions(+), 13 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/materialF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/deferred/materialV.glsl (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 6e5cc69e39..aaf1e5e572 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -31,9 +31,6 @@ out vec4 frag_data[3]; uniform sampler2D diffuseMap; uniform sampler2D bumpMap; -uniform sampler2D specularMap; -uniform float env_intensity; -uniform vec4 specular_color; VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; @@ -45,17 +42,15 @@ VARYING vec2 vary_texcoord0; void main() { vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb; - vec4 spec = texture2D(specularMap, vary_texcoord0.xy); - vec4 norm = texture2D(bumpMap, vary_texcoord0.xy); - norm.xyz = norm.xyz * 2 - 1; + vec3 norm = texture2D(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0; - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); - - frag_data[0] = vec4(col * (1 - spec.a * env_intensity), 0); - frag_data[1] = vec4(spec.xyz * specular_color.xyz, specular_color.a * norm.a); // spec + vec3 tnorm = vec3(dot(norm,vary_mat0), + dot(norm,vary_mat1), + dot(norm,vary_mat2)); + + frag_data[0] = vec4(col * (1 - vertex_color.a), 0.0); + frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(tnorm); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, spec.a * env_intensity); + frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, vertex_color.a); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl new file mode 100644 index 0000000000..4f7fc6a411 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -0,0 +1,89 @@ +/** + * @file materialF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif + +uniform sampler2D diffuseMap; + +uniform sampler2D bumpMap; + +uniform sampler2D specularMap; +uniform float env_intensity; +uniform vec4 specular_color; + +#ifdef ALPHA_TEST +uniform float minimum_alpha; +#endif + +VARYING vec3 vary_mat0; +VARYING vec3 vary_mat1; +VARYING vec3 vary_mat2; + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void main() +{ + vec4 col = texture2D(diffuseMap, vary_texcoord0.xy) * vertex_color; + + #ifdef ALPHA_TEST + if (col.a < minimum_alpha) + { + discard; + } + #endif + + vec4 spec = texture2D(specularMap, vary_texcoord0.xy); + + vec4 norm = texture2D(bumpMap, vary_texcoord0.xy); + + norm.xyz = norm.xyz * 2 - 1; + + vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); + + vec4 final_color = col; + final_color.rgb *= 1 - spec.a * env_intensity; + + #ifndef EMISSIVE_MASK + final_color.a = 0; + #endif + + vec4 final_specular = spec; + final_specular.rgb *= specular_color.rgb; + final_specular.a = specular_color.a * norm.a; + + vec4 final_normal = vec4(normalize(tnorm), spec.a * env_intensity); + final_normal.xyz = final_normal.xyz * 0.5 + 0.5; + + frag_data[0] = final_color; + frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. + frag_data[2] = final_normal; // XYZ = Normal. W = Env. intensity. +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl new file mode 100644 index 0000000000..c8d38bb8f7 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -0,0 +1,57 @@ +/** + * @file bumpV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform mat3 normal_matrix; +uniform mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec3 normal; +ATTRIBUTE vec2 texcoord0; +ATTRIBUTE vec3 binormal; + +VARYING vec3 vary_mat0; +VARYING vec3 vary_mat1; +VARYING vec3 vary_mat2; +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void main() +{ + //transform vertex + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + vec3 n = normalize(normal_matrix * normal); + vec3 b = normalize(normal_matrix * binormal); + vec3 t = cross(b, n); + + vary_mat0 = vec3(t.x, b.x, n.x); + vary_mat1 = vec3(t.y, b.y, n.y); + vary_mat2 = vec3(t.z, b.z, n.z); + + vertex_color = diffuse_color; +} -- cgit v1.2.3 From c107afcb1ed02266d6f63910338c6095fcad9e23 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 26 Mar 2013 16:23:49 -0500 Subject: NORSPEC-57, NORSPEC-58 Remove sRGB and gamma correction from shaders to remove banding and not break all shiny objects. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 1 - .../app_settings/shaders/class1/deferred/bumpF.glsl | 2 +- .../app_settings/shaders/class1/deferred/diffuseF.glsl | 2 +- .../shaders/class1/deferred/diffuseIndexedF.glsl | 2 +- .../shaders/class1/deferred/postDeferredF.glsl | 3 +-- .../shaders/class1/deferred/postDeferredNoDoFF.glsl | 3 +-- .../shaders/class1/deferred/softenLightF.glsl | 17 ++++++----------- .../shaders/class1/deferred/spotLightF.glsl | 6 ------ .../class1/lighting/lightFullbrightAlphaMaskF.glsl | 4 +--- 9 files changed, 12 insertions(+), 28 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index ef04ef5ce6..dd87ddb330 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -59,7 +59,6 @@ void main() vec4 pos = vec4(vary_position, 1.0); vec4 diff= diffuseLookup(vary_texcoord0.xy); - diff.rgb = pow(diff.rgb, vec3(2.2)); vec4 col = vec4(vary_ambient + vary_directional.rgb, vertex_color.a); vec4 color = diff * col; diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index aaf1e5e572..a887728493 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -48,7 +48,7 @@ void main() dot(norm,vary_mat1), dot(norm,vary_mat2)); - frag_data[0] = vec4(col * (1 - vertex_color.a), 0.0); + frag_data[0] = vec4(col, 0.0); frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(tnorm); diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 85f28f68c0..2e456d00dd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -38,7 +38,7 @@ VARYING vec2 vary_texcoord0; void main() { vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb; - frag_data[0] = vec4(col * (1 - vertex_color.a), 0.0); + frag_data[0] = vec4(col, 0.0); frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(vary_normal); diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 6b5a922c29..bb6dc9a57d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -37,7 +37,7 @@ void main() { vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; - frag_data[0] = vec4(col * (1 - vertex_color.a), 0.0); + frag_data[0] = vec4(col, 0.0); frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(vary_normal); diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl index 3f57b006cd..bf362e21a4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl @@ -37,7 +37,6 @@ uniform mat4 inv_proj; uniform vec2 screen_res; uniform float max_cof; uniform float res_scale; -uniform float global_gamma; VARYING vec2 vary_fragcoord; @@ -124,6 +123,6 @@ void main() diff /= w; } - diff.rgb = pow(diff.rgb, vec3(1.0/global_gamma)); + frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl index c891c4e445..eb5beeef39 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl @@ -35,13 +35,12 @@ uniform sampler2DRect diffuseRect; uniform sampler2D bloomMap; uniform vec2 screen_res; -uniform float global_gamma; VARYING vec2 vary_fragcoord; void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); - diff.rgb = pow(diff.rgb, vec3(1.0/global_gamma)); + vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res); frag_color = diff + bloom; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 2ec3fe4a52..2905cc91b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -77,11 +77,6 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 samplesRGB(vec3 color) -{ - return pow(color, vec3(2.2)); -} - vec4 getPosition_d(vec2 pos_screen, float depth) { vec2 sc = pos_screen.xy*2.0; @@ -106,15 +101,15 @@ vec3 getPositionEye() } vec3 getSunlitColor() { - return samplesRGB(vary_SunlitColor) * 4.4; + return vary_SunlitColor; } vec3 getAmblitColor() { - return samplesRGB((vary_AmblitColor)) * 2.2; + return vary_AmblitColor; } vec3 getAdditiveColor() { - return samplesRGB(vary_AdditiveColor) * 2.2; + return vary_AdditiveColor; } vec3 getAtmosAttenuation() { @@ -305,7 +300,7 @@ void main() // vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = vary_SunlitColor*(6 * texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -314,8 +309,8 @@ void main() //add environmentmap vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, samplesRGB(textureCube(environmentMap, env_vec).rgb) * 2.2, - max(norm.a-diffuse.a*2.0, 0.0)); + col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, + max(spec.a-diffuse.a*2.0, 0.0)); } col = atmosLighting(col); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 9bdf87678f..cca63872de 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -72,8 +72,6 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = pow(ret.rgb, vec3(2.2)); - vec2 dist = tc-vec2(0.5); float det = max(1.0-lod/(proj_lod*0.5), 0.0); @@ -89,8 +87,6 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = pow(ret.rgb, vec3(2.2)); - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -108,8 +104,6 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = pow(ret.rgb, vec3(2.2)); - vec2 dist = tc-vec2(0.5); float d = dot(dist,dist); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl index 9543be562b..6c34643aab 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl @@ -37,8 +37,6 @@ vec3 fullbrightScaleSoftClip(vec3 light); VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -uniform float texture_gamma; - void fullbright_lighting() { vec4 color = diffuseLookup(vary_texcoord0.xy) * vertex_color; @@ -47,7 +45,7 @@ void fullbright_lighting() { discard; } - color.rgb = pow(color.rgb, vec3(texture_gamma)); + color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); -- cgit v1.2.3 From 6300f4f768de13823a754831797cb34022f87b60 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 27 Mar 2013 21:59:14 -0500 Subject: NORSPEC-61 Hook up material parameters to shaders. --- .../shaders/class1/deferred/materialF.glsl | 54 +++++++++++++++++----- .../shaders/class1/deferred/materialV.glsl | 11 +++++ .../shaders/class1/deferred/softenLightF.glsl | 2 +- 3 files changed, 55 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 4f7fc6a411..5392466b25 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -23,6 +23,12 @@ * $/LicenseInfo$ */ +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_GLOW 3 + + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else @@ -31,36 +37,52 @@ out vec4 frag_data[3]; uniform sampler2D diffuseMap; +#if HAS_NORMAL_MAP uniform sampler2D bumpMap; +#endif +#if HAS_SPECULAR_MAP uniform sampler2D specularMap; uniform float env_intensity; +#endif + uniform vec4 specular_color; -#ifdef ALPHA_TEST +#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK uniform float minimum_alpha; #endif +#if HAS_NORMAL_MAP VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; VARYING vec3 vary_mat2; +#else +VARYING vec3 vary_normal; +#endif VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; + void main() { - vec4 col = texture2D(diffuseMap, vary_texcoord0.xy) * vertex_color; + vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); + col.rgb *= vertex_color.rgb; - #ifdef ALPHA_TEST +#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK if (col.a < minimum_alpha) { discard; } - #endif - +#endif + +#if HAS_SPECULAR_MAP vec4 spec = texture2D(specularMap, vary_texcoord0.xy); +#else + vec4 spec = specular_color; +#endif +#if HAS_NORMAL_MAP vec4 norm = texture2D(bumpMap, vary_texcoord0.xy); norm.xyz = norm.xyz * 2 - 1; @@ -68,19 +90,29 @@ void main() vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), dot(norm.xyz,vary_mat1), dot(norm.xyz,vary_mat2)); +#else + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm = vary_normal; +#endif vec4 final_color = col; - final_color.rgb *= 1 - spec.a * env_intensity; - - #ifndef EMISSIVE_MASK + +#if DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_GLOW final_color.a = 0; - #endif +#endif vec4 final_specular = spec; +#if HAS_SPECULAR_MAP + //final_color.rgb *= 1 - spec.a * env_intensity; final_specular.rgb *= specular_color.rgb; - final_specular.a = specular_color.a * norm.a; - + vec4 final_normal = vec4(normalize(tnorm), spec.a * env_intensity); + final_specular.a = specular_color.a * spec.a; +#else + vec4 final_normal = vec4(normalize(tnorm), 0.0); + final_specular.a = spec.a; +#endif + final_normal.xyz = final_normal.xyz * 0.5 + 0.5; frag_data[0] = final_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index c8d38bb8f7..f92ad63100 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -31,11 +31,17 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; + +#if HAS_NORMAL_MAP ATTRIBUTE vec3 binormal; VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; VARYING vec3 vary_mat2; +#else +VARYING vec3 vary_normal; +#endif + VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; @@ -45,13 +51,18 @@ void main() gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vec3 n = normalize(normal_matrix * normal); +#if HAS_NORMAL_MAP vec3 b = normalize(normal_matrix * binormal); vec3 t = cross(b, n); vary_mat0 = vec3(t.x, b.x, n.x); vary_mat1 = vec3(t.y, b.y, n.y); vary_mat2 = vec3(t.z, b.z, n.z); +#else + vary_normal = n; +#endif vertex_color = diffuse_color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 2905cc91b6..f50935c1a8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -310,7 +310,7 @@ void main() //add environmentmap vec3 env_vec = env_mat * refnormpersp; col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, - max(spec.a-diffuse.a*2.0, 0.0)); + max(norm.a-diffuse.a*2.0, 0.0)); } col = atmosLighting(col); -- cgit v1.2.3 From 5121dd1a533b1d589cf259e96fa6d0ba22b383ea Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 28 Mar 2013 12:15:32 -0500 Subject: NORSPEC-62 Fix for fullbright checkbox not working with materials --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5392466b25..fdaad550f7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -26,7 +26,7 @@ #define DIFFUSE_ALPHA_MODE_IGNORE 0 #define DIFFUSE_ALPHA_MODE_BLEND 1 #define DIFFUSE_ALPHA_MODE_MASK 2 -#define DIFFUSE_ALPHA_MODE_GLOW 3 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 #ifdef DEFINE_GL_FRAGCOLOR @@ -97,7 +97,7 @@ void main() vec4 final_color = col; -#if DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_GLOW +#if DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE final_color.a = 0; #endif -- cgit v1.2.3 From fc4869fb7871632b95dd293157b9965fb2edcb73 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 29 Mar 2013 16:13:36 -0500 Subject: NORSPEC-65 Hook up texture offset/scale/rotation for normal and specular maps. --- .../app_settings/shaders/class1/deferred/materialF.glsl | 7 +++++-- .../app_settings/shaders/class1/deferred/materialV.glsl | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index fdaad550f7..e406bf14a9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -44,6 +44,8 @@ uniform sampler2D bumpMap; #if HAS_SPECULAR_MAP uniform sampler2D specularMap; uniform float env_intensity; + +VARYING vec2 vary_texcoord2; #endif uniform vec4 specular_color; @@ -56,6 +58,7 @@ uniform float minimum_alpha; VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; VARYING vec3 vary_mat2; +VARYING vec2 vary_texcoord1; #else VARYING vec3 vary_normal; #endif @@ -77,13 +80,13 @@ void main() #endif #if HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord0.xy); + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); #else vec4 spec = specular_color; #endif #if HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord0.xy); + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); norm.xyz = norm.xyz * 2 - 1; diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index f92ad63100..744f79c0c9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -34,14 +34,22 @@ ATTRIBUTE vec2 texcoord0; #if HAS_NORMAL_MAP ATTRIBUTE vec3 binormal; +ATTRIBUTE vec2 texcoord1; VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; VARYING vec3 vary_mat2; + +VARYING vec2 vary_texcoord1; #else VARYING vec3 vary_normal; #endif +#if HAS_SPECULAR_MAP +ATTRIBUTE vec2 texcoord2; +VARYING vec2 vary_texcoord2; +#endif + VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; @@ -51,6 +59,13 @@ void main() gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +#if HAS_NORMAL_MAP + vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; +#endif + +#if HAS_SPECULAR_MAP + vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; +#endif vec3 n = normalize(normal_matrix * normal); #if HAS_NORMAL_MAP -- cgit v1.2.3 From 14f02e48b877569539c96ef5f261ac8b3943579f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 29 Mar 2013 20:12:27 -0500 Subject: NORSPEC-66 Hook up material parameters to rigged attachments. --- .../shaders/class1/deferred/materialV.glsl | 42 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 744f79c0c9..6475d8d003 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -23,15 +23,24 @@ * $/LicenseInfo$ */ +#if HAS_SKIN +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else uniform mat3 normal_matrix; -uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; +#endif + +uniform mat4 texture_matrix0; + ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; + #if HAS_NORMAL_MAP ATTRIBUTE vec3 binormal; ATTRIBUTE vec2 texcoord1; @@ -55,8 +64,21 @@ VARYING vec2 vary_texcoord0; void main() { +#if HAS_SKIN + mat4 mat = getObjectSkinnedTransform(); + + mat = modelview_matrix * mat; + + vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; + + gl_Position = projection_matrix*vec4(pos,1.0); + +#else //transform vertex gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + +#endif + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; #if HAS_NORMAL_MAP @@ -67,6 +89,19 @@ void main() vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; #endif +#if HAS_SKIN + vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); +#if HAS_NORMAL_MAP + vec3 b = normalize((mat*vec4(binormal.xyz+position.xyz,1.0)).xyz-pos.xyz); + vec3 t = cross(b, n); + + vary_mat0 = vec3(t.x, b.x, n.x); + vary_mat1 = vec3(t.y, b.y, n.y); + vary_mat2 = vec3(t.z, b.z, n.z); +#else //HAS_NORMAL_MAP +vary_normal = n; +#endif //HAS_NORMAL_MAP +#else //HAS_SKIN vec3 n = normalize(normal_matrix * normal); #if HAS_NORMAL_MAP vec3 b = normalize(normal_matrix * binormal); @@ -75,9 +110,10 @@ void main() vary_mat0 = vec3(t.x, b.x, n.x); vary_mat1 = vec3(t.y, b.y, n.y); vary_mat2 = vec3(t.z, b.z, n.z); -#else +#else //HAS_NORMAL_MAP vary_normal = n; -#endif +#endif //HAS_NORMAL_MAP +#endif //HAS_SKIN vertex_color = diffuse_color; } -- cgit v1.2.3 From 1f739cb7bc8de7a1cc5faf3218fb350689c7fbcd Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 30 Mar 2013 15:50:51 -0500 Subject: Cleanup a couple more places where gamma curves were getting applied. --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 1 - .../app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 6 ------ 2 files changed, 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index b6a9417fe7..36433a5827 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -43,7 +43,6 @@ void main() float shadow = 1.0; vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; - color.rgb = pow(color.rgb, vec3(2.2)); color.rgb = fullbrightAtmosTransport(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 53e5a228fa..bff87cb6aa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -70,8 +70,6 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = pow(ret.rgb, vec3(2.2)); - vec2 dist = tc-vec2(0.5); float det = max(1.0-lod/(proj_lod*0.5), 0.0); @@ -87,8 +85,6 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = pow(ret.rgb, vec3(2.2)); - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -106,8 +102,6 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = pow(ret.rgb, vec3(2.2)); - vec2 dist = tc-vec2(0.5); float d = dot(dist,dist); -- cgit v1.2.3 From 8da8e05964710bea633af2bee36a7aa89f3a8656 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 2 Apr 2013 01:47:12 -0500 Subject: NORSPEC-58 Followup -- put back blinn phong, and do gamma correction approximation in light curves. Fix fresnel math. --- .../shaders/class1/deferred/multiPointLightF.glsl | 21 ++++++++++------ .../shaders/class1/deferred/multiSpotLightF.glsl | 29 +++++++++++++++++++--- .../shaders/class1/deferred/pointLightF.glsl | 10 +++++--- .../shaders/class1/deferred/softenLightF.glsl | 4 ++- .../shaders/class1/deferred/spotLightF.glsl | 25 +++++++++++++++++-- 5 files changed, 71 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index ad50690c02..c11298aadd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -110,14 +110,18 @@ void main() { lv = normalize(lv); da = dot(norm, lv); - + float fa = light_col[i].a+1.0; float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten *= noise; float lit = da * dist_atten; - + + lit = pow(lit,0.7); + vec3 col = light_col[i].rgb*lit*diff; + //vec3 col = vec3(dist2, light_col[i].a, lit); if (spec.a > 0.0) @@ -128,15 +132,16 @@ void main() float nv = dot(norm, npos); float vh = dot(npos, h); float sa = nh; - vec3 fres = spec.rgb + pow(1 - dot(h, npos), 5) * (1 - spec.rgb); + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - - if (sa > 0.0) + + if (nh > 0.0) { - vec3 scol = (fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt) / (nh * da); - col += lit*scol*light_col[i].rgb; + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += lit*scol*light_col[i].rgb*spec.rgb; + //col += spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index bff87cb6aa..09d23db096 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -40,6 +40,7 @@ uniform sampler2DRect normalMap; uniform samplerCube environmentMap; uniform sampler2D noiseMap; uniform sampler2D projectionMap; +uniform sampler2D lightFunc; uniform mat4 proj_mat; //screen space to light space uniform float proj_near; //near clip for projection @@ -142,7 +143,7 @@ void main() } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - norm = vec3((norm.xy-0.5)*2.0, norm.z); + norm = norm = (norm.xyz-0.5)*2.0; norm = normalize(norm); float l_dist = -dot(lv, proj_n); @@ -190,6 +191,8 @@ void main() vec3 lcol = color.rgb * plcol.rgb * plcol.a; lit = da * dist_atten * noise; + + lit = pow(lit, 0.7); col = lcol*lit*diff_tex; amb_da += (da*0.5)*proj_ambiance; @@ -236,8 +239,28 @@ void main() stc.x > 0.0 && stc.y > 0.0) { - vec4 scol = texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod); - col += dist_atten*scol.rgb*color.rgb*scol.a*spec.rgb; + + vec3 npos = -normalize(pos); + lv = pfinal-pos.xyz; + lv = normalize(lv); + + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); + + if (sa > 0.0) + { + float scol = fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt / (nh * da); + col += scol*color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod).rgb*spec.rgb; + } + + //vec4 scol = texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod); + //col += dist_atten*scol.rgb*color.rgb*scol.a*spec.rgb; } } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 03b036375b..e99329bbf2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -102,6 +102,8 @@ void main() float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); float lit = da * dist_atten * noise; + lit = pow(lit, 0.7); + col = color.rgb*lit*col; vec4 spec = texture2DRect(specularRect, frag.xy); @@ -113,14 +115,14 @@ void main() float nv = dot(norm, npos); float vh = dot(npos, h); float sa = nh; - vec3 fres = spec.rgb + pow(1 - dot(h, npos), 5) * (1 - spec.rgb); + float fres = pow(1 - dot(h, npos), 5) * 0.4+0.5; float gtdenom = 2 * nh; float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); - if (sa > 0.0) + if (nh > 0.0) { - vec3 scol = (fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt) / (nh * da); - col += lit*scol*color.rgb; + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += lit*scol*color.rgb*spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index f50935c1a8..437a06320e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -280,6 +280,8 @@ void main() float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + da = pow(da, 0.7); + vec4 diffuse = texture2DRect(diffuseRect, tc); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); @@ -300,7 +302,7 @@ void main() // vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*(6 * texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index cca63872de..2f18e1a13d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -41,6 +41,8 @@ uniform sampler2DRect normalMap; uniform samplerCube environmentMap; uniform sampler2D noiseMap; uniform sampler2D projectionMap; +uniform sampler2D lightFunc; + uniform mat4 proj_mat; //screen space to light space uniform float proj_near; //near clip for projection @@ -193,6 +195,8 @@ void main() lit = da * dist_atten * noise; + lit = pow(lit, 0.7); + col = lcol*lit*diff_tex; amb_da += (da*0.5)*proj_ambiance; } @@ -238,8 +242,25 @@ void main() stc.x > 0.0 && stc.y > 0.0) { - vec4 scol = texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod); - col += dist_atten*scol.rgb*color.rgb*scol.a*spec.rgb; + vec3 npos = -normalize(pos); + lv = pfinal-pos.xyz; + lv = normalize(lv); + + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += scol*color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod).rgb*spec.rgb; + } } } } -- cgit v1.2.3 From 3f01526e7120724e56f073e199bdc365f3f4b8db Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 8 Apr 2013 21:09:29 -0400 Subject: Fix for specular exponents not being applied appropriately from the normal map alpha. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index e406bf14a9..de404cbffe 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -110,10 +110,10 @@ void main() final_specular.rgb *= specular_color.rgb; vec4 final_normal = vec4(normalize(tnorm), spec.a * env_intensity); - final_specular.a = specular_color.a * spec.a; + final_specular.a = specular_color.a * norm.a; #else vec4 final_normal = vec4(normalize(tnorm), 0.0); - final_specular.a = spec.a; + final_specular.a = specular_color.a; #endif final_normal.xyz = final_normal.xyz * 0.5 + 0.5; -- cgit v1.2.3 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/alphaF.glsl | 57 +++++++++++++++++++++- .../shaders/class1/deferred/alphaNonIndexedF.glsl | 54 +++++++++++++++++++- .../shaders/class1/deferred/alphaSkinnedV.glsl | 20 +++----- .../shaders/class1/deferred/alphaV.glsl | 16 ++---- 4 files changed, 117 insertions(+), 30 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index dd87ddb330..abf8da051c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -49,8 +49,53 @@ VARYING vec3 vary_pointlight_col; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +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]; + + +uniform float shadow_offset; + +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; +} + void main() { vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; @@ -60,14 +105,22 @@ void main() vec4 diff= diffuseLookup(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; } 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); diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl index 5a0e8ff684..5f93986f1d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaSkinnedV.glsl @@ -46,6 +46,7 @@ VARYING vec3 vary_pointlight_col; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +VARYING vec3 vary_norm; uniform float near_clip; @@ -104,7 +105,7 @@ void main() norm = position.xyz + normal.xyz; norm = normalize(( trans*vec4(norm, 1.0) ).xyz-pos.xyz); - + vary_norm = norm; vec4 frag_pos = projection_matrix * pos; gl_Position = frag_pos; @@ -112,27 +113,18 @@ void main() calcAtmospherics(pos.xyz); + //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - - // Collect normal lights - col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z); - col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z); - col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].y, light_attenuation[4].z); - col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].y, light_attenuation[5].z); - col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].y, light_attenuation[6].z); - col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].y, light_attenuation[7].z); - - vary_pointlight_col = col.rgb*diffuse_color.rgb; - + vary_pointlight_col = diffuse_color.rgb; col.rgb = vec3(0,0,0); // Add windlight lights col.rgb = atmosAmbient(vec3(0.)); vary_ambient = col.rgb*diffuse_color.rgb; - vary_directional = diffuse_color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), (1.0-diffuse_color.a)*(1.0-diffuse_color.a))); + vary_directional.rgb = atmosAffectDirectionalLight(1); - col.rgb = min(col.rgb*diffuse_color.rgb, 1.0); + col.rgb = col.rgb*diffuse_color.rgb; vertex_color = col; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index cf38a2f4f7..bc08cc6dbf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -53,6 +53,7 @@ VARYING vec3 vary_pointlight_col; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +VARYING vec3 vary_norm; uniform float near_clip; uniform float shadow_offset; @@ -110,7 +111,7 @@ void main() vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; vec3 norm = normalize(normal_matrix * normal); - + vary_norm = norm; float dp_directional_light = max(0.0, dot(norm, light_position[0].xyz)); vary_position = pos.xyz + light_position[0].xyz * (1.0-dp_directional_light)*shadow_offset; @@ -118,23 +119,14 @@ void main() //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - - // Collect normal lights - col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z); - col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z); - col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].y, light_attenuation[4].z); - col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].y, light_attenuation[5].z); - col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].y, light_attenuation[6].z); - col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].y, light_attenuation[7].z); - - vary_pointlight_col = col.rgb*diffuse_color.rgb; + vary_pointlight_col = diffuse_color.rgb; col.rgb = vec3(0,0,0); // Add windlight lights col.rgb = atmosAmbient(vec3(0.)); vary_ambient = col.rgb*diffuse_color.rgb; - vary_directional.rgb = diffuse_color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), (1.0-diffuse_color.a)*(1.0-diffuse_color.a))); + vary_directional.rgb = atmosAffectDirectionalLight(1); col.rgb = col.rgb*diffuse_color.rgb; -- 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/alphaF.glsl | 6 +++--- .../shaders/class1/deferred/alphaNonIndexedF.glsl | 6 +++--- .../app_settings/shaders/class1/deferred/avatarF.glsl | 8 +++++++- .../app_settings/shaders/class1/deferred/bumpF.glsl | 8 +++++++- .../shaders/class1/deferred/diffuseAlphaMaskF.glsl | 8 +++++++- .../class1/deferred/diffuseAlphaMaskIndexedF.glsl | 8 +++++++- .../class1/deferred/diffuseAlphaMaskNoColorF.glsl | 8 +++++++- .../app_settings/shaders/class1/deferred/diffuseF.glsl | 8 +++++++- .../shaders/class1/deferred/diffuseIndexedF.glsl | 9 ++++++++- .../app_settings/shaders/class1/deferred/materialF.glsl | 15 +++++++++------ .../shaders/class1/deferred/multiPointLightF.glsl | 13 ++++++++++++- .../shaders/class1/deferred/multiSpotLightF.glsl | 13 ++++++++++++- .../shaders/class1/deferred/pointLightF.glsl | 13 ++++++++++++- .../app_settings/shaders/class1/deferred/skyF.glsl | 2 +- .../shaders/class1/deferred/softenLightF.glsl | 16 ++++++++++++++-- .../app_settings/shaders/class1/deferred/spotLightF.glsl | 13 ++++++++++++- .../shaders/class1/deferred/sunLightSSAOF.glsl | 13 ++++++++++++- .../app_settings/shaders/class1/deferred/terrainF.glsl | 8 +++++++- .../app_settings/shaders/class1/deferred/treeF.glsl | 8 +++++++- 19 files changed, 154 insertions(+), 29 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index abf8da051c..4ef69824a1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -62,7 +62,7 @@ uniform float shadow_offset; 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; } @@ -90,7 +90,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; @@ -120,7 +120,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; } 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); diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index bfd9b9b3eb..bcccbf77d2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -34,6 +34,12 @@ uniform sampler2D diffuseMap; VARYING vec3 vary_normal; VARYING vec2 vary_texcoord0; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + void main() { vec4 diff = texture2D(diffuseMap, vary_texcoord0.xy); @@ -46,6 +52,6 @@ void main() frag_data[0] = vec4(diff.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index a887728493..595c11fae2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -39,6 +39,12 @@ VARYING vec3 vary_mat2; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + void main() { vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb; @@ -52,5 +58,5 @@ void main() frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(tnorm); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, vertex_color.a); + frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index c1fa9e4aac..7930b5d18b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -37,6 +37,12 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + void main() { vec4 col = texture2D(diffuseMap, vary_texcoord0.xy) * vertex_color; @@ -49,6 +55,6 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index 4c68123fac..59d109b886 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -36,6 +36,12 @@ uniform float minimum_alpha; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + void main() { vec4 col = diffuseLookup(vary_texcoord0.xy) * vertex_color; @@ -48,5 +54,5 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index ad65c7d330..37d70a2412 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -37,6 +37,12 @@ uniform sampler2D diffuseMap; VARYING vec3 vary_normal; VARYING vec2 vary_texcoord0; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + void main() { vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); @@ -49,6 +55,6 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 2e456d00dd..6befb1bd8b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -35,6 +35,12 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + void main() { vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb; @@ -42,6 +48,6 @@ void main() frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, vertex_color.a); + frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index bb6dc9a57d..40b980bf51 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -33,6 +33,13 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + + void main() { vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; @@ -41,5 +48,5 @@ void main() frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, vertex_color.a); + frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index de404cbffe..35b176b457 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -43,11 +43,11 @@ uniform sampler2D bumpMap; #if HAS_SPECULAR_MAP uniform sampler2D specularMap; -uniform float env_intensity; VARYING vec2 vary_texcoord2; #endif +uniform float env_intensity; uniform vec4 specular_color; #if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK @@ -66,6 +66,11 @@ VARYING vec3 vary_normal; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} void main() { @@ -109,16 +114,14 @@ void main() //final_color.rgb *= 1 - spec.a * env_intensity; final_specular.rgb *= specular_color.rgb; - vec4 final_normal = vec4(normalize(tnorm), spec.a * env_intensity); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), spec.a * env_intensity, 0.0); final_specular.a = specular_color.a * norm.a; #else - vec4 final_normal = vec4(normalize(tnorm), 0.0); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); final_specular.a = specular_color.a; #endif - - final_normal.xyz = final_normal.xyz * 0.5 + 0.5; frag_data[0] = final_color; frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XYZ = Normal. W = Env. intensity. + frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index c11298aadd..5329ae9dd7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -56,6 +56,17 @@ uniform float far_z; uniform mat4 inv_proj; +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + vec4 getPosition(vec2 pos_screen) { float depth = texture2DRect(depthMap, pos_screen.xy).r; @@ -79,7 +90,7 @@ void main() } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - norm = (norm.xyz-0.5)*2.0; // unpack norm + norm = decode_normal(norm.xy); // unpack norm norm = normalize(norm); vec4 spec = texture2DRect(specularRect, frag.xy); vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 09d23db096..9746218ea6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -67,6 +67,17 @@ uniform vec2 screen_res; uniform mat4 inv_proj; +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); @@ -143,7 +154,7 @@ void main() } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - norm = norm = (norm.xyz-0.5)*2.0; + norm = decode_normal(norm.xy); norm = normalize(norm); float l_dist = -dot(lv, proj_n); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index e99329bbf2..27863b0095 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -54,6 +54,17 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + vec4 getPosition(vec2 pos_screen) { float depth = texture2DRect(depthMap, pos_screen.xy).r; @@ -84,7 +95,7 @@ void main() } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - norm = (norm.xyz-0.5)*2.0; // unpack norm + norm = decode_normal(norm.xy); // unpack norm float da = dot(norm, lv); if (da < 0.0) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index faa54a316e..20a756530a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -61,6 +61,6 @@ void main() /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0,0,1,0); + frag_data[2] = vec4(0.5,0.5,0.5,0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 437a06320e..5f88cca30b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -77,6 +77,17 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + vec4 getPosition_d(vec2 pos_screen, float depth) { vec2 sc = pos_screen.xy*2.0; @@ -276,7 +287,8 @@ void main() float depth = texture2DRect(depthMap, tc.xy).r; vec3 pos = getPosition_d(tc, depth).xyz; vec4 norm = texture2DRect(normalMap, tc); - norm.xyz = (norm.xyz-0.5)*2.0; // unpack norm + float envIntensity = norm.z; + norm.xyz = decode_normal(norm.xy); // unpack norm float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); @@ -312,7 +324,7 @@ void main() //add environmentmap vec3 env_vec = env_mat * refnormpersp; col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, - max(norm.a-diffuse.a*2.0, 0.0)); + max(envIntensity-diffuse.a*2.0, 0.0)); } col = atmosLighting(col); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 2f18e1a13d..d7f0ab6d8e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -70,6 +70,17 @@ uniform vec2 screen_res; uniform mat4 inv_proj; +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); @@ -146,7 +157,7 @@ void main() } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - norm = vec3((norm.xy-0.5)*2.0, norm.z); + norm = decode_normal(norm.xy); norm = normalize(norm); float l_dist = -dot(lv, proj_n); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index bac74cbbef..1470239a71 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -49,6 +49,17 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + vec4 getPosition(vec2 pos_screen) { float depth = texture2DRect(depthMap, pos_screen.xy).r; @@ -123,7 +134,7 @@ void main() vec4 pos = getPosition(pos_screen); vec3 norm = texture2DRect(normalMap, pos_screen).xyz; - norm = (norm.xyz-0.5)*2.0; // unpack norm + norm = decode_normal(norm.xy); frag_color[0] = 1.0; frag_color[1] = calcAmbientOcclusion(pos, norm); diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index daf1cc7ea2..52a429465f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -39,6 +39,12 @@ VARYING vec3 vary_normal; VARYING vec4 vary_texcoord0; VARYING vec4 vary_texcoord1; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + void main() { /// Note: This should duplicate the blending functionality currently used for the terrain rendering. @@ -56,6 +62,6 @@ void main() frag_data[0] = vec4(outColor.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index da253846ef..808750496f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -37,6 +37,12 @@ VARYING vec2 vary_texcoord0; uniform float minimum_alpha; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + void main() { vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); @@ -48,5 +54,5 @@ void main() frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz * 0.5 + 0.5, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); } -- cgit v1.2.3 From e4faf91bb20c33cba5b060064f03da5f1e863984 Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 9 Apr 2013 14:45:27 -0400 Subject: Start using R16F again, and divide the bloom contrib by 6. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 5f88cca30b..63c819f941 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -318,7 +318,7 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 4; + bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; //add environmentmap -- 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') 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 cfc375777871ec3d04b9969793379d0cd78a012e Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 11 Apr 2013 14:57:11 -0400 Subject: First pass on alpha blended materials --- .../shaders/class1/deferred/alphaF.glsl | 27 ++++++++++++++++++++-- .../class1/deferred/avatarAlphaNoColorV.glsl | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 4ef69824a1..55dda06b46 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -25,6 +25,10 @@ #extension GL_ARB_texture_rectangle : enable +#define INDEXED 1 +#define NON_INDEXED 2 +#define NON_INDEXED_NO_COLOR 3 + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -33,7 +37,13 @@ out vec4 frag_color; uniform sampler2DRect depthMap; +#if INDEX_MODE != INDEXED +uniform sampler2D diffuseMap; +#endif + +#if INDEX_MODE == INDEXED vec4 diffuseLookup(vec2 texcoord); +#endif uniform vec2 screen_res; @@ -46,7 +56,10 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; +#if INDEX_MODE != NON_INDEXED_NO_COLOR VARYING vec4 vertex_color; +#endif + VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; @@ -103,11 +116,21 @@ void main() vec4 pos = vec4(vary_position, 1.0); - vec4 diff= diffuseLookup(vary_texcoord0.xy); +#if INDEX_MODE == INDEXED + vec4 diff = diffuseLookup(vary_texcoord0.xy); +#else + vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); +#endif + +#if INDEX_MODE == NON_INDEXED_NO_COLOR + float vertex_color_alpha = 1.0; +#else + float vertex_color_alpha = vertex_color.a; +#endif 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 col = vec4(vary_ambient + dlight, vertex_color_alpha); vec4 color = diff * col; color.rgb = atmosLighting(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl index 5f395801e5..c8ddefac26 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl @@ -47,6 +47,7 @@ VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; +VARYING vec3 vary_norm; uniform float near_clip; @@ -112,6 +113,7 @@ void main() norm.y = dot(trans[1].xyz, normal); norm.z = dot(trans[2].xyz, normal); norm = normalize(norm); + vary_norm = norm; vec4 frag_pos = projection_matrix * pos; gl_Position = frag_pos; -- 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/alphaF.glsl | 21 +++++++++++++++------ .../shaders/class1/deferred/alphaNonIndexedF.glsl | 11 ++++------- 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 4ef69824a1..d6baec0ee0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -105,7 +105,10 @@ void main() vec4 diff= diffuseLookup(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; @@ -115,11 +118,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; 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 --- .../newview/app_settings/shaders/class1/deferred/alphaF.glsl | 10 ++++++++-- .../shaders/class1/deferred/alphaNonIndexedF.glsl | 11 ++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index d6baec0ee0..eff94b143a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -118,7 +118,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) @@ -128,7 +129,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; 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 7bf67f786621e88e69415c5750a3b900d7b1e544 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Fri, 12 Apr 2013 08:14:46 -0700 Subject: NORSPEC-111 probable fix for IntelHD advanced lighting crasher --- .../shaders/class1/avatar/objectSkinV.glsl | 28 +++++++++++++--------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl index 43ed41a205..ff30560adc 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl @@ -26,22 +26,28 @@ ATTRIBUTE vec4 weight4; -uniform mat4 matrixPalette[32]; +uniform mat4 matrixPalette[64]; mat4 getObjectSkinnedTransform() { - int i; - vec4 w = fract(weight4); - vec4 index = floor(weight4); - - float scale = 1.0/(w.x+w.y+w.z+w.w); - w *= scale; + float w0 = fract(weight4.x); + float w1 = fract(weight4.y); + float w2 = fract(weight4.z); + float w3 = fract(weight4.w); + + int i0 = int(floor(weight4.x)); + int i1 = int(floor(weight4.y)); + int i2 = int(floor(weight4.z)); + int i3 = int(floor(weight4.w)); + + //float scale = 1.0/(w.x+w.y+w.z+w.w); + //w *= scale; - mat4 mat = matrixPalette[int(index.x)]*w.x; - mat += matrixPalette[int(index.y)]*w.y; - mat += matrixPalette[int(index.z)]*w.z; - mat += matrixPalette[int(index.w)]*w.w; + mat4 mat = matrixPalette[i0]*w0; + mat += matrixPalette[i1]*w1; + mat += matrixPalette[i2]*w2; + mat += matrixPalette[i3]*w3; return mat; } -- cgit v1.2.3 From 6257a8394c23b518febdf5ec9c9ecbdce224e046 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 15 Apr 2013 01:35:21 -0400 Subject: Normal mapped alpha support. Specular and environment map support needs a bit of extra work (in progress). --- .../shaders/class1/deferred/alphaF.glsl | 37 +++++++--- .../shaders/class1/deferred/alphaV.glsl | 81 ++++++++++++++++++++-- 2 files changed, 101 insertions(+), 17 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 55dda06b46..8fb1d6f7b3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -55,14 +55,14 @@ VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; +VARYING vec2 vary_texcoord0; +VARYING vec3 vary_norm; +VARYING mat3 vary_rotation; #if INDEX_MODE != NON_INDEXED_NO_COLOR VARYING vec4 vertex_color; #endif -VARYING vec2 vary_texcoord0; - -VARYING vec3 vary_norm; uniform mat4 inv_proj; uniform vec4 light_position[8]; @@ -70,13 +70,21 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +uniform sampler2D bumpMap; +uniform samplerCube environmentMap; +uniform mat3 env_mat; + +uniform vec4 specular_color; + uniform float shadow_offset; -float calcDirectionalLight(vec3 n, vec3 l) +vec2 calcDirectionalLight(vec3 n, vec3 l) { - float a = pow(max(dot(n,l),0.0), 0.7); - return a; + vec3 refl = normalize(reflect(vary_position.xyz, n.xyz)); + float a = pow(max(dot(n,l),0.0), 0.7); + refl.x = pow(pow(max(dot(refl, l), 0.0), specular_color.w * 128), 0.6); + return vec2(a, refl.x); } float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) @@ -127,8 +135,15 @@ void main() #else float vertex_color_alpha = vertex_color.a; #endif - - vec3 dlight = calcDirectionalLight(vary_norm, light_position[0].xyz) * vary_directional.rgb * vary_pointlight_col; + + vec3 normal = vary_norm; + normal = texture2D(bumpMap, vary_texcoord0.xy).xyz * 2 - 1; + normal = vec3(dot(normal.xyz, vary_rotation[0]), + dot(normal.xyz, vary_rotation[1]), + dot(normal.xyz, vary_rotation[2])); + + vec2 slight = calcDirectionalLight(normal, light_position[0].xyz); + vec3 dlight = slight.x * vary_directional.rgb * vary_pointlight_col; vec4 col = vec4(vary_ambient + dlight, vertex_color_alpha); vec4 color = diff * col; @@ -140,9 +155,11 @@ void main() 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); + light_col += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); } - + + vec3 n = normalize(reflect(vary_position.xyz, normal.xyz)); + n = vec3(dot(n, light_position[0].xyz)); color.rgb += diff.rgb * vary_pointlight_col * light_col; frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index bc08cc6dbf..784472c987 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -23,16 +23,30 @@ * $/LicenseInfo$ */ +#define INDEXED 1 +#define NON_INDEXED 2 +#define NON_INDEXED_NO_COLOR 3 + uniform mat3 normal_matrix; uniform mat4 texture_matrix0; +uniform mat4 projection_matrix; uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; +#if INDEX_MODE == INDEXED void passTextureIndex(); +#endif ATTRIBUTE vec3 normal; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; +ATTRIBUTE vec3 binormal; + +#if HAS_SKIN +mat4 getObjectSkinnedTransform(); +#elif IS_AVATAR_SKIN +mat4 getSkinnedTransform(); +#endif vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); void calcAtmospherics(vec3 inPositionEye); @@ -50,10 +64,14 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; +#if INDEX_MODE != NON_INDEXED_NO_COLOR VARYING vec4 vertex_color; +#endif + VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; +VARYING mat3 vary_rotation; uniform float near_clip; uniform float shadow_offset; @@ -102,24 +120,68 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa void main() { + vec4 pos; + vec3 norm; + //transform vertex +#if HAS_SKIN + mat4 trans = getObjectSkinnedTransform(); + trans = modelview_matrix * trans; + + pos = trans * vec4(position.xyz, 1.0); + + norm = position.xyz + normal.xyz; + norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz); + vec4 frag_pos = projection_matrix * pos; + gl_Position = frag_pos; +#elif IS_AVATAR_SKIN + mat4 trans = getSkinnedTransform(); + vec4 pos_in = vec4(position.xyz, 1.0); + pos.x = dot(trans[0], pos_in); + pos.y = dot(trans[1], pos_in); + pos.z = dot(trans[2], pos_in); + pos.w = 1.0; + + norm.x = dot(trans[0].xyz, normal); + norm.y = dot(trans[1].xyz, normal); + norm.z = dot(trans[2].xyz, normal); + norm = normalize(norm); + + vec4 frag_pos = projection_matrix * pos; + gl_Position = frag_pos; +#else + norm = normalize(normal_matrix * normal); vec4 vert = vec4(position.xyz, 1.0); - passTextureIndex(); - vec4 pos = (modelview_matrix * vert); + pos = (modelview_matrix * vert); gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); +#endif +#if INDEX_MODE == INDEXED + passTextureIndex(); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; +#else + vary_texcoord0 = texcoord0; +#endif - vec3 norm = normalize(normal_matrix * normal); vary_norm = norm; float dp_directional_light = max(0.0, dot(norm, light_position[0].xyz)); vary_position = pos.xyz + light_position[0].xyz * (1.0-dp_directional_light)*shadow_offset; - + + vec3 n = norm; + vec3 b = normalize(normal_matrix * binormal); + vec3 t = cross(b, n); + + vary_rotation[0] = vec3(t.x, b.x, n.x); + vary_rotation[1] = vec3(t.y, b.y, n.y); + vary_rotation[2] = vec3(t.z, b.z, n.z); + calcAtmospherics(pos.xyz); //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); + vary_pointlight_col = diffuse_color.rgb; + col.rgb = vec3(0,0,0); // Add windlight lights @@ -129,12 +191,17 @@ void main() vary_directional.rgb = atmosAffectDirectionalLight(1); col.rgb = col.rgb*diffuse_color.rgb; - +#if INDEX_MODE != NON_INDEXED_NO_COLOR vertex_color = col; - - +#endif +#if HAS_SKIN + vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); +#elif IS_AVATAR_SKIN + vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); +#else pos = modelview_projection_matrix * vert; vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); +#endif } -- cgit v1.2.3 From 39544a3b06e3221602444eb81c7df8c1030c6bb5 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 15 Apr 2013 02:29:03 -0400 Subject: Hooked up normal and specular texture coordinates. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 4 +++- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 8fb1d6f7b3..eb0c546af7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -56,6 +56,8 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; VARYING vec3 vary_norm; VARYING mat3 vary_rotation; @@ -137,7 +139,7 @@ void main() #endif vec3 normal = vary_norm; - normal = texture2D(bumpMap, vary_texcoord0.xy).xyz * 2 - 1; + normal = texture2D(bumpMap, vary_texcoord1.xy).xyz * 2 - 1; normal = vec3(dot(normal.xyz, vary_rotation[0]), dot(normal.xyz, vary_rotation[1]), dot(normal.xyz, vary_rotation[2])); diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 784472c987..e6b63657e6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -41,6 +41,8 @@ ATTRIBUTE vec3 normal; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; ATTRIBUTE vec3 binormal; +ATTRIBUTE vec2 texcoord1; +ATTRIBUTE vec2 texcoord2; #if HAS_SKIN mat4 getObjectSkinnedTransform(); @@ -69,6 +71,8 @@ VARYING vec4 vertex_color; #endif VARYING vec2 vary_texcoord0; +VARYING vec2 vary_texcoord1; +VARYING vec2 vary_texcoord2; VARYING vec3 vary_norm; VARYING mat3 vary_rotation; @@ -155,7 +159,8 @@ void main() pos = (modelview_matrix * vert); gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); #endif - + vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; + vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; #if INDEX_MODE == INDEXED passTextureIndex(); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -- cgit v1.2.3 From 8025b8b2bc6028ed268e191d432cb3f740e351db Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 15 Apr 2013 13:16:14 -0500 Subject: NORSPEC-49 Add shader profiler, add support for ARB_depth_clamp where available --- .../shaders/class1/deferred/attachmentShadowV.glsl | 5 +++++ .../app_settings/shaders/class1/deferred/avatarShadowF.glsl | 4 ++++ .../app_settings/shaders/class1/deferred/avatarShadowV.glsl | 6 ++++++ .../app_settings/shaders/class1/deferred/diffuseIndexedF.glsl | 2 +- .../newview/app_settings/shaders/class1/deferred/diffuseV.glsl | 2 +- .../app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl | 6 ++++++ .../app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl | 10 ++++++++++ .../app_settings/shaders/class1/deferred/shadowCubeV.glsl | 10 ++++++++-- .../newview/app_settings/shaders/class1/deferred/shadowF.glsl | 5 +++++ .../newview/app_settings/shaders/class1/deferred/shadowV.glsl | 8 +++++++- 10 files changed, 53 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl index 81961d7746..3f90600ace 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl @@ -39,7 +39,12 @@ void main() mat = modelview_matrix * mat; vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz; + vec4 p = projection_matrix * vec4(pos, 1.0); +#if !DEPTH_CLAMP p.z = max(p.z, -p.w+0.01); gl_Position = p; +#else + gl_Position = p; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl index 3686f2f647..b809b73973 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl @@ -31,12 +31,16 @@ out vec4 frag_color; uniform sampler2D diffuseMap; +#if !DEPTH_CLAMP VARYING vec4 post_pos; +#endif void main() { frag_color = vec4(1,1,1,1); +#if !DEPTH_CLAMP gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl index 23feb09d72..bde1ad4e9f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl @@ -31,7 +31,9 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; +#if !DEPTH_CLAMP VARYING vec4 post_pos; +#endif void main() { @@ -51,9 +53,13 @@ void main() norm = normalize(norm); pos = projection_matrix * pos; +#if !DEPTH_CLAMP post_pos = pos; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 40b980bf51..a2c3ec3355 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -46,7 +46,7 @@ void main() frag_data[0] = vec4(col, 0.0); frag_data[1] = vertex_color.aaaa; // spec - //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested + frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl index 76d29b1df7..3c026796c8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl @@ -47,6 +47,6 @@ void main() passTextureIndex(); vary_normal = normalize(normal_matrix * normal); - + vertex_color = diffuse_color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index bced4a5577..91a96977f0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -31,8 +31,12 @@ out vec4 frag_color; uniform sampler2D diffuseMap; +#if !DEPTH_CLAMP VARYING float pos_zd2; +#endif + VARYING float pos_w; + VARYING float target_pos_x; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; @@ -56,5 +60,7 @@ void main() frag_color = vec4(1,1,1,1); +#if !DEPTH_CLAMP gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl index c1f2d90712..11411a605c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl @@ -31,8 +31,12 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; +#if !DEPTH_CLAMP VARYING float pos_zd2; +#endif + VARYING float pos_w; + VARYING float target_pos_x; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; @@ -45,10 +49,16 @@ void main() vec4 pre_pos = vec4(position.xyz, 1.0); vec4 pos = modelview_projection_matrix * pre_pos; target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + pos_w = pos.w; + +#if !DEPTH_CLAMP pos_zd2 = pos.z * 0.5; gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif passTextureIndex(); diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl index 6195e2f1ec..ef153dfc5b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl @@ -27,7 +27,9 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; +#if !DEPTH_CLAMP VARYING vec4 post_pos; +#endif uniform vec3 box_center; uniform vec3 box_size; @@ -37,8 +39,12 @@ void main() //transform vertex vec3 p = position*box_size+box_center; vec4 pos = modelview_projection_matrix*vec4(p.xyz, 1.0); - + +#if !DEPTH_CLAMP post_pos = pos; - + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl index 7e55fdc12a..3d1b182875 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -29,11 +29,16 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +#if !DEPTH_CLAMP VARYING vec4 post_pos; +#endif void main() { frag_color = vec4(1,1,1,1); +#if !DEPTH_CLAMP gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); +#endif + } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl index 8b46e81f90..cc77a4cea0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl @@ -27,14 +27,20 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; +#if !DEPTH_CLAMP VARYING vec4 post_pos; +#endif void main() { //transform vertex vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0); +#if !DEPTH_CLAMP post_pos = pos; - + gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); +#else + gl_Position = pos; +#endif } -- cgit v1.2.3 From 359b6cad5b8ae2a88927d53eaa12b58a126e0d1c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 15 Apr 2013 14:12:16 -0500 Subject: NORSPEC-117 Fix distance attenuation to not use pow(lit, 0.7) function so distance falloff is still soft --- .../app_settings/shaders/class1/deferred/multiPointLightF.glsl | 4 ++-- .../newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 4 +--- indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl | 4 +--- indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl | 4 +--- 4 files changed, 5 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 5329ae9dd7..3bd433c283 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -127,9 +127,9 @@ void main() dist_atten *= noise; - float lit = da * dist_atten; + float lit = pow(da, 0.7) * dist_atten; - lit = pow(lit,0.7); + vec3 col = light_col[i].rgb*lit*diff; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 9746218ea6..959a85330e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -201,9 +201,7 @@ void main() vec3 lcol = color.rgb * plcol.rgb * plcol.a; - lit = da * dist_atten * noise; - - lit = pow(lit, 0.7); + lit = pow(da, 0.7) * dist_atten * noise; col = lcol*lit*diff_tex; amb_da += (da*0.5)*proj_ambiance; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 27863b0095..6976fc7bd9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -111,10 +111,8 @@ void main() vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; float fa = falloff+1.0; float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); - float lit = da * dist_atten * noise; + float lit = pow(da, 0.7) * dist_atten * noise; - lit = pow(lit, 0.7); - col = color.rgb*lit*col; vec4 spec = texture2DRect(specularRect, frag.xy); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index d7f0ab6d8e..918cdce040 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -204,9 +204,7 @@ void main() vec3 lcol = color.rgb * plcol.rgb * plcol.a; - lit = da * dist_atten * noise; - - lit = pow(lit, 0.7); + lit = pow(da, 0.7) * dist_atten * noise; col = lcol*lit*diff_tex; amb_da += (da*0.5)*proj_ambiance; -- 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 --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 16 +++++----------- .../shaders/class1/deferred/alphaNonIndexedF.glsl | 17 ++++++----------- 2 files changed, 11 insertions(+), 22 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index eff94b143a..4942abbadf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -60,13 +60,13 @@ uniform vec3 light_diffuse[8]; uniform float shadow_offset; -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; @@ -93,7 +93,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); } void main() @@ -118,7 +118,6 @@ 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); @@ -129,12 +128,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; 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 119c0a35f15d0f82ebf99507300357609769520b Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Tue, 16 Apr 2013 18:07:25 -0700 Subject: NORSPEC-59 fix? for mac crasher --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index fc628e60cf..8c9fe95590 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -152,10 +152,10 @@ void main() color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); - vec3 light_col = vec3(0,0,0); + col = vec3(0,0,0); #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); + 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) @@ -165,7 +165,7 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - color.rgb += diff.rgb * vary_pointlight_col * light_col; + color.rgb += diff.rgb * vary_pointlight_col * col; frag_color = color; } -- cgit v1.2.3 From 67af268b785e8a47d7db10aa3a566c269b0f16e3 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 17 Apr 2013 01:51:39 -0500 Subject: NORSPEC-90 Alpha pool hookups for materials. --- .../shaders/class1/deferred/materialF.glsl | 538 ++++++++++++++++++++- .../shaders/class1/deferred/materialV.glsl | 25 +- .../shaders/class1/deferred/softenLightF.glsl | 3 +- 3 files changed, 560 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 35b176b457..79a06bed2c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -29,11 +29,362 @@ #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 +#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + + +#if HAS_SUN_SHADOW + +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; + +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform vec2 shadow_res; +uniform float shadow_bias; + +float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias; + + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + + return shadow*0.2; +} + +#endif + +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +//uniform vec4 camPosWorld; +uniform vec4 gamma; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; +uniform float scene_light_strength; +uniform mat3 env_mat; +uniform mat3 ssao_effect_mat; + +uniform vec3 sun_dir; +VARYING vec2 vary_fragcoord; + +VARYING vec3 vary_position; + +vec3 vary_PositionEye; + +vec3 vary_SunlitColor; +vec3 vary_AmblitColor; +vec3 vary_AdditiveColor; +vec3 vary_AtmosAttenuation; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec3 light_attenuation[8]; +uniform vec3 light_diffuse[8]; + +vec3 calcDirectionalLight(vec3 n, vec3 l) +{ + float a = pow(max(dot(n,l),0.0), 0.7); + return vec3(a,a,a); +} + + +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, 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 = 1.0; + + vec3 col = vec3(0,0,0); + + if (d > 0.0 && la > 0.0 && fa > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist2 = d/la; + float dist_atten = 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(dot(n, lv), 0.0); + + float lit = max(da * dist_atten, 0.0); + + lit = pow(lit, 0.7); + + col = light_col*lit*diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += lit*scol*light_col.rgb*spec.rgb; + //col += spec.rgb; + } + } + } + + return max(col, vec3(0.0,0.0,0.0)); + +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec3 getPositionEye() +{ + return vary_PositionEye; +} +vec3 getSunlitColor() +{ + return vary_SunlitColor; +} +vec3 getAmblitColor() +{ + return vary_AmblitColor; +} +vec3 getAdditiveColor() +{ + return vary_AdditiveColor; +} +vec3 getAtmosAttenuation() +{ + return vary_AtmosAttenuation; +} + +void setPositionEye(vec3 v) +{ + vary_PositionEye = v; +} + +void setSunlitColor(vec3 v) +{ + vary_SunlitColor = v; +} + +void setAmblitColor(vec3 v) +{ + vary_AmblitColor = v; +} + +void setAdditiveColor(vec3 v) +{ + vary_AdditiveColor = v; +} + +void setAtmosAttenuation(vec3 v) +{ + vary_AtmosAttenuation = v; +} + +void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + + vec3 P = inPositionEye; + setPositionEye(P); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(vec3(sunlight * .5)); + setAmblitColor(vec3(tmpAmbient * .25)); + setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); +} + +vec3 atmosLighting(vec3 light) +{ + light *= getAtmosAttenuation().r; + light += getAdditiveColor(); + return (2.0 * light); +} + +vec3 atmosTransport(vec3 light) { + light *= getAtmosAttenuation().r; + light += getAdditiveColor() * 2.0; + return light; +} +vec3 atmosGetDiffuseSunlightColor() +{ + return getSunlitColor(); +} + +vec3 scaleDownLight(vec3 light) +{ + return (light / scene_light_strength ); +} + +vec3 scaleUpLight(vec3 light) +{ + return (light * scene_light_strength); +} + +vec3 atmosAmbient(vec3 light) +{ + return getAmblitColor() + light / 2.0; +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ + return getSunlitColor() * lightIntensity; +} + +vec3 scaleSoftClip(vec3 light) +{ + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + + return light; +} + +#else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else #define frag_data gl_FragData #endif +#endif uniform sampler2D diffuseMap; @@ -74,11 +425,11 @@ vec2 encode_normal(vec3 n) void main() { - vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); - col.rgb *= vertex_color.rgb; + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + diffcol.rgb *= vertex_color.rgb; #if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK - if (col.a < minimum_alpha) + if (diffcol.a < minimum_alpha) { discard; } @@ -103,7 +454,7 @@ void main() vec3 tnorm = vary_normal; #endif - vec4 final_color = col; + vec4 final_color = diffcol; #if DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE final_color.a = 0; @@ -121,7 +472,186 @@ void main() final_specular.a = specular_color.a; #endif + +#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND + { + //forward rendering, output just lit RGBA + vec3 pos = vary_position; + +#if HAS_SUN_SHADOW + float shadow = 0.0; + + vec4 spos = vec4(pos,1.0); + + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap2, lpos)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadow(shadowMap1, lpos)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos)*w; + weight += w; + } + + + shadow /= weight; + } + else + { + shadow = 1.0; + } +#else + float shadow = 1.0; +#endif + + vec4 diffuse = final_color; + vec3 norm = normalize(tnorm); + vec4 spec = final_specular; + float envIntensity = final_normal.z; + + vec3 col; + float bloom = 0.0; + { + calcAtmospherics(pos.xyz, 1.0); + + float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + + da = pow(da, 0.7); + + col = atmosAmbient(vec3(0)); + col += atmosAffectDirectionalLight(max(min(da, shadow), diffuse.a)); + + col *= diffuse.rgb; + + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + col += spec_contrib; + + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, + max(envIntensity-diffuse.a*2.0, 0.0)); + } + + col = atmosLighting(col); + col = scaleSoftClip(col); + + //col = mix(col.rgb, diffuse.rgb, diffuse.a); + } + + vec3 light_col = vec3(0,0,0); + + vec3 npos = normalize(-pos.xyz); + + + /*vec3 calcPointLightOrSpotLight( + vec3 light_col, + vec3 npos, + vec3 diffuse, + vec4 spec, + vec3 v, + vec3 n, + vec4 lp, + vec3 ln, + float la, + float fa, + float is_pointlight) + + */ + + /* +#ifdef MAC_GEFORCE_HACK + #define LIGHT_LOOP(i) \ + light_col += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, 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) +#else*/ + for (int i = 2; i < 8; i++) + { + light_col += calcPointLightOrSpotLight( + light_diffuse[i].rgb, + npos, + diffuse.rgb, + final_specular, + pos.xyz, + norm, + light_position[i], + light_direction[i], + light_attenuation[i].x, + light_attenuation[i].y, + light_attenuation[i].z); + } +//#endif + + col += light_col; + frag_color.rgb = col; + + } + + + frag_color.a = diffcol.a*vertex_color.a; + +#else frag_data[0] = final_color; 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/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 6475d8d003..f578795abe 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -23,6 +23,11 @@ * $/LicenseInfo$ */ +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + #if HAS_SKIN uniform mat4 modelview_matrix; uniform mat4 projection_matrix; @@ -32,8 +37,16 @@ uniform mat3 normal_matrix; uniform mat4 modelview_projection_matrix; #endif -uniform mat4 texture_matrix0; +#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if !HAS_SKIN +uniform mat4 modelview_matrix; +#endif +VARYING vec3 vary_position; + +#endif + +uniform mat4 texture_matrix0; ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; @@ -71,6 +84,10 @@ void main() vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; +#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND + vary_position = pos; +#endif + gl_Position = projection_matrix*vec4(pos,1.0); #else @@ -116,4 +133,10 @@ vary_normal = n; #endif //HAS_SKIN vertex_color = diffuse_color; + +#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if !HAS_SKIN + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; +#endif +#endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 63c819f941..d2b4da89ce 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -339,5 +339,6 @@ void main() frag_color.rgb = col; - frag_color.a = bloom; + //frag_color.a = bloom; + frag_color.a = 0.0; } -- cgit v1.2.3 From e40bcc4e16c8baeb3945e89c5d035d89416896e3 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 17 Apr 2013 09:05:40 -0700 Subject: NORSPEC-59 and NORSPEC-133 work-around crash with RenderDebugGL on and fix breakage in shaders from Mac changes --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 8c9fe95590..e8cbf318a1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -136,8 +136,7 @@ void main() float vertex_color_alpha = vertex_color.a; #endif - vec3 normal = vary_norm; - normal = texture2D(bumpMap, vary_texcoord1.xy).xyz * 2 - 1; + vec3 normal = texture2D(bumpMap, vary_texcoord1.xy).xyz * 2 - 1; normal = vec3(dot(normal.xyz, vary_rotation[0]), dot(normal.xyz, vary_rotation[1]), dot(normal.xyz, vary_rotation[2])); @@ -152,10 +151,10 @@ void main() color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); - col = vec3(0,0,0); + col = vec4(0,0,0,0); #define LIGHT_LOOP(i) \ - 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); + col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -165,7 +164,7 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - color.rgb += diff.rgb * vary_pointlight_col * col; + color.rgb += diff.rgb * vary_pointlight_col * col.rgb; frag_color = color; } -- cgit v1.2.3 From bb5bf632c6c3dea22865a86dc8c13f5de9ce06f0 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 17 Apr 2013 15:53:09 -0400 Subject: First pass of gamma correction reimplementation. --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 3 +-- .../app_settings/shaders/class1/deferred/alphaV.glsl | 8 ++++---- .../app_settings/shaders/class1/deferred/emissiveF.glsl | 2 +- .../app_settings/shaders/class1/deferred/fullbrightF.glsl | 2 +- .../shaders/class1/deferred/multiPointLightF.glsl | 5 ++--- .../shaders/class1/deferred/multiSpotLightF.glsl | 5 +++-- .../app_settings/shaders/class1/deferred/pointLightF.glsl | 5 ++--- .../shaders/class1/deferred/postDeferredNoDoFF.glsl | 2 +- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 14 +++++++------- .../app_settings/shaders/class1/deferred/softenLightV.glsl | 2 +- .../app_settings/shaders/class1/deferred/spotLightF.glsl | 12 ++++++++---- 11 files changed, 31 insertions(+), 29 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 00717cd6a9..a25d0f2773 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -129,7 +129,7 @@ void main() #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif - + diff.rgb = pow(diff.rgb, vec3(2.2)); #if INDEX_MODE == NON_INDEXED_NO_COLOR float vertex_color_alpha = 1.0; #else @@ -173,7 +173,6 @@ void main() #endif color.rgb += diff.rgb * vary_pointlight_col * light_col; - frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index e6b63657e6..13676ceead 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -181,21 +181,21 @@ void main() vary_rotation[2] = vec3(t.z, b.z, n.z); calcAtmospherics(pos.xyz); - + vec3 dff = pow(diffuse_color.rgb, vec3(2.2)); //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - vary_pointlight_col = diffuse_color.rgb; + vary_pointlight_col = dff; col.rgb = vec3(0,0,0); // Add windlight lights col.rgb = atmosAmbient(vec3(0.)); - vary_ambient = col.rgb*diffuse_color.rgb; vary_directional.rgb = atmosAffectDirectionalLight(1); + vary_ambient = col.rgb*dff; - col.rgb = col.rgb*diffuse_color.rgb; + col.rgb = col.rgb*dff; #if INDEX_MODE != NON_INDEXED_NO_COLOR vertex_color = col; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl index 6aa4d7b4ed..ed02c4a481 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl @@ -42,7 +42,7 @@ void main() float shadow = 1.0; vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; - + color.rgb = pow(color.rgb, vec3(2.2)); color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 36433a5827..b91aaf80fb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -43,7 +43,7 @@ void main() float shadow = 1.0; vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; - + color.rgb = pow(color.rgb, vec3(2.2)); color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 5329ae9dd7..d29c9a2b77 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -93,7 +93,8 @@ void main() norm = decode_normal(norm.xy); // unpack norm norm = normalize(norm); vec4 spec = texture2DRect(specularRect, frag.xy); - vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; + spec.rgb = pow(spec.rgb, vec3(2.2)); + vec3 diff = pow(texture2DRect(diffuseRect, frag.xy).rgb, vec3(2.2)); float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 out_col = vec3(0,0,0); vec3 npos = normalize(-pos); @@ -128,8 +129,6 @@ void main() dist_atten *= noise; float lit = da * dist_atten; - - lit = pow(lit,0.7); vec3 col = light_col[i].rgb*lit*diff; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 9746218ea6..5129ecf128 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -181,6 +181,7 @@ void main() vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + diff_tex = pow(diff_tex, vec3(2.2)); float noise = texture2D(noiseMap, frag.xy/128.0).b; if (proj_tc.z > 0.0 && @@ -202,8 +203,6 @@ void main() vec3 lcol = color.rgb * plcol.rgb * plcol.a; lit = da * dist_atten * noise; - - lit = pow(lit, 0.7); col = lcol*lit*diff_tex; amb_da += (da*0.5)*proj_ambiance; @@ -223,6 +222,8 @@ void main() vec4 spec = texture2DRect(specularRect, frag.xy); + spec.rgb = pow(spec.rgb, vec3(2.2)); + if (spec.a > 0.0) { vec3 ref = reflect(normalize(pos), norm); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 27863b0095..fa514e5585 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -108,16 +108,15 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; - vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; + vec3 col = pow(texture2DRect(diffuseRect, frag.xy).rgb, vec3(2.2)); float fa = falloff+1.0; float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); float lit = da * dist_atten * noise; - - lit = pow(lit, 0.7); col = color.rgb*lit*col; vec4 spec = texture2DRect(specularRect, frag.xy); + spec.rgb = pow(spec.rgb, vec3(2.2)); if (spec.a > 0.0) { vec3 npos = -normalize(pos); diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl index eb5beeef39..cceb1b11ab 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl @@ -42,6 +42,6 @@ void main() vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res); - frag_color = diff + bloom; + frag_color = pow(diff + bloom, vec4(0.454545, 0.454545, 0.454545, 1.0)); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 63c819f941..8600f69b8a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -60,6 +60,7 @@ uniform float density_multiplier; uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; +uniform float global_gamma; uniform float scene_light_strength; uniform mat3 env_mat; uniform mat3 ssao_effect_mat; @@ -230,9 +231,9 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + tmpAmbient))); //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); + setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * 3.3); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * 3.3); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * 3.3); } vec3 atmosLighting(vec3 light) @@ -291,12 +292,11 @@ void main() norm.xyz = decode_normal(norm.xy); // unpack norm float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - - da = pow(da, 0.7); vec4 diffuse = texture2DRect(diffuseRect, tc); + diffuse.rgb = pow(diffuse.rgb, vec3(2.2)); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - + spec.rgb = pow(spec.rgb, vec3(2.2)); vec3 col; float bloom = 0.0; if (diffuse.a < 0.9) @@ -323,7 +323,7 @@ void main() //add environmentmap vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, + col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2, max(envIntensity-diffuse.a*2.0, 0.0)); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index c6031fc45a..b59fcbe017 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -35,6 +35,6 @@ void main() //transform vertex vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); gl_Position = pos; - + vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index d7f0ab6d8e..4b4063f51c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -84,6 +84,7 @@ vec3 decode_normal (vec2 enc) vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = pow(ret.rgb, vec3(2.2)); vec2 dist = tc-vec2(0.5); @@ -99,7 +100,8 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - + ret.rgb = pow(ret.rgb, vec3(2.2)); + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -116,7 +118,8 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - + ret.rgb = pow(ret.rgb, vec3(2.2)); + vec2 dist = tc-vec2(0.5); float d = dot(dist,dist); @@ -184,6 +187,7 @@ void main() vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + diff_tex = pow(diff_tex, vec3(2.2)); float noise = texture2D(noiseMap, frag.xy/128.0).b; if (proj_tc.z > 0.0 && @@ -205,8 +209,6 @@ void main() vec3 lcol = color.rgb * plcol.rgb * plcol.a; lit = da * dist_atten * noise; - - lit = pow(lit, 0.7); col = lcol*lit*diff_tex; amb_da += (da*0.5)*proj_ambiance; @@ -226,6 +228,8 @@ void main() vec4 spec = texture2DRect(specularRect, frag.xy); + spec.rgb = pow(spec.rgb, vec3(2.2)); + if (spec.a > 0.0) { vec3 ref = reflect(normalize(pos), norm); -- cgit v1.2.3 From 83f3fd0dd68092b2f8917342ac45f31d322674c5 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 17 Apr 2013 14:27:50 -0700 Subject: NORSPEC-59 new shader changes -> new decrepit shader compiler workarounds --- .../app_settings/shaders/class1/deferred/alphaV.glsl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index e6b63657e6..b9cd611105 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -53,7 +53,7 @@ mat4 getSkinnedTransform(); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); void calcAtmospherics(vec3 inPositionEye); -float calcDirectionalLight(vec3 n, vec3 l); +vec3 calcDirectionalLight(vec3 n, vec3 l); vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); @@ -86,13 +86,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 = max(dot(n,l),0.0); - 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; @@ -119,14 +119,13 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa da *= max(dot(n, lv), 0.0); } - return da; + return vec3(da,da,da); } void main() { vec4 pos; vec3 norm; - //transform vertex #if HAS_SKIN mat4 trans = getObjectSkinnedTransform(); @@ -159,6 +158,7 @@ void main() pos = (modelview_matrix * vert); gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); #endif + vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; #if INDEX_MODE == INDEXED @@ -190,10 +190,11 @@ void main() col.rgb = vec3(0,0,0); // Add windlight lights - col.rgb = atmosAmbient(vec3(0.)); + col.rgb = atmosAmbient(col.rgb); vary_ambient = col.rgb*diffuse_color.rgb; - vary_directional.rgb = atmosAffectDirectionalLight(1); + + vary_directional.rgb = atmosAffectDirectionalLight(1.0f); col.rgb = col.rgb*diffuse_color.rgb; #if INDEX_MODE != NON_INDEXED_NO_COLOR @@ -208,5 +209,5 @@ void main() pos = modelview_projection_matrix * vert; vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #endif - + } -- cgit v1.2.3 From 8ed49bb828dc785684bd2c9764e34aa53d077c93 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 17 Apr 2013 16:50:03 -0700 Subject: Simplify ifdefs in alpha shaders for Mac --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 10 +++++----- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e8cbf318a1..057c0a1ec9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -37,11 +37,11 @@ out vec4 frag_color; uniform sampler2DRect depthMap; -#if INDEX_MODE != INDEXED +#if !INDEX_MODE || INDEX_MODE_NO_COLOR uniform sampler2D diffuseMap; #endif -#if INDEX_MODE == INDEXED +#if INDEX_MODE vec4 diffuseLookup(vec2 texcoord); #endif @@ -61,7 +61,7 @@ VARYING vec2 vary_texcoord2; VARYING vec3 vary_norm; VARYING mat3 vary_rotation; -#if INDEX_MODE != NON_INDEXED_NO_COLOR +#if !INDEX_MODE_NO_COLOR VARYING vec4 vertex_color; #endif @@ -124,13 +124,13 @@ void main() vec4 pos = vec4(vary_position, 1.0); -#if INDEX_MODE == INDEXED +#if INDEX_MODE vec4 diff= diffuseLookup(vary_texcoord0.xy); #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif -#if INDEX_MODE == NON_INDEXED_NO_COLOR +#if INDEX_MODE_NO_COLOR float vertex_color_alpha = 1.0; #else float vertex_color_alpha = vertex_color.a; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index b9cd611105..7506123a94 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -34,7 +34,7 @@ uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if INDEX_MODE == INDEXED +#if INDEX_MODE void passTextureIndex(); #endif ATTRIBUTE vec3 normal; @@ -66,7 +66,7 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; -#if INDEX_MODE != NON_INDEXED_NO_COLOR +#if !INDEX_MODE_NO_COLOR VARYING vec4 vertex_color; #endif @@ -161,7 +161,7 @@ void main() vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; -#if INDEX_MODE == INDEXED +#if INDEX_MODE passTextureIndex(); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; #else @@ -197,7 +197,7 @@ void main() vary_directional.rgb = atmosAffectDirectionalLight(1.0f); col.rgb = col.rgb*diffuse_color.rgb; -#if INDEX_MODE != NON_INDEXED_NO_COLOR +#if !INDEX_MODE_NO_COLOR vertex_color = col; #endif -- cgit v1.2.3 From fc965b3c897140ba794f0ece9ad3e943e79a0fcb Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 18 Apr 2013 00:15:18 -0500 Subject: NORSPEC-135 Fix for environment map not showing up if glossiness is zero. --- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 63c819f941..4b4cb5c8ce 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -308,11 +308,13 @@ void main() col *= diffuse.rgb; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection // - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + float sa = dot(refnormpersp, sun_dir.xyz); vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); @@ -320,13 +322,15 @@ void main() vec3 spec_contrib = dumbshiny * spec.rgb; bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; - - //add environmentmap + } + + if (envIntensity > 0.0) + { //add environmentmap vec3 env_vec = env_mat * refnormpersp; col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, max(envIntensity-diffuse.a*2.0, 0.0)); } - + col = atmosLighting(col); col = scaleSoftClip(col); -- cgit v1.2.3 From f76b3d7e7d778fec7f082c46491197cac9867a50 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Thu, 18 Apr 2013 05:30:44 -0700 Subject: NORSPEC-125 fiddle with ifdefs in alpha shaders again in hopes of linking on mobile geforce macs --- .../shaders/class1/deferred/alphaF.glsl | 20 ++++++++---------- .../shaders/class1/deferred/alphaV.glsl | 24 +++++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 057c0a1ec9..713aae9187 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -25,10 +25,6 @@ #extension GL_ARB_texture_rectangle : enable -#define INDEXED 1 -#define NON_INDEXED 2 -#define NON_INDEXED_NO_COLOR 3 - #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -37,11 +33,13 @@ out vec4 frag_color; uniform sampler2DRect depthMap; -#if !INDEX_MODE || INDEX_MODE_NO_COLOR +#ifndef INDEX_MODE +#ifndef INDEX_MODE_USE_COLOR uniform sampler2D diffuseMap; #endif +#endif -#if INDEX_MODE +#ifdef INDEX_MODE vec4 diffuseLookup(vec2 texcoord); #endif @@ -61,7 +59,7 @@ VARYING vec2 vary_texcoord2; VARYING vec3 vary_norm; VARYING mat3 vary_rotation; -#if !INDEX_MODE_NO_COLOR +#ifdef INDEX_MODE_USE_COLOR VARYING vec4 vertex_color; #endif @@ -124,16 +122,16 @@ void main() vec4 pos = vec4(vary_position, 1.0); -#if INDEX_MODE +#ifdef INDEX_MODE vec4 diff= diffuseLookup(vary_texcoord0.xy); #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif -#if INDEX_MODE_NO_COLOR - float vertex_color_alpha = 1.0; -#else +#ifdef INDEX_MODE_USE_COLOR float vertex_color_alpha = vertex_color.a; +#else + float vertex_color_alpha = 1.0; #endif vec3 normal = texture2D(bumpMap, vary_texcoord1.xy).xyz * 2 - 1; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 7506123a94..55d15ce847 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -34,7 +34,7 @@ uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if INDEX_MODE +#ifdef INDEX_MODE void passTextureIndex(); #endif ATTRIBUTE vec3 normal; @@ -44,7 +44,7 @@ ATTRIBUTE vec3 binormal; ATTRIBUTE vec2 texcoord1; ATTRIBUTE vec2 texcoord2; -#if HAS_SKIN +#ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); #elif IS_AVATAR_SKIN mat4 getSkinnedTransform(); @@ -66,7 +66,7 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; -#if !INDEX_MODE_NO_COLOR +#ifdef INDEX_MODE_USE_COLOR VARYING vec4 vertex_color; #endif @@ -127,7 +127,7 @@ void main() vec4 pos; vec3 norm; //transform vertex -#if HAS_SKIN +#ifdef HAS_SKIN mat4 trans = getObjectSkinnedTransform(); trans = modelview_matrix * trans; @@ -137,7 +137,8 @@ void main() norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz); vec4 frag_pos = projection_matrix * pos; gl_Position = frag_pos; -#elif IS_AVATAR_SKIN +#else +#ifdef IS_AVATAR_SKIN mat4 trans = getSkinnedTransform(); vec4 pos_in = vec4(position.xyz, 1.0); pos.x = dot(trans[0], pos_in); @@ -157,11 +158,13 @@ void main() vec4 vert = vec4(position.xyz, 1.0); pos = (modelview_matrix * vert); gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); +#endif #endif vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; -#if INDEX_MODE + +#ifdef INDEX_MODE passTextureIndex(); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; #else @@ -197,17 +200,18 @@ void main() vary_directional.rgb = atmosAffectDirectionalLight(1.0f); col.rgb = col.rgb*diffuse_color.rgb; -#if !INDEX_MODE_NO_COLOR +#ifdef INDEX_MODE_USE_COLOR vertex_color = col; #endif -#if HAS_SKIN +#ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -#elif IS_AVATAR_SKIN +#else +#ifdef IS_AVATAR_SKIN vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #else pos = modelview_projection_matrix * vert; vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #endif - +#endif } -- cgit v1.2.3 From 3200f07ae26d063b7d91cf77b40b717a83ee1a95 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Thu, 18 Apr 2013 08:20:26 -0700 Subject: NORSPEC-125 Materials V shader cleansing --- .../shaders/class1/deferred/alphaV.glsl | 6 +++++- .../shaders/class1/deferred/materialV.glsl | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 55d15ce847..71e8e430e5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -46,10 +46,14 @@ ATTRIBUTE vec2 texcoord2; #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); -#elif IS_AVATAR_SKIN +#else + +#ifdef IS_AVATAR_SKIN mat4 getSkinnedTransform(); #endif +#endif + vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); void calcAtmospherics(vec3 inPositionEye); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 6475d8d003..88095a81e8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -23,7 +23,7 @@ * $/LicenseInfo$ */ -#if HAS_SKIN +#ifdef HAS_SKIN uniform mat4 modelview_matrix; uniform mat4 projection_matrix; mat4 getObjectSkinnedTransform(); @@ -64,7 +64,7 @@ VARYING vec2 vary_texcoord0; void main() { -#if HAS_SKIN +#ifdef HAS_SKIN mat4 mat = getObjectSkinnedTransform(); mat = modelview_matrix * mat; @@ -89,7 +89,7 @@ void main() vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; #endif -#if HAS_SKIN +#ifdef HAS_SKIN vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); #if HAS_NORMAL_MAP vec3 b = normalize((mat*vec4(binormal.xyz+position.xyz,1.0)).xyz-pos.xyz); @@ -98,10 +98,11 @@ void main() vary_mat0 = vec3(t.x, b.x, n.x); vary_mat1 = vec3(t.y, b.y, n.y); vary_mat2 = vec3(t.z, b.z, n.z); -#else //HAS_NORMAL_MAP -vary_normal = n; -#endif //HAS_NORMAL_MAP -#else //HAS_SKIN +#else + vary_normal = n; +#endif + +#else vec3 n = normalize(normal_matrix * normal); #if HAS_NORMAL_MAP vec3 b = normalize(normal_matrix * binormal); @@ -110,10 +111,11 @@ vary_normal = n; vary_mat0 = vec3(t.x, b.x, n.x); vary_mat1 = vec3(t.y, b.y, n.y); vary_mat2 = vec3(t.z, b.z, n.z); -#else //HAS_NORMAL_MAP +#else vary_normal = n; -#endif //HAS_NORMAL_MAP -#endif //HAS_SKIN +#endif + +#endif vertex_color = diffuse_color; } -- cgit v1.2.3 From 1a5bba865c096473164b47a56dbb0ba1e055613d Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 18 Apr 2013 18:00:56 -0500 Subject: NORSPEC-90 Cleanup of alpha pool hook ups for materials. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 5 ++--- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e8cbf318a1..f63e2f7198 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -72,7 +72,6 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -uniform sampler2D bumpMap; uniform samplerCube environmentMap; uniform mat3 env_mat; @@ -125,7 +124,7 @@ void main() vec4 pos = vec4(vary_position, 1.0); #if INDEX_MODE == INDEXED - vec4 diff= diffuseLookup(vary_texcoord0.xy); + vec4 diff = diffuseLookup(vary_texcoord0.xy); #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif @@ -136,7 +135,7 @@ void main() float vertex_color_alpha = vertex_color.a; #endif - vec3 normal = texture2D(bumpMap, vary_texcoord1.xy).xyz * 2 - 1; + vec3 normal = vec3(0,0,1); normal = vec3(dot(normal.xyz, vary_rotation[0]), dot(normal.xyz, vary_rotation[1]), dot(normal.xyz, vary_rotation[2])); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 79a06bed2c..9674d9e88e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -566,11 +566,13 @@ void main() col *= diffuse.rgb; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection // - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + float sa = dot(refnormpersp, sun_dir.xyz); vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); @@ -578,7 +580,10 @@ void main() vec3 spec_contrib = dumbshiny * spec.rgb; bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; + } + if (envIntensity > 0.0) + { //add environmentmap vec3 env_vec = env_mat * refnormpersp; col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, -- cgit v1.2.3 From 28fcb3d54987a056b3dfe4d1d01a75339f8e6689 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 18 Apr 2013 18:31:49 -0500 Subject: NORSPEC-90 Remove unused state from alphaF/alphaV --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 9 ++------- .../app_settings/shaders/class1/deferred/alphaV.glsl | 19 +------------------ 2 files changed, 3 insertions(+), 25 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index f63e2f7198..94ce8a658a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -56,8 +56,6 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; VARYING vec3 vary_norm; VARYING mat3 vary_rotation; @@ -135,11 +133,8 @@ void main() float vertex_color_alpha = vertex_color.a; #endif - vec3 normal = vec3(0,0,1); - normal = vec3(dot(normal.xyz, vary_rotation[0]), - dot(normal.xyz, vary_rotation[1]), - dot(normal.xyz, vary_rotation[2])); - + vec3 normal = vary_norm; + vec3 l = light_position[0].xyz; vec3 dlight = calcDirectionalLight(normal, l); dlight = dlight * vary_directional.rgb * vary_pointlight_col; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index e6b63657e6..76277069d5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -40,9 +40,6 @@ void passTextureIndex(); ATTRIBUTE vec3 normal; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec3 binormal; -ATTRIBUTE vec2 texcoord1; -ATTRIBUTE vec2 texcoord2; #if HAS_SKIN mat4 getObjectSkinnedTransform(); @@ -71,11 +68,8 @@ VARYING vec4 vertex_color; #endif VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; VARYING vec3 vary_norm; -VARYING mat3 vary_rotation; uniform float near_clip; uniform float shadow_offset; @@ -159,8 +153,7 @@ void main() pos = (modelview_matrix * vert); gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); #endif - vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; - vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; + #if INDEX_MODE == INDEXED passTextureIndex(); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; @@ -169,17 +162,7 @@ void main() #endif vary_norm = norm; - float dp_directional_light = max(0.0, dot(norm, light_position[0].xyz)); - vary_position = pos.xyz + light_position[0].xyz * (1.0-dp_directional_light)*shadow_offset; - vec3 n = norm; - vec3 b = normalize(normal_matrix * binormal); - vec3 t = cross(b, n); - - vary_rotation[0] = vec3(t.x, b.x, n.x); - vary_rotation[1] = vec3(t.y, b.y, n.y); - vary_rotation[2] = vec3(t.z, b.z, n.z); - calcAtmospherics(pos.xyz); //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); -- cgit v1.2.3 From 6b836eacafd21c1ccac2c7276483ed393a4b406e Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 18 Apr 2013 19:43:30 -0400 Subject: Use GL_SRGB8_ALPHA8 for the diffuse and specular buffers, and correct gamma *before* glow and other post processing effects that don't care about being gamma correct. --- .../shaders/class1/deferred/multiPointLightF.glsl | 3 +- .../shaders/class1/deferred/multiSpotLightF.glsl | 2 - .../shaders/class1/deferred/pointLightF.glsl | 3 +- .../class1/deferred/postDeferredGammaCorrect.glsl | 44 ++++++++++++++++++++++ .../class1/deferred/postDeferredNoDoFF.glsl | 2 +- .../shaders/class1/deferred/softenLightF.glsl | 2 - .../shaders/class1/deferred/spotLightF.glsl | 2 - 7 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index d29c9a2b77..63863fb836 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -93,8 +93,7 @@ void main() norm = decode_normal(norm.xy); // unpack norm norm = normalize(norm); vec4 spec = texture2DRect(specularRect, frag.xy); - spec.rgb = pow(spec.rgb, vec3(2.2)); - vec3 diff = pow(texture2DRect(diffuseRect, frag.xy).rgb, vec3(2.2)); + vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 out_col = vec3(0,0,0); vec3 npos = normalize(-pos); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 5129ecf128..377df49815 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -181,7 +181,6 @@ void main() vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - diff_tex = pow(diff_tex, vec3(2.2)); float noise = texture2D(noiseMap, frag.xy/128.0).b; if (proj_tc.z > 0.0 && @@ -222,7 +221,6 @@ void main() vec4 spec = texture2DRect(specularRect, frag.xy); - spec.rgb = pow(spec.rgb, vec3(2.2)); if (spec.a > 0.0) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index fa514e5585..332b610197 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -108,7 +108,7 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; - vec3 col = pow(texture2DRect(diffuseRect, frag.xy).rgb, vec3(2.2)); + vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; float fa = falloff+1.0; float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); float lit = da * dist_atten * noise; @@ -116,7 +116,6 @@ void main() col = color.rgb*lit*col; vec4 spec = texture2DRect(specularRect, frag.xy); - spec.rgb = pow(spec.rgb, vec3(2.2)); if (spec.a > 0.0) { vec3 npos = -normalize(pos); diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl new file mode 100644 index 0000000000..404e284abb --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -0,0 +1,44 @@ +/** + * @file postDeferredGammaCorrect.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#extension GL_ARB_texture_rectangle : enable + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; + +uniform vec2 screen_res; +VARYING vec2 vary_fragcoord; + +void main() +{ + vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); + frag_color = pow(diff, vec4(0.454545, 0.454545, 0.454545, 1.0)); +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl index cceb1b11ab..eb5beeef39 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl @@ -42,6 +42,6 @@ void main() vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res); - frag_color = pow(diff + bloom, vec4(0.454545, 0.454545, 0.454545, 1.0)); + frag_color = diff + bloom; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 8600f69b8a..026039a0e7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -294,9 +294,7 @@ void main() float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); vec4 diffuse = texture2DRect(diffuseRect, tc); - diffuse.rgb = pow(diffuse.rgb, vec3(2.2)); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - spec.rgb = pow(spec.rgb, vec3(2.2)); vec3 col; float bloom = 0.0; if (diffuse.a < 0.9) diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 4b4063f51c..a339f6506e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -187,7 +187,6 @@ void main() vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - diff_tex = pow(diff_tex, vec3(2.2)); float noise = texture2D(noiseMap, frag.xy/128.0).b; if (proj_tc.z > 0.0 && @@ -228,7 +227,6 @@ void main() vec4 spec = texture2DRect(specularRect, frag.xy); - spec.rgb = pow(spec.rgb, vec3(2.2)); if (spec.a > 0.0) { -- cgit v1.2.3 From 509c35d5bae7dbd938198c3e038011932693ff36 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 18 Apr 2013 19:21:08 -0500 Subject: NORSPEC-90 Cleanup avatar alpha shaders --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 17 ----------------- .../app_settings/shaders/class1/deferred/alphaV.glsl | 10 +++++++--- 2 files changed, 7 insertions(+), 20 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 94ce8a658a..495ed33e9e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -35,16 +35,10 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect depthMap; - #if INDEX_MODE != INDEXED uniform sampler2D diffuseMap; #endif -#if INDEX_MODE == INDEXED -vec4 diffuseLookup(vec2 texcoord); -#endif - uniform vec2 screen_res; vec3 atmosLighting(vec3 light); @@ -57,27 +51,16 @@ VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; -VARYING mat3 vary_rotation; #if INDEX_MODE != NON_INDEXED_NO_COLOR VARYING vec4 vertex_color; #endif -uniform mat4 inv_proj; - uniform vec4 light_position[8]; uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; -uniform samplerCube environmentMap; -uniform mat3 env_mat; - -uniform vec4 specular_color; - - -uniform float shadow_offset; - vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = pow(max(dot(n,l),0.0), 0.7); diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 76277069d5..4c26621a88 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -38,7 +38,9 @@ ATTRIBUTE vec3 position; void passTextureIndex(); #endif ATTRIBUTE vec3 normal; +#if INDEX_MODE != NON_INDEXED_NO_COLOR ATTRIBUTE vec4 diffuse_color; +#endif ATTRIBUTE vec2 texcoord0; #if HAS_SKIN @@ -72,8 +74,6 @@ VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; uniform float near_clip; -uniform float shadow_offset; -uniform float shadow_bias; uniform vec4 light_position[8]; uniform vec3 light_direction[8]; @@ -162,9 +162,13 @@ void main() #endif vary_norm = norm; - + vary_position = pos.xyz; + calcAtmospherics(pos.xyz); +#if INDEX_MODE == NON_INDEXED_NO_COLOR + vec4 diffuse_color = vec4(1,1,1,1); +#endif //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); -- cgit v1.2.3 From 15bf1a81d1fef78961e5a220324b91aa3a3f565a Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 18 Apr 2013 20:42:31 -0400 Subject: This should take care of alpha blended full bright objects and gamma correction. --- .../shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl | 3 ++- .../shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl index 6c34643aab..e130ef5d91 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl @@ -30,6 +30,7 @@ out vec4 frag_color; #endif uniform float minimum_alpha; +uniform float texture_gamma; vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); @@ -45,7 +46,7 @@ void fullbright_lighting() { discard; } - + color.rgb = pow(color.rgb, vec3(texture_gamma)); color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl index f4477bd29a..56ad658696 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl @@ -30,6 +30,7 @@ out vec4 frag_color; #endif uniform float minimum_alpha; +uniform float texture_gamma; vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); @@ -47,7 +48,7 @@ void fullbright_lighting() { discard; } - + color.rgb = pow(color.rgb, vec3(texture_gamma)); color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); -- cgit v1.2.3 From 14b807e55efcfb8a9b52909fd554c9ba1cea0f36 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 18 Apr 2013 21:05:16 -0400 Subject: Don't apply gamma correction underwater (for now). --- .../shaders/class1/deferred/postDeferredGammaCorrect.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 404e284abb..2d6bce02c9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -36,9 +36,11 @@ uniform sampler2DRect diffuseRect; uniform vec2 screen_res; VARYING vec2 vary_fragcoord; +uniform float texture_gamma; + void main() { vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - frag_color = pow(diff, vec4(0.454545, 0.454545, 0.454545, 1.0)); + frag_color = pow(diff, vec4(texture_gamma, texture_gamma, texture_gamma, 1.0)); } -- cgit v1.2.3 From b6a6479c372e311b45e27eafd368e2045ca21790 Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 18 Apr 2013 21:31:10 -0400 Subject: Mitigation for light attenuation looking different with gamma correction. Assume that light attenuation wants to be linearized before we apply gamma correction. --- .../newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl | 1 + 4 files changed, 5 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 63863fb836..db42a54e42 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -125,6 +125,8 @@ void main() float fa = light_col[i].a+1.0; float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten = pow(dist_atten, 2.2) * 2.2; + dist_atten *= noise; float lit = da * dist_atten; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 377df49815..9e8f2f16f9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -169,6 +169,7 @@ void main() float fa = falloff+1.0; float dist_atten = min(1.0-(dist2-1.0*(1.0-fa))/fa, 1.0); + dist_atten = pow(dist_atten, 2.2) * 2.2; if (dist_atten <= 0.0) { discard; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 332b610197..36406cbf57 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -111,6 +111,7 @@ void main() vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; float fa = falloff+1.0; float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); + dist_atten = pow(dist_atten, 2.2) * 2.2; float lit = da * dist_atten * noise; col = color.rgb*lit*col; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index a339f6506e..56c10e25cc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -175,6 +175,7 @@ void main() float fa = falloff+1.0; float dist_atten = min(1.0-(dist2-1.0*(1.0-fa))/fa, 1.0); + dist_atten = pow(dist_atten, 2.2) * 2.2; if (dist_atten <= 0.0) { discard; -- cgit v1.2.3 From b145007941c0dd9d30fadc834426e22e5a113edf Mon Sep 17 00:00:00 2001 From: Geenz Date: Thu, 18 Apr 2013 23:18:21 -0400 Subject: Fix for alpha blended objects becoming too bright when gamma correction is applied. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 97767964f0..d175d2b518 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -109,7 +109,7 @@ void main() #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif - + diff.rgb = pow(diff.rgb, vec3(2.2)); #if INDEX_MODE == NON_INDEXED_NO_COLOR float vertex_color_alpha = 1.0; #else -- cgit v1.2.3 From f9ff68b5e3b016a53fe987e5b51442741ca88f15 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 19 Apr 2013 02:56:15 -0500 Subject: Cleanup specular highlights from spot lights --- .../shaders/class1/deferred/multiSpotLightF.glsl | 52 ++++++++++++---------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 9e8f2f16f9..50938d3ef9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -154,6 +154,8 @@ void main() } vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + float envIntensity = norm.z; + norm = decode_normal(norm.xy); norm = normalize(norm); @@ -224,6 +226,30 @@ void main() vec4 spec = texture2DRect(specularRect, frag.xy); if (spec.a > 0.0) + { + float lit = da * dist_atten * noise; + vec3 npos = -normalize(pos); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += lit*scol*color.rgb*spec.rgb; + //col += spec.rgb; + } + } + + if (envIntensity > 0.0) { vec3 ref = reflect(normalize(pos), norm); @@ -241,8 +267,9 @@ void main() { stc.xy /= stc.w; - float fatten = clamp(spec.a*spec.a+spec.a*0.5, 0.25, 1.0); + float fatten = clamp(envIntensity*envIntensity+envIntensity*0.5, 0.25, 1.0); + //stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); if (stc.x < 1.0 && @@ -250,28 +277,7 @@ void main() stc.x > 0.0 && stc.y > 0.0) { - - vec3 npos = -normalize(pos); - lv = pfinal-pos.xyz; - lv = normalize(lv); - - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - float gtdenom = 2 * nh; - float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); - - if (sa > 0.0) - { - float scol = fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt / (nh * da); - col += scol*color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod).rgb*spec.rgb; - } - - //vec4 scol = texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod); - //col += dist_atten*scol.rgb*color.rgb*scol.a*spec.rgb; + col += color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-envIntensity*proj_lod).rgb*spec.rgb; } } } -- cgit v1.2.3 From c5410a5d22ac5234226ab8f67144a753ef2d3019 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Fri, 19 Apr 2013 11:53:58 -0700 Subject: Shader changes for Mac compat --- .../shaders/class1/deferred/alphaF.glsl | 12 +- .../shaders/class1/deferred/alphaV.glsl | 24 ++- .../shaders/class1/deferred/materialF.glsl | 172 ++++++++------------- .../shaders/class1/deferred/materialV.glsl | 7 +- 4 files changed, 94 insertions(+), 121 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 17ac5a276d..ac8393edf8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -35,7 +35,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#if INDEX_MODE != INDEXED +#if (INDEX_MODE != INDEXED) uniform sampler2D diffuseMap; #endif @@ -52,7 +52,7 @@ VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; -#if INDEX_MODE != NON_INDEXED_NO_COLOR +#if (INDEX_MODE != NON_INDEXED_NO_COLOR) VARYING vec4 vertex_color; #endif @@ -104,20 +104,20 @@ void main() vec4 pos = vec4(vary_position, 1.0); -#if INDEX_MODE == INDEXED - vec4 diff= diffuseLookup(vary_texcoord0.xy); +#if (INDEX_MODE == INDEXED) + vec4 diff = diffuseLookup(vary_texcoord0.xy); #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif diff.rgb = pow(diff.rgb, vec3(2.2)); -#if INDEX_MODE == NON_INDEXED_NO_COLOR +#if (INDEX_MODE == NON_INDEXED_NO_COLOR) float vertex_color_alpha = 1.0; #else float vertex_color_alpha = vertex_color.a; #endif vec3 normal = vary_norm; - + vec3 l = light_position[0].xyz; vec3 dlight = calcDirectionalLight(normal, l); dlight = dlight * vary_directional.rgb * vary_pointlight_col; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index a4b4cd51e3..141a817991 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -34,11 +34,11 @@ uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if INDEX_MODE == INDEXED +#if (INDEX_MODE == INDEXED) void passTextureIndex(); #endif ATTRIBUTE vec3 normal; -#if INDEX_MODE != NON_INDEXED_NO_COLOR +#if (INDEX_MODE != NON_INDEXED_NO_COLOR) ATTRIBUTE vec4 diffuse_color; #endif ATTRIBUTE vec2 texcoord0; @@ -132,7 +132,9 @@ void main() norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz); vec4 frag_pos = projection_matrix * pos; gl_Position = frag_pos; -#elif IS_AVATAR_SKIN +#else + +#if IS_AVATAR_SKIN mat4 trans = getSkinnedTransform(); vec4 pos_in = vec4(position.xyz, 1.0); pos.x = dot(trans[0], pos_in); @@ -153,8 +155,10 @@ void main() pos = (modelview_matrix * vert); gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); #endif - -#if INDEX_MODE == INDEXED + +#endif + +#if (INDEX_MODE == INDEXED) passTextureIndex(); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; #else @@ -166,7 +170,7 @@ void main() calcAtmospherics(pos.xyz); -#if INDEX_MODE == NON_INDEXED_NO_COLOR +#if (INDEX_MODE == NON_INDEXED_NO_COLOR) vec4 diffuse_color = vec4(1,1,1,1); #endif //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); @@ -184,17 +188,21 @@ void main() vary_directional.rgb = atmosAffectDirectionalLight(1.0f); col.rgb = col.rgb*diffuse_color.rgb; -#if INDEX_MODE != NON_INDEXED_NO_COLOR +#if (INDEX_MODE != NON_INDEXED_NO_COLOR) vertex_color = col; #endif #if HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -#elif IS_AVATAR_SKIN +#else + +#if IS_AVATAR_SKIN vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #else pos = modelview_projection_matrix * vert; vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #endif +#endif + } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5e75cc3ce6..43848761b3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -29,7 +29,8 @@ #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -349,39 +350,44 @@ vec3 atmosGetDiffuseSunlightColor() vec3 scaleDownLight(vec3 light) { - return (light / scene_light_strength ); + return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); } vec3 scaleUpLight(vec3 light) { - return (light * scene_light_strength); + return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); } vec3 atmosAmbient(vec3 light) { - return getAmblitColor() + light / 2.0; + return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); } vec3 atmosAffectDirectionalLight(float lightIntensity) { - return getSunlitColor() * lightIntensity; + return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); } vec3 scaleSoftClip(vec3 light) { //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); + vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); + vec3 ones = vec3(1.0f, 1.0f, 1.0f); + + light = ones - clamp(light, zeroes, ones); + light = ones - pow(light, gamma.xxx); return light; } #else + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else #define frag_data gl_FragData #endif + #endif uniform sampler2D diffuseMap; @@ -399,7 +405,7 @@ VARYING vec2 vary_texcoord2; uniform float env_intensity; uniform vec4 specular_color; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) uniform float minimum_alpha; #endif @@ -426,14 +432,14 @@ void main() vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffcol.a < minimum_alpha) { discard; } #endif -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); #endif @@ -456,9 +462,12 @@ void main() vec3 tnorm = vary_normal; #endif + norm.xyz = tnorm; + norm.xyz = normalize(norm.xyz); + vec4 final_color = diffcol; -#if DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = 0; #endif @@ -475,9 +484,8 @@ void main() #endif -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND - { - //forward rendering, output just lit RGBA +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + //forward rendering, output just lit RGBA vec3 pos = vary_position; #if HAS_SUN_SHADOW @@ -549,110 +557,65 @@ void main() float shadow = 1.0; #endif - vec4 diffuse = final_color; - vec3 norm = normalize(tnorm); - vec4 spec = final_specular; - float envIntensity = final_normal.z; + spec = final_specular; + vec4 diffuse = final_color; + float envIntensity = final_normal.z; - vec3 col; - float bloom = 0.0; - { - calcAtmospherics(pos.xyz, 1.0); + vec3 col = vec3(0.0f,0.0f,0.0f); + + float bloom = 0.0; + calcAtmospherics(pos.xyz, 1.0); - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - da = pow(da, 0.7); + float da =dot(norm.xyz, sun_dir.xyz); + float final_da = pow(da, 0.7f); + final_da = min(final_da, shadow); + final_da = max(final_da, diffuse.a); + final_da = max(final_da, 0.0f); - col = atmosAmbient(vec3(0)); - col += atmosAffectDirectionalLight(max(min(da, shadow), diffuse.a)); - - col *= diffuse.rgb; + col.rgb = atmosAmbient(col); + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); + col.rgb *= diffuse.rgb; - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - col += spec_contrib; - } - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, - max(envIntensity-diffuse.a*2.0, 0.0)); - } - - col = atmosLighting(col); - col = scaleSoftClip(col); - - //col = mix(col.rgb, diffuse.rgb, diffuse.a); - } - - vec3 light_col = vec3(0,0,0); - - vec3 npos = normalize(-pos.xyz); + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + col += spec_contrib; + } - - /*vec3 calcPointLightOrSpotLight( - vec3 light_col, - vec3 npos, - vec3 diffuse, - vec4 spec, - vec3 v, - vec3 n, - vec4 lp, - vec3 ln, - float la, - float fa, - float is_pointlight) - - */ - - /* -#ifdef MAC_GEFORCE_HACK - #define LIGHT_LOOP(i) \ - light_col += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, 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) -#else*/ - for (int i = 2; i < 8; i++) + if (envIntensity > 0.0) { - light_col += calcPointLightOrSpotLight( - light_diffuse[i].rgb, - npos, - diffuse.rgb, - final_specular, - pos.xyz, - norm, - light_position[i], - light_direction[i], - light_attenuation[i].x, - light_attenuation[i].y, - light_attenuation[i].z); + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, + max(envIntensity-diffuse.a*2.0, 0.0)); } -//#endif + + col = atmosLighting(col); + col = scaleSoftClip(col); - col += light_col; - frag_color.rgb = col; + vec3 npos = normalize(-pos.xyz); - } + #define LIGHT_LOOP(i) \ + frag_color.rgb = frag_color.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, 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) frag_color.a = diffcol.a*vertex_color.a; @@ -661,4 +624,5 @@ void main() 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/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index f578795abe..0638dcfa55 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -37,7 +37,8 @@ uniform mat3 normal_matrix; uniform mat4 modelview_projection_matrix; #endif -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + #if !HAS_SKIN uniform mat4 modelview_matrix; #endif @@ -84,7 +85,7 @@ void main() vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vary_position = pos; #endif @@ -134,7 +135,7 @@ vary_normal = n; vertex_color = diffuse_color; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #if !HAS_SKIN vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; #endif -- cgit v1.2.3 From 7c0bea5bb4fe60c009a7f262297990f4792b9ae4 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Fri, 19 Apr 2013 13:08:57 -0700 Subject: Rework ifdefing and fix windows shader compiler warnings from materialF --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 14 ++++++++------ .../app_settings/shaders/class1/deferred/alphaV.glsl | 18 ++++++++++++------ .../shaders/class1/deferred/materialF.glsl | 3 ++- 3 files changed, 22 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index ac8393edf8..7c58749929 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -35,7 +35,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#if (INDEX_MODE != INDEXED) +#if USE_DIFFUSE_TEX uniform sampler2D diffuseMap; #endif @@ -52,7 +52,7 @@ VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; -#if (INDEX_MODE != NON_INDEXED_NO_COLOR) +#if USE_VERTEX_COLOR VARYING vec4 vertex_color; #endif @@ -104,16 +104,18 @@ void main() vec4 pos = vec4(vary_position, 1.0); -#if (INDEX_MODE == INDEXED) +#if USE_INDEXED_TEX vec4 diff = diffuseLookup(vary_texcoord0.xy); #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif + diff.rgb = pow(diff.rgb, vec3(2.2)); -#if (INDEX_MODE == NON_INDEXED_NO_COLOR) - float vertex_color_alpha = 1.0; + +#if USE_VERTEX_COLOR + float vertex_color_alpha = vertex_color.a; #else - float vertex_color_alpha = vertex_color.a; + float vertex_color_alpha = 1.0; #endif vec3 normal = vary_norm; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 141a817991..b8d43c0586 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -34,13 +34,17 @@ uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if (INDEX_MODE == INDEXED) + +#if USE_INDEXED_TEX void passTextureIndex(); #endif + ATTRIBUTE vec3 normal; -#if (INDEX_MODE != NON_INDEXED_NO_COLOR) + +#if USE_VERTEX_COLOR ATTRIBUTE vec4 diffuse_color; #endif + ATTRIBUTE vec2 texcoord0; #if HAS_SKIN @@ -65,7 +69,7 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; -#if INDEX_MODE != NON_INDEXED_NO_COLOR +#if USE_VERTEX_COLOR VARYING vec4 vertex_color; #endif @@ -158,7 +162,7 @@ void main() #endif -#if (INDEX_MODE == INDEXED) +#if USE_INDEXED_TEX passTextureIndex(); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; #else @@ -170,9 +174,10 @@ void main() calcAtmospherics(pos.xyz); -#if (INDEX_MODE == NON_INDEXED_NO_COLOR) +#if !USE_VERTEX_COLOR vec4 diffuse_color = vec4(1,1,1,1); #endif + //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); @@ -188,7 +193,8 @@ void main() vary_directional.rgb = atmosAffectDirectionalLight(1.0f); col.rgb = col.rgb*diffuse_color.rgb; -#if (INDEX_MODE != NON_INDEXED_NO_COLOR) + +#if USE_VERTEX_COLOR vertex_color = col; #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 43848761b3..7752189e1d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -607,7 +607,7 @@ void main() vec3 npos = normalize(-pos.xyz); #define LIGHT_LOOP(i) \ - frag_color.rgb = frag_color.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -617,6 +617,7 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) + frag_color.rgb = col.rgb; frag_color.a = diffcol.a*vertex_color.a; #else -- cgit v1.2.3 From 8137a3c26f950127d4b37470d1d68c7b43d5c6e4 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham Linden)" Date: Fri, 19 Apr 2013 13:52:10 -0700 Subject: Change #ifs to #ifdefs for mac compiler --- .../shaders/class1/deferred/alphaF.glsl | 8 ++++---- .../shaders/class1/deferred/alphaV.glsl | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 7c58749929..a3be4bb0c3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -35,7 +35,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#if USE_DIFFUSE_TEX +#ifdef USE_DIFFUSE_TEX uniform sampler2D diffuseMap; #endif @@ -52,7 +52,7 @@ VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; -#if USE_VERTEX_COLOR +#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; #endif @@ -104,7 +104,7 @@ void main() vec4 pos = vec4(vary_position, 1.0); -#if USE_INDEXED_TEX +#ifdef USE_INDEXED_TEX vec4 diff = diffuseLookup(vary_texcoord0.xy); #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); @@ -112,7 +112,7 @@ void main() diff.rgb = pow(diff.rgb, vec3(2.2)); -#if USE_VERTEX_COLOR +#ifdef USE_VERTEX_COLOR float vertex_color_alpha = vertex_color.a; #else float vertex_color_alpha = 1.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index b8d43c0586..3f42e8a24b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -35,19 +35,19 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if USE_INDEXED_TEX +#ifdef USE_INDEXED_TEX void passTextureIndex(); #endif ATTRIBUTE vec3 normal; -#if USE_VERTEX_COLOR +#ifdef USE_VERTEX_COLOR ATTRIBUTE vec4 diffuse_color; #endif ATTRIBUTE vec2 texcoord0; -#if HAS_SKIN +#ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); #elif IS_AVATAR_SKIN mat4 getSkinnedTransform(); @@ -69,7 +69,7 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; -#if USE_VERTEX_COLOR +#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; #endif @@ -126,7 +126,7 @@ void main() vec3 norm; //transform vertex -#if HAS_SKIN +#ifdef HAS_SKIN mat4 trans = getObjectSkinnedTransform(); trans = modelview_matrix * trans; @@ -138,7 +138,7 @@ void main() gl_Position = frag_pos; #else -#if IS_AVATAR_SKIN +#ifdef IS_AVATAR_SKIN mat4 trans = getSkinnedTransform(); vec4 pos_in = vec4(position.xyz, 1.0); pos.x = dot(trans[0], pos_in); @@ -162,7 +162,7 @@ void main() #endif -#if USE_INDEXED_TEX +#ifdef USE_INDEXED_TEX passTextureIndex(); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; #else @@ -174,7 +174,7 @@ void main() calcAtmospherics(pos.xyz); -#if !USE_VERTEX_COLOR +#ifndef USE_VERTEX_COLOR vec4 diffuse_color = vec4(1,1,1,1); #endif @@ -194,15 +194,15 @@ void main() col.rgb = col.rgb*diffuse_color.rgb; -#if USE_VERTEX_COLOR +#ifdef USE_VERTEX_COLOR vertex_color = col; #endif -#if HAS_SKIN +#ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); #else -#if IS_AVATAR_SKIN +#ifdef IS_AVATAR_SKIN vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #else pos = modelview_projection_matrix * vert; -- cgit v1.2.3 From 6881b01ea9f652507cb5dfc5da70458ca80c6d52 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 19 Apr 2013 17:20:52 -0500 Subject: NORSPEC-139 Fix for non-fullscreen spotlight lighting mismatching fullscreen spotlight lighting --- .../shaders/class1/deferred/spotLightF.glsl | 87 ++++++++++++---------- 1 file changed, 47 insertions(+), 40 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 56c10e25cc..8d2a4f2dd6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -22,18 +22,15 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - +#extension GL_ARB_texture_rectangle : enable + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else #define frag_color gl_FragColor #endif -//class 1 -- no shadows - -#extension GL_ARB_texture_rectangle : enable - uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect depthMap; @@ -43,7 +40,6 @@ uniform sampler2D noiseMap; uniform sampler2D projectionMap; uniform sampler2D lightFunc; - uniform mat4 proj_mat; //screen space to light space uniform float proj_near; //near clip for projection uniform vec3 proj_p; //plane projection is emitting from (in screen space) @@ -59,13 +55,12 @@ uniform float far_clip; uniform vec3 proj_origin; //origin of projection to be used for angular attenuation uniform float sun_wash; +uniform float size; uniform vec3 color; uniform float falloff; -uniform float size; -VARYING vec4 vary_fragcoord; VARYING vec3 trans_center; - +VARYING vec4 vary_fragcoord; uniform vec2 screen_res; uniform mat4 inv_proj; @@ -84,7 +79,6 @@ vec3 decode_normal (vec2 enc) vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = pow(ret.rgb, vec3(2.2)); vec2 dist = tc-vec2(0.5); @@ -100,8 +94,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = pow(ret.rgb, vec3(2.2)); - + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -118,8 +111,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = pow(ret.rgb, vec3(2.2)); - + vec2 dist = tc-vec2(0.5); float d = dot(dist,dist); @@ -158,8 +150,10 @@ void main() { discard; } + vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + float envIntensity = norm.z; norm = decode_normal(norm.xy); norm = normalize(norm); @@ -189,6 +183,10 @@ void main() vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + vec4 spec = texture2DRect(specularRect, frag.xy); + + + float noise = texture2D(noiseMap, frag.xy/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && @@ -196,11 +194,13 @@ void main() proj_tc.x > 0.0 && proj_tc.y > 0.0) { - float lit = 0.0; float amb_da = proj_ambiance; + float lit = 0.0; if (da > 0.0) { + lit = da * dist_atten * noise; + float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); float lod = diff * proj_lod; @@ -208,10 +208,8 @@ void main() vec3 lcol = color.rgb * plcol.rgb * plcol.a; - lit = da * dist_atten * noise; - col = lcol*lit*diff_tex; - amb_da += (da*0.5)*proj_ambiance; + //amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); @@ -226,10 +224,36 @@ void main() col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; } - - vec4 spec = texture2DRect(specularRect, frag.xy); if (spec.a > 0.0) + { + float lit = da * dist_atten * noise; + vec3 npos = -normalize(pos); + + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(norm, h); + float nv = dot(norm, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + col += lit*scol*color.rgb*spec.rgb; + //col += spec.rgb; + } + } + + + + + + if (envIntensity > 0.0) { vec3 ref = reflect(normalize(pos), norm); @@ -247,8 +271,9 @@ void main() { stc.xy /= stc.w; - float fatten = clamp(spec.a*spec.a+spec.a*0.5, 0.25, 1.0); + float fatten = clamp(envIntensity*envIntensity+envIntensity*0.5, 0.25, 1.0); + //stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); stc.xy = (stc.xy - vec2(0.5)) * fatten + vec2(0.5); if (stc.x < 1.0 && @@ -256,25 +281,7 @@ void main() stc.x > 0.0 && stc.y > 0.0) { - vec3 npos = -normalize(pos); - lv = pfinal-pos.xyz; - lv = normalize(lv); - - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += scol*color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-spec.a*proj_lod).rgb*spec.rgb; - } + col += color.rgb*texture2DLodSpecular(projectionMap, stc.xy, proj_lod-envIntensity*proj_lod).rgb*spec.rgb; } } } -- cgit v1.2.3 From 894412285b3bbcb1f790145202e77a5aa6f369ec Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Fri, 19 Apr 2013 18:00:13 -0700 Subject: Fix forward decl to match changed func def and clear defines between shader compiles for ifdef sanity --- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 3f42e8a24b..11759af2ad 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -56,7 +56,7 @@ mat4 getSkinnedTransform(); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); void calcAtmospherics(vec3 inPositionEye); -float calcDirectionalLight(vec3 n, vec3 l); +vec3 calcDirectionalLight(vec3 n, vec3 l); vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); -- cgit v1.2.3 From b2344cfd13bc0dc7175cf3895b7111186dc573c9 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Sat, 20 Apr 2013 03:36:21 -0700 Subject: Fix rendering artifacts on Mac Mobile GeForce cards --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 7752189e1d..09a2d4467a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -622,6 +622,13 @@ void main() #else frag_data[0] = final_color; + +#ifdef UGLY_MAC_HACK + // magic spec exp clamp fixes rendering artifacts on older mac GF drivers + // + final_specular = min(final_specular, vec4(1.0f, 1.0f, 1.0f, 0.125f)); +#endif + frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif -- cgit v1.2.3 From ff54e85daa04e80f926955d1a57460229e6d9d1b Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Sat, 20 Apr 2013 04:32:03 -0700 Subject: Fixup merge with vwr-dev-mat --- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 1 - indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 --- 2 files changed, 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 11759af2ad..93f9e05aec 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -177,7 +177,6 @@ void main() #ifndef USE_VERTEX_COLOR vec4 diffuse_color = vec4(1,1,1,1); #endif - //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 09a2d4467a..482d0ccc74 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -381,13 +381,11 @@ vec3 scaleSoftClip(vec3 light) } #else - #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else #define frag_data gl_FragData #endif - #endif uniform sampler2D diffuseMap; @@ -632,5 +630,4 @@ void main() frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif - } -- cgit v1.2.3 From 38b222e76bc5fc4dd3f05787a45f38087b4af5cc Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham)" Date: Mon, 22 Apr 2013 09:56:08 -0700 Subject: Fix regression in alpha shader on non-Mac from recent changes --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 6 ++++-- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index a3be4bb0c3..ec04f856fb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -106,11 +106,13 @@ void main() #ifdef USE_INDEXED_TEX vec4 diff = diffuseLookup(vary_texcoord0.xy); -#else +#endif + +#ifdef USE_DIFFUSE_TEX vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif - diff.rgb = pow(diff.rgb, vec3(2.2)); + diff.rgb = pow(diff.rgb, vec3(2.2f, 2.2f, 2.2f)); #ifdef USE_VERTEX_COLOR float vertex_color_alpha = vertex_color.a; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 93f9e05aec..91f7b007f3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -49,9 +49,11 @@ ATTRIBUTE vec2 texcoord0; #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); -#elif IS_AVATAR_SKIN +#else +ifdef IS_AVATAR_SKIN mat4 getSkinnedTransform(); #endif +#endif vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); void calcAtmospherics(vec3 inPositionEye); @@ -211,3 +213,4 @@ void main() #endif } + -- cgit v1.2.3 From 3d7c1000625af4089476d14d1a8110842a23a104 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 22 Apr 2013 13:59:25 -0500 Subject: NORSPEC-141 Back out a change that seems to cause shadow artifacts on rigged attachments. --- .../shaders/class1/avatar/objectSkinV.glsl | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl index ff30560adc..2745d5fd95 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl @@ -30,24 +30,18 @@ uniform mat4 matrixPalette[64]; mat4 getObjectSkinnedTransform() { + int i; - float w0 = fract(weight4.x); - float w1 = fract(weight4.y); - float w2 = fract(weight4.z); - float w3 = fract(weight4.w); - - int i0 = int(floor(weight4.x)); - int i1 = int(floor(weight4.y)); - int i2 = int(floor(weight4.z)); - int i3 = int(floor(weight4.w)); - - //float scale = 1.0/(w.x+w.y+w.z+w.w); - //w *= scale; + vec4 w = fract(weight4); + vec4 index = floor(weight4); + + float scale = 1.0/(w.x+w.y+w.z+w.w); + w *= scale; - mat4 mat = matrixPalette[i0]*w0; - mat += matrixPalette[i1]*w1; - mat += matrixPalette[i2]*w2; - mat += matrixPalette[i3]*w3; + mat4 mat = matrixPalette[int(index.x)]*w.x; + mat += matrixPalette[int(index.y)]*w.y; + mat += matrixPalette[int(index.z)]*w.z; + mat += matrixPalette[int(index.w)]*w.w; return mat; } -- cgit v1.2.3 From b5868bda0d441823fa9783a1c712c258f4cecfa5 Mon Sep 17 00:00:00 2001 From: "Graham Madarasz (Graham)" Date: Mon, 22 Apr 2013 14:12:34 -0700 Subject: Fix avatar alpha shader define setup --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 4 +--- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index ec04f856fb..9f1fdb4385 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -106,9 +106,7 @@ void main() #ifdef USE_INDEXED_TEX vec4 diff = diffuseLookup(vary_texcoord0.xy); -#endif - -#ifdef USE_DIFFUSE_TEX +#else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 91f7b007f3..20042f2248 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -50,7 +50,7 @@ ATTRIBUTE vec2 texcoord0; #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); #else -ifdef IS_AVATAR_SKIN +#ifdef IS_AVATAR_SKIN mat4 getSkinnedTransform(); #endif #endif -- cgit v1.2.3 From fbbbb80752e91deff0bbaf5893210fddff53eb13 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 24 Apr 2013 05:16:02 -0400 Subject: Fix for overbrigtened alpha blended objects in deferred. Linearize diffuse surface color in the vertex shader before passing it to the fragment shader. --- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 4c26621a88..6a1bfd5bef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -172,17 +172,19 @@ void main() //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - vary_pointlight_col = diffuse_color.rgb; + vec3 diff = pow(diffuse_color.rgb, vec3(2.2)); + + vary_pointlight_col = diff; col.rgb = vec3(0,0,0); // Add windlight lights col.rgb = atmosAmbient(vec3(0.)); - vary_ambient = col.rgb*diffuse_color.rgb; + vary_ambient = col.rgb*diff; vary_directional.rgb = atmosAffectDirectionalLight(1); - col.rgb = col.rgb*diffuse_color.rgb; + col.rgb = col.rgb*diff; #if INDEX_MODE != NON_INDEXED_NO_COLOR vertex_color = col; #endif -- cgit v1.2.3 From 79318043218a9ec6cb6e52eca936487177554903 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 24 Apr 2013 06:24:21 -0700 Subject: NORSPEC-59 NORSPEC-125 make materials and alpha shaders work on Mac laptops with nV mobile graphics cards --- .../shaders/class1/deferred/alphaF.glsl | 16 +-- .../shaders/class1/deferred/alphaV.glsl | 63 +++++++----- .../shaders/class1/deferred/materialF.glsl | 111 ++++++++------------- .../shaders/class1/deferred/materialV.glsl | 7 +- 4 files changed, 92 insertions(+), 105 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index d175d2b518..9f1fdb4385 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -35,7 +35,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -#if INDEX_MODE != INDEXED +#ifdef USE_DIFFUSE_TEX uniform sampler2D diffuseMap; #endif @@ -52,7 +52,7 @@ VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; -#if INDEX_MODE != NON_INDEXED_NO_COLOR +#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; #endif @@ -104,16 +104,18 @@ void main() vec4 pos = vec4(vary_position, 1.0); -#if INDEX_MODE == INDEXED +#ifdef USE_INDEXED_TEX vec4 diff = diffuseLookup(vary_texcoord0.xy); #else vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); #endif - diff.rgb = pow(diff.rgb, vec3(2.2)); -#if INDEX_MODE == NON_INDEXED_NO_COLOR - float vertex_color_alpha = 1.0; + + diff.rgb = pow(diff.rgb, vec3(2.2f, 2.2f, 2.2f)); + +#ifdef USE_VERTEX_COLOR + float vertex_color_alpha = vertex_color.a; #else - float vertex_color_alpha = vertex_color.a; + float vertex_color_alpha = 1.0; #endif vec3 normal = vary_norm; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 6a1bfd5bef..a8efd3e95b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -34,25 +34,31 @@ uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if INDEX_MODE == INDEXED + +#ifdef USE_INDEXED_TEX void passTextureIndex(); #endif + ATTRIBUTE vec3 normal; -#if INDEX_MODE != NON_INDEXED_NO_COLOR + +#ifdef USE_VERTEX_COLOR ATTRIBUTE vec4 diffuse_color; #endif + ATTRIBUTE vec2 texcoord0; -#if HAS_SKIN +#ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); -#elif IS_AVATAR_SKIN +#else +#ifdef IS_AVATAR_SKIN mat4 getSkinnedTransform(); #endif +#endif vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol); void calcAtmospherics(vec3 inPositionEye); -float calcDirectionalLight(vec3 n, vec3 l); +vec3 calcDirectionalLight(vec3 n, vec3 l); vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); @@ -65,7 +71,7 @@ VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; VARYING vec3 vary_pointlight_col; -#if INDEX_MODE != NON_INDEXED_NO_COLOR +#ifdef USE_VERTEX_COLOR VARYING vec4 vertex_color; #endif @@ -80,13 +86,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 = max(dot(n,l),0.0); - 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; @@ -113,7 +119,7 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa da *= max(dot(n, lv), 0.0); } - return da; + return vec3(da,da,da); } void main() @@ -122,7 +128,7 @@ void main() vec3 norm; //transform vertex -#if HAS_SKIN +#ifdef HAS_SKIN mat4 trans = getObjectSkinnedTransform(); trans = modelview_matrix * trans; @@ -132,7 +138,9 @@ void main() norm = normalize((trans * vec4(norm, 1.0)).xyz - pos.xyz); vec4 frag_pos = projection_matrix * pos; gl_Position = frag_pos; -#elif IS_AVATAR_SKIN +#else + +#ifdef IS_AVATAR_SKIN mat4 trans = getSkinnedTransform(); vec4 pos_in = vec4(position.xyz, 1.0); pos.x = dot(trans[0], pos_in); @@ -154,7 +162,9 @@ void main() gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); #endif -#if INDEX_MODE == INDEXED +#endif + +#ifdef USE_INDEXED_TEX passTextureIndex(); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; #else @@ -166,36 +176,41 @@ void main() calcAtmospherics(pos.xyz); -#if INDEX_MODE == NON_INDEXED_NO_COLOR +#ifndef USE_VERTEX_COLOR vec4 diffuse_color = vec4(1,1,1,1); #endif //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - vec3 diff = pow(diffuse_color.rgb, vec3(2.2)); - - vary_pointlight_col = diff; + vary_pointlight_col = diffuse_color.rgb; col.rgb = vec3(0,0,0); // Add windlight lights - col.rgb = atmosAmbient(vec3(0.)); + col.rgb = atmosAmbient(col.rgb); - vary_ambient = col.rgb*diff; - vary_directional.rgb = atmosAffectDirectionalLight(1); + vary_ambient = col.rgb*diffuse_color.rgb; + + vary_directional.rgb = atmosAffectDirectionalLight(1.0f); - col.rgb = col.rgb*diff; -#if INDEX_MODE != NON_INDEXED_NO_COLOR + col.rgb = col.rgb*diffuse_color.rgb; + +#ifdef USE_VERTEX_COLOR vertex_color = col; #endif -#if HAS_SKIN +#ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -#elif IS_AVATAR_SKIN +#else + +#ifdef IS_AVATAR_SKIN vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #else pos = modelview_projection_matrix * vert; vary_fragcoord.xyz = pos.xyz + vec3(0,0,near_clip); #endif +#endif + } + diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5e75cc3ce6..b3c1a067ee 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -29,7 +29,8 @@ #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -349,29 +350,32 @@ vec3 atmosGetDiffuseSunlightColor() vec3 scaleDownLight(vec3 light) { - return (light / scene_light_strength ); + return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); } vec3 scaleUpLight(vec3 light) { - return (light * scene_light_strength); + return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); } vec3 atmosAmbient(vec3 light) { - return getAmblitColor() + light / 2.0; + return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); } vec3 atmosAffectDirectionalLight(float lightIntensity) { - return getSunlitColor() * lightIntensity; + return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); } vec3 scaleSoftClip(vec3 light) { //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); + vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); + vec3 ones = vec3(1.0f, 1.0f, 1.0f); + + light = ones - clamp(light, zeroes, ones); + light = ones - pow(light, gamma.xxx); return light; } @@ -399,7 +403,7 @@ VARYING vec2 vary_texcoord2; uniform float env_intensity; uniform vec4 specular_color; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) uniform float minimum_alpha; #endif @@ -426,14 +430,14 @@ void main() vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffcol.a < minimum_alpha) { discard; } #endif -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); #endif @@ -456,9 +460,12 @@ void main() vec3 tnorm = vary_normal; #endif + norm.xyz = tnorm; + norm.xyz = normalize(norm.xyz); + vec4 final_color = diffcol; -#if DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = 0; #endif @@ -475,8 +482,7 @@ void main() #endif -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND - { +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output just lit RGBA vec3 pos = vary_position; @@ -549,26 +555,27 @@ void main() float shadow = 1.0; #endif + spec = final_specular; vec4 diffuse = final_color; - vec3 norm = normalize(tnorm); - vec4 spec = final_specular; float envIntensity = final_normal.z; - vec3 col; + vec3 col = vec3(0.0f,0.0f,0.0f); + float bloom = 0.0; - { calcAtmospherics(pos.xyz, 1.0); - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - da = pow(da, 0.7); + float da =dot(norm.xyz, sun_dir.xyz); + float final_da = pow(da, 0.7f); + final_da = min(final_da, shadow); + final_da = max(final_da, diffuse.a); + final_da = max(final_da, 0.0f); - col = atmosAmbient(vec3(0)); - col += atmosAffectDirectionalLight(max(min(da, shadow), diffuse.a)); - - col *= diffuse.rgb; + col.rgb = atmosAmbient(col); + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); + col.rgb *= diffuse.rgb; - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection { @@ -595,33 +602,10 @@ void main() col = atmosLighting(col); col = scaleSoftClip(col); - //col = mix(col.rgb, diffuse.rgb, diffuse.a); - } - - vec3 light_col = vec3(0,0,0); - vec3 npos = normalize(-pos.xyz); - - /*vec3 calcPointLightOrSpotLight( - vec3 light_col, - vec3 npos, - vec3 diffuse, - vec4 spec, - vec3 v, - vec3 n, - vec4 lp, - vec3 ln, - float la, - float fa, - float is_pointlight) - - */ - - /* -#ifdef MAC_GEFORCE_HACK #define LIGHT_LOOP(i) \ - light_col += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i], light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -630,34 +614,19 @@ void main() LIGHT_LOOP(5) LIGHT_LOOP(6) LIGHT_LOOP(7) -#else*/ - for (int i = 2; i < 8; i++) - { - light_col += calcPointLightOrSpotLight( - light_diffuse[i].rgb, - npos, - diffuse.rgb, - final_specular, - pos.xyz, - norm, - light_position[i], - light_direction[i], - light_attenuation[i].x, - light_attenuation[i].y, - light_attenuation[i].z); - } -//#endif - - col += light_col; - frag_color.rgb = col; - - } - + frag_color.rgb = col.rgb; frag_color.a = diffcol.a*vertex_color.a; #else frag_data[0] = final_color; + +#ifdef UGLY_MAC_HACK + // magic spec exp clamp fixes rendering artifacts on older mac GF drivers + // + final_specular = min(final_specular, vec4(1.0f, 1.0f, 1.0f, 0.125f)); +#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/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index f578795abe..0638dcfa55 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -37,7 +37,8 @@ uniform mat3 normal_matrix; uniform mat4 modelview_projection_matrix; #endif -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + #if !HAS_SKIN uniform mat4 modelview_matrix; #endif @@ -84,7 +85,7 @@ void main() vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vary_position = pos; #endif @@ -134,7 +135,7 @@ vary_normal = n; vertex_color = diffuse_color; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #if !HAS_SKIN vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; #endif -- cgit v1.2.3 From ce48b9d8cf0722f011e12f5bdc09b6e441625813 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 24 Apr 2013 10:33:38 -0700 Subject: Fix mismerge that lost Geenz colorspace conversion of diffuse in alphaV --- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index a8efd3e95b..ae3769c786 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -182,7 +182,12 @@ void main() //vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.)); vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a); - vary_pointlight_col = diffuse_color.rgb; + vec3 diff = pow(diffuse_color.rgb, vec3(2.2)); + + + + vary_pointlight_col = diff; + col.rgb = vec3(0,0,0); -- cgit v1.2.3 From 4ae48c225b1bb82a5667757fea53ff5c0646a5c4 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 24 Apr 2013 10:37:29 -0700 Subject: Correct fix to include affect on ambient term and make work on Mac nV --- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index ae3769c786..77d02b36ff 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -194,11 +194,11 @@ void main() // Add windlight lights col.rgb = atmosAmbient(col.rgb); - vary_ambient = col.rgb*diffuse_color.rgb; + vary_ambient = col.rgb*diff.rgb; vary_directional.rgb = atmosAffectDirectionalLight(1.0f); - col.rgb = col.rgb*diffuse_color.rgb; + col.rgb = col.rgb*diff.rgb; #ifdef USE_VERTEX_COLOR vertex_color = col; -- cgit v1.2.3 From 3a2576cefa97f50640adb596a5d01fa287f7033f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 25 Apr 2013 13:29:40 -0500 Subject: NORSPEC-118 Compatibility pass against advanced lighting disabled. --- .../app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightShinyWaterF.glsl | 2 +- .../shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl | 2 +- indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl | 2 +- .../newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl | 2 +- .../shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl index 777c8b45bb..c8282e9a51 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyF.glsl @@ -50,7 +50,7 @@ void fullbright_shiny_lighting() color.rgb = fullbrightScaleSoftClip(color.rgb); - color.a = max(color.a, vertex_color.a); + color.a = 1.0; frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl index 4fa3b1d939..e7dbd4bbd2 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyNonIndexedF.glsl @@ -51,7 +51,7 @@ void fullbright_shiny_lighting() color.rgb = fullbrightScaleSoftClip(color.rgb); - color.a = max(color.a, vertex_color.a); + color.a = 1.0; frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl index 58984a4263..5886fc65be 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterF.glsl @@ -48,7 +48,7 @@ void fullbright_shiny_lighting_water() color.rgb = fullbrightShinyAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); - color.a = max(color.a, vertex_color.a); + color.a = 1.0; frag_color = applyWaterFog(color); } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl index a39b7205d7..cddc7d8df8 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightShinyWaterNonIndexedF.glsl @@ -49,7 +49,7 @@ void fullbright_shiny_lighting_water() color.rgb = fullbrightShinyAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); - color.a = max(color.a, vertex_color.a); + color.a = 1.0; frag_color = applyWaterFog(color); } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl index 52e3b2ad02..9208c148ef 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyF.glsl @@ -50,7 +50,7 @@ void shiny_lighting() color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); - color.a = max(color.a, vertex_color.a); + color.a = 1.0; frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl index 474d5ea496..92628faa68 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyNonIndexedF.glsl @@ -51,7 +51,7 @@ void shiny_lighting() color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); - color.a = max(color.a, vertex_color.a); + color.a = 1.0; frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl index d2a4c47aac..61841674e2 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterF.glsl @@ -47,7 +47,7 @@ void shiny_lighting_water() color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); color.rgb = atmosLighting(color.rgb); - color.a = max(color.a, vertex_color.a); + color.a = 1.0; frag_color = applyWaterFog(color); } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl index f3bd662364..0b6e835fd0 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightShinyWaterNonIndexedF.glsl @@ -48,7 +48,7 @@ void shiny_lighting_water() color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); color.rgb = atmosLighting(color.rgb); - color.a = max(color.a, vertex_color.a); + color.a = 1.0; frag_color = applyWaterFog(color); } -- cgit v1.2.3 From 4102d3fb06c42846796cccb39a03d520c90b325c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 25 Apr 2013 16:03:19 -0500 Subject: NORSPEC-106 Fix for emissive mask overriding environment mask. --- .../newview/app_settings/shaders/class1/deferred/skyF.glsl | 2 +- .../app_settings/shaders/class1/deferred/softenLightF.glsl | 14 +++++--------- .../app_settings/shaders/class1/deferred/waterF.glsl | 8 +++++++- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 20a756530a..49ad064364 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -61,6 +61,6 @@ void main() /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.5,0.5,0.5,0); + frag_data[2] = vec4(0.5,0.5,0.0,0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index aafa932b8f..064ec51028 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -297,7 +297,7 @@ void main() vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 col; float bloom = 0.0; - if (diffuse.a < 0.9) + //if (diffuse.a < 0.9) { calcAtmospherics(pos.xyz, 1.0); @@ -322,23 +322,19 @@ void main() col += spec_contrib; } + col = mix(col.rgb, diffuse.rgb, diffuse.a); + if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2, - max(envIntensity-diffuse.a*2.0, 0.0)); + envIntensity); } col = atmosLighting(col); col = scaleSoftClip(col); - - col = mix(col.rgb, diffuse.rgb, diffuse.a); } - else - { - col = diffuse.rgb; - } - + frag_color.rgb = col; //frag_color.a = bloom; diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 3427d6db57..de858b34b5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -67,6 +67,12 @@ VARYING vec4 littleWave; VARYING vec4 view; VARYING vec4 vary_position; +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + void main() { vec4 color; @@ -161,5 +167,5 @@ void main() frag_data[0] = vec4(color.rgb, 0.5); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec - frag_data[2] = vec4(screenspacewavef.xyz*0.5+0.5, screenspacewavef.z*0.5); // normalxyz, displace + frag_data[2] = vec4(encode_normal(screenspacewavef), 0.0, 0.0); // normalxyz, displace } -- cgit v1.2.3 From 8bf4f1591114f135c64bee5cb9cb5e67bbcf8acd Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 25 Apr 2013 17:15:47 -0500 Subject: NORSPEC-104 Fix for texture animation sometimes not overriding specular and normal map texture coordinates. --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 064ec51028..90cf085524 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -297,7 +297,6 @@ void main() vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec3 col; float bloom = 0.0; - //if (diffuse.a < 0.9) { calcAtmospherics(pos.xyz, 1.0); -- cgit v1.2.3 From 2a96a5f3eae9c0cf5a239a6734a8a656a71c2cb7 Mon Sep 17 00:00:00 2001 From: Geenz Date: Mon, 29 Apr 2013 14:15:59 -0400 Subject: Fix any missing color space conversions where appropriate, tweak the sun's intensity to match pre-gamma correction results, and also mask spotlight specular by the projected texture. --- .../shaders/class1/deferred/alphaF.glsl | 2 +- .../shaders/class1/deferred/materialF.glsl | 12 +++++------ .../shaders/class1/deferred/multiSpotLightF.glsl | 16 +++++++-------- .../shaders/class1/deferred/softenLightF.glsl | 8 ++++---- .../shaders/class1/deferred/spotLightF.glsl | 23 ++++++++++++++-------- 5 files changed, 33 insertions(+), 28 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 9f1fdb4385..fec79ebf62 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -121,7 +121,7 @@ void main() vec3 normal = vary_norm; vec3 l = light_position[0].xyz; - vec3 dlight = calcDirectionalLight(normal, l); + vec3 dlight = calcDirectionalLight(normal, l) * 2.6; dlight = dlight * vary_directional.rgb * vary_pointlight_col; vec4 col = vec4(vary_ambient + dlight, vertex_color_alpha); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b3c1a067ee..9d3e6882b7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -326,9 +326,9 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + tmpAmbient))); //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); + setSunlitColor(pow(vec3(sunlight * .5), vec3(2.2)) * 2.2); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(2.2)) * 2.2); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(2.2)) * 2.2); } vec3 atmosLighting(vec3 light) @@ -567,13 +567,13 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); float da =dot(norm.xyz, sun_dir.xyz); - float final_da = pow(da, 0.7f); + float final_da = da; final_da = min(final_da, shadow); final_da = max(final_da, diffuse.a); final_da = max(final_da, 0.0f); col.rgb = atmosAmbient(col); - col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da * 2.6); col.rgb *= diffuse.rgb; @@ -595,7 +595,7 @@ void main() { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, + col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2, max(envIntensity-diffuse.a*2.0, 0.0)); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 50938d3ef9..893a92299a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -184,7 +184,8 @@ void main() vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - + vec3 dlit = vec3(0, 0, 0); + float noise = texture2D(noiseMap, frag.xy/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && @@ -202,14 +203,13 @@ void main() vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - vec3 lcol = color.rgb * plcol.rgb * plcol.a; + dlit = color.rgb * plcol.rgb * plcol.a; lit = da * dist_atten * noise; - col = lcol*lit*diff_tex; + col = dlit*lit*diff_tex; amb_da += (da*0.5)*proj_ambiance; } - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); @@ -218,8 +218,7 @@ void main() amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + col += amb_da*color.rgb*diff_tex*amb_plcol.rgb*amb_plcol.a; } @@ -227,7 +226,6 @@ void main() if (spec.a > 0.0) { - float lit = da * dist_atten * noise; vec3 npos = -normalize(pos); //vec3 ref = dot(pos+lv, norm); @@ -240,11 +238,11 @@ void main() float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - + if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += lit*scol*color.rgb*spec.rgb; + col += dlit*scol*spec.rgb; //col += spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index aafa932b8f..97ea1a3fe5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -231,9 +231,9 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + tmpAmbient))); //brightness of surface both sunlight and ambient - setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * 3.3); - setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * 3.3); - setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * 3.3); + setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * 2.2); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * 2.2); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * 2.2); } vec3 atmosLighting(vec3 light) @@ -302,7 +302,7 @@ void main() calcAtmospherics(pos.xyz, 1.0); col = atmosAmbient(vec3(0)); - col += atmosAffectDirectionalLight(max(min(da, 1.0), diffuse.a)); + col += atmosAffectDirectionalLight(max(min(da, 1.0) * 2.6, diffuse.a)); col *= diffuse.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 8d2a4f2dd6..b29f676ecc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -76,9 +76,15 @@ vec3 decode_normal (vec2 enc) return n; } +vec4 correctWithGamma(vec4 col) +{ + return vec4(pow(col.rgb, vec3(2.2)), col.a); +} + vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = tc-vec2(0.5); @@ -94,6 +100,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -111,6 +118,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = tc-vec2(0.5); @@ -188,6 +196,8 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; + vec3 dlit = vec3(0, 0, 0); + if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && @@ -205,13 +215,11 @@ void main() float lod = diff * proj_lod; vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - vec3 lcol = color.rgb * plcol.rgb * plcol.a; + dlit = color.rgb * plcol.rgb * plcol.a; - col = lcol*lit*diff_tex; + col = dlit*lit*diff_tex; //amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; } - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); @@ -220,14 +228,12 @@ void main() amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a*diff_tex.rgb; } if (spec.a > 0.0) { - float lit = da * dist_atten * noise; vec3 npos = -normalize(pos); //vec3 ref = dot(pos+lv, norm); @@ -243,8 +249,9 @@ void main() if (nh > 0.0) { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += lit*scol*color.rgb*spec.rgb; + col += dlit*scol*spec.rgb; //col += spec.rgb; } } -- cgit v1.2.3 From ad9e30817411b373baf73e63653ad6d10661e35f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 29 Apr 2013 15:01:48 -0500 Subject: NORSPEC-153 Workaround for AMD driver bug that doesn't like '\' on #define's --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 3 +-- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index fec79ebf62..737c658126 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -132,8 +132,7 @@ void main() color.rgb = scaleSoftClip(color.rgb); col = vec4(0,0,0,0); - #define LIGHT_LOOP(i) \ - col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + #define LIGHT_LOOP(i) col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) LIGHT_LOOP(2) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 9d3e6882b7..a4eaac8483 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -604,8 +604,7 @@ void main() vec3 npos = normalize(-pos.xyz); - #define LIGHT_LOOP(i) \ - col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) LIGHT_LOOP(2) -- cgit v1.2.3 From b06ec66a5d11628905da256e084d0036f39ba529 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 30 Apr 2013 14:49:53 -0500 Subject: MATBUG-78 Fix for alpha lighting distance attenuation not matching opaque distance attenuation --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 737c658126..e2fe4a1e9e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -85,6 +85,7 @@ vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float //distance attenuation float dist2 = d/la; da = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); + da = pow(da, 2.2) * 2.2; // spotlight coefficient. float spot = max(dot(-ln, lv), is_pointlight); -- cgit v1.2.3 From d659b29f6ca180cac774e4576bba9da791510633 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Tue, 30 Apr 2013 13:44:35 -0700 Subject: Fix vwr-dev-mat merge bugs in llpanelface (missing Oz fix) and XML --- .../shaders/class1/deferred/alphaF.glsl | 5 ++--- .../shaders/class1/deferred/materialF.glsl | 15 +++++++------- .../shaders/class1/deferred/multiSpotLightF.glsl | 12 +++++------ .../shaders/class1/deferred/softenLightF.glsl | 8 ++++---- .../shaders/class1/deferred/spotLightF.glsl | 24 ++++++++++++++-------- 5 files changed, 34 insertions(+), 30 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 9f1fdb4385..737c658126 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -121,7 +121,7 @@ void main() vec3 normal = vary_norm; vec3 l = light_position[0].xyz; - vec3 dlight = calcDirectionalLight(normal, l); + vec3 dlight = calcDirectionalLight(normal, l) * 2.6; dlight = dlight * vary_directional.rgb * vary_pointlight_col; vec4 col = vec4(vary_ambient + dlight, vertex_color_alpha); @@ -132,8 +132,7 @@ void main() color.rgb = scaleSoftClip(color.rgb); col = vec4(0,0,0,0); - #define LIGHT_LOOP(i) \ - col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + #define LIGHT_LOOP(i) col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) LIGHT_LOOP(2) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b3c1a067ee..a4eaac8483 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -326,9 +326,9 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + tmpAmbient))); //brightness of surface both sunlight and ambient - setSunlitColor(vec3(sunlight * .5)); - setAmblitColor(vec3(tmpAmbient * .25)); - setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); + setSunlitColor(pow(vec3(sunlight * .5), vec3(2.2)) * 2.2); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(2.2)) * 2.2); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(2.2)) * 2.2); } vec3 atmosLighting(vec3 light) @@ -567,13 +567,13 @@ void main() vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); float da =dot(norm.xyz, sun_dir.xyz); - float final_da = pow(da, 0.7f); + float final_da = da; final_da = min(final_da, shadow); final_da = max(final_da, diffuse.a); final_da = max(final_da, 0.0f); col.rgb = atmosAmbient(col); - col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da * 2.6); col.rgb *= diffuse.rgb; @@ -595,7 +595,7 @@ void main() { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, + col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2, max(envIntensity-diffuse.a*2.0, 0.0)); } @@ -604,8 +604,7 @@ void main() vec3 npos = normalize(-pos.xyz); - #define LIGHT_LOOP(i) \ - col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); LIGHT_LOOP(1) LIGHT_LOOP(2) diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 50938d3ef9..97ccc77ca8 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -184,6 +184,7 @@ void main() vec3 col = vec3(0,0,0); vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + vec3 dlit = vec3(0, 0, 0); float noise = texture2D(noiseMap, frag.xy/128.0).b; if (proj_tc.z > 0.0 && @@ -202,14 +203,13 @@ void main() vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - vec3 lcol = color.rgb * plcol.rgb * plcol.a; + dlit = color.rgb * plcol.rgb * plcol.a; lit = da * dist_atten * noise; - col = lcol*lit*diff_tex; + col = dlit*lit*diff_tex; amb_da += (da*0.5)*proj_ambiance; } - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); @@ -218,8 +218,7 @@ void main() amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + col += amb_da*color.rgb*diff_tex*amb_plcol.rgb*amb_plcol.a; } @@ -227,7 +226,6 @@ void main() if (spec.a > 0.0) { - float lit = da * dist_atten * noise; vec3 npos = -normalize(pos); //vec3 ref = dot(pos+lv, norm); @@ -244,7 +242,7 @@ void main() if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += lit*scol*color.rgb*spec.rgb; + col += dlit*scol*spec.rgb; //col += spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 90cf085524..5d936233fe 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -231,9 +231,9 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + tmpAmbient))); //brightness of surface both sunlight and ambient - setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * 3.3); - setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * 3.3); - setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * 3.3); + setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * 2.2); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * 2.2); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * 2.2); } vec3 atmosLighting(vec3 light) @@ -301,7 +301,7 @@ void main() calcAtmospherics(pos.xyz, 1.0); col = atmosAmbient(vec3(0)); - col += atmosAffectDirectionalLight(max(min(da, 1.0), diffuse.a)); + col += atmosAffectDirectionalLight(max(min(da, 1.0) * 2.6, diffuse.a)); col *= diffuse.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 8d2a4f2dd6..35d4f314af 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -76,9 +76,15 @@ vec3 decode_normal (vec2 enc) return n; } +vec4 correctWithGamma(vec4 col) +{ + return vec4(pow(col.rgb, vec3(2.2)), col.a); +} + vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = tc-vec2(0.5); @@ -94,6 +100,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -111,6 +118,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = tc-vec2(0.5); @@ -188,6 +196,8 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; + vec3 dlit = vec3(0, 0, 0); + if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && @@ -205,13 +215,12 @@ void main() float lod = diff * proj_lod; vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); + dlit = color.rgb * plcol.rgb * plcol.a; - vec3 lcol = color.rgb * plcol.rgb * plcol.a; - - col = lcol*lit*diff_tex; + col = dlit*lit*diff_tex; //amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; } - + //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); @@ -220,14 +229,12 @@ void main() amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; + col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a*diff_tex.rgb; } if (spec.a > 0.0) { - float lit = da * dist_atten * noise; vec3 npos = -normalize(pos); //vec3 ref = dot(pos+lv, norm); @@ -243,8 +250,9 @@ void main() if (nh > 0.0) { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += lit*scol*color.rgb*spec.rgb; + col += dlit*scol*spec.rgb; //col += spec.rgb; } } -- cgit v1.2.3 From 806d09b1143894ad66cea2c228f467e8c39a8adf Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Tue, 30 Apr 2013 19:50:05 -0700 Subject: Merge 3.5.1 into Materials --- indra/newview/app_settings/shaders/class1/environment/waterV.glsl | 1 + .../shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl | 2 +- .../app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl index f66ba1d2d9..a2a567eff1 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl @@ -28,6 +28,7 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; + void calcAtmospherics(vec3 inPositionEye); uniform vec2 d1; diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl index 99a6fe85fe..9c82056fd7 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl @@ -31,7 +31,7 @@ out vec4 frag_color; uniform float minimum_alpha; -vec4 diffuseLookup(vec2 texcoord); +/* vec4 diffuseLookup(vec2 texcoord); */ vec3 fullbrightAtmosTransport(vec3 light); vec4 applyWaterFog(vec4 color); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl index df182168f3..d3dacf9bc4 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterF.glsl @@ -32,7 +32,7 @@ out vec4 frag_color; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; -vec4 diffuseLookup(vec2 texcoord); +/* vec4 diffuseLookup(vec2 texcoord); */ vec3 fullbrightAtmosTransport(vec3 light); vec4 applyWaterFog(vec4 color); -- cgit v1.2.3 From 0938ce04f7d12439740285b61db3dd0bdadebb4f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 1 May 2013 16:42:07 -0500 Subject: Fix up specular highlights and gamma correction for projectors. --- .../shaders/class1/deferred/multiPointLightF.glsl | 1 + .../shaders/class1/deferred/multiSpotLightF.glsl | 14 ++++++++++++-- .../app_settings/shaders/class1/deferred/pointLightF.glsl | 2 ++ .../app_settings/shaders/class1/deferred/spotLightF.glsl | 1 + .../shaders/class1/objects/emissiveSkinnedV.glsl | 4 ---- 5 files changed, 16 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index db42a54e42..338532e71d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -137,6 +137,7 @@ void main() if (spec.a > 0.0) { + lit = min(da*6.0, 1.0) * dist_atten; //vec3 ref = dot(pos+lv, norm); vec3 h = normalize(lv+npos); float nh = dot(norm, h); diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 893a92299a..6675bfde69 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -78,9 +78,15 @@ vec3 decode_normal (vec2 enc) return n; } +vec4 correctWithGamma(vec4 col) +{ + return vec4(pow(col.rgb, vec3(2.2)), col.a); +} + vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); + ret = correctWithGamma(ret); vec2 dist = tc-vec2(0.5); @@ -96,7 +102,8 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - + ret = correctWithGamma(ret); + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); float det = min(lod/(proj_lod*0.5), 1.0); @@ -113,7 +120,8 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - + ret = correctWithGamma(ret); + vec2 dist = tc-vec2(0.5); float d = dot(dist,dist); @@ -226,6 +234,8 @@ void main() if (spec.a > 0.0) { + dlit *= min(da*6.0, 1.0) * dist_atten; + vec3 npos = -normalize(pos); //vec3 ref = dot(pos+lv, norm); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 36406cbf57..69cdb2ce71 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -119,6 +119,8 @@ void main() vec4 spec = texture2DRect(specularRect, frag.xy); if (spec.a > 0.0) { + lit = min(da*6.0, 1.0) * dist_atten; + vec3 npos = -normalize(pos); vec3 h = normalize(lv+npos); float nh = dot(norm, h); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index b29f676ecc..c918a42c73 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -234,6 +234,7 @@ void main() if (spec.a > 0.0) { + dlit *= min(da*6.0, 1.0) * dist_atten; vec3 npos = -normalize(pos); //vec3 ref = dot(pos+lv, norm); diff --git a/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl index 8494ffba52..3dab224258 100644 --- a/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl @@ -50,9 +50,5 @@ void main() calcAtmospherics(pos.xyz); - vertex_color = emissive; - gl_Position = projection_matrix*vec4(pos, 1.0); - - } -- cgit v1.2.3 From 73404da266ffd5560d6faef5243d45c3478c1d6e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 1 May 2013 16:48:27 -0500 Subject: Fix for sky being too bright with advanced lighting enabled --- indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 5d936233fe..a1dff9188f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -321,8 +321,6 @@ void main() col += spec_contrib; } - col = mix(col.rgb, diffuse.rgb, diffuse.a); - if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; @@ -332,6 +330,8 @@ void main() col = atmosLighting(col); col = scaleSoftClip(col); + + col = mix(col.rgb, diffuse.rgb, diffuse.a); } frag_color.rgb = col; -- cgit v1.2.3 From 90c2be46bf677db00207a45478ade362b90d7a6c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 1 May 2013 20:01:37 -0500 Subject: NORSPEC-145 Fix for improper rendering of glow pass for rigged meshes. --- indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl index 3dab224258..9064904191 100644 --- a/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/emissiveSkinnedV.glsl @@ -48,6 +48,8 @@ void main() mat = modelview_matrix * mat; vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz; + vertex_color = emissive; + calcAtmospherics(pos.xyz); gl_Position = projection_matrix*vec4(pos, 1.0); -- cgit v1.2.3 From df6bb7ace2f2ca26f5fabf8305e190e7d0066cf1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 6 May 2013 11:11:49 -0500 Subject: MATBUG-78 Fix for alpha lighting falloff not matching for sunlight when shadows are enabled. --- .../shaders/class1/deferred/alphaF.glsl | 111 ++++++++++++++++++++- 1 file changed, 109 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e2fe4a1e9e..50b43f6a8d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -35,12 +35,24 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +#if HAS_SHADOW +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; + +uniform vec2 shadow_res; + +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float shadow_bias; + +#endif + #ifdef USE_DIFFUSE_TEX uniform sampler2D diffuseMap; #endif -uniform vec2 screen_res; - vec3 atmosLighting(vec3 light); vec3 scaleSoftClip(vec3 light); @@ -61,6 +73,8 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +uniform vec2 screen_res; + vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -98,6 +112,27 @@ vec3 calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float return vec3(da,da,da); } +#if HAS_SHADOW +float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias; + + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + + return shadow*0.2; +} +#endif + + void main() { vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; @@ -105,6 +140,73 @@ void main() vec4 pos = vec4(vary_position, 1.0); + +#if HAS_SHADOW + float shadow = 0.0; + vec4 spos = pos; + + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap2, lpos)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadow(shadowMap1, lpos)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos)*w; + weight += w; + } + + + shadow /= weight; + } + else + { + shadow = 1.0; + } +#endif + #ifdef USE_INDEXED_TEX vec4 diff = diffuseLookup(vary_texcoord0.xy); #else @@ -125,7 +227,12 @@ void main() vec3 dlight = calcDirectionalLight(normal, l) * 2.6; dlight = dlight * vary_directional.rgb * vary_pointlight_col; +#if HAS_SHADOW + vec4 col = vec4(vary_ambient + dlight * shadow, vertex_color_alpha); +#else vec4 col = vec4(vary_ambient + dlight, vertex_color_alpha); +#endif + vec4 color = diff * col; color.rgb = atmosLighting(color.rgb); -- cgit v1.2.3 From b5ecd3865728e048be8bf394fc8d1a06a317d88f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 7 May 2013 17:11:47 -0500 Subject: Fix for bad light map generation/sampling. --- .../app_settings/shaders/class1/deferred/blurLightF.glsl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index f400eb7a5b..c030c23515 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -64,11 +64,23 @@ vec4 getPosition(vec2 pos_screen) return pos; } +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} + void main() { vec2 tc = vary_fragcoord.xy; vec3 norm = texture2DRect(normalMap, tc).xyz; - norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm + norm = decode_normal(norm.xy); // unpack norm + vec3 pos = getPosition(tc).xyz; vec4 ccol = texture2DRect(lightMap, tc).rgba; -- cgit v1.2.3 From 5c6d52f260900a483b7c9d8421ed5619b897d026 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 8 May 2013 12:01:38 -0700 Subject: NORSPEC-156 modify fullbrightF colorspace conversion to eliminate delta with non-deferred fullbright look --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index b91aaf80fb..4dfd13d406 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,12 +42,9 @@ void main() { float shadow = 1.0; - vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; - color.rgb = pow(color.rgb, vec3(2.2)); + vec4 color = diffuseLookup(vary_texcoord0.xy)*pow(vertex_color.rgb,vec3(2.2f,2.2f,2.2f)); color.rgb = fullbrightAtmosTransport(color.rgb); - color.rgb = fullbrightScaleSoftClip(color.rgb); - frag_color = color; } -- cgit v1.2.3 From 8f5fc2d4c19dfaadc8113d17c219e3316e42d5bc Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 8 May 2013 12:14:08 -0700 Subject: NORSPEC-156 move gamma correction to vert shader --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 4dfd13d406..bb28f02aab 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,7 +42,7 @@ void main() { float shadow = 1.0; - vec4 color = diffuseLookup(vary_texcoord0.xy)*pow(vertex_color.rgb,vec3(2.2f,2.2f,2.2f)); + vec4 color = diffuseLookup(vary_texcoord0.xy)* vertex_color; color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index 2e6982d101..dd56a8c2b0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -58,7 +58,7 @@ void main() calcAtmospherics(pos.xyz); - vertex_color = diffuse_color; - + vertex_color.rgb = pow(diffuse_color, vec3(2.2f,2.2f,2.2f)); + vertex_color.a = diffuse_color.a; } -- cgit v1.2.3 From f1340d91a8117ccbbef87fd2ece27f89c2d4e4e1 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 8 May 2013 12:01:38 -0700 Subject: NORSPEC-156 modify fullbrightF colorspace conversion to eliminate delta with non-deferred fullbright look --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index b91aaf80fb..4dfd13d406 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,12 +42,9 @@ void main() { float shadow = 1.0; - vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; - color.rgb = pow(color.rgb, vec3(2.2)); + vec4 color = diffuseLookup(vary_texcoord0.xy)*pow(vertex_color.rgb,vec3(2.2f,2.2f,2.2f)); color.rgb = fullbrightAtmosTransport(color.rgb); - color.rgb = fullbrightScaleSoftClip(color.rgb); - frag_color = color; } -- cgit v1.2.3 From fd8b34e44b9acce23b2c2405ce9f1ad22b71b5b5 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 8 May 2013 12:14:08 -0700 Subject: NORSPEC-156 move gamma correction to vert shader --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 2 +- indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 4dfd13d406..bb28f02aab 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,7 +42,7 @@ void main() { float shadow = 1.0; - vec4 color = diffuseLookup(vary_texcoord0.xy)*pow(vertex_color.rgb,vec3(2.2f,2.2f,2.2f)); + vec4 color = diffuseLookup(vary_texcoord0.xy)* vertex_color; color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index 2e6982d101..dd56a8c2b0 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -58,7 +58,7 @@ void main() calcAtmospherics(pos.xyz); - vertex_color = diffuse_color; - + vertex_color.rgb = pow(diffuse_color, vec3(2.2f,2.2f,2.2f)); + vertex_color.a = diffuse_color.a; } -- cgit v1.2.3 From 415599b54d2450e915870b1a16065340fad53f4c Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 8 May 2013 12:53:47 -0700 Subject: NORSPEC-156 back to the fix that actually works --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 5 ++++- indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl | 6 ++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index bb28f02aab..cb050c800f 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,9 +42,12 @@ void main() { float shadow = 1.0; - vec4 color = diffuseLookup(vary_texcoord0.xy)* vertex_color; + vec4 color = diffuseLookup(vary_texcoord0.xy) * pow(vertex_color.rgb,vec3(2.2f)); + color.rgb = fullbrightAtmosTransport(color.rgb); + color.rgb = fullbrightScaleSoftClip(color.rgb); + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index dd56a8c2b0..3f09a15375 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -57,8 +57,6 @@ void main() vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; calcAtmospherics(pos.xyz); - - vertex_color.rgb = pow(diffuse_color, vec3(2.2f,2.2f,2.2f)); - vertex_color.a = diffuse_color.a; - + + vertex_color = diffuse_color; } -- cgit v1.2.3 From 5aaab576ba42d35449ec8696d79aeb85d6d8015c Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 8 May 2013 12:53:47 -0700 Subject: NORSPEC-156 back to the fix that actually works --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 5 ++++- indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl | 6 ++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index bb28f02aab..cb050c800f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,9 +42,12 @@ void main() { float shadow = 1.0; - vec4 color = diffuseLookup(vary_texcoord0.xy)* vertex_color; + vec4 color = diffuseLookup(vary_texcoord0.xy) * pow(vertex_color.rgb,vec3(2.2f)); + color.rgb = fullbrightAtmosTransport(color.rgb); + color.rgb = fullbrightScaleSoftClip(color.rgb); + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index dd56a8c2b0..3f09a15375 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -57,8 +57,6 @@ void main() vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; calcAtmospherics(pos.xyz); - - vertex_color.rgb = pow(diffuse_color, vec3(2.2f,2.2f,2.2f)); - vertex_color.a = diffuse_color.a; - + + vertex_color = diffuse_color; } -- cgit v1.2.3 From 1e8263772c7d1097e1b373ac4f4b6f13e62ac60f Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 8 May 2013 13:58:53 -0700 Subject: Fix fullbrightF in the eyes of ancient nV compiler --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index cb050c800f..c5513414dd 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,7 +42,8 @@ void main() { float shadow = 1.0; - vec4 color = diffuseLookup(vary_texcoord0.xy) * pow(vertex_color.rgb,vec3(2.2f)); + vec3 vcolor = pow(vertex_color.rgb, vec3(2.2f,2.2f,2.2f)); + vec4 color = diffuseLookup(vary_texcoord0.xy) * vec4(vcolor.rgb,1.0f); color.rgb = fullbrightAtmosTransport(color.rgb); -- cgit v1.2.3 From ae0f362f220c54e72700b96545b9f4956ee8a113 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 8 May 2013 20:00:38 -0700 Subject: Rollback NORSPEC-156 change which fails to compile due to implicit cast --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index cb050c800f..8d76485886 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,7 +42,8 @@ void main() { float shadow = 1.0; - vec4 color = diffuseLookup(vary_texcoord0.xy) * pow(vertex_color.rgb,vec3(2.2f)); + vec4 color = diffuseLookup(vary_texcoord0.xy) * vertex_color; + color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); color.rgb = fullbrightAtmosTransport(color.rgb); -- cgit v1.2.3 From 0ee0f952c29e0b8bdcfe332823adbdab86190c71 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 8 May 2013 20:00:38 -0700 Subject: Rollback NORSPEC-156 change which fails to compile due to implicit cast --- indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index c5513414dd..ce5584534e 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -42,8 +42,8 @@ void main() { float shadow = 1.0; - vec3 vcolor = pow(vertex_color.rgb, vec3(2.2f,2.2f,2.2f)); - vec4 color = diffuseLookup(vary_texcoord0.xy) * vec4(vcolor.rgb,1.0f); + vec4 color = diffuseLookup(vary_texcoord0.xy) * vertex_color; + color.rgb = pow(color.rgb, vec3(2.2f,2.2f,2.2f)); color.rgb = fullbrightAtmosTransport(color.rgb); -- cgit v1.2.3 From efe8d75fe31ada16d00d0b5545071d2adbab54ad Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 10 May 2013 16:08:48 -0500 Subject: NORSPEC-173 Shrink size of matrix palette for backwards compatibility. --- indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl index 2745d5fd95..43ed41a205 100644 --- a/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl +++ b/indra/newview/app_settings/shaders/class1/avatar/objectSkinV.glsl @@ -26,7 +26,7 @@ ATTRIBUTE vec4 weight4; -uniform mat4 matrixPalette[64]; +uniform mat4 matrixPalette[32]; mat4 getObjectSkinnedTransform() { -- cgit v1.2.3 From dc38ef5d3922829873b95de9f4696f74b48fc472 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 13 May 2013 17:26:51 -0500 Subject: NORSPEC-177 Add glare to transparent surfaces. --- .../shaders/class1/deferred/materialF.glsl | 38 +++++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index a4eaac8483..599477ad9e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -121,7 +121,7 @@ vec3 calcDirectionalLight(vec3 n, vec3 l) } -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare) { //get light vector vec3 lv = lp.xyz-v; @@ -169,7 +169,13 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe if (nh > 0.0) { float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += lit*scol*light_col.rgb*spec.rgb; + vec3 speccol = lit*scol*light_col.rgb*spec.rgb; + col += speccol; + + float cur_glare = max(speccol.r, speccol.g); + cur_glare = max(cur_glare, speccol.b); + glare = max(glare, speccol.r); + glare += max(cur_glare, 0.0); //col += spec.rgb; } } @@ -442,7 +448,7 @@ void main() #endif #if HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + vec4 spec = texture2D(specularMap, vary_texcoord2.xy)*specular_color; #else vec4 spec = specular_color; #endif @@ -472,7 +478,7 @@ void main() vec4 final_specular = spec; #if HAS_SPECULAR_MAP //final_color.rgb *= 1 - spec.a * env_intensity; - final_specular.rgb *= specular_color.rgb; + //final_specular.rgb *= specular_color.rgb; vec4 final_normal = vec4(encode_normal(normalize(tnorm)), spec.a * env_intensity, 0.0); final_specular.a = specular_color.a * norm.a; @@ -577,6 +583,8 @@ void main() col.rgb *= diffuse.rgb; + float glare = 0.0; + if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection @@ -588,6 +596,10 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; bloom = dot(spec_contrib, spec_contrib) / 6; + + glare = max(spec_contrib.r, spec_contrib.g); + glare = max(glare, spec_contrib.b); + col += spec_contrib; } @@ -595,8 +607,15 @@ void main() { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2, + vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2; + + col = mix(col.rgb, refcol, max(envIntensity-diffuse.a*2.0, 0.0)); + + float cur_glare = max(refcol.r, refcol.g); + cur_glare = max(cur_glare, refcol.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; } col = atmosLighting(col); @@ -604,18 +623,19 @@ void main() vec3 npos = normalize(-pos.xyz); - #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); + #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); - LIGHT_LOOP(1) + /*LIGHT_LOOP(1) LIGHT_LOOP(2) LIGHT_LOOP(3) LIGHT_LOOP(4) LIGHT_LOOP(5) LIGHT_LOOP(6) - LIGHT_LOOP(7) + LIGHT_LOOP(7)*/ frag_color.rgb = col.rgb; - frag_color.a = diffcol.a*vertex_color.a; + glare = min(glare, 1.0); + frag_color.a = max(diffcol.a*vertex_color.a, glare); #else frag_data[0] = final_color; -- cgit v1.2.3 From 1d5a85366928d4765f33406e58f66c294ea285cd Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Tue, 14 May 2013 16:12:53 -0700 Subject: NORSPEC-103 added new shaders for using norm/spec TCs in overlay --- .../shaders/class1/interface/highlightNormV.glsl | 42 ++++++++++++++++++++++ .../shaders/class1/interface/highlightSpecV.glsl | 42 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/interface/highlightNormV.glsl create mode 100644 indra/newview/app_settings/shaders/class1/interface/highlightSpecV.glsl (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/interface/highlightNormV.glsl b/indra/newview/app_settings/shaders/class1/interface/highlightNormV.glsl new file mode 100644 index 0000000000..947c2b0065 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/highlightNormV.glsl @@ -0,0 +1,42 @@ +/** + * @file highlightV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; +ATTRIBUTE vec2 texcoord1; +ATTRIBUTE vec2 texcoord2; + +VARYING vec2 vary_texcoord0; + +void main() +{ + //transform vertex + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_texcoord0 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; +} + diff --git a/indra/newview/app_settings/shaders/class1/interface/highlightSpecV.glsl b/indra/newview/app_settings/shaders/class1/interface/highlightSpecV.glsl new file mode 100644 index 0000000000..c5d102b739 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/highlightSpecV.glsl @@ -0,0 +1,42 @@ +/** + * @file highlightV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; +ATTRIBUTE vec2 texcoord0; +ATTRIBUTE vec2 texcoord1; +ATTRIBUTE vec2 texcoord2; + +VARYING vec2 vary_texcoord0; + +void main() +{ + //transform vertex + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_texcoord0 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; +} + -- cgit v1.2.3 From b3df764bd3c461df49f0f2289b66c87a76e71d34 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 15 May 2013 17:35:28 -0500 Subject: Attempt at making deferred rendering work on OpenGL 2.1 --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 12 ++++-------- .../app_settings/shaders/class1/deferred/alphaV.glsl | 13 ++++--------- 2 files changed, 8 insertions(+), 17 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 50b43f6a8d..84e83d4c8b 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -60,14 +60,10 @@ VARYING vec3 vary_ambient; VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; -VARYING vec3 vary_pointlight_col; +VARYING vec4 vary_pointlight_col; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; -#ifdef USE_VERTEX_COLOR -VARYING vec4 vertex_color; -#endif - uniform vec4 light_position[8]; uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; @@ -216,7 +212,7 @@ void main() diff.rgb = pow(diff.rgb, vec3(2.2f, 2.2f, 2.2f)); #ifdef USE_VERTEX_COLOR - float vertex_color_alpha = vertex_color.a; + float vertex_color_alpha = vary_pointlight_col.a; #else float vertex_color_alpha = 1.0; #endif @@ -225,7 +221,7 @@ void main() vec3 l = light_position[0].xyz; vec3 dlight = calcDirectionalLight(normal, l) * 2.6; - dlight = dlight * vary_directional.rgb * vary_pointlight_col; + dlight = dlight * vary_directional.rgb * vary_pointlight_col.rgb; #if HAS_SHADOW vec4 col = vec4(vary_ambient + dlight * shadow, vertex_color_alpha); @@ -250,7 +246,7 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - color.rgb += diff.rgb * vary_pointlight_col * col.rgb; + color.rgb += diff.rgb * vary_pointlight_col.rgb * col.rgb; frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 77d02b36ff..9cc2eb0cf3 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -69,11 +69,8 @@ VARYING vec3 vary_ambient; VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; -VARYING vec3 vary_pointlight_col; +VARYING vec4 vary_pointlight_col; -#ifdef USE_VERTEX_COLOR -VARYING vec4 vertex_color; -#endif VARYING vec2 vary_texcoord0; @@ -186,9 +183,9 @@ void main() - vary_pointlight_col = diff; + vary_pointlight_col.rgb = diff; + vary_pointlight_col.a = vertex_color.a; - col.rgb = vec3(0,0,0); // Add windlight lights @@ -200,9 +197,7 @@ void main() col.rgb = col.rgb*diff.rgb; -#ifdef USE_VERTEX_COLOR - vertex_color = col; -#endif + #ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -- cgit v1.2.3 From 4afa3557971f3a7cf750472112ef1755c7ff98db Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 16 May 2013 14:36:22 -0500 Subject: NORSPEC-185 Fix for regression caused by accidentally checking in debug code. --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 599477ad9e..3c25f49fe0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -625,13 +625,13 @@ void main() #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); - /*LIGHT_LOOP(1) + LIGHT_LOOP(1) LIGHT_LOOP(2) LIGHT_LOOP(3) LIGHT_LOOP(4) LIGHT_LOOP(5) LIGHT_LOOP(6) - LIGHT_LOOP(7)*/ + LIGHT_LOOP(7) frag_color.rgb = col.rgb; glare = min(glare, 1.0); -- cgit v1.2.3 From f18fd226c32747dfb53f4d4f7b00b7d682133d5e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 16 May 2013 17:13:16 -0500 Subject: Fix for compilation error in shadows disabled and don't load transform feedback shaders unless transform feedback is enabled. --- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 9cc2eb0cf3..dc497e063b 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -184,7 +184,7 @@ void main() vary_pointlight_col.rgb = diff; - vary_pointlight_col.a = vertex_color.a; + vary_pointlight_col.a = col.a; col.rgb = vec3(0,0,0); -- cgit v1.2.3 From 559934705fd766430ccdd4b4e41e26a277f63637 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 17 May 2013 12:27:50 -0500 Subject: Backout OpenGL 2.1 compatibility attempt --- .../app_settings/shaders/class1/deferred/alphaF.glsl | 12 ++++++++---- .../app_settings/shaders/class1/deferred/alphaV.glsl | 13 +++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 84e83d4c8b..50b43f6a8d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -60,10 +60,14 @@ VARYING vec3 vary_ambient; VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; -VARYING vec4 vary_pointlight_col; +VARYING vec3 vary_pointlight_col; VARYING vec2 vary_texcoord0; VARYING vec3 vary_norm; +#ifdef USE_VERTEX_COLOR +VARYING vec4 vertex_color; +#endif + uniform vec4 light_position[8]; uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; @@ -212,7 +216,7 @@ void main() diff.rgb = pow(diff.rgb, vec3(2.2f, 2.2f, 2.2f)); #ifdef USE_VERTEX_COLOR - float vertex_color_alpha = vary_pointlight_col.a; + float vertex_color_alpha = vertex_color.a; #else float vertex_color_alpha = 1.0; #endif @@ -221,7 +225,7 @@ void main() vec3 l = light_position[0].xyz; vec3 dlight = calcDirectionalLight(normal, l) * 2.6; - dlight = dlight * vary_directional.rgb * vary_pointlight_col.rgb; + dlight = dlight * vary_directional.rgb * vary_pointlight_col; #if HAS_SHADOW vec4 col = vec4(vary_ambient + dlight * shadow, vertex_color_alpha); @@ -246,7 +250,7 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - color.rgb += diff.rgb * vary_pointlight_col.rgb * col.rgb; + color.rgb += diff.rgb * vary_pointlight_col * col.rgb; frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index dc497e063b..77d02b36ff 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -69,8 +69,11 @@ VARYING vec3 vary_ambient; VARYING vec3 vary_directional; VARYING vec3 vary_fragcoord; VARYING vec3 vary_position; -VARYING vec4 vary_pointlight_col; +VARYING vec3 vary_pointlight_col; +#ifdef USE_VERTEX_COLOR +VARYING vec4 vertex_color; +#endif VARYING vec2 vary_texcoord0; @@ -183,9 +186,9 @@ void main() - vary_pointlight_col.rgb = diff; - vary_pointlight_col.a = col.a; + vary_pointlight_col = diff; + col.rgb = vec3(0,0,0); // Add windlight lights @@ -197,7 +200,9 @@ void main() col.rgb = col.rgb*diff.rgb; - +#ifdef USE_VERTEX_COLOR + vertex_color = col; +#endif #ifdef HAS_SKIN vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -- cgit v1.2.3 From 174eda3ed010280277cf2771e838e902a74d6561 Mon Sep 17 00:00:00 2001 From: callum_linden Date: Fri, 17 May 2013 11:35:12 -0700 Subject: Extra fix for Dave's shader OS X related shader change --- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 9cc2eb0cf3..6ed2ad5192 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -184,7 +184,7 @@ void main() vary_pointlight_col.rgb = diff; - vary_pointlight_col.a = vertex_color.a; + vary_pointlight_col.a = diffuse_color.a; col.rgb = vec3(0,0,0); -- cgit v1.2.3 From 88a42cd453b19e66551a36d635981da5aaa04933 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 17 May 2013 13:54:58 -0500 Subject: NORSPEC-187 Add directionality to ambient lighting. --- indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl | 9 +++++++++ .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 8 ++++++++ .../app_settings/shaders/class1/deferred/softenLightF.glsl | 7 +++++++ 3 files changed, 24 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl index 77d02b36ff..247ee0a34f 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -86,6 +86,8 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +uniform vec3 sun_dir; + vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); @@ -194,6 +196,13 @@ void main() // Add windlight lights col.rgb = atmosAmbient(col.rgb); + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + col.rgb *= ambient; + vary_ambient = col.rgb*diff.rgb; vary_directional.rgb = atmosAffectDirectionalLight(1.0f); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 3c25f49fe0..fc4b8b33f8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -579,6 +579,14 @@ void main() final_da = max(final_da, 0.0f); col.rgb = atmosAmbient(col); + + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + col.rgb *= ambient; + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da * 2.6); col.rgb *= diffuse.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index a1dff9188f..9197df2628 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -301,6 +301,13 @@ void main() calcAtmospherics(pos.xyz, 1.0); col = atmosAmbient(vec3(0)); + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + col.rgb *= ambient; + col += atmosAffectDirectionalLight(max(min(da, 1.0) * 2.6, diffuse.a)); col *= diffuse.rgb; -- cgit v1.2.3 From 933d4c40f42babf74320dca70ac08009b8577fa1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 23 May 2013 12:47:52 -0500 Subject: NORSPEC-198, NORSPEC-176, NORSPEC-106 WIP Fix for various fullbright/shiny descrepencies. --- .../shaders/class1/deferred/fullbrightF.glsl | 2 -- .../shaders/class1/deferred/materialF.glsl | 7 ++++-- .../app_settings/shaders/class1/deferred/skyF.glsl | 2 +- .../shaders/class1/deferred/softenLightF.glsl | 27 +++++++++++++++------- 4 files changed, 25 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 975180606a..efb4d48845 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -40,8 +40,6 @@ vec3 fullbrightScaleSoftClip(vec3 light); void main() { - float shadow = 1.0; - vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index fc4b8b33f8..539efa3499 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -28,6 +28,9 @@ #define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 +#if DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE +uniform float emissive_brightness; +#endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -37,7 +40,6 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif - #if HAS_SUN_SHADOW uniform sampler2DShadow shadowMap0; @@ -472,7 +474,7 @@ void main() vec4 final_color = diffcol; #if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = 0; + final_color.a = emissive_brightness; #endif vec4 final_specular = spec; @@ -646,6 +648,7 @@ void main() frag_color.a = max(diffcol.a*vertex_color.a, glare); #else + frag_data[0] = final_color; #ifdef UGLY_MAC_HACK diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 49ad064364..22f4729e2e 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -61,6 +61,6 @@ void main() /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(scaleSoftClip(color.rgb), 1.0); frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.5,0.5,0.0,0); + frag_data[2] = vec4(0.5,0.5,0.0,1.0); //1.0 in norm.w masks off fog } diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 9197df2628..b688c1a70c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -231,9 +231,9 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + tmpAmbient))); //brightness of surface both sunlight and ambient - setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * 2.2); - setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * 2.2); - setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * 2.2); + setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * global_gamma); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * global_gamma); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * global_gamma); } vec3 atmosLighting(vec3 light) @@ -308,7 +308,7 @@ void main() col.rgb *= ambient; - col += atmosAffectDirectionalLight(max(min(da, 1.0) * 2.6, diffuse.a)); + col += atmosAffectDirectionalLight(max(min(da, 1.0) * 2.6, 0.0)); col *= diffuse.rgb; @@ -328,17 +328,28 @@ void main() col += spec_contrib; } + col = mix(col.rgb, diffuse.rgb, diffuse.a); + if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2, + + float exponent = mix(2.2, 1.0, diffuse.a); + + col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent)) * exponent, envIntensity); + + exponent = mix(1.0, 2.2, diffuse.a); + col.rgb = pow(col.rgb, vec3(exponent))/exponent; } - col = atmosLighting(col); - col = scaleSoftClip(col); + if (norm.w < 0.5) + { + col = atmosLighting(col); + col = scaleSoftClip(col); + } - col = mix(col.rgb, diffuse.rgb, diffuse.a); + //col.g = envIntensity; } frag_color.rgb = col; -- cgit v1.2.3 From 6a9564eeadf54937a63d60e265cf304e6f81dc01 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 23 May 2013 12:48:30 -0500 Subject: NORSPEC-198, NORSPEC-176, NORSPEC-106 WIP Fix for various fullbright/shiny descrepencies. --- .../shaders/class1/deferred/fullbrightShinyF.glsl | 68 ++++++++++++++++++++++ .../shaders/class1/deferred/fullbrightShinyV.glsl | 67 +++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl new file mode 100644 index 0000000000..b2bfd69f6e --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -0,0 +1,68 @@ +/** + * @file fullbrightShinyF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + + + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +#ifndef diffuseLookup +uniform sampler2D diffuseMap; +#endif + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; +VARYING vec3 vary_texcoord1; + +uniform samplerCube environmentMap; + +vec3 fullbrightShinyAtmosTransport(vec3 light); +vec3 fullbrightScaleSoftClip(vec3 light); + +void main() +{ +#ifdef diffuseLookup + vec4 color = diffuseLookup(vary_texcoord0.xy); +#else + vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); +#endif + color.rgb *= vertex_color.rgb; + + vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; + color.rgb = mix(color.rgb, envColor.rgb, vertex_color.a); + + color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); + + color.rgb = fullbrightShinyAtmosTransport(color.rgb); + color.rgb = fullbrightScaleSoftClip(color.rgb); + + color.a = 1.0; + + frag_color = color; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl new file mode 100644 index 0000000000..34bd8d445a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl @@ -0,0 +1,67 @@ +/** + * @file fullbrightShinyV.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform mat3 normal_matrix; +uniform mat4 texture_matrix0; +uniform mat4 texture_matrix1; +uniform mat4 modelview_matrix; +uniform mat4 modelview_projection_matrix; + + +void calcAtmospherics(vec3 inPositionEye); + +uniform vec4 origin; + + + +ATTRIBUTE vec3 position; +void passTextureIndex(); +ATTRIBUTE vec3 normal; +ATTRIBUTE vec4 diffuse_color; +ATTRIBUTE vec2 texcoord0; + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; +VARYING vec3 vary_texcoord1; + + +void main() +{ + //transform vertex + vec4 vert = vec4(position.xyz,1.0); + passTextureIndex(); + vec4 pos = (modelview_matrix * vert); + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + + vec3 norm = normalize(normal_matrix * normal); + vec3 ref = reflect(pos.xyz, -norm); + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vary_texcoord1 = (texture_matrix1*vec4(ref,1.0)).xyz; + + calcAtmospherics(pos.xyz); + + vertex_color = diffuse_color; +} -- cgit v1.2.3 From 743d1a777e5c2827d50051c3f5e0942a870a6ff9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 29 May 2013 18:48:09 -0500 Subject: NORSPEC-198, NORSPEC-176, NORSPEC-106, NORSPEC-202 et al -- Material matrix testing based overhaul WIP Reviewed by Graham --- .../shaders/class1/deferred/fullbrightF.glsl | 9 +++++ .../shaders/class1/deferred/materialF.glsl | 37 +++++++++++++++----- .../shaders/class1/deferred/softenLightF.glsl | 40 ++++++++++++++++------ .../shaders/class1/lighting/lightFullbrightF.glsl | 4 +++ 4 files changed, 72 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index efb4d48845..5c164f7759 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -31,6 +31,10 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif +#if !HAS_DIFFUSE_LOOKUP +uniform sampler2D diffuseMap; +#endif + VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; @@ -40,7 +44,12 @@ vec3 fullbrightScaleSoftClip(vec3 light); void main() { +#if HAS_DIFFUSE_LOOKUP vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; +#else + vec4 color = texture2D(diffuseMap, vary_texcoord0.xy)*vertex_color; +#endif + color.rgb = pow(color.rgb,vec3(2.2f,2.2f,2.2f)); color.rgb = fullbrightAtmosTransport(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 539efa3499..17aa0e32a7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -28,9 +28,7 @@ #define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -#if DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE uniform float emissive_brightness; -#endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -388,6 +386,18 @@ vec3 scaleSoftClip(vec3 light) return light; } +vec3 fullbrightAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + +vec3 fullbrightScaleSoftClip(vec3 light) +{ + //soft clip effect: + return light; +} + #else #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; @@ -446,6 +456,7 @@ void main() #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec3 old_diffcol = diffcol.rgb; diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); #endif @@ -475,6 +486,8 @@ void main() #if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = emissive_brightness; +#else + final_color.a = max(final_color.a, emissive_brightness); #endif vec4 final_specular = spec; @@ -613,24 +626,33 @@ void main() col += spec_contrib; } + col = mix(col.rgb, old_diffcol.rgb, diffuse.a); + if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2; + float exponent = mix(2.2, 1.0, diffuse.a); + + vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; col = mix(col.rgb, refcol, - max(envIntensity-diffuse.a*2.0, 0.0)); - + envIntensity); + float cur_glare = max(refcol.r, refcol.g); cur_glare = max(cur_glare, refcol.b); cur_glare *= envIntensity*4.0; glare += cur_glare; } + + float exponent = mix(1.0, 2.2, diffuse.a); + col = pow(col, vec3(exponent)); + - col = atmosLighting(col); - col = scaleSoftClip(col); + col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + vec3 npos = normalize(-pos.xyz); #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); @@ -646,7 +668,6 @@ void main() frag_color.rgb = col.rgb; glare = min(glare, 1.0); frag_color.a = max(diffcol.a*vertex_color.a, glare); - #else frag_data[0] = final_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index b688c1a70c..45d672c290 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -248,6 +248,15 @@ vec3 atmosTransport(vec3 light) { light += getAdditiveColor() * 2.0; return light; } + +vec3 fullbrightAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + + + vec3 atmosGetDiffuseSunlightColor() { return getSunlitColor(); @@ -282,6 +291,13 @@ vec3 scaleSoftClip(vec3 light) return light; } + +vec3 fullbrightScaleSoftClip(vec3 light) +{ + //soft clip effect: + return light; +} + void main() { vec2 tc = vary_fragcoord.xy; @@ -328,32 +344,36 @@ void main() col += spec_contrib; } - col = mix(col.rgb, diffuse.rgb, diffuse.a); - + + col = mix(col.rgb, pow(diffuse.rgb, vec3(1.0/2.2)), diffuse.a); + + if (envIntensity > 0.0) { //add environmentmap vec3 env_vec = env_mat * refnormpersp; float exponent = mix(2.2, 1.0, diffuse.a); + vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; - col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent)) * exponent, - envIntensity); + col = mix(col.rgb, refcol, + envIntensity); - exponent = mix(1.0, 2.2, diffuse.a); - col.rgb = pow(col.rgb, vec3(exponent))/exponent; } + float exponent = mix(1.0, 2.2, diffuse.a); + col = pow(col, vec3(exponent)); + if (norm.w < 0.5) { - col = atmosLighting(col); - col = scaleSoftClip(col); + col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } + //col = vec3(1,0,1); //col.g = envIntensity; } frag_color.rgb = col; - //frag_color.a = bloom; - frag_color.a = 0.0; + frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl index 2ff7f795b0..361f316065 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl @@ -32,6 +32,8 @@ out vec4 frag_color; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +uniform float texture_gamma; + vec3 fullbrightAtmosTransport(vec3 light); vec3 fullbrightScaleSoftClip(vec3 light); @@ -39,6 +41,8 @@ void fullbright_lighting() { vec4 color = diffuseLookup(vary_texcoord0.xy) * vertex_color; + color.rgb = pow(color.rgb, vec3(texture_gamma)); + color.rgb = fullbrightAtmosTransport(color.rgb); color.rgb = fullbrightScaleSoftClip(color.rgb); -- cgit v1.2.3 From 38f62f5ceed5ec7a9c5bcfd8afe443475b343b08 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 30 May 2013 17:44:05 -0500 Subject: Fix for some objects not rendering underwater with advanced lighting enabled --- .../shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl | 4 +++- .../app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl | 4 +++- .../shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl index 9c82056fd7..6dd3bb937f 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightWaterAlphaMaskF.glsl @@ -41,7 +41,9 @@ VARYING vec2 vary_texcoord0; void fullbright_lighting_water() { - vec4 color = diffuseLookup(vary_texcoord0.xy) * vertex_color; + vec4 color = diffuseLookup(vary_texcoord0.xy); + + color.rgb *= vertex_color.rgb; if (color.a < minimum_alpha) { diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl index b68240ba0d..3426fea52f 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskF.glsl @@ -39,7 +39,9 @@ VARYING vec2 vary_texcoord0; void default_lighting_water() { - vec4 color = diffuseLookup(vary_texcoord0.xy) * vertex_color; + vec4 color = diffuseLookup(vary_texcoord0.xy); + + color.rgb *= vertex_color.rgb; if (color.a < minimum_alpha) { diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl index da3b20012d..d9faa9b314 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightWaterAlphaMaskNonIndexedF.glsl @@ -41,7 +41,9 @@ VARYING vec2 vary_texcoord0; void default_lighting_water() { - vec4 color = texture2D(diffuseMap,vary_texcoord0.xy) * vertex_color; + vec4 color = texture2D(diffuseMap,vary_texcoord0.xy); + + color.rgb *= vertex_color.rgb; if (color.a < minimum_alpha) { -- cgit v1.2.3 From 2cfd002a3be43698f1524a099c9298a63e635092 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 30 May 2013 19:07:44 -0500 Subject: NORSPEC-216 Fix for some HUD objects not rendering with advanced lighting/materials enabled. --- .../app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl | 4 +++- .../shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl | 4 +++- .../shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl | 5 ++++- .../shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl | 5 ++++- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl index cf29939cb2..eaaa7b208d 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskF.glsl @@ -39,13 +39,15 @@ VARYING vec2 vary_texcoord0; void default_lighting() { - vec4 color = diffuseLookup(vary_texcoord0.xy) * vertex_color; + vec4 color = diffuseLookup(vary_texcoord0.xy); if (color.a < minimum_alpha) { discard; } + color.rgb *= vertex_color.rgb; + color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl index 4070d41f47..b9ddbc8e1c 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightAlphaMaskNonIndexedF.glsl @@ -41,13 +41,15 @@ VARYING vec2 vary_texcoord0; void default_lighting() { - vec4 color = texture2D(diffuseMap,vary_texcoord0.xy) * vertex_color; + vec4 color = texture2D(diffuseMap,vary_texcoord0.xy); if (color.a < minimum_alpha) { discard; } + color.rgb *= vertex_color.rgb; + color.rgb = atmosLighting(color.rgb); color.rgb = scaleSoftClip(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl index e130ef5d91..5740987ab1 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightAlphaMaskF.glsl @@ -40,12 +40,15 @@ VARYING vec2 vary_texcoord0; void fullbright_lighting() { - vec4 color = diffuseLookup(vary_texcoord0.xy) * vertex_color; + vec4 color = diffuseLookup(vary_texcoord0.xy); if (color.a < minimum_alpha) { discard; } + + color.rgb *= vertex_color.rgb; + color.rgb = pow(color.rgb, vec3(texture_gamma)); color.rgb = fullbrightAtmosTransport(color.rgb); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl index 56ad658696..d64584c015 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl @@ -42,12 +42,15 @@ VARYING vec2 vary_texcoord0; void fullbright_lighting() { - vec4 color = texture2D(diffuseMap,vary_texcoord0.xy) * vertex_color; + vec4 color = texture2D(diffuseMap,vary_texcoord0.xy); if (color.a < minimum_alpha) { discard; } + + color.rgb *= vertex_color.rgb; + color.rgb = pow(color.rgb, vec3(texture_gamma)); color.rgb = fullbrightAtmosTransport(color.rgb); -- cgit v1.2.3 From 08f9ef92399ab4abdc8652c48c85c1110b907e37 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 31 May 2013 12:53:58 -0500 Subject: NORSPEC-223 Fix for wrong textures displaying on fullbright+shiny faces with advanced lighting enabled. --- .../app_settings/shaders/class1/deferred/fullbrightShinyF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index b2bfd69f6e..f3d04a22f2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -46,11 +46,13 @@ vec3 fullbrightScaleSoftClip(vec3 light); void main() { -#ifdef diffuseLookup +#if HAS_DIFFUSE_LOOKUP vec4 color = diffuseLookup(vary_texcoord0.xy); #else vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); #endif + + color.rgb *= vertex_color.rgb; vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; -- cgit v1.2.3 From c3f14b915c38a4978745f12f1f816572cce4b5a0 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 3 Jun 2013 12:50:48 -0500 Subject: NORSPEC-229 Fix for bad binormals on mirrored surfaces (use tangent calculator instead of binormal calculator, convert binormal centric code to tangent centric) --- .../app_settings/shaders/class1/deferred/bumpSkinnedV.glsl | 6 +++--- indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl | 6 +++--- .../app_settings/shaders/class1/deferred/materialF.glsl | 2 +- .../app_settings/shaders/class1/deferred/materialV.glsl | 11 ++++++----- .../app_settings/shaders/class1/transform/binormalV.glsl | 6 +++--- 5 files changed, 16 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl index 8ba75010a2..10144f3e16 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpSkinnedV.glsl @@ -30,7 +30,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec3 binormal; +ATTRIBUTE vec4 tangent; VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; @@ -52,8 +52,8 @@ void main() vec3 n = normalize((mat * vec4(normal.xyz+position.xyz, 1.0)).xyz-pos.xyz); - vec3 b = normalize((mat * vec4(binormal.xyz+position.xyz, 1.0)).xyz-pos.xyz); - vec3 t = cross(b, n); + vec3 t = normalize((mat * vec4(tangent.xyz+position.xyz, 1.0)).xyz-pos.xyz); + vec3 b = cross(n, t) * tangent.w; vary_mat0 = vec3(t.x, b.x, n.x); vary_mat1 = vec3(t.y, b.y, n.y); diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl index c8d38bb8f7..9f9749394e 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl @@ -31,7 +31,7 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec4 diffuse_color; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec3 binormal; +ATTRIBUTE vec4 tangent; VARYING vec3 vary_mat0; VARYING vec3 vary_mat1; @@ -46,8 +46,8 @@ void main() vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; vec3 n = normalize(normal_matrix * normal); - vec3 b = normalize(normal_matrix * binormal); - vec3 t = cross(b, n); + vec3 t = normalize(normal_matrix * tangent.xyz); + vec3 b = cross(n, t) * tangent.w; vary_mat0 = vec3(t.x, b.x, n.x); vary_mat1 = vec3(t.y, b.y, n.y); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 17aa0e32a7..df8e7a6c0b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -495,7 +495,7 @@ void main() //final_color.rgb *= 1 - spec.a * env_intensity; //final_specular.rgb *= specular_color.rgb; - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), spec.a * env_intensity, 0.0); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); final_specular.a = specular_color.a * norm.a; #else vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 0638dcfa55..b25032866b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -56,7 +56,7 @@ ATTRIBUTE vec2 texcoord0; #if HAS_NORMAL_MAP -ATTRIBUTE vec3 binormal; +ATTRIBUTE vec4 tangent; ATTRIBUTE vec2 texcoord1; VARYING vec3 vary_mat0; @@ -110,8 +110,8 @@ void main() #if HAS_SKIN vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); #if HAS_NORMAL_MAP - vec3 b = normalize((mat*vec4(binormal.xyz+position.xyz,1.0)).xyz-pos.xyz); - vec3 t = cross(b, n); + vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz); + vec3 b = cross(n, t)*tangent.w; vary_mat0 = vec3(t.x, b.x, n.x); vary_mat1 = vec3(t.y, b.y, n.y); @@ -122,8 +122,9 @@ vary_normal = n; #else //HAS_SKIN vec3 n = normalize(normal_matrix * normal); #if HAS_NORMAL_MAP - vec3 b = normalize(normal_matrix * binormal); - vec3 t = cross(b, n); + vec3 t = normalize(normal_matrix * tangent.xyz); + vec3 b = cross(n,t)*tangent.w; + //vec3 t = cross(b,n) * binormal.w; vary_mat0 = vec3(t.x, b.x, n.x); vary_mat1 = vec3(t.y, b.y, n.y); diff --git a/indra/newview/app_settings/shaders/class1/transform/binormalV.glsl b/indra/newview/app_settings/shaders/class1/transform/binormalV.glsl index 44f1aa34a0..449d8d8b4e 100755 --- a/indra/newview/app_settings/shaders/class1/transform/binormalV.glsl +++ b/indra/newview/app_settings/shaders/class1/transform/binormalV.glsl @@ -25,12 +25,12 @@ uniform mat3 normal_matrix; -ATTRIBUTE vec3 binormal; +ATTRIBUTE vec4 tangent; -VARYING vec4 binormal_out; +VARYING vec4 tangent_out; void main() { - binormal_out = vec4(normal_matrix * binormal, 0.0); + tangent_out = vec4(normal_matrix * tangent.xyz), tangent.w); } -- 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. --- indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl | 2 ++ .../newview/app_settings/shaders/class1/deferred/alphaNonIndexedF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl | 2 ++ .../newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 3 +++ .../newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl | 2 ++ .../shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl | 2 ++ 7 files changed, 15 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 50b43f6a8d..77a53a71aa 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -252,6 +252,8 @@ void main() color.rgb += diff.rgb * vary_pointlight_col * col.rgb; + color.rgb = pow(color.rgb, vec3(1.0/2.2)); + frag_color = color; } 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; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 5c164f7759..dc1dead656 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -56,6 +56,8 @@ void main() color.rgb = fullbrightScaleSoftClip(color.rgb); + color.rgb = pow(color.rgb, vec3(1.0/2.2)); + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index f3d04a22f2..b0db9876d3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -65,6 +65,8 @@ void main() color.a = 1.0; + color.rgb = pow(color.rgb, vec3(1.0/2.2)); + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index df8e7a6c0b..bb8d26c9dc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -665,6 +665,9 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) + + col.rgb = pow(col.rgb, vec3(1.0/2.2)); + frag_color.rgb = col.rgb; glare = min(glare, 1.0); frag_color.a = max(diffcol.a*vertex_color.a, glare); diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl index 361f316065..c8771a3f1e 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightF.glsl @@ -47,6 +47,8 @@ void fullbright_lighting() color.rgb = fullbrightScaleSoftClip(color.rgb); + color.rgb = pow(color.rgb, vec3(1.0/texture_gamma)); + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl index d64584c015..f72f20b03d 100755 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFullbrightNonIndexedAlphaMaskF.glsl @@ -56,6 +56,8 @@ void fullbright_lighting() color.rgb = fullbrightScaleSoftClip(color.rgb); + color.rgb = pow(color.rgb, vec3(1.0/texture_gamma)); + frag_color = color; } -- cgit v1.2.3 From 2996f34e861ab2d671df5625f26d88920e679e98 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 5 Jun 2013 10:04:51 -0700 Subject: NORSPEC-238 spec map env mask term in alpha chan ignored --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index bb8d26c9dc..660a962108 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -492,10 +492,7 @@ void main() vec4 final_specular = spec; #if HAS_SPECULAR_MAP - //final_color.rgb *= 1 - spec.a * env_intensity; - //final_specular.rgb *= specular_color.rgb; - - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), spec.a, 0.0); final_specular.a = specular_color.a * norm.a; #else vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); -- cgit v1.2.3 From 8d4864750e151a2807c78c644eb5af832a869565 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Wed, 5 Jun 2013 10:08:10 -0700 Subject: NORSPEC-238 NORSPEC-225 fix issues with env mask term being ignored and or damped by glossiness --- indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 660a962108..9b2d308824 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -492,7 +492,7 @@ void main() vec4 final_specular = spec; #if HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), spec.a, 0.0); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), min(spec.a, env_intensity), 0.0); final_specular.a = specular_color.a * norm.a; #else vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); -- cgit v1.2.3 From e454c3d48cbefd37de0564a5ba85e0d127850456 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 5 Jun 2013 12:31:55 -0500 Subject: NORSPEC-238, NORSPEC-225 Fix for specular map alpha channel being improperly used and glossiness bludgeoning environment intensity. Reviewed/written by Graham. --- .../newview/app_settings/shaders/class1/deferred/materialF.glsl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index bb8d26c9dc..9c79f3a51f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -419,7 +419,7 @@ VARYING vec2 vary_texcoord2; #endif uniform float env_intensity; -uniform vec4 specular_color; +uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) uniform float minimum_alpha; @@ -461,9 +461,10 @@ void main() #endif #if HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy)*specular_color; + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + spec.rgb *= specular_color.rgb; #else - vec4 spec = specular_color; + vec4 spec = vec4(specular_color.rgb, 1.0); #endif #if HAS_NORMAL_MAP @@ -495,7 +496,7 @@ void main() //final_color.rgb *= 1 - spec.a * env_intensity; //final_specular.rgb *= specular_color.rgb; - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); final_specular.a = specular_color.a * norm.a; #else vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); -- cgit v1.2.3 From c120feb18d2b98abf6071846d2806da16b710632 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Sun, 9 Jun 2013 06:12:11 -0700 Subject: NORSPEC-246 WIP fix handling of encoded normals with single FP only cards --- .../shaders/class1/deferred/blurLightF.glsl | 46 +- .../shaders/class1/deferred/materialF.glsl | 1390 ++++++++++---------- .../shaders/class1/deferred/multiPointLightF.glsl | 46 +- .../shaders/class1/deferred/multiSpotLightF.glsl | 46 +- .../shaders/class1/deferred/pointLightF.glsl | 46 +- .../class1/deferred/postDeferredGammaCorrect.glsl | 92 +- .../shaders/class1/deferred/softenLightF.glsl | 772 +++++------ .../shaders/class1/deferred/spotLightF.glsl | 46 +- .../shaders/class1/deferred/sunLightSSAOF.glsl | 46 +- 9 files changed, 1360 insertions(+), 1170 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index c030c23515..e8279241d1 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -64,16 +64,42 @@ vec4 getPosition(vec2 pos_screen) return pos; } -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ + float f = sqrt(2 * n.z + 2); + return (n.xy / vec2(f)) + vec2(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); +} +#else +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8d89485e22..70cc884209 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -1,685 +1,705 @@ -/** - * @file materialF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#define DIFFUSE_ALPHA_MODE_IGNORE 0 -#define DIFFUSE_ALPHA_MODE_BLEND 1 -#define DIFFUSE_ALPHA_MODE_MASK 2 -#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 - -uniform float emissive_brightness; - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -#if HAS_SUN_SHADOW - -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform vec2 shadow_res; -uniform float shadow_bias; - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.2; -} - -#endif - -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec4 glow; -uniform float scene_light_strength; -uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; - -uniform vec3 sun_dir; -VARYING vec2 vary_fragcoord; - -VARYING vec3 vary_position; - -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - -uniform mat4 inv_proj; -uniform vec2 screen_res; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -vec3 calcDirectionalLight(vec3 n, vec3 l) -{ - float a = max(dot(n,l),0.0); - return vec3(a,a,a); -} - - -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare) -{ - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = dot(lv,lv); - - float da = 1.0; - - vec3 col = vec3(0,0,0); - - if (d > 0.0 && la > 0.0 && fa > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist2 = d/la; - float dist_atten = 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(dot(n, lv), 0.0); - - float lit = max(da * dist_atten, 0.0); - - col = light_col*lit*diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = lit*scol*light_col.rgb*spec.rgb; - col += speccol; - - float cur_glare = max(speccol.r, speccol.g); - cur_glare = max(cur_glare, speccol.b); - glare = max(glare, speccol.r); - glare += max(cur_glare, 0.0); - //col += spec.rgb; - } - } - } - - return max(col, vec3(0.0,0.0,0.0)); - -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(pow(vec3(sunlight * .5), vec3(2.2)) * 2.2); - setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(2.2)) * 2.2); - setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(2.2)) * 2.2); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); - vec3 ones = vec3(1.0f, 1.0f, 1.0f); - - light = ones - clamp(light, zeroes, ones); - light = ones - pow(light, gamma.xxx); - - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} - -#else -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif -#endif - -uniform sampler2D diffuseMap; - -#if HAS_NORMAL_MAP -uniform sampler2D bumpMap; -#endif - -#if HAS_SPECULAR_MAP -uniform sampler2D specularMap; - -VARYING vec2 vary_texcoord2; -#endif - -uniform float env_intensity; -uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -uniform float minimum_alpha; -#endif - -#if HAS_NORMAL_MAP -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; -VARYING vec2 vary_texcoord1; -#else -VARYING vec3 vary_normal; -#endif - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -void main() -{ - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); - diffcol.rgb *= vertex_color.rgb; - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffcol.a < minimum_alpha) - { - discard; - } -#endif - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 old_diffcol = diffcol.rgb; - diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); -#endif - -#if HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); - spec.rgb *= specular_color.rgb; -#else - vec4 spec = vec4(specular_color.rgb, 1.0); -#endif - -#if HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); - - norm.xyz = norm.xyz * 2 - 1; - - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); -#else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; -#endif - - norm.xyz = tnorm; - norm.xyz = normalize(norm.xyz); - - vec4 final_color = diffcol; - -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = emissive_brightness; -#else - final_color.a = max(final_color.a, emissive_brightness); -#endif - - vec4 final_specular = spec; -#if HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); - final_specular.a = specular_color.a * norm.a; -#else - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); - final_specular.a = specular_color.a; -#endif - - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - //forward rendering, output just lit RGBA - vec3 pos = vary_position; - -#if HAS_SUN_SHADOW - float shadow = 0.0; - - vec4 spos = vec4(pos,1.0); - - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadow(shadowMap0, lpos)*w; - weight += w; - } - - - shadow /= weight; - } - else - { - shadow = 1.0; - } -#else - float shadow = 1.0; -#endif - - spec = final_specular; - vec4 diffuse = final_color; - float envIntensity = final_normal.z; - - vec3 col = vec3(0.0f,0.0f,0.0f); - - float bloom = 0.0; - calcAtmospherics(pos.xyz, 1.0); - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - float da =dot(norm.xyz, sun_dir.xyz); - float final_da = da; - final_da = min(final_da, shadow); - final_da = max(final_da, diffuse.a); - final_da = max(final_da, 0.0f); - - col.rgb = atmosAmbient(col); - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= ambient; - - col.rgb = col.rgb + atmosAffectDirectionalLight(final_da * 2.6); - col.rgb *= diffuse.rgb; - - - float glare = 0.0; - - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // - - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - - glare = max(spec_contrib.r, spec_contrib.g); - glare = max(glare, spec_contrib.b); - - col += spec_contrib; - } - - col = mix(col.rgb, old_diffcol.rgb, diffuse.a); - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - float exponent = mix(2.2, 1.0, diffuse.a); - - vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; - - col = mix(col.rgb, refcol, - envIntensity); - - float cur_glare = max(refcol.r, refcol.g); - cur_glare = max(cur_glare, refcol.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } - - float exponent = mix(1.0, 2.2, diffuse.a); - col = pow(col, vec3(exponent)); - - - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - - - vec3 npos = normalize(-pos.xyz); - - #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); - - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) - - - col.rgb = pow(col.rgb, vec3(1.0/2.2)); - - frag_color.rgb = col.rgb; - glare = min(glare, 1.0); - frag_color.a = max(diffcol.a*vertex_color.a, glare); -#else - - frag_data[0] = final_color; - -#ifdef UGLY_MAC_HACK - // magic spec exp clamp fixes rendering artifacts on older mac GF drivers - // - final_specular = min(final_specular, vec4(1.0f, 1.0f, 1.0f, 0.125f)); -#endif - - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -#endif -} +/** + * @file materialF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +uniform float emissive_brightness; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +#if HAS_SUN_SHADOW + +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; + +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform vec2 shadow_res; +uniform float shadow_bias; + +float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias; + + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + + return shadow*0.2; +} + +#endif + +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +//uniform vec4 camPosWorld; +uniform vec4 gamma; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; +uniform float scene_light_strength; +uniform mat3 env_mat; +uniform mat3 ssao_effect_mat; + +uniform vec3 sun_dir; +VARYING vec2 vary_fragcoord; + +VARYING vec3 vary_position; + +vec3 vary_PositionEye; + +vec3 vary_SunlitColor; +vec3 vary_AmblitColor; +vec3 vary_AdditiveColor; +vec3 vary_AtmosAttenuation; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec3 light_attenuation[8]; +uniform vec3 light_diffuse[8]; + +vec3 calcDirectionalLight(vec3 n, vec3 l) +{ + float a = max(dot(n,l),0.0); + return vec3(a,a,a); +} + + +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare) +{ + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float d = dot(lv,lv); + + float da = 1.0; + + vec3 col = vec3(0,0,0); + + if (d > 0.0 && la > 0.0 && fa > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist2 = d/la; + float dist_atten = 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(dot(n, lv), 0.0); + + float lit = max(da * dist_atten, 0.0); + + col = light_col*lit*diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = lit*scol*light_col.rgb*spec.rgb; + col += speccol; + + float cur_glare = max(speccol.r, speccol.g); + cur_glare = max(cur_glare, speccol.b); + glare = max(glare, speccol.r); + glare += max(cur_glare, 0.0); + //col += spec.rgb; + } + } + } + + return max(col, vec3(0.0,0.0,0.0)); + +} + +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec3 getPositionEye() +{ + return vary_PositionEye; +} +vec3 getSunlitColor() +{ + return vary_SunlitColor; +} +vec3 getAmblitColor() +{ + return vary_AmblitColor; +} +vec3 getAdditiveColor() +{ + return vary_AdditiveColor; +} +vec3 getAtmosAttenuation() +{ + return vary_AtmosAttenuation; +} + +void setPositionEye(vec3 v) +{ + vary_PositionEye = v; +} + +void setSunlitColor(vec3 v) +{ + vary_SunlitColor = v; +} + +void setAmblitColor(vec3 v) +{ + vary_AmblitColor = v; +} + +void setAdditiveColor(vec3 v) +{ + vary_AdditiveColor = v; +} + +void setAtmosAttenuation(vec3 v) +{ + vary_AtmosAttenuation = v; +} + +void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + + vec3 P = inPositionEye; + setPositionEye(P); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(pow(vec3(sunlight * .5), vec3(2.2)) * 2.2); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(2.2)) * 2.2); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(2.2)) * 2.2); +} + +vec3 atmosLighting(vec3 light) +{ + light *= getAtmosAttenuation().r; + light += getAdditiveColor(); + return (2.0 * light); +} + +vec3 atmosTransport(vec3 light) { + light *= getAtmosAttenuation().r; + light += getAdditiveColor() * 2.0; + return light; +} +vec3 atmosGetDiffuseSunlightColor() +{ + return getSunlitColor(); +} + +vec3 scaleDownLight(vec3 light) +{ + return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); +} + +vec3 scaleUpLight(vec3 light) +{ + return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); +} + +vec3 atmosAmbient(vec3 light) +{ + return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ + return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); +} + +vec3 scaleSoftClip(vec3 light) +{ + //soft clip effect: + vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); + vec3 ones = vec3(1.0f, 1.0f, 1.0f); + + light = ones - clamp(light, zeroes, ones); + light = ones - pow(light, gamma.xxx); + + return light; +} + +vec3 fullbrightAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + +vec3 fullbrightScaleSoftClip(vec3 light) +{ + //soft clip effect: + return light; +} + +#else +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif +#endif + +uniform sampler2D diffuseMap; + +#if HAS_NORMAL_MAP +uniform sampler2D bumpMap; +#endif + +#if HAS_SPECULAR_MAP +uniform sampler2D specularMap; + +VARYING vec2 vary_texcoord2; +#endif + +uniform float env_intensity; +uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) +uniform float minimum_alpha; +#endif + +#if HAS_NORMAL_MAP +VARYING vec3 vary_mat0; +VARYING vec3 vary_mat1; +VARYING vec3 vary_mat2; +VARYING vec2 vary_texcoord1; +#else +VARYING vec3 vary_normal; +#endif + +VARYING vec4 vertex_color; +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); +} + +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); +} +#else +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif + +void main() +{ + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + diffcol.rgb *= vertex_color.rgb; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) + if (diffcol.a < minimum_alpha) + { + discard; + } +#endif + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec3 old_diffcol = diffcol.rgb; + diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); +#endif + +#if HAS_SPECULAR_MAP + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + spec.rgb *= specular_color.rgb; +#else + vec4 spec = vec4(specular_color.rgb, 1.0); +#endif + +#if HAS_NORMAL_MAP + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + + norm.xyz = norm.xyz * 2 - 1; + + vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); +#else + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm = vary_normal; +#endif + + norm.xyz = tnorm; + norm.xyz = normalize(norm.xyz); + + vec4 final_color = diffcol; + +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = emissive_brightness; +#else + final_color.a = max(final_color.a, emissive_brightness); +#endif + + vec4 final_specular = spec; +#if HAS_SPECULAR_MAP + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); + final_specular.a = specular_color.a * norm.a; +#else + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + final_specular.a = specular_color.a; +#endif + + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + //forward rendering, output just lit RGBA + vec3 pos = vary_position; + +#if HAS_SUN_SHADOW + float shadow = 0.0; + + vec4 spos = vec4(pos,1.0); + + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap2, lpos)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadow(shadowMap1, lpos)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos)*w; + weight += w; + } + + + shadow /= weight; + } + else + { + shadow = 1.0; + } +#else + float shadow = 1.0; +#endif + + spec = final_specular; + vec4 diffuse = final_color; + float envIntensity = final_normal.z; + + vec3 col = vec3(0.0f,0.0f,0.0f); + + float bloom = 0.0; + calcAtmospherics(pos.xyz, 1.0); + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + + float da =dot(norm.xyz, sun_dir.xyz); + float final_da = da; + final_da = min(final_da, shadow); + final_da = max(final_da, diffuse.a); + final_da = max(final_da, 0.0f); + + col.rgb = atmosAmbient(col); + + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + col.rgb *= ambient; + + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da * 2.6); + col.rgb *= diffuse.rgb; + + + float glare = 0.0; + + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + + glare = max(spec_contrib.r, spec_contrib.g); + glare = max(glare, spec_contrib.b); + + col += spec_contrib; + } + + col = mix(col.rgb, old_diffcol.rgb, diffuse.a); + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + float exponent = mix(2.2, 1.0, diffuse.a); + + vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; + + col = mix(col.rgb, refcol, + envIntensity); + + float cur_glare = max(refcol.r, refcol.g); + cur_glare = max(cur_glare, refcol.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } + + float exponent = mix(1.0, 2.2, diffuse.a); + col = pow(col, vec3(exponent)); + + + col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + + + vec3 npos = normalize(-pos.xyz); + + #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); + + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + + col.rgb = pow(col.rgb, vec3(1.0/2.2)); + + frag_color.rgb = col.rgb; + glare = min(glare, 1.0); + frag_color.a = max(diffcol.a,glare)*vertex_color.a; + +#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 338532e71d..0d86840c1c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -56,16 +56,42 @@ uniform float far_z; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ + float f = sqrt(2 * n.z + 2); + return (n.xy / vec2(f)) + vec2(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); +} +#else +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 79f94fb131..f4d174729d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -67,16 +67,42 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ + float f = sqrt(2 * n.z + 2); + return (n.xy / vec2(f)) + vec2(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); +} +#else +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 69cdb2ce71..1313ba582f 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -54,16 +54,42 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ + float f = sqrt(2 * n.z + 2); + return (n.xy / vec2(f)) + vec2(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); +} +#else +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 2d6bce02c9..d4803f9aed 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -1,46 +1,46 @@ -/** - * @file postDeferredGammaCorrect.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; - -uniform vec2 screen_res; -VARYING vec2 vary_fragcoord; - -uniform float texture_gamma; - -void main() -{ - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - frag_color = pow(diff, vec4(texture_gamma, texture_gamma, texture_gamma, 1.0)); -} - +/** + * @file postDeferredGammaCorrect.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#extension GL_ARB_texture_rectangle : enable + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; + +uniform vec2 screen_res; +VARYING vec2 vary_fragcoord; + +uniform float texture_gamma; + +void main() +{ + vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); + frag_color = pow(diff, vec4(texture_gamma, texture_gamma, texture_gamma, 1.0f)); +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 45d672c290..3e3e0a5a5d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -1,379 +1,393 @@ -/** - * @file softenLightF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect positionMap; -uniform sampler2DRect normalMap; -uniform sampler2DRect lightMap; -uniform sampler2DRect depthMap; -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -uniform float blur_size; -uniform float blur_fidelity; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec4 glow; -uniform float global_gamma; -uniform float scene_light_strength; -uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; - -uniform vec3 sun_dir; -VARYING vec2 vary_fragcoord; - -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - -uniform mat4 inv_proj; -uniform vec2 screen_res; - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} - -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).a; - return getPosition_d(pos_screen, depth); -} - -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * global_gamma); - setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * global_gamma); - setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * global_gamma); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - - - -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / scene_light_strength ); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * scene_light_strength); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + light / 2.0; -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * lightIntensity; -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} - - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} - -void main() -{ - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - - vec4 diffuse = texture2DRect(diffuseRect, tc); - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; - float bloom = 0.0; - { - calcAtmospherics(pos.xyz, 1.0); - - col = atmosAmbient(vec3(0)); - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= ambient; - - col += atmosAffectDirectionalLight(max(min(da, 1.0) * 2.6, 0.0)); - - col *= diffuse.rgb; - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // - - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - col += spec_contrib; - } - - - col = mix(col.rgb, pow(diffuse.rgb, vec3(1.0/2.2)), diffuse.a); - - - if (envIntensity > 0.0) - { //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - float exponent = mix(2.2, 1.0, diffuse.a); - vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; - - col = mix(col.rgb, refcol, - envIntensity); - - } - - float exponent = mix(1.0, 2.2, diffuse.a); - col = pow(col, vec3(exponent)); - - if (norm.w < 0.5) - { - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - } - - //col = vec3(1,0,1); - //col.g = envIntensity; - } - - frag_color.rgb = col; - - frag_color.a = bloom; -} +/** + * @file softenLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#extension GL_ARB_texture_rectangle : enable + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect positionMap; +uniform sampler2DRect normalMap; +uniform sampler2DRect lightMap; +uniform sampler2DRect depthMap; +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; + +uniform float blur_size; +uniform float blur_fidelity; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +//uniform vec4 camPosWorld; +uniform vec4 gamma; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; +uniform float global_gamma; +uniform float scene_light_strength; +uniform mat3 env_mat; +uniform mat3 ssao_effect_mat; + +uniform vec3 sun_dir; +VARYING vec2 vary_fragcoord; + +vec3 vary_PositionEye; + +vec3 vary_SunlitColor; +vec3 vary_AmblitColor; +vec3 vary_AdditiveColor; +vec3 vary_AtmosAttenuation; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +#ifdef SINGLE_FP_ONLY +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); +} +#else +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif + +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec4 getPosition(vec2 pos_screen) +{ //get position in screen space (world units) given window coordinate and depth map + float depth = texture2DRect(depthMap, pos_screen.xy).a; + return getPosition_d(pos_screen, depth); +} + +vec3 getPositionEye() +{ + return vary_PositionEye; +} +vec3 getSunlitColor() +{ + return vary_SunlitColor; +} +vec3 getAmblitColor() +{ + return vary_AmblitColor; +} +vec3 getAdditiveColor() +{ + return vary_AdditiveColor; +} +vec3 getAtmosAttenuation() +{ + return vary_AtmosAttenuation; +} + +void setPositionEye(vec3 v) +{ + vary_PositionEye = v; +} + +void setSunlitColor(vec3 v) +{ + vary_SunlitColor = v; +} + +void setAmblitColor(vec3 v) +{ + vary_AmblitColor = v; +} + +void setAdditiveColor(vec3 v) +{ + vary_AdditiveColor = v; +} + +void setAtmosAttenuation(vec3 v) +{ + vary_AtmosAttenuation = v; +} + +void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + + vec3 P = inPositionEye; + setPositionEye(P); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * global_gamma); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * global_gamma); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * global_gamma); +} + +vec3 atmosLighting(vec3 light) +{ + light *= getAtmosAttenuation().r; + light += getAdditiveColor(); + return (2.0 * light); +} + +vec3 atmosTransport(vec3 light) { + light *= getAtmosAttenuation().r; + light += getAdditiveColor() * 2.0; + return light; +} + +vec3 fullbrightAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + + + +vec3 atmosGetDiffuseSunlightColor() +{ + return getSunlitColor(); +} + +vec3 scaleDownLight(vec3 light) +{ + return (light / scene_light_strength ); +} + +vec3 scaleUpLight(vec3 light) +{ + return (light * scene_light_strength); +} + +vec3 atmosAmbient(vec3 light) +{ + return getAmblitColor() + light / 2.0; +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ + return getSunlitColor() * lightIntensity; +} + +vec3 scaleSoftClip(vec3 light) +{ + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + + return light; +} + + +vec3 fullbrightScaleSoftClip(vec3 light) +{ + //soft clip effect: + return light; +} + +void main() +{ + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec3 pos = getPosition_d(tc, depth).xyz; + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = decode_normal(norm.xy); // unpack norm + + float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + + vec4 diffuse = texture2DRect(diffuseRect, tc); + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); + vec3 col; + float bloom = 0.0; + { + calcAtmospherics(pos.xyz, 1.0); + + col = atmosAmbient(vec3(0)); + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + col.rgb *= ambient; + + col += atmosAffectDirectionalLight(max(min(da, 1.0) * 2.6, 0.0)); + + col *= diffuse.rgb; + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + col += spec_contrib; + } + + + col = mix(col.rgb, pow(diffuse.rgb, vec3(1.0/2.2)), diffuse.a); + + + if (envIntensity > 0.0) + { //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + + float exponent = mix(2.2, 1.0, diffuse.a); + vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; + + col = mix(col.rgb, refcol, + envIntensity); + + } + + float exponent = mix(1.0, 2.2, diffuse.a); + col = pow(col, vec3(exponent)); + + if (norm.w < 0.5) + { + col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + } + + //col = vec3(1,0,1); + //col.g = envIntensity; + } + + frag_color.rgb = col; + + frag_color.a = bloom; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index c918a42c73..adfe012e4d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -65,16 +65,42 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ + float f = sqrt(2 * n.z + 2); + return (n.xy / vec2(f)) + vec2(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); +} +#else +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 1470239a71..7fcbb1aa85 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -49,16 +49,42 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ + float f = sqrt(2 * n.z + 2); + return (n.xy / vec2(f)) + vec2(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); +} +#else +vec2 encode_normal(vec3 n) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif vec4 getPosition(vec2 pos_screen) { -- cgit v1.2.3 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 ++++++--------- 8 files changed, 52 insertions(+), 85 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') 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) -- cgit v1.2.3 From df3df9de4fb47cf00f51f5bcaab82ac4ca48bf74 Mon Sep 17 00:00:00 2001 From: Graham Madarasz Date: Sun, 9 Jun 2013 21:12:40 -0700 Subject: NORSPEC-246 fix shader compile errors from missing return --- indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl | 1 + indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl | 1 + 8 files changed, 8 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index d071801e2d..589ace086d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -69,6 +69,7 @@ vec2 encode_normal(vec3 n) { vec2 sn; sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); + return sn; } vec3 decode_normal (vec2 enc) diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f58c69deaa..f2decdfa7d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -431,6 +431,7 @@ vec2 encode_normal(vec3 n) { vec2 sn; sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); + return sn; } vec3 decode_normal (vec2 enc) diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index e27250e13e..722020ccfe 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -61,6 +61,7 @@ vec2 encode_normal(vec3 n) { vec2 sn; sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); + return sn; } vec3 decode_normal (vec2 enc) diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index ca3fcdcadb..e99d7ee626 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -72,6 +72,7 @@ vec2 encode_normal(vec3 n) { vec2 sn; sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); + return sn; } vec3 decode_normal (vec2 enc) diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 850988a604..77d59c6ecf 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -59,6 +59,7 @@ vec2 encode_normal(vec3 n) { vec2 sn; sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); + return sn; } vec3 decode_normal (vec2 enc) diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index e94201df41..f7920f7595 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -83,6 +83,7 @@ vec2 encode_normal(vec3 n) { vec2 sn; sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); + return sn; } 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 879953b476..4e1add3e56 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -70,6 +70,7 @@ vec2 encode_normal(vec3 n) { vec2 sn; sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); + return sn; } vec3 decode_normal (vec2 enc) diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 6d3b3e23de..14d35d1f0f 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -54,6 +54,7 @@ vec2 encode_normal(vec3 n) { vec2 sn; sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); + return sn; } vec3 decode_normal (vec2 enc) -- cgit v1.2.3 From aaf42d473eb9eca9169e0800a7e7b6411db02cb2 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 10 Jun 2013 13:00:12 -0500 Subject: Line endings. --- .../shaders/class1/deferred/multiPointLightF.glsl | 64 +++++++++++----------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 722020ccfe..b35ba549f6 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -56,38 +56,38 @@ uniform float far_z; uniform mat4 inv_proj; -#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); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - 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) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#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); + return sn; +} + +vec3 decode_normal (vec2 enc) +{ + 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) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} #endif vec4 getPosition(vec2 pos_screen) -- cgit v1.2.3 From 1f2125cc1263bda3352e195654f963777d9926a6 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Thu, 13 Jun 2013 11:45:54 -0400 Subject: correct DOS line endings --- .../shaders/class1/deferred/blurLightF.glsl | 64 +- .../shaders/class1/deferred/materialF.glsl | 1390 ++++++++++---------- .../shaders/class1/deferred/multiSpotLightF.glsl | 64 +- .../shaders/class1/deferred/pointLightF.glsl | 64 +- .../class1/deferred/postDeferredGammaCorrect.glsl | 92 +- .../shaders/class1/deferred/softenLightF.glsl | 792 +++++------ .../shaders/class1/deferred/spotLightF.glsl | 64 +- .../shaders/class1/deferred/sunLightSSAOF.glsl | 64 +- 8 files changed, 1297 insertions(+), 1297 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1') diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 589ace086d..eebeb91bf8 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -64,38 +64,38 @@ vec4 getPosition(vec2 pos_screen) return pos; } -#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); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - 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) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#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); + return sn; +} + +vec3 decode_normal (vec2 enc) +{ + 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) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} #endif void main() diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index f2decdfa7d..de2f74b681 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -1,695 +1,695 @@ -/** - * @file materialF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#define DIFFUSE_ALPHA_MODE_IGNORE 0 -#define DIFFUSE_ALPHA_MODE_BLEND 1 -#define DIFFUSE_ALPHA_MODE_MASK 2 -#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 - -uniform float emissive_brightness; - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -#if HAS_SUN_SHADOW - -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform vec2 shadow_res; -uniform float shadow_bias; - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here - - float cs = shadow2D(shadowMap, stc.xyz).x; - float shadow = cs; - - shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - - return shadow*0.2; -} - -#endif - -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec4 glow; -uniform float scene_light_strength; -uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; - -uniform vec3 sun_dir; -VARYING vec2 vary_fragcoord; - -VARYING vec3 vary_position; - -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - -uniform mat4 inv_proj; -uniform vec2 screen_res; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -vec3 calcDirectionalLight(vec3 n, vec3 l) -{ - float a = max(dot(n,l),0.0); - return vec3(a,a,a); -} - - -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare) -{ - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float d = dot(lv,lv); - - float da = 1.0; - - vec3 col = vec3(0,0,0); - - if (d > 0.0 && la > 0.0 && fa > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist2 = d/la; - float dist_atten = 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(dot(n, lv), 0.0); - - float lit = max(da * dist_atten, 0.0); - - col = light_col*lit*diffuse; - - if (spec.a > 0.0) - { - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(n, h); - float nv = dot(n, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - vec3 speccol = lit*scol*light_col.rgb*spec.rgb; - col += speccol; - - float cur_glare = max(speccol.r, speccol.g); - cur_glare = max(cur_glare, speccol.b); - glare = max(glare, speccol.r); - glare += max(cur_glare, 0.0); - //col += spec.rgb; - } - } - } - - return max(col, vec3(0.0,0.0,0.0)); - -} - -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(pow(vec3(sunlight * .5), vec3(2.2)) * 2.2); - setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(2.2)) * 2.2); - setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(2.2)) * 2.2); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); - vec3 ones = vec3(1.0f, 1.0f, 1.0f); - - light = ones - clamp(light, zeroes, ones); - light = ones - pow(light, gamma.xxx); - - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} - -#else -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif -#endif - -uniform sampler2D diffuseMap; - -#if HAS_NORMAL_MAP -uniform sampler2D bumpMap; -#endif - -#if HAS_SPECULAR_MAP -uniform sampler2D specularMap; - -VARYING vec2 vary_texcoord2; -#endif - -uniform float env_intensity; -uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -uniform float minimum_alpha; -#endif - -#if HAS_NORMAL_MAP -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; -VARYING vec2 vary_texcoord1; -#else -VARYING vec3 vary_normal; -#endif - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -#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); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - 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) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} -#endif - -void main() -{ - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); - diffcol.rgb *= vertex_color.rgb; - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - if (diffcol.a < minimum_alpha) - { - discard; - } -#endif - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 old_diffcol = diffcol.rgb; - diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); -#endif - -#if HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); - spec.rgb *= specular_color.rgb; -#else - vec4 spec = vec4(specular_color.rgb, 1.0); -#endif - -#if HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); - - norm.xyz = norm.xyz * 2 - 1; - - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); -#else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; -#endif - - norm.xyz = tnorm; - norm.xyz = normalize(norm.xyz); - - vec4 final_color = diffcol; - -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = emissive_brightness; -#else - final_color.a = max(final_color.a, emissive_brightness); -#endif - - vec4 final_specular = spec; -#if HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); - final_specular.a = specular_color.a * norm.a; -#else - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); - final_specular.a = specular_color.a; -#endif - - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - //forward rendering, output just lit RGBA - vec3 pos = vary_position; - -#if HAS_SUN_SHADOW - float shadow = 0.0; - - vec4 spos = vec4(pos,1.0); - - if (spos.z > -shadow_clip.w) - { - vec4 lpos; - - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - vec4 transition_domain = near_split-far_split; - float weight = 0.0; - - if (spos.z < near_split.z) - { - lpos = shadow_matrix[3]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, lpos)*w; - weight += w; - shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); - } - - if (spos.z < near_split.y && spos.z > far_split.z) - { - lpos = shadow_matrix[2]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; - w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, lpos)*w; - weight += w; - } - - if (spos.z < near_split.x && spos.z > far_split.y) - { - lpos = shadow_matrix[1]*spos; - - float w = 1.0; - w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; - w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; - shadow += pcfShadow(shadowMap1, lpos)*w; - weight += w; - } - - if (spos.z > far_split.x) - { - lpos = shadow_matrix[0]*spos; - - float w = 1.0; - w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; - - shadow += pcfShadow(shadowMap0, lpos)*w; - weight += w; - } - - - shadow /= weight; - } - else - { - shadow = 1.0; - } -#else - float shadow = 1.0; -#endif - - spec = final_specular; - vec4 diffuse = final_color; - float envIntensity = final_normal.z; - - vec3 col = vec3(0.0f,0.0f,0.0f); - - float bloom = 0.0; - calcAtmospherics(pos.xyz, 1.0); - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - float da =dot(norm.xyz, sun_dir.xyz); - float final_da = da; - final_da = min(final_da, shadow); - final_da = max(final_da, diffuse.a); - final_da = max(final_da, 0.0f); - - col.rgb = atmosAmbient(col); - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= ambient; - - col.rgb = col.rgb + atmosAffectDirectionalLight(final_da * 2.6); - col.rgb *= diffuse.rgb; - - - float glare = 0.0; - - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // - - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - - glare = max(spec_contrib.r, spec_contrib.g); - glare = max(glare, spec_contrib.b); - - col += spec_contrib; - } - - col = mix(col.rgb, old_diffcol.rgb, diffuse.a); - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - float exponent = mix(2.2, 1.0, diffuse.a); - - vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; - - col = mix(col.rgb, refcol, - envIntensity); - - float cur_glare = max(refcol.r, refcol.g); - cur_glare = max(cur_glare, refcol.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } - - float exponent = mix(1.0, 2.2, diffuse.a); - col = pow(col, vec3(exponent)); - - - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - - - vec3 npos = normalize(-pos.xyz); - - #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); - - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) - - - col.rgb = pow(col.rgb, vec3(1.0/2.2)); - - frag_color.rgb = col.rgb; - glare = min(glare, 1.0); - frag_color.a = max(diffcol.a,glare)*vertex_color.a; - -#else - frag_data[0] = final_color; - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -#endif -} +/** + * @file materialF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +uniform float emissive_brightness; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +#if HAS_SUN_SHADOW + +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; + +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform vec2 shadow_res; +uniform float shadow_bias; + +float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +{ + stc.xyz /= stc.w; + stc.z += shadow_bias; + + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + + float cs = shadow2D(shadowMap, stc.xyz).x; + float shadow = cs; + + shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; + + return shadow*0.2; +} + +#endif + +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +//uniform vec4 camPosWorld; +uniform vec4 gamma; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; +uniform float scene_light_strength; +uniform mat3 env_mat; +uniform mat3 ssao_effect_mat; + +uniform vec3 sun_dir; +VARYING vec2 vary_fragcoord; + +VARYING vec3 vary_position; + +vec3 vary_PositionEye; + +vec3 vary_SunlitColor; +vec3 vary_AmblitColor; +vec3 vary_AdditiveColor; +vec3 vary_AtmosAttenuation; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec3 light_attenuation[8]; +uniform vec3 light_diffuse[8]; + +vec3 calcDirectionalLight(vec3 n, vec3 l) +{ + float a = max(dot(n,l),0.0); + return vec3(a,a,a); +} + + +vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare) +{ + //get light vector + vec3 lv = lp.xyz-v; + + //get distance + float d = dot(lv,lv); + + float da = 1.0; + + vec3 col = vec3(0,0,0); + + if (d > 0.0 && la > 0.0 && fa > 0.0) + { + //normalize light vector + lv = normalize(lv); + + //distance attenuation + float dist2 = d/la; + float dist_atten = 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(dot(n, lv), 0.0); + + float lit = max(da * dist_atten, 0.0); + + col = light_col*lit*diffuse; + + if (spec.a > 0.0) + { + //vec3 ref = dot(pos+lv, norm); + vec3 h = normalize(lv+npos); + float nh = dot(n, h); + float nv = dot(n, npos); + float vh = dot(npos, h); + float sa = nh; + float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; + + float gtdenom = 2 * nh; + float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + + if (nh > 0.0) + { + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + vec3 speccol = lit*scol*light_col.rgb*spec.rgb; + col += speccol; + + float cur_glare = max(speccol.r, speccol.g); + cur_glare = max(cur_glare, speccol.b); + glare = max(glare, speccol.r); + glare += max(cur_glare, 0.0); + //col += spec.rgb; + } + } + } + + return max(col, vec3(0.0,0.0,0.0)); + +} + +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec3 getPositionEye() +{ + return vary_PositionEye; +} +vec3 getSunlitColor() +{ + return vary_SunlitColor; +} +vec3 getAmblitColor() +{ + return vary_AmblitColor; +} +vec3 getAdditiveColor() +{ + return vary_AdditiveColor; +} +vec3 getAtmosAttenuation() +{ + return vary_AtmosAttenuation; +} + +void setPositionEye(vec3 v) +{ + vary_PositionEye = v; +} + +void setSunlitColor(vec3 v) +{ + vary_SunlitColor = v; +} + +void setAmblitColor(vec3 v) +{ + vary_AmblitColor = v; +} + +void setAdditiveColor(vec3 v) +{ + vary_AdditiveColor = v; +} + +void setAtmosAttenuation(vec3 v) +{ + vary_AtmosAttenuation = v; +} + +void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + + vec3 P = inPositionEye; + setPositionEye(P); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(pow(vec3(sunlight * .5), vec3(2.2)) * 2.2); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(2.2)) * 2.2); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(2.2)) * 2.2); +} + +vec3 atmosLighting(vec3 light) +{ + light *= getAtmosAttenuation().r; + light += getAdditiveColor(); + return (2.0 * light); +} + +vec3 atmosTransport(vec3 light) { + light *= getAtmosAttenuation().r; + light += getAdditiveColor() * 2.0; + return light; +} +vec3 atmosGetDiffuseSunlightColor() +{ + return getSunlitColor(); +} + +vec3 scaleDownLight(vec3 light) +{ + return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); +} + +vec3 scaleUpLight(vec3 light) +{ + return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); +} + +vec3 atmosAmbient(vec3 light) +{ + return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ + return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); +} + +vec3 scaleSoftClip(vec3 light) +{ + //soft clip effect: + vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); + vec3 ones = vec3(1.0f, 1.0f, 1.0f); + + light = ones - clamp(light, zeroes, ones); + light = ones - pow(light, gamma.xxx); + + return light; +} + +vec3 fullbrightAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + +vec3 fullbrightScaleSoftClip(vec3 light) +{ + //soft clip effect: + return light; +} + +#else +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[3]; +#else +#define frag_data gl_FragData +#endif +#endif + +uniform sampler2D diffuseMap; + +#if HAS_NORMAL_MAP +uniform sampler2D bumpMap; +#endif + +#if HAS_SPECULAR_MAP +uniform sampler2D specularMap; + +VARYING vec2 vary_texcoord2; +#endif + +uniform float env_intensity; +uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) +uniform float minimum_alpha; +#endif + +#if HAS_NORMAL_MAP +VARYING vec3 vary_mat0; +VARYING vec3 vary_mat1; +VARYING vec3 vary_mat2; +VARYING vec2 vary_texcoord1; +#else +VARYING vec3 vary_normal; +#endif + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +#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); + return sn; +} + +vec3 decode_normal (vec2 enc) +{ + 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) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif + +void main() +{ + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + diffcol.rgb *= vertex_color.rgb; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) + if (diffcol.a < minimum_alpha) + { + discard; + } +#endif + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec3 old_diffcol = diffcol.rgb; + diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); +#endif + +#if HAS_SPECULAR_MAP + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + spec.rgb *= specular_color.rgb; +#else + vec4 spec = vec4(specular_color.rgb, 1.0); +#endif + +#if HAS_NORMAL_MAP + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + + norm.xyz = norm.xyz * 2 - 1; + + vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); +#else + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm = vary_normal; +#endif + + norm.xyz = tnorm; + norm.xyz = normalize(norm.xyz); + + vec4 final_color = diffcol; + +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = emissive_brightness; +#else + final_color.a = max(final_color.a, emissive_brightness); +#endif + + vec4 final_specular = spec; +#if HAS_SPECULAR_MAP + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); + final_specular.a = specular_color.a * norm.a; +#else + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + final_specular.a = specular_color.a; +#endif + + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + //forward rendering, output just lit RGBA + vec3 pos = vary_position; + +#if HAS_SUN_SHADOW + float shadow = 0.0; + + vec4 spos = vec4(pos,1.0); + + if (spos.z > -shadow_clip.w) + { + vec4 lpos; + + vec4 near_split = shadow_clip*-0.75; + vec4 far_split = shadow_clip*-1.25; + vec4 transition_domain = near_split-far_split; + float weight = 0.0; + + if (spos.z < near_split.z) + { + lpos = shadow_matrix[3]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos)*w; + weight += w; + shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); + } + + if (spos.z < near_split.y && spos.z > far_split.z) + { + lpos = shadow_matrix[2]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; + w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap2, lpos)*w; + weight += w; + } + + if (spos.z < near_split.x && spos.z > far_split.y) + { + lpos = shadow_matrix[1]*spos; + + float w = 1.0; + w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; + w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; + shadow += pcfShadow(shadowMap1, lpos)*w; + weight += w; + } + + if (spos.z > far_split.x) + { + lpos = shadow_matrix[0]*spos; + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos)*w; + weight += w; + } + + + shadow /= weight; + } + else + { + shadow = 1.0; + } +#else + float shadow = 1.0; +#endif + + spec = final_specular; + vec4 diffuse = final_color; + float envIntensity = final_normal.z; + + vec3 col = vec3(0.0f,0.0f,0.0f); + + float bloom = 0.0; + calcAtmospherics(pos.xyz, 1.0); + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + + float da =dot(norm.xyz, sun_dir.xyz); + float final_da = da; + final_da = min(final_da, shadow); + final_da = max(final_da, diffuse.a); + final_da = max(final_da, 0.0f); + + col.rgb = atmosAmbient(col); + + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + col.rgb *= ambient; + + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da * 2.6); + col.rgb *= diffuse.rgb; + + + float glare = 0.0; + + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + + glare = max(spec_contrib.r, spec_contrib.g); + glare = max(glare, spec_contrib.b); + + col += spec_contrib; + } + + col = mix(col.rgb, old_diffcol.rgb, diffuse.a); + + if (envIntensity > 0.0) + { + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + float exponent = mix(2.2, 1.0, diffuse.a); + + vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; + + col = mix(col.rgb, refcol, + envIntensity); + + float cur_glare = max(refcol.r, refcol.g); + cur_glare = max(cur_glare, refcol.b); + cur_glare *= envIntensity*4.0; + glare += cur_glare; + } + + float exponent = mix(1.0, 2.2, diffuse.a); + col = pow(col, vec3(exponent)); + + + col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + + + vec3 npos = normalize(-pos.xyz); + + #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); + + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) + + + col.rgb = pow(col.rgb, vec3(1.0/2.2)); + + frag_color.rgb = col.rgb; + glare = min(glare, 1.0); + frag_color.a = max(diffcol.a,glare)*vertex_color.a; + +#else + frag_data[0] = final_color; + 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/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index e99d7ee626..36fb4afa52 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -67,38 +67,38 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -#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); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - 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) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#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); + return sn; +} + +vec3 decode_normal (vec2 enc) +{ + 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) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} #endif vec4 correctWithGamma(vec4 col) diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 77d59c6ecf..c6b1eb7c8d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -54,38 +54,38 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -#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); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - 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) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#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); + return sn; +} + +vec3 decode_normal (vec2 enc) +{ + 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) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} #endif vec4 getPosition(vec2 pos_screen) diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index d4803f9aed..6f2cfae6d2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -1,46 +1,46 @@ -/** - * @file postDeferredGammaCorrect.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; - -uniform vec2 screen_res; -VARYING vec2 vary_fragcoord; - -uniform float texture_gamma; - -void main() -{ - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - frag_color = pow(diff, vec4(texture_gamma, texture_gamma, texture_gamma, 1.0f)); -} - +/** + * @file postDeferredGammaCorrect.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#extension GL_ARB_texture_rectangle : enable + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; + +uniform vec2 screen_res; +VARYING vec2 vary_fragcoord; + +uniform float texture_gamma; + +void main() +{ + vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); + frag_color = pow(diff, vec4(texture_gamma, texture_gamma, texture_gamma, 1.0f)); +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index f7920f7595..b40850e769 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -1,396 +1,396 @@ -/** - * @file softenLightF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect positionMap; -uniform sampler2DRect normalMap; -uniform sampler2DRect lightMap; -uniform sampler2DRect depthMap; -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -uniform float blur_size; -uniform float blur_fidelity; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec4 glow; -uniform float global_gamma; -uniform float scene_light_strength; -uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; - -uniform vec3 sun_dir; -VARYING vec2 vary_fragcoord; - -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - -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); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - 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) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} -#endif - -vec4 getPosition_d(vec2 pos_screen, float depth) -{ - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map - float depth = texture2DRect(depthMap, pos_screen.xy).a; - return getPosition_d(pos_screen, depth); -} - -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - vec4 sunlight = sunlight_color; - vec4 light_atten; - - //sunlight attenuation effect (hue and brightness) due to atmosphere - //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); - //I had thought blue_density and haze_density should have equal weighting, - //but attenuation due to haze_density tends to seem too strong - - temp1 = blue_density + vec4(haze_density); - blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density) / temp1; - - //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) - temp2.y = max(0.0, tmpLightnorm.y); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati - // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) - + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x - + tmpAmbient))); - - //brightness of surface both sunlight and ambient - setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * global_gamma); - setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * global_gamma); - setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * global_gamma); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - - - -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / scene_light_strength ); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * scene_light_strength); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + light / 2.0; -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * lightIntensity; -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} - - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} - -void main() -{ - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPosition_d(tc, depth).xyz; - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = decode_normal(norm.xy); // unpack norm - - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - - vec4 diffuse = texture2DRect(diffuseRect, tc); - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; - float bloom = 0.0; - { - calcAtmospherics(pos.xyz, 1.0); - - col = atmosAmbient(vec3(0)); - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= ambient; - - col += atmosAffectDirectionalLight(max(min(da, 1.0) * 2.6, 0.0)); - - col *= diffuse.rgb; - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // - - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - col += spec_contrib; - } - - - col = mix(col.rgb, pow(diffuse.rgb, vec3(1.0/2.2)), diffuse.a); - - - if (envIntensity > 0.0) - { //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - float exponent = mix(2.2, 1.0, diffuse.a); - vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; - - col = mix(col.rgb, refcol, - envIntensity); - - } - - float exponent = mix(1.0, 2.2, diffuse.a); - col = pow(col, vec3(exponent)); - - if (norm.w < 0.5) - { - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - } - - //col = vec3(1,0,1); - //col.g = envIntensity; - } - - frag_color.rgb = col; - - frag_color.a = bloom; -} +/** + * @file softenLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#extension GL_ARB_texture_rectangle : enable + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect positionMap; +uniform sampler2DRect normalMap; +uniform sampler2DRect lightMap; +uniform sampler2DRect depthMap; +uniform samplerCube environmentMap; +uniform sampler2D lightFunc; + +uniform float blur_size; +uniform float blur_fidelity; + +// Inputs +uniform vec4 morphFactor; +uniform vec3 camPosLocal; +//uniform vec4 camPosWorld; +uniform vec4 gamma; +uniform vec4 lightnorm; +uniform vec4 sunlight_color; +uniform vec4 ambient; +uniform vec4 blue_horizon; +uniform vec4 blue_density; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; +uniform vec4 glow; +uniform float global_gamma; +uniform float scene_light_strength; +uniform mat3 env_mat; +uniform mat3 ssao_effect_mat; + +uniform vec3 sun_dir; +VARYING vec2 vary_fragcoord; + +vec3 vary_PositionEye; + +vec3 vary_SunlitColor; +vec3 vary_AmblitColor; +vec3 vary_AdditiveColor; +vec3 vary_AtmosAttenuation; + +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); + return sn; +} + +vec3 decode_normal (vec2 enc) +{ + 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) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif + +vec4 getPosition_d(vec2 pos_screen, float depth) +{ + vec2 sc = pos_screen.xy*2.0; + sc /= screen_res; + sc -= vec2(1.0,1.0); + vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); + vec4 pos = inv_proj * ndc; + pos /= pos.w; + pos.w = 1.0; + return pos; +} + +vec4 getPosition(vec2 pos_screen) +{ //get position in screen space (world units) given window coordinate and depth map + float depth = texture2DRect(depthMap, pos_screen.xy).a; + return getPosition_d(pos_screen, depth); +} + +vec3 getPositionEye() +{ + return vary_PositionEye; +} +vec3 getSunlitColor() +{ + return vary_SunlitColor; +} +vec3 getAmblitColor() +{ + return vary_AmblitColor; +} +vec3 getAdditiveColor() +{ + return vary_AdditiveColor; +} +vec3 getAtmosAttenuation() +{ + return vary_AtmosAttenuation; +} + +void setPositionEye(vec3 v) +{ + vary_PositionEye = v; +} + +void setSunlitColor(vec3 v) +{ + vary_SunlitColor = v; +} + +void setAmblitColor(vec3 v) +{ + vary_AmblitColor = v; +} + +void setAdditiveColor(vec3 v) +{ + vary_AdditiveColor = v; +} + +void setAtmosAttenuation(vec3 v) +{ + vary_AtmosAttenuation = v; +} + +void calcAtmospherics(vec3 inPositionEye, float ambFactor) { + + vec3 P = inPositionEye; + setPositionEye(P); + + vec3 tmpLightnorm = lightnorm.xyz; + + vec3 Pn = normalize(P); + float Plen = length(P); + + vec4 temp1 = vec4(0); + vec3 temp2 = vec3(0); + vec4 blue_weight; + vec4 haze_weight; + vec4 sunlight = sunlight_color; + vec4 light_atten; + + //sunlight attenuation effect (hue and brightness) due to atmosphere + //this is used later for sunlight modulation at various altitudes + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + //I had thought blue_density and haze_density should have equal weighting, + //but attenuation due to haze_density tends to seem too strong + + temp1 = blue_density + vec4(haze_density); + blue_weight = blue_density / temp1; + haze_weight = vec4(haze_density) / temp1; + + //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) + temp2.y = max(0.0, tmpLightnorm.y); + temp2.y = 1. / temp2.y; + sunlight *= exp( - light_atten * temp2.y); + + // main atmospheric scattering line integral + temp2.z = Plen * density_multiplier; + + // Transparency (-> temp1) + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati + // compiler gets confused. + temp1 = exp(-temp1 * temp2.z * distance_multiplier); + + //final atmosphere attenuation factor + setAtmosAttenuation(temp1.rgb); + + //compute haze glow + //(can use temp2.x as temp because we haven't used it yet) + temp2.x = dot(Pn, tmpLightnorm.xyz); + temp2.x = 1. - temp2.x; + //temp2.x is 0 at the sun and increases away from sun + temp2.x = max(temp2.x, .03); //was glow.y + //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) + temp2.x *= glow.x; + //higher glow.x gives dimmer glow (because next step is 1 / "angle") + temp2.x = pow(temp2.x, glow.z); + //glow.z should be negative, so we're doing a sort of (1 / "angle") function + + //add "minimum anti-solar illumination" + temp2.x += .25; + + //increase ambient when there are more clouds + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; + + /* decrease value and saturation (that in HSV, not HSL) for occluded areas + * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html + * // The following line of code performs the equivalent of: + * float ambAlpha = tmpAmbient.a; + * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis + * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); + * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); + */ + tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); + + //haze color + setAdditiveColor( + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + + tmpAmbient))); + + //brightness of surface both sunlight and ambient + setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * global_gamma); + setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * global_gamma); + setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * global_gamma); +} + +vec3 atmosLighting(vec3 light) +{ + light *= getAtmosAttenuation().r; + light += getAdditiveColor(); + return (2.0 * light); +} + +vec3 atmosTransport(vec3 light) { + light *= getAtmosAttenuation().r; + light += getAdditiveColor() * 2.0; + return light; +} + +vec3 fullbrightAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + + + +vec3 atmosGetDiffuseSunlightColor() +{ + return getSunlitColor(); +} + +vec3 scaleDownLight(vec3 light) +{ + return (light / scene_light_strength ); +} + +vec3 scaleUpLight(vec3 light) +{ + return (light * scene_light_strength); +} + +vec3 atmosAmbient(vec3 light) +{ + return getAmblitColor() + light / 2.0; +} + +vec3 atmosAffectDirectionalLight(float lightIntensity) +{ + return getSunlitColor() * lightIntensity; +} + +vec3 scaleSoftClip(vec3 light) +{ + //soft clip effect: + light = 1. - clamp(light, vec3(0.), vec3(1.)); + light = 1. - pow(light, gamma.xxx); + + return light; +} + + +vec3 fullbrightScaleSoftClip(vec3 light) +{ + //soft clip effect: + return light; +} + +void main() +{ + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec3 pos = getPosition_d(tc, depth).xyz; + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = decode_normal(norm.xy); // unpack norm + + float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + + vec4 diffuse = texture2DRect(diffuseRect, tc); + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); + vec3 col; + float bloom = 0.0; + { + calcAtmospherics(pos.xyz, 1.0); + + col = atmosAmbient(vec3(0)); + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + col.rgb *= ambient; + + col += atmosAffectDirectionalLight(max(min(da, 1.0) * 2.6, 0.0)); + + col *= diffuse.rgb; + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + + if (spec.a > 0.0) // specular reflection + { + // the old infinite-sky shiny reflection + // + + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + col += spec_contrib; + } + + + col = mix(col.rgb, pow(diffuse.rgb, vec3(1.0/2.2)), diffuse.a); + + + if (envIntensity > 0.0) + { //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + + float exponent = mix(2.2, 1.0, diffuse.a); + vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; + + col = mix(col.rgb, refcol, + envIntensity); + + } + + float exponent = mix(1.0, 2.2, diffuse.a); + col = pow(col, vec3(exponent)); + + if (norm.w < 0.5) + { + col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + } + + //col = vec3(1,0,1); + //col.g = envIntensity; + } + + frag_color.rgb = col; + + frag_color.a = bloom; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 4e1add3e56..3539c8d2b2 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -65,38 +65,38 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -#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); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - 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) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#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); + return sn; +} + +vec3 decode_normal (vec2 enc) +{ + 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) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} #endif vec4 correctWithGamma(vec4 col) diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 14d35d1f0f..6653f57ee1 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -49,38 +49,38 @@ VARYING vec2 vary_fragcoord; 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); - return sn; -} - -vec3 decode_normal (vec2 enc) -{ - 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) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -vec3 decode_normal (vec2 enc) -{ - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return n; -} +#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); + return sn; +} + +vec3 decode_normal (vec2 enc) +{ + 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) +{ + float f = sqrt(8 * n.z + 8); + return n.xy / f + 0.5; +} + +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} #endif vec4 getPosition(vec2 pos_screen) -- cgit v1.2.3