diff options
Diffstat (limited to 'indra/newview/app_settings')
5 files changed, 132 insertions, 106 deletions
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 049ec3ad34..129f593454 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -10080,6 +10080,17 @@ <key>Value</key> <string>00000000-0000-0000-0000-000000000000</string> </map> + <key>RenderCAS</key> + <map> + <key>Comment</key> + <string>Use Contrast Adaptive Sharpening post process effect</string> + <key>Persist</key> + <integer>0</integer> + <key>Type</key> + <string>Boolean</string> + <key>Value</key> + <integer>1</integer> + </map> <key>RenderCASSharpness</key> <map> <key>Comment</key> diff --git a/indra/newview/app_settings/shaders/class1/deferred/CASF.glsl b/indra/newview/app_settings/shaders/class1/deferred/CASF.glsl index e80c59b39f..abab71e5ce 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/CASF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/CASF.glsl @@ -38,6 +38,7 @@ uniform sampler2D diffuseRect; uniform vec2 out_screen_res; uniform uvec4 cas_param_0; uniform uvec4 cas_param_1; +uniform float gamma; vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); @@ -2545,11 +2546,69 @@ A_STATIC void CasSetup( #endif #ifdef A_GPU + +//================================= +// borrowed noise from: +// <https://www.shadertoy.com/view/4dS3Wd> +// By Morgan McGuire @morgan3d, http://graphicscodex.com +// +float hash(float n) { return fract(sin(n) * 1e4); } +float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); } + +float noise(float x) { + float i = floor(x); + float f = fract(x); + float u = f * f * (3.0 - 2.0 * f); + return mix(hash(i), hash(i + 1.0), u); +} + +float noise(vec2 x) { + vec2 i = floor(x); + vec2 f = fract(x); + + // Four corners in 2D of a tile + float a = hash(i); + float b = hash(i + vec2(1.0, 0.0)); + float c = hash(i + vec2(0.0, 1.0)); + float d = hash(i + vec2(1.0, 1.0)); + + // Simple 2D lerp using smoothstep envelope between the values. + // return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)), + // mix(c, d, smoothstep(0.0, 1.0, f.x)), + // smoothstep(0.0, 1.0, f.y))); + + // Same code, with the clamps in smoothstep and common subexpressions + // optimized away. + vec2 u = f * f * (3.0 - 2.0 * f); + return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; +} + +//=============================================================== + +vec3 legacyGamma(vec3 color) +{ + vec3 c = 1. - clamp(color, vec3(0.), vec3(1.)); + c = 1. - pow(c, vec3(gamma)); // s/b inverted already CPU-side + + return c; +} + void main() { vec4 diff = vec4(0.f); uvec2 point = uvec2(vary_fragcoord * out_screen_res.xy); CasFilter(diff.r, diff.g, diff.b, point, cas_param_0, cas_param_1, true); + diff.rgb = linear_to_srgb(diff.rgb); + +#ifdef LEGACY_GAMMA + diff.rgb = legacyGamma(diff.rgb); +#endif + + vec2 tc = vary_fragcoord.xy*out_screen_res.xy*4.0; + vec3 seed = (diff.rgb+vec3(1.0))*vec3(tc.xy, tc.x+tc.y); + vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb)); + diff.rgb += nz*0.003; + diff.a = texture(diffuseRect, vary_fragcoord).a; frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl deleted file mode 100644 index befd2ae6da..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ /dev/null @@ -1,58 +0,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$ - */ - -/*[EXTRA_CODE_HERE]*/ - -out vec4 frag_color; - -uniform sampler2D diffuseRect; - -uniform float gamma; -uniform vec2 screen_res; -in vec2 vary_fragcoord; - -vec3 linear_to_srgb(vec3 cl); - -vec3 legacyGamma(vec3 color) -{ - vec3 c = 1. - clamp(color, vec3(0.), vec3(1.)); - c = 1. - pow(c, vec3(gamma)); // s/b inverted already CPU-side - - return c; -} - -void main() -{ - //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) - vec4 diff = texture(diffuseRect, vary_fragcoord); - diff.rgb = linear_to_srgb(diff.rgb); - -#ifdef LEGACY_GAMMA - diff.rgb = legacyGamma(diff.rgb); -#endif - - frag_color = max(diff, vec4(0)); -} - diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl index 32b0a1ac8e..07384ebe9b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl @@ -33,57 +33,10 @@ uniform sampler2D depthMap; uniform vec2 screen_res; in vec2 vary_fragcoord; -//================================= -// borrowed noise from: -// <https://www.shadertoy.com/view/4dS3Wd> -// By Morgan McGuire @morgan3d, http://graphicscodex.com -// -float hash(float n) { return fract(sin(n) * 1e4); } -float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); } - -float noise(float x) { - float i = floor(x); - float f = fract(x); - float u = f * f * (3.0 - 2.0 * f); - return mix(hash(i), hash(i + 1.0), u); -} - -float noise(vec2 x) { - vec2 i = floor(x); - vec2 f = fract(x); - - // Four corners in 2D of a tile - float a = hash(i); - float b = hash(i + vec2(1.0, 0.0)); - float c = hash(i + vec2(0.0, 1.0)); - float d = hash(i + vec2(1.0, 1.0)); - - // Simple 2D lerp using smoothstep envelope between the values. - // return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)), - // mix(c, d, smoothstep(0.0, 1.0, f.x)), - // smoothstep(0.0, 1.0, f.y))); - - // Same code, with the clamps in smoothstep and common subexpressions - // optimized away. - vec2 u = f * f * (3.0 - 2.0 * f); - return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; -} - -//============================= - - - void main() { vec4 diff = texture(diffuseRect, vary_fragcoord.xy); -#ifdef HAS_NOISE - vec2 tc = vary_fragcoord.xy*screen_res*4.0; - vec3 seed = (diff.rgb+vec3(1.0))*vec3(tc.xy, tc.x+tc.y); - vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb)); - diff.rgb += nz*0.003; -#endif - frag_color = diff; gl_FragDepth = texture(depthMap, vary_fragcoord.xy).r; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredTonemap.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredTonemap.glsl index fc6d4d7727..9d449a5ae2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredTonemap.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredTonemap.glsl @@ -30,6 +30,7 @@ out vec4 frag_color; uniform sampler2D diffuseRect; uniform sampler2D exposureMap; +uniform float gamma; uniform vec2 screen_res; in vec2 vary_fragcoord; @@ -149,6 +150,42 @@ vec3 toneMap(vec3 color) return color; } +//================================= +// borrowed noise from: +// <https://www.shadertoy.com/view/4dS3Wd> +// By Morgan McGuire @morgan3d, http://graphicscodex.com +// +float hash(float n) { return fract(sin(n) * 1e4); } +float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); } + +float noise(float x) { + float i = floor(x); + float f = fract(x); + float u = f * f * (3.0 - 2.0 * f); + return mix(hash(i), hash(i + 1.0), u); +} + +float noise(vec2 x) { + vec2 i = floor(x); + vec2 f = fract(x); + + // Four corners in 2D of a tile + float a = hash(i); + float b = hash(i + vec2(1.0, 0.0)); + float c = hash(i + vec2(0.0, 1.0)); + float d = hash(i + vec2(1.0, 1.0)); + + // Simple 2D lerp using smoothstep envelope between the values. + // return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)), + // mix(c, d, smoothstep(0.0, 1.0, f.x)), + // smoothstep(0.0, 1.0, f.y))); + + // Same code, with the clamps in smoothstep and common subexpressions + // optimized away. + vec2 u = f * f * (3.0 - 2.0 * f); + return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; +} + //=============================================================== void debugExposure(inout vec3 color) @@ -161,16 +198,40 @@ void debugExposure(inout vec3 color) } } +vec3 legacyGamma(vec3 color) +{ + vec3 c = 1. - clamp(color, vec3(0.), vec3(1.)); + c = 1. - pow(c, vec3(gamma)); // s/b inverted already CPU-side + + return c; +} + void main() { //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) vec4 diff = texture(diffuseRect, vary_fragcoord); +#ifdef TONEMAP #ifndef NO_POST diff.rgb = toneMap(diff.rgb); -#else +#endif +#ifndef GAMMA_CORRECT diff.rgb = clamp(diff.rgb, vec3(0.0), vec3(1.0)); #endif +#endif + +#ifdef GAMMA_CORRECT + diff.rgb = linear_to_srgb(diff.rgb); + +#ifdef LEGACY_GAMMA + diff.rgb = legacyGamma(diff.rgb); +#endif + + vec2 tc = vary_fragcoord.xy*screen_res*4.0; + vec3 seed = (diff.rgb+vec3(1.0))*vec3(tc.xy, tc.x+tc.y); + vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb)); + diff.rgb += nz*0.003; +#endif //debugExposure(diff.rgb); frag_color = max(diff, vec4(0)); |