diff options
20 files changed, 139 insertions, 284 deletions
diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index ac16e30796..b854218e3d 100755 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -87,6 +87,7 @@ LLShaderFeatures::LLShaderFeatures() , mIndexedTextureChannels(0) , disableTextureIndex(false) , hasAlphaMask(false) + , hasSRGB(false) { } diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index eabdb9fc92..dadffeb6c4 100755 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -50,6 +50,7 @@ public: S32 mIndexedTextureChannels; bool disableTextureIndex; bool hasAlphaMask; + bool hasSRGB; // char numLights; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 942f6dc86f..c3e76f5e0e 100755 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -175,6 +175,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) // Attach Fragment Shader Features Next /////////////////////////////////////// + if (features->hasSRGB) + { + if (!shader->attachObject("deferred/srgb.glsl")) + { + return FALSE; + } + } + if(features->calculatesAtmospherics) { if (features->hasWaterFog) @@ -1137,12 +1145,13 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("projectionMap"); mReservedUniforms.push_back("global_gamma"); - mReservedUniforms.push_back("texture_gamma"); - mReservedUniforms.push_back("display_gamma"); + mReservedUniforms.push_back("texture_gamma"); mReservedUniforms.push_back("specular_color"); mReservedUniforms.push_back("env_intensity"); + mReservedUniforms.push_back("display_gamma"); + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); std::set<std::string> dupe_check; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 2cbeea5049..3c282bf24f 100755 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -167,12 +167,13 @@ public: DEFERRED_PROJECTION, GLOBAL_GAMMA, - TEXTURE_GAMMA, - DISPLAY_GAMMA, + TEXTURE_GAMMA, SPECULAR_COLOR, ENVIRONMENT_INTENSITY, + DISPLAY_GAMMA, + END_RESERVED_UNIFORMS } eGLSLReservedUniforms; diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index e3be7a52ec..075699c591 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -93,10 +93,13 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + vec3 calcDirectionalLight(vec3 n, vec3 l) { float a = max(dot(n,l),0.0); - //a = pow(a, 1.0/1.3); + a = pow(a, 1.0/1.3); return vec3(a,a,a); } @@ -392,37 +395,6 @@ vec3 fullbrightScaleSoftClip(vec3 light) return light; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - vec3 low_range = cs / vec3(12.92); - - if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) - return low_range; - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - - void main() { vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; @@ -533,7 +505,7 @@ void main() color.rgb *= ambient; - color.rgb += atmosAffectDirectionalLight(final_da); + color.rgb += atmosAffectDirectionalLight(pow(final_da, 1.0/1.3)); color.rgb *= gamma_diff.rgb; color.rgb = mix(atmosLighting(color.rgb), fullbrightAtmosTransport(color.rgb), diff.a); diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 6fe34b887a..adc361d7a2 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -39,15 +39,15 @@ vec2 encode_normal(vec3 n) return n.xy / f + 0.5; } + void main() { - vec4 diff = diffuseLookup(vary_texcoord0.xy); - vec3 col = vertex_color.rgb * diff.rgb; + vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; vec3 spec; spec.rgb = vec3(vertex_color.a); - frag_data[0] = vec4(col, 0); + frag_data[0] = vec4(col, 0.0); frag_data[1] = vec4(spec, vertex_color.a); // spec 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/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index da4ebfea58..00548ea826 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -39,6 +39,9 @@ VARYING vec3 vary_position; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + vec3 fullbrightAtmosTransportDeferred(vec3 light) { return light; @@ -100,31 +103,6 @@ vec4 applyWaterFogDeferred(vec3 pos, vec4 color) } #endif -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - void main() { #if HAS_DIFFUSE_LOOKUP diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b8c5360486..d3bd55da7a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -30,37 +30,6 @@ uniform float emissive_brightness; - -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - vec3 low_range = cs / vec3(12.92); - - if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) - return low_range; - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #ifdef DEFINE_GL_FRAGCOLOR @@ -145,6 +114,9 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + #ifdef WATER_FOG uniform vec4 waterPlane; uniform vec4 waterFogColor; @@ -558,7 +530,7 @@ void main() dot(norm.xyz,vary_mat1), dot(norm.xyz,vary_mat2)); #else - vec4 norm = vec4(0,1,0,1.0); + vec4 norm = vec4(0,0,0,1.0); vec3 tnorm = vary_normal; #endif @@ -682,7 +654,7 @@ void main() col.rgb *= ambient; - col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); //pow(final_da, 1.0/1.3)); + col.rgb = col.rgb + atmosAffectDirectionalLight(pow(final_da, 1.0/1.3)); col.rgb *= gamma_diff.rgb; float glare = 0.0; @@ -705,7 +677,7 @@ void main() col += spec_contrib; } - col = mix(col.rgb, diffcol.rgb, diffuse.a); + col = mix(col.rgb, gamma_diff.rgb, diffuse.a); if (envIntensity > 0.0) { @@ -724,11 +696,11 @@ void main() } col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); //convert to linear space before adding local lights col = srgb_to_linear(col); - + 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); @@ -747,6 +719,7 @@ void main() //convert to gamma space for display on screen col.rgb = linear_to_srgb(col.rgb); + #ifdef WATER_FOG vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 3b6724479c..0b62c4ec09 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -84,25 +84,8 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { @@ -198,7 +181,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 4ca0c35d91..106d48bd71 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -115,7 +115,7 @@ void main() float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 01f9d99682..89530f4082 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -38,19 +38,7 @@ VARYING vec2 vary_fragcoord; uniform float display_gamma; -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 linear_to_srgb(vec3 cl); void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 045b449bbf..39d613e02b 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -78,37 +78,8 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; - -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - vec3 low_range = cs / vec3(12.92); - - if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) - return low_range; - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} - +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc) { @@ -143,7 +114,6 @@ vec3 getPositionEye() { return vary_PositionEye; } - vec3 getSunlitColor() { return vary_SunlitColor; @@ -388,7 +358,7 @@ void main() norm.xyz = decode_normal(norm.xy); // unpack norm float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - //da = pow(da, 1.0/1.3); + da = pow(da, 1.0/1.3); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -408,7 +378,9 @@ void main() ambient = (1.0-ambient); col.rgb *= ambient; + col += atmosAffectDirectionalLight(max(min(da, 1.0), 0.0)); + col *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 53732e961c..251abfd119 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -82,25 +82,8 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 correctWithGamma(vec4 col) { @@ -201,7 +184,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl new file mode 100644 index 0000000000..177f6c25f8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -0,0 +1,49 @@ +/** + * @file srgb.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$ + */ + +vec3 srgb_to_linear(vec3 cs) +{ + +/* { cs / 12.92, cs <= 0.04045 + cl = { + { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ + + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + return mix(high_range, low_range, lessThanEqual(cs,vec3(0.04045))); +} + +vec3 linear_to_srgb(vec3 cl) +{ + /* { 0.0, 0 <= cl + { 12.92 * c, 0 < cl < 0.0031308 + cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 + { 1.0, cl >= 1*/ + + cl = clamp(cl, vec3(0), vec3(1)); + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + return mix(high_range, low_range, lessThan(cl,vec3(0.0031308))); +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 938947bbce..858c3a1fe9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -56,25 +56,8 @@ VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 34189deaad..5538c41d1c 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -67,25 +67,8 @@ VARYING vec4 littleWave; VARYING vec4 view; VARYING vec4 vary_position; -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 4af0970726..6d1cedee39 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -68,6 +68,9 @@ uniform vec2 screen_res; uniform mat4 inv_proj; +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); + vec2 encode_normal(vec3 n) { float f = sqrt(8 * n.z + 8); @@ -85,22 +88,11 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - vec4 correctWithGamma(vec4 col) { return vec4(srgb_to_linear(col.rgb), col.a); } - vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); @@ -207,7 +199,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index fa67c4ecea..db2faa65d7 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -78,35 +78,8 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - vec3 low_range = cs / vec3(12.92); - - if (((cs.r + cs.g + cs.b) / 3) <= 0.04045) - return low_range; - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} - -vec3 linear_to_srgb(vec3 cl) -{ - /*{ 0.0, 0 <= cl - { 12.92 * c, 0 < cl < 0.0031308 - cs = { 1.055 * cl^0.41666 - 0.055, 0.0031308 <= cl < 1 - { 1.0, cl >= 1*/ - - cl = clamp(cl, vec3(0), vec3(1)); - - if ((cl.r+cl.g+cl.b) < 0.0031308) - return 12.92 * cl; - - return 1.055 * pow(cl, vec3(0.41666)) - 0.055; -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec2 encode_normal(vec3 n) { @@ -395,8 +368,8 @@ void main() float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - //float light_gamma = 1.0/1.3; - //da = pow(da, light_gamma); + float light_gamma = 1.0/1.3; + da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -410,10 +383,12 @@ void main() vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; - //scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); + scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); float scol = max(scol_ambocc.r, diffuse.a); + + float ambocc = scol_ambocc.g; calcAtmospherics(pos.xyz, ambocc); @@ -430,7 +405,6 @@ void main() col *= diffuse.rgb; - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); if (spec.a > 0.0) // specular reflection @@ -456,7 +430,8 @@ void main() vec3 refcol = textureCube(environmentMap, env_vec).rgb; - col = mix(col.rgb, refcol, envIntensity); + col = mix(col.rgb, refcol, + envIntensity); } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 544a0a6730..cfb483ab54 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -85,15 +85,8 @@ vec3 decode_normal (vec2 enc) return n; } -vec3 srgb_to_linear(vec3 cs) -{ - -/* { cs / 12.92, cs <= 0.04045 - cl = { - { ((cs + 0.055)/1.055)^2.4, cs > 0.04045*/ - - return pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); -} +vec3 srgb_to_linear(vec3 cs); +vec3 linear_to_srgb(vec3 cl); vec4 correctWithGamma(vec4 col) { @@ -204,7 +197,7 @@ void main() proj_tc.xyz /= proj_tc.w; - float fa = falloff; + float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 1ea176565b..aa3d2f8349 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -911,6 +911,7 @@ BOOL LLViewerShaderMgr::loadBasicShaders() index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/atmosphericsF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "windlight/transportF.glsl", mVertexShaderLevel[SHADER_WINDLIGHT] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "environment/waterFogF.glsl", mVertexShaderLevel[SHADER_WATER] ) ); + index_channels.push_back(-1); shaders.push_back( make_pair( "deferred/srgb.glsl", mVertexShaderLevel[SHADER_DEFERRED] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightAlphaMaskNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); index_channels.push_back(-1); shaders.push_back( make_pair( "lighting/lightFullbrightNonIndexedF.glsl", mVertexShaderLevel[SHADER_LIGHTING] ) ); @@ -1185,7 +1186,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { - gDeferredDiffuseProgram.mName = "Deferred Diffuse Shader"; + gDeferredDiffuseProgram.mName = "Deferred Diffuse Shader"; gDeferredDiffuseProgram.mShaderFiles.clear(); gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseIndexedF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1261,6 +1262,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredSkinnedAlphaProgram.mName = "Deferred Skinned Alpha Shader"; + gDeferredSkinnedAlphaProgram.mFeatures.hasSRGB = true; gDeferredSkinnedAlphaProgram.mFeatures.hasObjectSkinning = true; gDeferredSkinnedAlphaProgram.mFeatures.calculatesLighting = false; gDeferredSkinnedAlphaProgram.mFeatures.hasLighting = false; @@ -1317,6 +1319,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() U32 alpha_mode = i & 0x3; gDeferredMaterialProgram[i].mShaderFiles.clear(); + gDeferredMaterialProgram[i].mFeatures.hasSRGB = true; gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMaterialProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1342,6 +1345,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() U32 alpha_mode = i & 0x3; gDeferredMaterialWaterProgram[i].mShaderFiles.clear(); + gDeferredMaterialWaterProgram[i].mFeatures.hasSRGB = true; gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMaterialWaterProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMaterialWaterProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1430,6 +1434,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredMultiLightProgram[i].mName = llformat("Deferred MultiLight Shader %d", i); gDeferredMultiLightProgram[i].mShaderFiles.clear(); + gDeferredMultiLightProgram[i].mFeatures.hasSRGB = true; gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiLightProgram[i].mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1442,6 +1447,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSpotLightProgram.mName = "Deferred SpotLight Shader"; gDeferredSpotLightProgram.mShaderFiles.clear(); + gDeferredSpotLightProgram.mFeatures.hasSRGB = true; gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1453,6 +1459,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredMultiSpotLightProgram.mName = "Deferred MultiSpotLight Shader"; gDeferredMultiSpotLightProgram.mShaderFiles.clear(); + gDeferredMultiSpotLightProgram.mFeatures.hasSRGB = true; gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiSpotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; @@ -1502,6 +1509,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredAlphaProgram.mName = "Deferred Alpha Shader"; + gDeferredAlphaProgram.mFeatures.hasSRGB = true; gDeferredAlphaProgram.mFeatures.calculatesLighting = false; gDeferredAlphaProgram.mFeatures.hasLighting = false; gDeferredAlphaProgram.mFeatures.isAlphaLighting = true; @@ -1532,6 +1540,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredAlphaWaterProgram.mName = "Deferred Alpha Underwater Shader"; + gDeferredAlphaWaterProgram.mFeatures.hasSRGB = true; gDeferredAlphaWaterProgram.mFeatures.calculatesLighting = false; gDeferredAlphaWaterProgram.mFeatures.hasLighting = false; gDeferredAlphaWaterProgram.mFeatures.isAlphaLighting = true; @@ -1577,6 +1586,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightProgram.mName = "Deferred Fullbright Shader"; + gDeferredFullbrightProgram.mFeatures.hasSRGB = true; gDeferredFullbrightProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightProgram.mFeatures.hasGamma = true; gDeferredFullbrightProgram.mFeatures.hasTransport = true; @@ -1591,6 +1601,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightAlphaMaskProgram.mName = "Deferred Fullbright Alpha Masking Shader"; + gDeferredFullbrightAlphaMaskProgram.mFeatures.hasSRGB = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasGamma = true; gDeferredFullbrightAlphaMaskProgram.mFeatures.hasTransport = true; @@ -1606,6 +1617,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightWaterProgram.mName = "Deferred Fullbright Underwater Shader"; + gDeferredFullbrightWaterProgram.mFeatures.hasSRGB = true; gDeferredFullbrightWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightWaterProgram.mFeatures.hasGamma = true; gDeferredFullbrightWaterProgram.mFeatures.hasTransport = true; @@ -1622,6 +1634,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredFullbrightAlphaMaskWaterProgram.mName = "Deferred Fullbright Underwater Alpha Masking Shader"; + gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasSRGB = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasGamma = true; gDeferredFullbrightAlphaMaskWaterProgram.mFeatures.hasTransport = true; @@ -1653,6 +1666,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredSkinnedFullbrightProgram.mName = "Skinned Fullbright Shader"; + gDeferredSkinnedFullbrightProgram.mFeatures.hasSRGB = true; gDeferredSkinnedFullbrightProgram.mFeatures.calculatesAtmospherics = true; gDeferredSkinnedFullbrightProgram.mFeatures.hasGamma = true; gDeferredSkinnedFullbrightProgram.mFeatures.hasTransport = true; @@ -1698,6 +1712,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { // load water shader gDeferredWaterProgram.mName = "Deferred Water Shader"; + gDeferredWaterProgram.mFeatures.hasSRGB = true; gDeferredWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredWaterProgram.mFeatures.hasGamma = true; gDeferredWaterProgram.mFeatures.hasTransport = true; @@ -1712,6 +1727,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { // load water shader gDeferredUnderWaterProgram.mName = "Deferred Under Water Shader"; + gDeferredUnderWaterProgram.mFeatures.hasSRGB = true; gDeferredUnderWaterProgram.mFeatures.calculatesAtmospherics = true; gDeferredUnderWaterProgram.mFeatures.hasGamma = true; gDeferredUnderWaterProgram.mFeatures.hasTransport = true; @@ -1726,6 +1742,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSoftenProgram.mName = "Deferred Soften Shader"; gDeferredSoftenProgram.mShaderFiles.clear(); + gDeferredSoftenProgram.mFeatures.hasSRGB = true; gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1743,7 +1760,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredSoftenWaterProgram.mName = "Deferred Soften Underwater Shader"; gDeferredSoftenWaterProgram.mShaderFiles.clear(); - + gDeferredSoftenWaterProgram.mFeatures.hasSRGB = true; gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSoftenWaterProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER_ARB)); @@ -1841,6 +1858,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() if (success) { gDeferredAvatarAlphaProgram.mName = "Avatar Alpha Shader"; + gDeferredAvatarAlphaProgram.mFeatures.hasSRGB = true; gDeferredAvatarAlphaProgram.mFeatures.hasSkinning = true; gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = false; gDeferredAvatarAlphaProgram.mFeatures.hasLighting = false; @@ -1864,6 +1882,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() { gDeferredPostGammaCorrectProgram.mName = "Deferred Gamma Correction Post Process"; gDeferredPostGammaCorrectProgram.mShaderFiles.clear(); + gDeferredPostGammaCorrectProgram.mFeatures.hasSRGB = true; gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredGammaCorrect.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredPostGammaCorrectProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; |