diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
106 files changed, 2345 insertions, 4115 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl deleted file mode 100644 index 02b2daf0ac..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ /dev/null @@ -1,329 +0,0 @@ -/** - * @file alphaF.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$ - */ - -//class1/deferred/alphaF.glsl - -#extension GL_ARB_texture_rectangle : enable - -/*[EXTRA_CODE_HERE]*/ - -#define INDEXED 1 -#define NON_INDEXED 2 -#define NON_INDEXED_NO_COLOR 3 - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform mat3 env_mat; -uniform vec3 sun_dir; -uniform vec3 moon_dir; - -#ifdef USE_DIFFUSE_TEX -uniform sampler2D diffuseMap; -#endif - -VARYING vec3 vary_fragcoord; -VARYING vec3 vary_position; -VARYING vec2 vary_texcoord0; -VARYING vec3 vary_norm; - -#ifdef USE_VERTEX_COLOR -VARYING vec4 vertex_color; //vertex color should be treated as sRGB -#endif - -#ifdef HAS_ALPHA_MASK -uniform float minimum_alpha; -#endif - -uniform mat4 proj_mat; -uniform mat4 inv_proj; -uniform vec2 screen_res; -uniform int sun_up_factor; -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - -vec3 srgb_to_linear(vec3 c); -vec3 linear_to_srgb(vec3 c); - -vec2 encode_normal (vec3 n); -vec3 scaleSoftClipFrag(vec3 l); -vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive, bool use_ao); - -#ifdef HAS_SHADOW -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -#endif - -float getAmbientClamp(); - -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) -{ - // SL-14895 inverted attenuation work-around - // This routine is tweaked to match deferred lighting, but previously used an inverted la value. To reconstruct - // that previous value now that the inversion is corrected, we reverse the calculations in LLPipeline::setupHWLights() - // to recover the `adjusted_radius` value previously being sent as la. - float falloff_factor = (12.0 * fa) - 9.0; - float inverted_la = falloff_factor / la; - // Yes, it makes me want to cry as well. DJH - - vec3 col = vec3(0); - - //get light vector - vec3 lv = lp.xyz-v; - - //get distance - float dist = length(lv); - float da = 1.0; - - /*if (dist > inverted_la) - { - return col; - } - - clip to projector bounds - vec4 proj_tc = proj_mat * lp; - - if (proj_tc.z < 0 - || proj_tc.z > 1 - || proj_tc.x < 0 - || proj_tc.x > 1 - || proj_tc.y < 0 - || proj_tc.y > 1) - { - return col; - }*/ - - if (dist > 0.0 && inverted_la > 0.0) - { - dist /= inverted_la; - - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= dot(n, lv); - da = max(0.0, da); - - float lit = 0.0f; - - float amb_da = 0.0;//ambiance; - if (da > 0) - { - lit = max(da * dist_atten,0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5+0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); - - // SL-10969 ... need to work out why this blows out in many setups... - //col.rgb += amb_da * light_col * diffuse; - - // no spec for alpha shader... - } - col = max(col, vec3(0)); - return col; -} - -void main() -{ - vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; - frag *= screen_res; - - vec4 pos = vec4(vary_position, 1.0); - vec3 norm = vary_norm; - - float shadow = 1.0f; - -#ifdef HAS_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); -#endif - -#ifdef USE_DIFFUSE_TEX - vec4 diffuse_tap = texture2D(diffuseMap,vary_texcoord0.xy); -#endif - -#ifdef USE_INDEXED_TEX - vec4 diffuse_tap = diffuseLookup(vary_texcoord0.xy); -#endif - - vec4 diffuse_srgb = diffuse_tap; - -#ifdef FOR_IMPOSTOR - vec4 color; - color.rgb = diffuse_srgb.rgb; - color.a = 1.0; - - float final_alpha = diffuse_srgb.a * vertex_color.a; - diffuse_srgb.rgb *= vertex_color.rgb; - - // Insure we don't pollute depth with invis pixels in impostor rendering - // - if (final_alpha < minimum_alpha) - { - discard; - } - - color.rgb = diffuse_srgb.rgb; - color.a = final_alpha; - -#else // FOR_IMPOSTOR - - vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); - - vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; - - float final_alpha = diffuse_linear.a; - -#ifdef USE_VERTEX_COLOR - final_alpha *= vertex_color.a; - - if (final_alpha < minimum_alpha) - { // TODO: figure out how to get invisible faces out of - // render batches without breaking glow - discard; - } - - diffuse_srgb.rgb *= vertex_color.rgb; - diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb); -#endif // USE_VERTEX_COLOR - - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - - vec2 abnormal = encode_normal(norm.xyz); - - float da = dot(norm.xyz, light_dir.xyz); - da = clamp(da, -1.0, 1.0); - da = pow(da, 1.0/1.3); - - float final_da = da; - final_da = clamp(final_da, 0.0f, 1.0f); - - vec4 color = vec4(0.0); - - color.a = final_alpha; - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - vec3 sun_contrib = min(final_da, shadow) * sunlit; - -#if !defined(AMBIENT_KILL) - color.rgb = amblit; - color.rgb *= ambient; -#endif // !defined(AMBIENT_KILL) - -vec3 post_ambient = color.rgb; - -#if !defined(SUNLIGHT_KILL) - color.rgb += sun_contrib; -#endif // !defined(SUNLIGHT_KILL) - -vec3 post_sunlight = color.rgb; - - color.rgb *= diffuse_srgb.rgb; - -vec3 post_diffuse = color.rgb; - - color.rgb = atmosFragLighting(color.rgb, additive, atten); - -vec3 post_atmo = color.rgb; - - vec4 light = vec4(0,0,0,0); - - color.rgb = scaleSoftClipFrag(color.rgb); - - //convert to linear before applying local lights - color.rgb = srgb_to_linear(color.rgb); - - #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); - - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) - - // sum local light contrib in linear colorspace -#if !defined(LOCAL_LIGHT_KILL) - color.rgb += light.rgb; -#endif // !defined(LOCAL_LIGHT_KILL) - // back to sRGB as we're going directly to the final RT post-deferred gamma correction - color.rgb = linear_to_srgb(color.rgb); - -//color.rgb = amblit; -//color.rgb = vec3(ambient); -//color.rgb = sunlit; -//color.rgb = vec3(final_da); -//color.rgb = post_ambient; -//color.rgb = post_sunlight; -//color.rgb = sun_contrib; -//color.rgb = diffuse_srgb.rgb; -//color.rgb = post_diffuse; -//color.rgb = post_atmo; - -#ifdef WATER_FOG - color = applyWaterFogView(pos.xyz, color); -#endif // WATER_FOG - -#endif // #else // FOR_IMPOSTOR - - 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 6a93bc2fd2..4c9d813c9c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaV.glsl @@ -33,19 +33,19 @@ uniform mat4 projection_matrix; uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; +in vec3 position; #ifdef USE_INDEXED_TEX void passTextureIndex(); #endif -ATTRIBUTE vec3 normal; +in vec3 normal; #ifdef USE_VERTEX_COLOR -ATTRIBUTE vec4 diffuse_color; +in vec4 diffuse_color; #endif -ATTRIBUTE vec2 texcoord0; +in vec2 texcoord0; #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); @@ -55,15 +55,15 @@ mat4 getSkinnedTransform(); #endif #endif -VARYING vec3 vary_fragcoord; -VARYING vec3 vary_position; +out vec3 vary_fragcoord; +out vec3 vary_position; #ifdef USE_VERTEX_COLOR -VARYING vec4 vertex_color; +out vec4 vertex_color; #endif -VARYING vec2 vary_texcoord0; -VARYING vec3 vary_norm; +out vec2 vary_texcoord0; +out vec3 vary_norm; uniform float near_clip; diff --git a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl index 23adbded5e..da467cd5da 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl @@ -24,8 +24,8 @@ */ uniform sampler2D noiseMap; -uniform sampler2DRect normalMap; -uniform sampler2DRect depthMap; +uniform sampler2D normalMap; +uniform sampler2D depthMap; uniform float ssao_radius; uniform float ssao_max_radius; @@ -38,16 +38,12 @@ uniform vec2 screen_res; vec2 getScreenCoordinateAo(vec2 screenpos) { vec2 sc = screenpos.xy * 2.0; - if (screen_res.x > 0 && screen_res.y > 0) - { - sc /= screen_res; - } return sc - vec2(1.0, 1.0); } float getDepthAo(vec2 pos_screen) { - float depth = texture2DRect(depthMap, pos_screen).r; + float depth = texture(depthMap, pos_screen).r; return depth; } @@ -75,7 +71,7 @@ vec2 getKern(int i) kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - return kern[i]; + return kern[i] / screen_res; } //calculate decreases in ambient lighting when crowded out (SSAO) @@ -83,8 +79,8 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) { float ret = 1.0; vec3 pos_world = pos.xyz; - vec2 noise_reflect = texture2D(noiseMap, pos_screen.xy/128.0).xy; - + vec2 noise_reflect = texture(noiseMap, pos_screen.xy * (screen_res / 128)).xy; + float angle_hidden = 0.0; float points = 0; @@ -95,7 +91,7 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) { vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); vec3 samppos_world = getPositionAo(samppos_screen).xyz; - + vec3 diff = pos_world - samppos_world; float dist2 = dot(diff, diff); diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaMaskShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaMaskShadowF.glsl deleted file mode 100644 index c64b6ba240..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaMaskShadowF.glsl +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file attachmentAlphaMaskShadowF.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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 - -uniform float minimum_alpha; - -uniform sampler2D diffuseMap; - -VARYING vec4 post_pos; -VARYING vec2 vary_texcoord0; -VARYING float pos_w; -VARYING float target_pos_x; -VARYING vec4 vertex_color; - -void main() -{ - float alpha = texture2D(diffuseMap, vary_texcoord0.xy).a; - - if (alpha < 0.05) // treat as totally transparent - { - discard; - } - - if (alpha < minimum_alpha) // treat as semi-transparent - { - //if (fract(0.5*floor(target_pos_x / pos_w )) < 0.25) - { - discard; - } - } - - 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/attachmentAlphaShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowF.glsl deleted file mode 100644 index b54c580ce9..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowF.glsl +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @file attachmentAlphaShadowF.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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 - -uniform float minimum_alpha; -uniform sampler2D diffuseMap; - -VARYING float pos_w; -VARYING float target_pos_x; - -#if !DEPTH_CLAMP -VARYING vec4 post_pos; -#endif - -VARYING vec2 vary_texcoord0; -VARYING vec4 vertex_color; - -void main() -{ - float alpha = texture2D(diffuseMap, vary_texcoord0.xy).a * vertex_color.a; - - if (alpha < 0.05) // treat as totally transparent - { - discard; - } - - if (alpha < minimum_alpha) - { - if (fract(0.5*floor(target_pos_x / pos_w )) < 0.25) - { - discard; - } - } - - 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/attachmentAlphaShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowV.glsl deleted file mode 100644 index 31b93dc36a..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowV.glsl +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @file attachmentShadowV.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 projection_matrix; -uniform mat4 modelview_matrix; -uniform mat4 texture_matrix0; -uniform float shadow_target_width; - -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; - -mat4 getObjectSkinnedTransform(); -void passTextureIndex(); - -#if !DEPTH_CLAMP -VARYING vec4 post_pos; -#endif -VARYING vec2 vary_texcoord0; -VARYING float pos_w; -VARYING float target_pos_x; -VARYING vec4 vertex_color; - -void main() -{ - //transform vertex - mat4 mat = getObjectSkinnedTransform(); - - mat = modelview_matrix * mat; - vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz; - - vec4 p = projection_matrix * vec4(pos, 1.0); - - pos_w = p.w; - - target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - - vertex_color = diffuse_color; - -#if !DEPTH_CLAMP - p.z = max(p.z, -p.w+0.01); - post_pos = p; - gl_Position = p; -#else - gl_Position = p; -#endif - - passTextureIndex(); -} - diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl deleted file mode 100644 index 0fa0edfd67..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @file attachmentShadowV.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 projection_matrix; -uniform mat4 modelview_matrix; -uniform mat4 texture_matrix0; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -mat4 getObjectSkinnedTransform(); - -void main() -{ - //transform vertex - mat4 mat = getObjectSkinnedTransform(); - - mat = modelview_matrix * mat; - vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz; - - - vec4 p = projection_matrix * vec4(pos, 1.0); -#if !defined(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/avatarAlphaMaskShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaMaskShadowF.glsl index b8ce54bcb1..f1dc1159d0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaMaskShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaMaskShadowF.glsl @@ -1,5 +1,5 @@ /** - * @file treeShadowF.glsl + * @file avatarAlphaMaskShadowF.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -23,26 +23,18 @@ * $/LicenseInfo$ */ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform float minimum_alpha; uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP -VARYING vec4 post_pos; -#endif - -VARYING float target_pos_x; -VARYING float pos_w; -VARYING vec2 vary_texcoord0; +in float target_pos_x; +in float pos_w; +in vec2 vary_texcoord0; void main() { - float alpha = texture2D(diffuseMap, vary_texcoord0.xy).a; + float alpha = texture(diffuseMap, vary_texcoord0.xy).a; if (alpha < 0.05) // treat as totally transparent { @@ -58,8 +50,4 @@ 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/avatarAlphaNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl deleted file mode 100644 index bbdc8fdd1c..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl +++ /dev/null @@ -1,112 +0,0 @@ -/** - * @file avatarAlphaNoColorV.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 projection_matrix; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; - -mat4 getSkinnedTransform(); -void calcAtmospherics(vec3 inPositionEye); - -float calcDirectionalLight(vec3 n, vec3 l); - -vec3 atmosAmbient(); -vec3 atmosAffectDirectionalLight(float lightIntensity); - -VARYING vec3 vary_position; -VARYING vec3 vary_ambient; -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; - -uniform vec4 color; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight); - -void main() -{ - vary_texcoord0 = texcoord0; - - vec4 pos; - vec3 norm; - - 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); - vary_norm = norm; - - vec4 frag_pos = projection_matrix * pos; - gl_Position = frag_pos; - - vary_position = pos.xyz; - - calcAtmospherics(pos.xyz); - - vec4 col = vec4(0.0, 0.0, 0.0, 1.0); - - // 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*color.rgb; - - col.rgb = vec3(0,0,0); - - // Add windlight lights - col.rgb = atmosAmbient(); - - vary_ambient = col.rgb*color.rgb; - vary_directional = color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), 0.0)); - - col.rgb = col.rgb * color.rgb; - - vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -} - - diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl index 1b16e4eb09..097e28aa0c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl @@ -23,28 +23,20 @@ * $/LicenseInfo$ */ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform float minimum_alpha; uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP -VARYING vec4 post_pos; -#endif - -VARYING float pos_w; -VARYING float target_pos_x; -VARYING vec2 vary_texcoord0; +in float pos_w; +in float target_pos_x; +in vec2 vary_texcoord0; uniform vec4 color; void main() { - float alpha = texture2D(diffuseMap, vary_texcoord0.xy).a * color.a; + float alpha = texture(diffuseMap, vary_texcoord0.xy).a * color.a; if (alpha < 0.05) // treat as totally transparent { @@ -60,9 +52,4 @@ 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/avatarAlphaShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowV.glsl index 1c5b142ebd..57e0b2b59f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowV.glsl @@ -1,5 +1,5 @@ /** - * @file avatarShadowV.glsl + * @file avatarAlphaShadowV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -30,16 +30,13 @@ uniform float shadow_target_width; mat4 getSkinnedTransform(); void passTextureIndex(); -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec3 normal; +in vec2 texcoord0; -#if !DEPTH_CLAMP -VARYING vec4 post_pos; -#endif -VARYING float pos_w; -VARYING float target_pos_x; -VARYING vec2 vary_texcoord0; +out float pos_w; +out float target_pos_x; +out vec2 vary_texcoord0; void main() { @@ -66,13 +63,7 @@ void main() vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -#if !DEPTH_CLAMP - post_pos = pos; - - 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/avatarEyesV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl index 01ffb862f7..83b0ba096c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl @@ -27,14 +27,14 @@ uniform mat3 normal_matrix; uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec3 normal; +in vec4 diffuse_color; +in vec2 texcoord0; -VARYING vec3 vary_normal; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +out vec3 vary_normal; +out vec4 vertex_color; +out vec2 vary_texcoord0; void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index 60d83cc623..6ebe4ce251 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -25,24 +25,20 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif uniform sampler2D diffuseMap; uniform float minimum_alpha; -VARYING vec3 vary_normal; -VARYING vec2 vary_texcoord0; +in vec3 vary_normal; +in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); void main() { - vec4 diff = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 diff = texture(diffuseMap, vary_texcoord0.xy); if (diff.a < minimum_alpha) { @@ -52,6 +48,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(encode_normal(nvn.xyz), 0.0, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl index 50020a50d8..0c386ade6c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowF.glsl @@ -25,24 +25,12 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform sampler2D diffuseMap; -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif - void main() { frag_color = vec4(1,1,1,1); - -#if !defined(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 91b25613e0..5c64d48399 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl @@ -27,13 +27,9 @@ uniform mat4 projection_matrix; mat4 getSkinnedTransform(); -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; - -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif +in vec3 position; +in vec3 normal; +in vec2 texcoord0; void main() { @@ -53,13 +49,7 @@ void main() norm = normalize(norm); pos = projection_matrix * pos; -#if !defined(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/avatarV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl index 1bd8fee7c9..bc0c11ec46 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl @@ -25,16 +25,16 @@ uniform mat4 projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec3 normal; +in vec2 texcoord0; mat4 getSkinnedTransform(); -ATTRIBUTE vec4 weight; +in vec4 weight; -VARYING vec3 vary_normal; -VARYING vec2 vary_texcoord0; +out vec3 vary_normal; +out vec2 vary_texcoord0; void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 596d0274af..08baf98686 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -23,26 +23,21 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2DRect normalMap; -uniform sampler2DRect lightMap; +uniform sampler2D normalMap; +uniform sampler2D lightMap; uniform float dist_factor; uniform float blur_size; uniform vec2 delta; +uniform vec2 screen_res; uniform vec3 kern[4]; uniform float kern_scale; -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; vec4 getPosition(vec2 pos_screen); vec3 getNorm(vec2 pos_screen); @@ -52,8 +47,8 @@ void main() vec2 tc = vary_fragcoord.xy; vec3 norm = getNorm(tc); vec3 pos = getPosition(tc).xyz; - vec4 ccol = texture2DRect(lightMap, tc).rgba; - + vec4 ccol = texture(lightMap, tc).rgba; + vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); dlt /= max(-pos.z*dist_factor, 1.0); @@ -64,43 +59,57 @@ void main() float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005; // perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large - float tc_mod = 0.5*(tc.x + tc.y); // mod(tc.x+tc.y,2) + tc *= screen_res; + float tc_mod = 0.5*(tc.x + tc.y); tc_mod -= floor(tc_mod); tc_mod *= 2.0; tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); - for (int i = 1; i < 4; i++) + // TODO: move this to kern instead of building kernel per pixel + vec3 k[7]; + k[0] = kern[0]; + k[2] = kern[1]; + k[4] = kern[2]; + k[6] = kern[3]; + + k[1] = (k[0]+k[2])*0.5f; + k[3] = (k[2]+k[4])*0.5f; + k[5] = (k[4]+k[6])*0.5f; + + for (int i = 1; i < 7; i++) { - vec2 samptc = tc + kern[i].z*dlt; + vec2 samptc = tc + k[i].z*dlt*2.0; + samptc /= screen_res; vec3 samppos = getPosition(samptc).xyz; float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane if (d*d <= pointplanedist_tolerance_pow2) { - col += texture2DRect(lightMap, samptc)*kern[i].xyxx; - defined_weight += kern[i].xy; + col += texture(lightMap, samptc)*k[i].xyxx; + defined_weight += k[i].xy; } } - for (int i = 1; i < 4; i++) + for (int i = 1; i < 7; i++) { - vec2 samptc = tc - kern[i].z*dlt; + vec2 samptc = tc - k[i].z*dlt*2.0; + samptc /= screen_res; vec3 samppos = getPosition(samptc).xyz; float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane if (d*d <= pointplanedist_tolerance_pow2) { - col += texture2DRect(lightMap, samptc)*kern[i].xyxx; - defined_weight += kern[i].xy; + col += texture(lightMap, samptc)*k[i].xyxx; + defined_weight += k[i].xy; } } col /= defined_weight.xyxx; - col.y *= col.y; + //col.y *= col.y; - frag_color = col; + frag_color = max(col, vec4(0)); #ifdef IS_AMD_CARD // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl index 212f7e56ad..5abaa1f2a6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl @@ -23,17 +23,15 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; +in vec3 position; -ATTRIBUTE vec3 position; - -VARYING vec2 vary_fragcoord; +out vec2 vary_fragcoord; uniform vec2 screen_res; void main() { //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 pos = vec4(position.xyz, 1.0); gl_Position = pos; - vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; + vary_fragcoord = (pos.xy*0.5+0.5); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index b5677a07ee..35f483f633 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -25,28 +25,24 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; uniform float minimum_alpha; uniform sampler2D diffuseMap; uniform sampler2D bumpMap; -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; +in vec3 vary_mat0; +in vec3 vary_mat1; +in vec3 vary_mat2; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec4 vertex_color; +in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); void main() { - vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col = texture(diffuseMap, vary_texcoord0.xy); if(col.a < minimum_alpha) { @@ -54,7 +50,7 @@ void main() } col *= vertex_color; - vec3 norm = texture2D(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0; + vec3 norm = texture(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0; vec3 tnorm = vec3(dot(norm,vary_mat0), dot(norm,vary_mat1), @@ -64,5 +60,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(tnorm); - frag_data[2] = vec4(encode_normal(nvn), vertex_color.a, 0.0); + frag_data[2] = vec4(encode_normal(nvn), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl index d90891aa20..3af2eab1e4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl @@ -27,17 +27,17 @@ 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 vec4 tangent; +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec2 texcoord0; +in vec4 tangent; -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +out vec3 vary_mat0; +out vec3 vary_mat1; +out vec3 vary_mat2; +out vec4 vertex_color; +out vec2 vary_texcoord0; #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl deleted file mode 100644 index 0157d166e0..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl +++ /dev/null @@ -1,127 +0,0 @@ -/** - * @file class3/deferred/cloudsF.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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 - -uniform sampler2D diffuseMap; - -VARYING vec4 pos; -VARYING float target_pos_x; -VARYING float vary_CloudDensity; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; - -uniform sampler2D cloud_noise_texture; -uniform sampler2D cloud_noise_texture_next; -uniform float blend_factor; -uniform vec4 cloud_pos_density1; -uniform vec4 cloud_pos_density2; -uniform vec4 sunlight_color; -uniform vec4 cloud_color; -uniform float cloud_shadow; -uniform float cloud_scale; -uniform float cloud_variance; -uniform vec3 camPosLocal; -uniform vec3 sun_dir; -uniform float sun_size; -uniform float far_z; - -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif - -vec4 cloudNoise(vec2 uv) -{ - vec4 a = texture2D(cloud_noise_texture, uv); - vec4 b = texture2D(cloud_noise_texture_next, uv); - vec4 cloud_noise_sample = mix(a, b, blend_factor); - return normalize(cloud_noise_sample); -} - -void main() -{ - // Set variables - vec2 uv1 = vary_texcoord0.xy; - vec2 uv2 = vary_texcoord1.xy; - vec2 uv3 = vary_texcoord2.xy; - float cloudDensity = 2.0 * (cloud_shadow - 0.25); - - if (cloud_scale >= 0.0001) - { - vec2 uv4 = vary_texcoord3.xy; - - vec2 disturbance = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); - - // Offset texture coords - uv1 += cloud_pos_density1.xy + (disturbance * 0.2); //large texture, visible density - uv2 += cloud_pos_density1.xy; //large texture, self shadow - uv3 += cloud_pos_density2.xy; //small texture, visible density - uv4 += cloud_pos_density2.xy; //small texture, self shadow - - float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); - - cloudDensity *= 1.0 - (density_variance * density_variance); - - // Compute alpha1, the main cloud opacity - float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; - alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); - - // And smooth - alpha1 = 1. - alpha1 * alpha1; - alpha1 = 1. - alpha1 * alpha1; - - if (alpha1 < 0.001f) - { - discard; - } - - // Compute alpha2, for self shadowing effect - // (1 - alpha2) will later be used as percentage of incoming sunlight - float alpha2 = (cloudNoise(uv2).x - 0.5); - alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); - - // And smooth - alpha2 = 1. - alpha2; - alpha2 = 1. - alpha2 * alpha2; - - frag_color = vec4(alpha1, alpha1, alpha1, 1); - } - else - { - frag_color = vec4(1); - } - -#if !defined(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/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl deleted file mode 100644 index effb070f93..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @file cloudShadowV.glsl - * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2011, 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; -uniform float shadow_target_width; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; - -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING vec4 pos; -VARYING float target_pos_x; -VARYING vec2 vary_texcoord0; -VARYING vec4 vertex_color; - -void passTextureIndex(); - -void main() -{ - //transform vertex - vec4 pre_pos = vec4(position.xyz, 1.0); - pos = modelview_projection_matrix * pre_pos; - target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; - -#if !defined(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(); - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - vertex_color = diffuse_color; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index ae1ac5de7f..f6870c3ff0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -24,41 +24,34 @@ */ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; ///////////////////////////////////////////////////////////////////////// // The fragment shader for the sky ///////////////////////////////////////////////////////////////////////// -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; -VARYING float vary_CloudDensity; +in vec3 vary_CloudColorSun; +in vec3 vary_CloudColorAmbient; +in float vary_CloudDensity; uniform sampler2D cloud_noise_texture; uniform sampler2D cloud_noise_texture_next; uniform float blend_factor; -uniform vec4 cloud_pos_density1; -uniform vec4 cloud_pos_density2; +uniform vec3 cloud_pos_density1; +uniform vec3 cloud_pos_density2; uniform float cloud_scale; uniform float cloud_variance; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; -VARYING float altitude_blend_factor; - -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light); +in vec2 vary_texcoord0; +in vec2 vary_texcoord1; +in vec2 vary_texcoord2; +in vec2 vary_texcoord3; +in float altitude_blend_factor; vec4 cloudNoise(vec2 uv) { - vec4 a = texture2D(cloud_noise_texture, uv); - vec4 b = texture2D(cloud_noise_texture_next, uv); + vec4 a = texture(cloud_noise_texture, uv); + vec4 b = texture(cloud_noise_texture_next, uv); vec4 cloud_noise_sample = mix(a, b, blend_factor); return cloud_noise_sample; } @@ -69,8 +62,8 @@ void main() vec2 uv1 = vary_texcoord0.xy; vec2 uv2 = vary_texcoord1.xy; - vec4 cloudColorSun = vary_CloudColorSun; - vec4 cloudColorAmbient = vary_CloudColorAmbient; + vec3 cloudColorSun = vary_CloudColorSun; + vec3 cloudColorAmbient = vary_CloudColorAmbient; float cloudDensity = vary_CloudDensity; vec2 uv3 = vary_texcoord2.xy; vec2 uv4 = vary_texcoord3.xy; @@ -115,17 +108,15 @@ void main() alpha2 = 1. - alpha2 * alpha2; // Combine - vec4 color; + vec3 color; color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient); - color.rgb= max(vec3(0), color.rgb); + color.rgb = clamp(color.rgb, vec3(0), vec3(1)); color.rgb *= 2.0; - color.rgb = scaleSoftClip(color.rgb); /// Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(color.rgb, alpha1); + frag_data[0] = vec4(0); frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0,0,0,1); - - gl_FragDepth = 0.99995f; + frag_data[2] = vec4(0,0,0,GBUFFER_FLAG_SKIP_ATMOS); + frag_data[3] = vec4(color.rgb, alpha1); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 8e0a001403..98314d39d3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -25,34 +25,34 @@ uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec2 texcoord0; ////////////////////////////////////////////////////////////////////////// // The vertex shader for creating the atmospheric sky /////////////////////////////////////////////////////////////////////////////// // Output parameters -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; -VARYING float vary_CloudDensity; +out vec3 vary_CloudColorSun; +out vec3 vary_CloudColorAmbient; +out float vary_CloudDensity; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; -VARYING float altitude_blend_factor; +out vec2 vary_texcoord0; +out vec2 vary_texcoord1; +out vec2 vary_texcoord2; +out vec2 vary_texcoord3; +out float altitude_blend_factor; // Inputs uniform vec3 camPosLocal; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; +uniform vec3 lightnorm; +uniform vec3 sunlight_color; +uniform vec3 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient_color; -uniform vec4 blue_horizon; -uniform vec4 blue_density; +uniform vec3 ambient_color; +uniform vec3 blue_horizon; +uniform vec3 blue_density; uniform float haze_horizon; uniform float haze_density; @@ -60,10 +60,10 @@ uniform float cloud_shadow; uniform float density_multiplier; uniform float max_y; -uniform vec4 glow; +uniform vec3 glow; uniform float sun_moon_glow_factor; -uniform vec4 cloud_color; +uniform vec3 cloud_color; uniform float cloud_scale; @@ -114,17 +114,17 @@ void main() float rel_pos_len = length(rel_pos); // Initialize temp variables - vec4 sunlight = sunlight_color; - vec4 light_atten; + vec3 sunlight = sunlight_color; + vec3 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); + light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights - vec4 combined_haze = abs(blue_density) + vec4(abs(haze_density)); - vec4 blue_weight = blue_density / combined_haze; - vec4 haze_weight = haze_density / combined_haze; + vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density)); + vec3 blue_weight = blue_density / combined_haze; + vec3 haze_weight = haze_density / combined_haze; // Compute sunlight from rel_pos & lightnorm (for long rays like sky) float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y); @@ -155,18 +155,18 @@ void main() haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (haze_glow + 0.25); // Increase ambient when there are more clouds - vec4 tmpAmbient = ambient_color; + vec3 tmpAmbient = ambient_color; tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage sunlight *= (1. - cloud_shadow); // Haze color below cloud - vec4 additiveColorBelowCloud = + vec3 additiveColorBelowCloud = (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + tmpAmbient)); // CLOUDS - sunlight = sunlight_color; // SL-14707 reset color -- Clouds are unusually dim in EEP + sunlight = sunlight_color; off_axis = 1.0 / max(1e-6, lightnorm.y * 2.); sunlight *= exp(-light_atten * off_axis); @@ -178,7 +178,7 @@ void main() combined_haze = sqrt(combined_haze); // less atmos opacity (more transparency) below clouds vary_CloudColorSun *= combined_haze; vary_CloudColorAmbient *= combined_haze; - vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - combined_haze); + vec3 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - combined_haze); // Make a nice cloud density based on the cloud_shadow value that was passed in. vary_CloudDensity = 2. * (cloud_shadow - 0.25); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl index 079d8458c9..d95a33a6be 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl @@ -23,19 +23,12 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect depthMap; -uniform sampler2D bloomMap; +uniform sampler2D diffuseRect; +uniform sampler2D depthMap; uniform float depth_cutoff; uniform float norm_cutoff; @@ -48,7 +41,7 @@ uniform float max_cof; uniform mat4 inv_proj; uniform vec2 screen_res; -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; float calc_cof(float depth) { @@ -69,19 +62,18 @@ void main() { vec2 tc = vary_fragcoord.xy; - float z = texture2DRect(depthMap, tc).r; + float z = texture(depthMap, tc).r; z = z*2.0-1.0; vec4 ndc = vec4(0.0, 0.0, z, 1.0); vec4 p = inv_proj*ndc; float depth = p.z/p.w; - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); + vec4 diff = texture(diffuseRect, vary_fragcoord.xy); float sc = calc_cof(depth); sc = min(sc, max_cof); sc = max(sc, -max_cof); - vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res); - frag_color.rgb = diff.rgb + bloom.rgb; + frag_color.rgb = diff.rgb; frag_color.a = sc/max_cof*0.5+0.5; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index e27bbce094..c8eaba6418 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -23,25 +23,128 @@ * $/LicenseInfo$ */ -uniform sampler2DRect normalMap; -uniform sampler2DRect depthMap; + +/* Parts of this file are taken from Sascha Willem's Vulkan GLTF refernce implementation +MIT License + +Copyright (c) 2018 Sascha Willems + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +uniform sampler2D normalMap; +uniform sampler2D depthMap; +uniform sampler2D projectionMap; // rgba +uniform sampler2D brdfLut; + +// projected lighted params +uniform mat4 proj_mat; //screen space to light space projector +uniform vec3 proj_n; // projector normal +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform float proj_focus; // distance from plane to begin blurring +uniform float proj_lod ; // (number of mips in proj map) +uniform float proj_range; // range between near clip and far clip plane of projection +uniform float proj_ambiance; + +// light params +uniform vec3 color; // light_color +uniform float size; // light_size uniform mat4 inv_proj; uniform vec2 screen_res; -vec2 getScreenCoordinate(vec2 screenpos) +const float M_PI = 3.14159265; +const float ONE_OVER_PI = 0.3183098861; + +vec3 srgb_to_linear(vec3 cs); +vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); + +float calcLegacyDistanceAttenuation(float distance, float falloff) { - vec2 sc = screenpos.xy * 2.0; - if (screen_res.x > 0 && screen_res.y > 0) + float dist_atten = 1.0 - clamp((distance + falloff)/(1.0 + falloff), 0.0, 1.0); + dist_atten *= dist_atten; + + // Tweak falloff slightly to match pre-EEP attenuation + // NOTE: this magic number also shows up in a great many other places, search for dist_atten *= to audit + dist_atten *= 2.0; + return dist_atten; +} + +// In: +// lv unnormalized surface to light vector +// n normal of the surface +// pos unnormalized camera to surface vector +// Out: +// l normalized surace to light vector +// nl diffuse angle +// nh specular angle +void calcHalfVectors(vec3 lv, vec3 n, vec3 v, + out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist) +{ + l = normalize(lv); + h = normalize(l + v); + nh = clamp(dot(n, h), 0.0, 1.0); + nl = clamp(dot(n, l), 0.0, 1.0); + nv = clamp(dot(n, v), 0.0, 1.0); + vh = clamp(dot(v, h), 0.0, 1.0); + + lightDist = length(lv); +} + +// In: +// light_center +// pos +// Out: +// dist +// l_dist +// lv +// proj_tc Projector Textue Coordinates +bool clipProjectedLightVars(vec3 light_center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ) +{ + lv = light_center - pos.xyz; + dist = length(lv); + bool clipped = (dist >= size); + if ( !clipped ) { - sc /= screen_res; + dist /= size; + + l_dist = -dot(lv, proj_n); + vec4 projected_point = (proj_mat * vec4(pos.xyz, 1.0)); + clipped = (projected_point.z < 0.0); + projected_point.xyz /= projected_point.w; + proj_tc = projected_point; } + + return clipped; +} + +vec2 getScreenCoordinate(vec2 screenpos) +{ + vec2 sc = screenpos.xy * 2.0; return sc - vec2(1.0, 1.0); } +// See: https://aras-p.info/texts/CompactNormalStorage.html +// Method #4: Spheremap Transform, Lambert Azimuthal Equal-Area projection vec3 getNorm(vec2 screenpos) { - vec2 enc = texture2DRect(normalMap, screenpos.xy).xy; + vec2 enc = texture(normalMap, screenpos.xy).xy; vec2 fenc = enc*4-2; float f = dot(fenc,fenc); float g = sqrt(1-f/4); @@ -51,12 +154,160 @@ vec3 getNorm(vec2 screenpos) return n; } +vec3 getNormalFromPacked(vec4 packedNormalEnvIntensityFlags) +{ + vec2 enc = packedNormalEnvIntensityFlags.xy; + 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 normalize(n); // TODO: Is this normalize redundant? +} + +// return packedNormalEnvIntensityFlags since GBUFFER_FLAG_HAS_PBR needs .w +// See: C++: addDeferredAttachments(), GLSL: softenLightF +vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity) +{ + vec4 packedNormalEnvIntensityFlags = texture(normalMap, screenpos.xy); + n = getNormalFromPacked( packedNormalEnvIntensityFlags ); + envIntensity = packedNormalEnvIntensityFlags.z; + return packedNormalEnvIntensityFlags; +} + +// get linear depth value given a depth buffer sample d and znear and zfar values +float linearDepth(float d, float znear, float zfar) +{ + d = d * 2.0 - 1.0; + return znear * 2.0 * zfar / (zfar + znear - d * (zfar - znear)); +} + +float linearDepth01(float d, float znear, float zfar) +{ + return linearDepth(d, znear, zfar) / zfar; +} + float getDepth(vec2 pos_screen) { - float depth = texture2DRect(depthMap, pos_screen).r; + float depth = texture(depthMap, pos_screen).r; return depth; } +vec4 getTexture2DLodAmbient(vec2 tc, float lod) +{ +#ifndef FXAA_GLSL_120 + vec4 ret = textureLod(projectionMap, tc, lod); +#else + vec4 ret = texture(projectionMap, tc); +#endif + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = tc-vec2(0.5); + float d = dot(dist,dist); + ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + + return ret; +} + +vec4 getTexture2DLodDiffuse(vec2 tc, float lod) +{ +#ifndef FXAA_GLSL_120 + vec4 ret = textureLod(projectionMap, tc, lod); +#else + vec4 ret = texture(projectionMap, tc); +#endif + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + float det = min(lod/(proj_lod*0.5), 1.0); + float d = min(dist.x, dist.y); + float edge = 0.25*det; + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +// lit This is set by the caller: if (nl > 0.0) { lit = attenuation * nl * noise; } +// Uses: +// color Projected spotlight color +vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv) +{ + vec4 amb_plcol = getTexture2DLodAmbient(projected_uv, proj_lod); + vec3 amb_rgb = amb_plcol.rgb * amb_plcol.a; + + amb_da += proj_ambiance; + amb_da += (nl*nl*0.5+0.5) * proj_ambiance; + amb_da *= attenuation * noise; + amb_da = min(amb_da, 1.0-lit); + + return (amb_da * color.rgb * amb_rgb); +} + +// Returns projected light in Linear +// Uses global spotlight color: +// color +// NOTE: projected.a will be pre-multiplied with projected.rgb +vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv) +{ + float diff = clamp((light_distance - proj_focus)/proj_range, 0.0, 1.0); + float lod = diff * proj_lod; + vec4 plcol = getTexture2DLodDiffuse(projected_uv.xy, lod); + + return color.rgb * plcol.rgb * plcol.a; +} + +vec4 texture2DLodSpecular(vec2 tc, float lod) +{ +#ifndef FXAA_GLSL_120 + vec4 ret = textureLod(projectionMap, tc, lod); +#else + vec4 ret = texture(projectionMap, tc); +#endif + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + float det = min(lod/(proj_lod*0.5), 1.0); + float d = min(dist.x, dist.y); + d *= min(1, d * (proj_lod - lod)); // BUG? extra factor compared to diffuse causes N repeats + float edge = 0.25*det; + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +// See: clipProjectedLightVars() +vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n ) +{ + vec3 slit = vec3(0); + vec3 ref = reflect(normalize(pos), n); + + //project from point pos in direction ref to plane proj_p, proj_n + vec3 pdelta = proj_p-pos; + float l_dist = length(pdelta); + float ds = dot(ref, proj_n); + if (ds < 0.0) + { + vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + if (stc.z > 0.0) + { + stc /= stc.w; + slit = getProjectedLightDiffuseColor( l_dist, stc.xy ); // NOTE: Using diffuse due to texture2DLodSpecular() has extra: d *= min(1, d * (proj_lod - lod)); + } + } + return slit; // specular light +} + +vec3 getProjectedLightSpecularColor(float light_distance, vec2 projected_uv) +{ + float diff = clamp((light_distance - proj_focus)/proj_range, 0.0, 1.0); + float lod = diff * proj_lod; + vec4 plcol = getTexture2DLodDiffuse(projected_uv.xy, lod); // NOTE: Using diffuse due to texture2DLodSpecular() has extra: d *= min(1, d * (proj_lod - lod)); + + return color.rgb * plcol.rgb * plcol.a; +} + vec4 getPosition(vec2 pos_screen) { float depth = getDepth(pos_screen); @@ -68,12 +319,286 @@ vec4 getPosition(vec2 pos_screen) return pos; } +// get position given a normalized device coordinate +vec3 getPositionWithNDC(vec3 ndc) +{ + vec4 pos = inv_proj * vec4(ndc, 1.0); + return pos.xyz / pos.w; +} + vec4 getPositionWithDepth(vec2 pos_screen, float depth) { vec2 sc = getScreenCoordinate(pos_screen); - 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 ndc = vec3(sc.x, sc.y, 2.0*depth-1.0); + return vec4(getPositionWithNDC(ndc), 1.0); +} + +vec2 getScreenCoord(vec4 clip) +{ + vec4 ndc = clip; + ndc.xyz /= clip.w; + vec2 screen = vec2( ndc.xy * 0.5 ); + screen += 0.5; + return screen; +} + +vec2 getScreenXY(vec4 clip) +{ + vec4 ndc = clip; + ndc.xyz /= clip.w; + vec2 screen = vec2( ndc.xy * 0.5 ); + screen += 0.5; + screen *= screen_res; + return screen; +} + +// Color utils + +vec3 colorize_dot(float x) +{ + if (x > 0.0) return vec3( 0, x, 0 ); + if (x < 0.0) return vec3(-x, 0, 0 ); + return vec3( 0, 0, 1 ); +} + +vec3 hue_to_rgb(float hue) +{ + if (hue > 1.0) return vec3(0.5); + vec3 rgb = abs(hue * 6. - vec3(3, 2, 4)) * vec3(1, -1, -1) + vec3(-1, 2, 2); + return clamp(rgb, 0.0, 1.0); +} + +// PBR Utils + +vec2 BRDF(float NoV, float roughness) +{ + return texture(brdfLut, vec2(NoV, roughness)).rg; +} + +// set colorDiffuse and colorSpec to the results of GLTF PBR style IBL +vec3 pbrIbl(vec3 diffuseColor, + vec3 specularColor, + vec3 radiance, // radiance map sample + vec3 irradiance, // irradiance map sample + float ao, // ambient occlusion factor + float nv, // normal dot view vector + float perceptualRough, + out vec3 specContrib) +{ + // retrieve a scale and bias to F0. See [1], Figure 3 + vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRough); + vec3 diffuseLight = irradiance; + vec3 specularLight = radiance; + + vec3 diffuse = diffuseLight * diffuseColor; + vec3 specular = specularLight * (specularColor * brdf.x + brdf.y); + + specContrib = specular * ao; + + return (diffuse + specular) * ao; +} + +vec3 pbrIbl(vec3 diffuseColor, + vec3 specularColor, + vec3 radiance, // radiance map sample + vec3 irradiance, // irradiance map sample + float ao, // ambient occlusion factor + float nv, // normal dot view vector + float perceptualRough) +{ + vec3 specContrib; + return pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, nv, perceptualRough, specContrib); +} + + +// Encapsulate the various inputs used by the various functions in the shading equation +// We store values in this struct to simplify the integration of alternative implementations +// of the shading terms, outlined in the Readme.MD Appendix. +struct PBRInfo +{ + float NdotL; // cos angle between normal and light direction + float NdotV; // cos angle between normal and view direction + float NdotH; // cos angle between normal and half vector + float LdotH; // cos angle between light direction and half vector + float VdotH; // cos angle between view direction and half vector + float perceptualRoughness; // roughness value, as authored by the model creator (input to shader) + float metalness; // metallic value at the surface + vec3 reflectance0; // full reflectance color (normal incidence angle) + vec3 reflectance90; // reflectance color at grazing angle + float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2]) + vec3 diffuseColor; // color contribution from diffuse lighting + vec3 specularColor; // color contribution from specular lighting +}; + +// Basic Lambertian diffuse +// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog +// See also [1], Equation 1 +vec3 diffuse(PBRInfo pbrInputs) +{ + return pbrInputs.diffuseColor / M_PI; +} + +// The following equation models the Fresnel reflectance term of the spec equation (aka F()) +// Implementation of fresnel from [4], Equation 15 +vec3 specularReflection(PBRInfo pbrInputs) +{ + return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0); +} + +// This calculates the specular geometric attenuation (aka G()), +// where rougher material will reflect less light back to the viewer. +// This implementation is based on [1] Equation 4, and we adopt their modifications to +// alphaRoughness as input as originally proposed in [2]. +float geometricOcclusion(PBRInfo pbrInputs) +{ + float NdotL = pbrInputs.NdotL; + float NdotV = pbrInputs.NdotV; + float r = pbrInputs.alphaRoughness; + + float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL))); + float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV))); + return attenuationL * attenuationV; } + +// The following equation(s) model the distribution of microfacet normals across the area being drawn (aka D()) +// Implementation from "Average Irregularity Representation of a Roughened Surface for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz +// Follows the distribution function recommended in the SIGGRAPH 2013 course notes from EPIC Games [1], Equation 3. +float microfacetDistribution(PBRInfo pbrInputs) +{ + float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness; + float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0; + return roughnessSq / (M_PI * f * f); +} + +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, + float metallic, + vec3 n, // normal + vec3 v, // surface point to camera + vec3 l, //surface point to light + out vec3 specContrib) //specular contribution (exposed to alpha shaders to calculate "glare") +{ + // make sure specular highlights from punctual lights don't fall off of polished surfaces + perceptualRoughness = max(perceptualRoughness, 8.0/255.0); + + float alphaRoughness = perceptualRoughness * perceptualRoughness; + + // Compute reflectance. + float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b); + + // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect. + // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%. + float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0); + vec3 specularEnvironmentR0 = specularColor.rgb; + vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90; + + vec3 h = normalize(l+v); // Half vector between both l and v + vec3 reflection = -normalize(reflect(v, n)); + reflection.y *= -1.0f; + + float NdotL = clamp(dot(n, l), 0.001, 1.0); + float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0); + float NdotH = clamp(dot(n, h), 0.0, 1.0); + float LdotH = clamp(dot(l, h), 0.0, 1.0); + float VdotH = clamp(dot(v, h), 0.0, 1.0); + + PBRInfo pbrInputs = PBRInfo( + NdotL, + NdotV, + NdotH, + LdotH, + VdotH, + perceptualRoughness, + metallic, + specularEnvironmentR0, + specularEnvironmentR90, + alphaRoughness, + diffuseColor, + specularColor + ); + + // Calculate the shading terms for the microfacet specular shading model + vec3 F = specularReflection(pbrInputs); + float G = geometricOcclusion(pbrInputs); + float D = microfacetDistribution(pbrInputs); + + // Calculation of analytical lighting contribution + vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs); + specContrib = F * G * D / (4.0 * NdotL * NdotV); + // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) + vec3 color = NdotL * (diffuseContrib + specContrib); + + specContrib *= NdotL; + specContrib = max(specContrib, vec3(0)); + + return clamp(color, vec3(0), vec3(10)); +} + +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, + float metallic, + vec3 n, // normal + vec3 v, // surface point to camera + vec3 l) //surface point to light +{ + vec3 specContrib; + + return pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n, v, l, specContrib); +} + +void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor) +{ + vec3 f0 = vec3(0.04); + diffuseColor = baseColor*(vec3(1.0)-f0); + diffuseColor *= 1.0 - metallic; + specularColor = mix(f0, baseColor, metallic); +} + +vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, vec3 norm, float perceptualRoughness, vec3 light_dir, vec3 sunlit, float scol, vec3 radiance, vec3 irradiance, vec3 colorEmissive, float ao, vec3 additive, vec3 atten, out vec3 specContrib) +{ + vec3 color = vec3(0); + + float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); + + vec3 ibl_spec; + color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness, ibl_spec); + + color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir), specContrib) * sunlit * 3.0 * scol; //magic number to balance with legacy materials + specContrib *= sunlit * 2.75 * scol; + specContrib += ibl_spec; + + color += colorEmissive; + + return color; +} + +vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, vec3 norm, float perceptualRoughness, vec3 light_dir, vec3 sunlit, float scol, vec3 radiance, vec3 irradiance, vec3 colorEmissive, float ao, vec3 additive, vec3 atten) +{ + vec3 specContrib; + return pbrBaseLight(diffuseColor, specularColor, metallic, v, norm, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten, specContrib); +} + +uniform vec4 waterPlane; +uniform float waterSign; + +// discard if given position in eye space is on the wrong side of the waterPlane according to waterSign +void waterClip(vec3 pos) +{ + // TODO: make this less branchy + if (waterSign > 0) + { + if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) < 0.0) + { + discard; + } + } + else + { + if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) > 0.0) + { + discard; + } + } + +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index b328ee9483..6f3b94f734 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -25,25 +25,21 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; uniform float minimum_alpha; uniform sampler2D diffuseMap; -VARYING vec3 vary_normal; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec3 vary_normal; +in vec4 vertex_color; +in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); void main() { - vec4 col = texture2D(diffuseMap, vary_texcoord0.xy) * vertex_color; + vec4 col = texture(diffuseMap, vary_texcoord0.xy) * vertex_color; if (col.a < minimum_alpha) { @@ -53,6 +49,7 @@ 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(encode_normal(nvn.xyz), 0.0, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index fc5c86b4d6..e5f2af2c53 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -25,18 +25,14 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; -VARYING vec3 vary_normal; +in vec3 vary_normal; uniform float minimum_alpha; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec4 vertex_color; +in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); @@ -52,5 +48,6 @@ 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(encode_normal(nvn.xyz), 0.0, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index 1bb8eb8bd0..234f096ed5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -25,24 +25,20 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; uniform float minimum_alpha; uniform sampler2D diffuseMap; -VARYING vec3 vary_normal; -VARYING vec2 vary_texcoord0; +in vec3 vary_normal; +in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); void main() { - vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col = texture(diffuseMap, vary_texcoord0.xy); if (col.a < minimum_alpha) { @@ -52,6 +48,7 @@ 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(encode_normal(nvn.xyz), 0.0, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 8319e61242..68fb8bf499 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -25,27 +25,24 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; uniform sampler2D diffuseMap; -VARYING vec3 vary_normal; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec3 vary_normal; +in vec4 vertex_color; +in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); void main() { - vec3 col = vertex_color.rgb * texture2D(diffuseMap, vary_texcoord0.xy).rgb; + vec3 col = vertex_color.rgb * texture(diffuseMap, vary_texcoord0.xy).rgb; 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); - frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index ccd1df84f9..93d561504e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -25,15 +25,11 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; -VARYING vec3 vary_normal; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec3 vary_normal; +in vec4 vertex_color; +in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); @@ -48,5 +44,6 @@ void main() 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); + frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl index 9461e3e32e..13cc612fab 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseNoColorV.glsl @@ -27,13 +27,13 @@ uniform mat3 normal_matrix; uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec3 normal; +in vec2 texcoord0; -VARYING vec3 vary_normal; +out vec3 vary_normal; -VARYING vec2 vary_texcoord0; +out vec2 vary_texcoord0; void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl index d64bcefade..2402cc3b70 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl @@ -27,15 +27,15 @@ 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; +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec2 texcoord0; -VARYING vec3 vary_normal; +out vec3 vary_normal; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +out vec4 vertex_color; +out vec2 vary_texcoord0; void passTextureIndex(); diff --git a/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl b/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl index 8d48bb016b..3b9b8ae696 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl @@ -23,18 +23,12 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect lightMap; +uniform sampler2D diffuseRect; +uniform sampler2D lightMap; uniform mat4 inv_proj; uniform vec2 screen_res; @@ -44,14 +38,14 @@ uniform float res_scale; uniform float dof_width; uniform float dof_height; -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; -vec4 dofSample(sampler2DRect tex, vec2 tc) +vec4 dofSample(sampler2D tex, vec2 tc) { tc.x = min(tc.x, dof_width); tc.y = min(tc.y, dof_height); - return texture2DRect(tex, tc); + return texture(tex, tc); } void main() @@ -60,7 +54,7 @@ void main() vec4 dof = dofSample(diffuseRect, vary_fragcoord.xy*res_scale); - vec4 diff = texture2DRect(lightMap, vary_fragcoord.xy); + vec4 diff = texture(lightMap, vary_fragcoord.xy); float a = min(abs(diff.a*2.0-1.0) * max_cof*res_scale*res_scale, 1.0); @@ -69,10 +63,10 @@ void main() float sc = a/res_scale; vec4 col; - col = texture2DRect(lightMap, vary_fragcoord.xy+vec2(sc,sc)); - col += texture2DRect(lightMap, vary_fragcoord.xy+vec2(-sc,sc)); - col += texture2DRect(lightMap, vary_fragcoord.xy+vec2(sc,-sc)); - col += texture2DRect(lightMap, vary_fragcoord.xy+vec2(-sc,-sc)); + col = texture(lightMap, vary_fragcoord.xy+vec2(sc,sc)/screen_res); + col += texture(lightMap, vary_fragcoord.xy+vec2(-sc,sc)/screen_res); + col += texture(lightMap, vary_fragcoord.xy+vec2(sc,-sc)/screen_res); + col += texture(lightMap, vary_fragcoord.xy+vec2(-sc,-sc)/screen_res); diff = mix(diff, col*0.25, a); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl index f0522850de..9e61b6b894 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveF.glsl @@ -23,31 +23,17 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -vec3 fullbrightAtmosTransport(vec3 light); -vec3 fullbrightScaleSoftClip(vec3 light); -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec4 vertex_color; +in vec2 vary_texcoord0; void main() { - float shadow = 1.0; - - vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color; - color.rgb = fullbrightAtmosTransport(color.rgb); - - color.rgb = fullbrightScaleSoftClip(color.rgb); - - frag_color = color; + // NOTE: when this shader is used, only alpha is being written to + float a = diffuseLookup(vary_texcoord0.xy).a*vertex_color.a; + frag_color = vec4(0, 0, 0, a); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl index 08b1147ab0..5a0913a970 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/emissiveV.glsl @@ -27,18 +27,18 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; +in vec3 position; void passTextureIndex(); -ATTRIBUTE vec4 emissive; -ATTRIBUTE vec2 texcoord0; +in vec4 emissive; +in vec2 texcoord0; void calcAtmospherics(vec3 inPositionEye); vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +out vec4 vertex_color; +out vec2 vary_texcoord0; #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl index 15f141cbe5..9ac4ceb37e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl @@ -1,8 +1,9 @@ /** - * @file sunLightSSAOF.glsl - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * @file exposureF.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. + * Copyright (C) 2023, 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 @@ -22,41 +23,39 @@ * $/LicenseInfo$ */ - -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -//class 1 -- no shadow, SSAO only -uniform sampler2DRect normalMap; +uniform sampler2D emissiveRect; +uniform sampler2D exposureMap; -// Inputs -VARYING vec2 vary_fragcoord; +uniform float dt; +uniform vec2 noiseVec; -vec3 getNorm(vec2 pos_screen); -vec4 getPosition(vec2 pos_screen); +uniform vec3 dynamic_exposure_params; -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); +float lum(vec3 col) +{ + vec3 l = vec3(0.2126, 0.7152, 0.0722); + return dot(l, col); +} void main() { - vec2 pos_screen = vary_fragcoord.xy; - - //try doing an unproject here - - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); - - frag_color[0] = 1.0; - frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen); - frag_color[2] = 1.0; - frag_color[3] = 1.0; + vec2 tc = vec2(0.5,0.5); + + float L = textureLod(emissiveRect, tc, 8).r; + float max_L = dynamic_exposure_params.x; + L = clamp(L, 0.0, max_L); + L /= max_L; + L = pow(L, 2.0); + float s = mix(dynamic_exposure_params.z, dynamic_exposure_params.y, L); + + float prev = texture(exposureMap, vec2(0.5,0.5)).r; + + s = mix(prev, s, min(dt*2.0*abs(prev-s), 0.04)); + + frag_color = max(vec4(s, s, s, dt), vec4(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 57420158ca..b752307d13 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -23,66 +23,87 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif #if !defined(HAS_DIFFUSE_LOOKUP) uniform sampler2D diffuseMap; #endif -VARYING vec3 vary_position; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec3 vary_position; +in vec4 vertex_color; +in vec2 vary_texcoord0; #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); #endif vec3 srgb_to_linear(vec3 cs); +vec3 legacy_adjust_fullbright(vec3 c); +vec3 legacy_adjust(vec3 c); vec3 linear_to_srgb(vec3 cl); -vec3 fullbrightAtmosTransport(vec3 light); -vec3 fullbrightScaleSoftClip(vec3 light); +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); #ifdef HAS_ALPHA_MASK uniform float minimum_alpha; #endif +#ifdef IS_ALPHA +void waterClip(vec3 pos); +#endif + void main() { + +#ifdef IS_ALPHA + waterClip(vary_position.xyz); +#endif + #ifdef HAS_DIFFUSE_LOOKUP - vec4 color = diffuseLookup(vary_texcoord0.xy); + vec4 color = diffuseLookup(vary_texcoord0.xy); #else - vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 color = texture(diffuseMap, vary_texcoord0.xy); #endif - float final_alpha = color.a * vertex_color.a; + float final_alpha = color.a * vertex_color.a; #ifdef HAS_ALPHA_MASK - if (color.a < minimum_alpha) - { - discard; - } + if (color.a < minimum_alpha) + { + discard; + } #endif - color.rgb *= vertex_color.rgb; + color.rgb *= vertex_color.rgb; + + vec3 pos = vary_position; + +#ifndef IS_HUD + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten); +#endif #ifdef WATER_FOG - vec3 pos = vary_position; - vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha)); - color.rgb = fogged.rgb; - color.a = fogged.a; + + vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha)); + color.rgb = fogged.rgb; + color.a = fogged.a; #else color.a = final_alpha; #endif - frag_color.rgb = color.rgb; - frag_color.a = color.a; +#ifndef IS_HUD + color.rgb = legacy_adjust(color.rgb); + color.rgb = srgb_to_linear(color.rgb); + color.rgb = legacy_adjust_fullbright(color.rgb); + color.rgb = atmosFragLighting(color.rgb, additive, atten); +#endif + + frag_color = max(color, vec4(0)); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl deleted file mode 100644 index 9fcee04c32..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ /dev/null @@ -1,106 +0,0 @@ -/** - * @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$ - */ - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -#ifndef HAS_DIFFUSE_LOOKUP -uniform sampler2D diffuseMap; -#endif - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; -VARYING vec3 vary_texcoord1; -VARYING vec4 vary_position; - -uniform samplerCube environmentMap; - -// render_hud_attachments() -> HUD objects set LLShaderMgr::NO_ATMO; used in LLDrawPoolAlpha::beginRenderPass() -uniform int no_atmo; - -vec3 fullbrightShinyAtmosTransport(vec3 light); -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClip(vec3 light); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); - -vec3 linear_to_srgb(vec3 c); -vec3 srgb_to_linear(vec3 c); - -// See: -// class1\deferred\fullbrightShinyF.glsl -// class1\lighting\lightFullbrightShinyF.glsl -void main() -{ -#ifdef HAS_DIFFUSE_LOOKUP - vec4 color = diffuseLookup(vary_texcoord0.xy); -#else - vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); -#endif - - color.rgb *= vertex_color.rgb; - - // SL-9632 HUDs are affected by Atmosphere - if (no_atmo == 0) - { - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - vec3 pos = vary_position.xyz/vary_position.w; - - calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); - - vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; - float env_intensity = vertex_color.a; - - //color.rgb = srgb_to_linear(color.rgb); - color.rgb = mix(color.rgb, envColor.rgb, env_intensity); - color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); - color.rgb = fullbrightScaleSoftClip(color.rgb); - } - -/* - // NOTE: HUD objects will be full bright. Uncomment if you want "some" environment lighting effecting these HUD objects. - else - { - vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; - float env_intensity = vertex_color.a; - color.rgb = mix(color.rgb, envColor.rgb, env_intensity); - } -*/ - - color.a = 1.0; - - //color.rgb = linear_to_srgb(color.rgb); - - 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 index 3bd6b693fa..5795384b47 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl @@ -36,16 +36,16 @@ uniform vec4 origin; -ATTRIBUTE vec3 position; +in vec3 position; void passTextureIndex(); -ATTRIBUTE vec3 normal; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; +in vec3 normal; +in vec4 diffuse_color; +in vec2 texcoord0; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; -VARYING vec3 vary_texcoord1; -VARYING vec4 vary_position; +out vec4 vertex_color; +out vec2 vary_texcoord0; +out vec3 vary_texcoord1; +out vec3 vary_position; #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); @@ -62,17 +62,18 @@ void main() mat4 mat = getObjectSkinnedTransform(); mat = modelview_matrix * mat; vec4 pos = mat * vert; - vary_position = gl_Position = projection_matrix * pos; + gl_Position = projection_matrix * pos; vec3 norm = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); #else vec4 pos = (modelview_matrix * vert); - vary_position = gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); vec3 norm = normalize(normal_matrix * normal); #endif - vec3 ref = reflect(pos.xyz, -norm); + vary_position = pos.xyz; vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - vary_texcoord1 = (texture_matrix1 * vec4(ref,1.0)).xyz; + + vary_texcoord1 = norm; calcAtmospherics(pos.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index e71636f2c9..77e63e6360 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -28,22 +28,20 @@ uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; +in vec3 position; void passTextureIndex(); -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; +in vec4 diffuse_color; +in vec2 texcoord0; void calcAtmospherics(vec3 inPositionEye); vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); -#ifdef WATER_FOG -VARYING vec3 vary_position; -#endif +out vec3 vary_position; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +out vec4 vertex_color; +out vec2 vary_texcoord0; #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); @@ -66,9 +64,7 @@ void main() gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); #endif -#ifdef WATER_FOG vary_position = pos.xyz; -#endif vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl index 226e63cdda..cd56ed0adf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl @@ -28,11 +28,7 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif #define FXAA_PC 1 //#define FXAA_GLSL_130 1 @@ -2092,12 +2088,13 @@ half4 FxaaPixelShader( #endif uniform sampler2D diffuseMap; +uniform sampler2D depthMap; uniform vec2 rcp_screen_res; uniform vec4 rcp_frame_opt; uniform vec4 rcp_frame_opt2; -VARYING vec2 vary_fragcoord; -VARYING vec2 vary_tc; +in vec2 vary_fragcoord; +in vec2 vary_tc; void main() { @@ -2120,8 +2117,7 @@ void main() - //diff = texture2D(diffuseMap, vary_tc); - - frag_color = diff; - + frag_color = diff; + + gl_FragDepth = texture(depthMap, vary_fragcoord.xy).r; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/genbrdflutF.glsl b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutF.glsl new file mode 100644 index 0000000000..e40d070268 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutF.glsl @@ -0,0 +1,141 @@ +/** + * @file class1/deferred/genbrdflut.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + +/* Taken from Sascha Willem's Vulkan GLTF refernce implementation +MIT License + +Copyright (c) 2018 Sascha Willems + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/*[EXTRA_CODE_HERE]*/ + +in vec2 vary_uv; + +out vec4 outColor; + +#define NUM_SAMPLES 1024u + +const float PI = 3.1415926536; + +// Based omn http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/ +float random(vec2 co) +{ + float a = 12.9898; + float b = 78.233; + float c = 43758.5453; + float dt= dot(co.xy ,vec2(a,b)); + float sn= mod(dt,3.14); + return fract(sin(sn) * c); +} + +vec2 hammersley2d(uint i, uint N) +{ + // Radical inverse based on http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html + uint bits = (i << 16u) | (i >> 16u); + bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); + bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); + bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); + bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); + float rdi = float(bits) * 2.3283064365386963e-10; + return vec2(float(i) /float(N), rdi); +} + +// Based on http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf +vec3 importanceSample_GGX(vec2 Xi, float roughness, vec3 normal) +{ + // Maps a 2D point to a hemisphere with spread based on roughness + float alpha = roughness * roughness; + float phi = 2.0 * PI * Xi.x + random(normal.xz) * 0.1; + float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (alpha*alpha - 1.0) * Xi.y)); + float sinTheta = sqrt(1.0 - cosTheta * cosTheta); + vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta); + + // Tangent space + vec3 up = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); + vec3 tangentX = normalize(cross(up, normal)); + vec3 tangentY = normalize(cross(normal, tangentX)); + + // Convert to world Space + return normalize(tangentX * H.x + tangentY * H.y + normal * H.z); +} + +// Geometric Shadowing function +float G_SchlicksmithGGX(float dotNL, float dotNV, float roughness) +{ + float k = (roughness * roughness) / 2.0; + float GL = dotNL / (dotNL * (1.0 - k) + k); + float GV = dotNV / (dotNV * (1.0 - k) + k); + return GL * GV; +} + +vec2 BRDF(float NoV, float roughness) +{ + // Normal always points along z-axis for the 2D lookup + const vec3 N = vec3(0.0, 0.0, 1.0); + vec3 V = vec3(sqrt(1.0 - NoV*NoV), 0.0, NoV); + + vec2 LUT = vec2(0.0); + for(uint i = 0u; i < NUM_SAMPLES; i++) { + vec2 Xi = hammersley2d(i, NUM_SAMPLES); + vec3 H = importanceSample_GGX(Xi, roughness, N); + vec3 L = 2.0 * dot(V, H) * H - V; + + float dotNL = max(dot(N, L), 0.0); + float dotNV = max(dot(N, V), 0.0); + float dotVH = max(dot(V, H), 0.0); + float dotNH = max(dot(H, N), 0.0); + + if (dotNL > 0.0) { + float G = G_SchlicksmithGGX(dotNL, dotNV, roughness); + float G_Vis = (G * dotVH) / (dotNH * dotNV); + float Fc = pow(1.0 - dotVH, 5.0); + LUT += vec2((1.0 - Fc) * G_Vis, Fc * G_Vis); + } + } + return LUT / float(NUM_SAMPLES); +} + +void main() +{ + outColor = vec4(BRDF(vary_uv.s, 1.0-vary_uv.t), 0.0, 1.0); +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutV.glsl index eefefa640d..3a1572996f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutV.glsl @@ -1,9 +1,9 @@ /** - * @file multiPointLightV.glsl + * @file class3\deferred\genbrdflutV.glsl * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. + * Copyright (C) 2022, 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 @@ -25,15 +25,15 @@ uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; +in vec3 position; -VARYING vec4 vary_fragcoord; +out vec2 vary_uv; void main() { //transform vertex vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); - vary_fragcoord = pos; + vary_uv = position.xy*0.5+0.5; - gl_Position = pos; + gl_Position = vec4(position.xyz, 1.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl index 90566393d2..748fcbed80 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl @@ -23,20 +23,17 @@ * $/LicenseInfo$ */ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; uniform vec4 color; uniform sampler2D diffuseMap; -VARYING vec2 vary_texcoord0; +in vec2 vary_texcoord0; void main() { - frag_data[0] = color*texture2D(diffuseMap, vary_texcoord0.xy); + frag_data[0] = color*texture(diffuseMap, vary_texcoord0.xy); frag_data[1] = vec4(0.0); - frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); + frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index a58cc3d12d..aae595f619 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -25,11 +25,7 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; uniform float minimum_alpha; @@ -38,23 +34,25 @@ uniform sampler2D diffuseMap; uniform sampler2D normalMap; uniform sampler2D specularMap; -VARYING vec2 vary_texcoord0; +in vec2 vary_texcoord0; vec3 linear_to_srgb(vec3 c); +vec2 encode_normal (vec3 n); void main() { - vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col = texture(diffuseMap, vary_texcoord0.xy); if (col.a < minimum_alpha) { discard; } - vec4 norm = texture2D(normalMap, vary_texcoord0.xy); - vec4 spec = texture2D(specularMap, vary_texcoord0.xy); + vec4 norm = texture(normalMap, vary_texcoord0.xy); + vec4 spec = texture(specularMap, vary_texcoord0.xy); frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = spec; - frag_data[2] = norm; + frag_data[2] = vec4(encode_normal(norm.xyz),0,GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl index 42266e9378..444c54a31e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorV.glsl @@ -26,10 +26,10 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec2 texcoord0; -VARYING vec2 vary_texcoord0; +out vec2 vary_texcoord0; void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index be1003a7e0..c8afacf9bb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -1,9 +1,9 @@ /** * @file luminanceF.glsl * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. + * Copyright (C) 2023, 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 @@ -22,19 +22,31 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ + /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR +// take a luminance sample of diffuseRect and emissiveRect + out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2DRect diffuseMap; -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; + +uniform sampler2D diffuseRect; +uniform sampler2D emissiveRect; + +float lum(vec3 col) +{ + vec3 l = vec3(0.2126, 0.7152, 0.0722); + return dot(l, col); +} void main() { - frag_color = texture2DRect(diffuseMap, vary_fragcoord.xy); + vec2 tc = vary_fragcoord*0.6+0.2; + tc.y -= 0.1; // HACK - nudge exposure sample down a little bit to favor ground over sky + vec3 c = texture(diffuseRect, tc).rgb + texture(emissiveRect, tc).rgb; + float L = lum(c); + frag_color = vec4(max(L, 0.0)); } + diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl deleted file mode 100644 index f2dc60aa5d..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @file giV.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 modelview_projection_matrix; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; - -VARYING vec2 vary_fragcoord; -VARYING vec4 vertex_color; - -uniform vec2 screen_res; - -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; - - vertex_color = diffuse_color; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b30d7655db..4dee23372f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -1,9 +1,9 @@ /** * @file materialF.glsl * -* $LicenseInfo:firstyear=2007&license=viewerlgpl$ +* $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code -* Copyright (C) 2007, Linden Research, Inc. +* Copyright (C) 2023, 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 @@ -25,429 +25,26 @@ /*[EXTRA_CODE_HERE]*/ -//class1/deferred/materialF.glsl +// debug stub -// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. - -#define DIFFUSE_ALPHA_MODE_NONE 0 #define DIFFUSE_ALPHA_MODE_BLEND 1 -#define DIFFUSE_ALPHA_MODE_MASK 2 -#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 - -uniform float emissive_brightness; // fullbright flag, 1.0 == fullbright, 0.0 otherwise -uniform int sun_up_factor; - -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); - -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClip(vec3 light); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); - -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cs); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else -#define frag_color gl_FragColor -#endif - -#ifdef HAS_SUN_SHADOW -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +out vec4 frag_data[4]; #endif -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -uniform mat3 env_mat; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -VARYING vec2 vary_fragcoord; - -VARYING vec3 vary_position; - -uniform mat4 proj_mat; -uniform mat4 inv_proj; -uniform vec2 screen_res; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -float getAmbientClamp(); - -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, float ambiance) -{ - // SL-14895 inverted attenuation work-around - // This routine is tweaked to match deferred lighting, but previously used an inverted la value. To reconstruct - // that previous value now that the inversion is corrected, we reverse the calculations in LLPipeline::setupHWLights() - // to recover the `adjusted_radius` value previously being sent as la. - float falloff_factor = (12.0 * fa) - 9.0; - float inverted_la = falloff_factor / la; - // Yes, it makes me want to cry as well. DJH - - vec3 col = vec3(0); - - //get light vector - vec3 lv = lp.xyz - v; - - //get distance - float dist = length(lv); - float da = 1.0; - - dist /= inverted_la; - - if (dist > 0.0 && inverted_la > 0.0) - { - //normalize light vector - lv = normalize(lv); - - //distance attenuation - float dist_atten = clamp(1.0 - (dist - 1.0*(1.0 - fa)) / fa, 0.0, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0f; - - if (dist_atten <= 0.0) - { - return col; - } - - // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); - da *= spot*spot; // GL_SPOT_EXPONENT=2 - - //angular attenuation - da *= dot(n, lv); - - float lit = 0.0f; - - float amb_da = ambiance; - if (da >= 0) - { - lit = max(da * dist_atten, 0.0); - col = lit * light_col * diffuse; - amb_da += (da*0.5 + 0.5) * ambiance; - } - amb_da += (da*da*0.5 + 0.5) * ambiance; - amb_da *= dist_atten; - amb_da = min(amb_da, 1.0f - lit); - - // SL-10969 need to see why these are blown out - //col.rgb += amb_da * light_col * 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; - speccol = clamp(speccol, vec3(0), vec3(1)); - 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); - } - } - } - - return max(col, vec3(0.0, 0.0, 0.0)); -} - -#else -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif -#endif - -uniform sampler2D diffuseMap; //always in sRGB space - -#ifdef HAS_NORMAL_MAP -uniform sampler2D bumpMap; -#endif - -#ifdef 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 - -#ifdef 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); - void main() { - vec2 pos_screen = vary_texcoord0.xy; - - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); - diffcol.rgb *= vertex_color.rgb; - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - - // Comparing floats cast from 8-bit values, produces acne right at the 8-bit transition points - float bias = 0.001953125; // 1/512, or half an 8-bit quantization (SL-18637) - if (diffcol.a < minimum_alpha-bias) - { - discard; - } -#endif - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = diffcol.rgb; - diffcol.rgb = srgb_to_linear(diffcol.rgb); -#endif - -#ifdef 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 - -#ifdef 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 = normalize(tnorm.xyz); - - vec2 abnormal = encode_normal(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; - -#ifdef 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 sRGBA - vec3 pos = vary_position; - - float shadow = 1.0f; - -#ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); -#endif - - spec = final_specular; - vec4 diffuse = final_color; - float envIntensity = final_normal.z; - - vec3 color = vec3(0,0,0); - - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - - float bloom = 0.0; - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - - // This call breaks the Mac GLSL compiler/linker for unknown reasons (17Mar2020) - // The call is either a no-op or a pure (pow) gamma adjustment, depending on GPU level - // TODO: determine if we want to re-apply the gamma adjustment, and if so understand & fix Mac breakage - //color = fullbrightScaleSoftClip(color); - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - //we're in sRGB space, so gamma correct this dot product so - // lighting from the sun stays sharp - float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); - da = pow(da, 1.0 / 1.3); - - color = amblit; - - //darken ambient for normals perpendicular to light vector so surfaces in shadow - // and facing away from light still have some definition to them. - // do NOT gamma correct this dot product so ambient lighting stays soft - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - vec3 sun_contrib = min(da, shadow) * sunlit; - - color *= ambient; - - color += sun_contrib; - - color *= gamma_diff.rgb; - - float glare = 0.0; - - if (spec.a > 0.0) // specular reflection - { - /* // Reverting this specular calculation to previous 'dumbshiny' version - DJH 6/17/2020 - // Preserving the refactored version as a comment for potential reconsideration, - // overriding the general rule to avoid pollutiong the source with commented code. - // - // If you're reading this in 2021+, feel free to obliterate. - - vec3 npos = -normalize(pos.xyz); - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(light_dir.xyz + npos); - float nh = dot(norm.xyz, h); - float nv = dot(norm.xyz, 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 sp = sun_contrib*scol / 6.0f; - sp = clamp(sp, vec3(0), vec3(1)); - bloom = dot(sp, sp) / 4.0; - color += sp * spec.rgb; - } - */ - - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit * 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); - - color += spec_contrib; - } - - color = mix(color.rgb, diffcol.rgb, diffuse.a); - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - - color = mix(color, reflected_color, envIntensity); - - float cur_glare = max(reflected_color.r, reflected_color.g); - cur_glare = max(cur_glare, reflected_color.b); - cur_glare *= envIntensity*4.0; - glare += cur_glare; - } - - color = atmosFragLighting(color, additive, atten); - color = scaleSoftClipFrag(color); - - //convert to linear before adding local lights - color = srgb_to_linear(color); - - vec3 npos = normalize(-pos.xyz); - - vec3 light = vec3(0, 0, 0); - - final_specular.rgb = srgb_to_linear(final_specular.rgb); // SL-14035 - -#define LIGHT_LOOP(i) light.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_attenuation[i].w ); - - LIGHT_LOOP(1) - LIGHT_LOOP(2) - LIGHT_LOOP(3) - LIGHT_LOOP(4) - LIGHT_LOOP(5) - LIGHT_LOOP(6) - LIGHT_LOOP(7) - - color += light; - - glare = min(glare, 1.0); - float al = max(diffcol.a, glare)*vertex_color.a; - - //convert to srgb as this color is being written post gamma correction - color = linear_to_srgb(color); - -#ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color, al)); - color = temp.rgb; - al = temp.a; -#endif - - frag_color = vec4(color, al); - + frag_color = vec4(0.5, 0, 1, 0.5); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer - - // deferred path - frag_data[0] = final_color; //gbuffer is sRGB - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. + // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl + frag_data[0] = vec4(0.5, 0, 1, 0); // gbuffer is sRGB for legacy materials + frag_data[1] = vec4(0); // XYZ = Specular color. W = Specular exponent. + frag_data[2] = vec4(0); // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) + frag_data[3] = vec4(0); #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 7e29ada205..7cdddfe8db 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -1,5 +1,5 @@ /** - * @file bumpV.glsl + * @file materialV.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -43,38 +43,38 @@ uniform mat4 modelview_projection_matrix; uniform mat4 modelview_matrix; #endif -VARYING vec3 vary_position; +out vec3 vary_position; #endif uniform mat4 texture_matrix0; -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec2 texcoord0; #ifdef HAS_NORMAL_MAP -ATTRIBUTE vec4 tangent; -ATTRIBUTE vec2 texcoord1; +in vec4 tangent; +in vec2 texcoord1; -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; +out vec3 vary_tangent; +flat out float vary_sign; +out vec3 vary_normal; -VARYING vec2 vary_texcoord1; +out vec2 vary_texcoord1; #else -VARYING vec3 vary_normal; +out vec3 vary_normal; #endif #ifdef HAS_SPECULAR_MAP -ATTRIBUTE vec2 texcoord2; -VARYING vec2 vary_texcoord2; +in vec2 texcoord2; +out vec2 vary_texcoord2; #endif -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +out vec4 vertex_color; +out vec2 vary_texcoord0; void main() { @@ -111,24 +111,21 @@ void main() vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); #ifdef HAS_NORMAL_MAP 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); - vary_mat2 = vec3(t.z, b.z, n.z); + + vary_tangent = t; + vary_sign = tangent.w; + vary_normal = n; #else //HAS_NORMAL_MAP -vary_normal = n; + vary_normal = n; #endif //HAS_NORMAL_MAP #else //HAS_SKIN vec3 n = normalize(normal_matrix * normal); #ifdef HAS_NORMAL_MAP 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); - vary_mat2 = vec3(t.z, b.z, n.z); + + vary_tangent = t; + vary_sign = tangent.w; + vary_normal = n; #else //HAS_NORMAL_MAP vary_normal = n; #endif //HAS_NORMAL_MAP diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 35068899ee..f3e7b2ee72 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -23,29 +23,16 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; uniform vec4 color; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; uniform vec3 moon_dir; uniform float moon_brightness; uniform sampler2D diffuseMap; -VARYING vec2 vary_texcoord0; - -vec3 srgb_to_linear(vec3 c); - -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light); +in vec2 vary_texcoord0; void main() { @@ -54,20 +41,21 @@ void main() if( moon_dir.z > 0 ) fade = clamp( moon_dir.z*moon_dir.z*4.0, 0.0, 1.0 ); - vec4 c = texture2D(diffuseMap, vary_texcoord0.xy); -// c.rgb = srgb_to_linear(c.rgb); - c.rgb *= moonlight_color.rgb; - c.rgb *= moon_brightness; + vec4 c = texture(diffuseMap, vary_texcoord0.xy); - c.rgb *= fade; - c.a *= fade; + // SL-14113 Don't write to depth; prevent moon's quad from hiding stars which should be visible + // Moon texture has transparent pixels <0x55,0x55,0x55,0x00> + if (c.a <= 2./255.) // 0.00784 + { + discard; + } - c.rgb = scaleSoftClip(c.rgb); + c.rgb *= moon_brightness; + c.a *= fade; - frag_data[0] = vec4(c.rgb, c.a); + frag_data[0] = vec4(0); frag_data[1] = vec4(0.0); - frag_data[2] = vec4(0.0f); - - gl_FragDepth = 0.999985f; + frag_data[2] = vec4(0.0, 0.0, 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(c.rgb, c.a); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl index c4922afd7d..032245a01c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonV.glsl @@ -27,18 +27,20 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec2 texcoord0; -VARYING vec2 vary_texcoord0; +out vec2 vary_texcoord0; void main() { //transform vertex vec4 vert = vec4(position.xyz, 1.0); - vec4 pos = (modelview_matrix * vert); + vec4 pos = (modelview_projection_matrix * vert); - gl_Position = modelview_projection_matrix*vert; + // smash to *almost* far clip plane -- stars are still behind + pos.z = pos.w*0.999999; + gl_Position = pos; vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl deleted file mode 100644 index 09c47165dd..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ /dev/null @@ -1,145 +0,0 @@ -/** - * @file class1/deferred/multiPointLightF.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 - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect depthMap; -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform samplerCube environmentMap; -uniform sampler2D noiseMap; -uniform sampler2D lightFunc; - -uniform vec3 env_mat[3]; -uniform float sun_wash; -uniform int light_count; -uniform vec4 light[LIGHT_COUNT]; -uniform vec4 light_col[LIGHT_COUNT]; - -uniform vec2 screen_res; -uniform float far_z; -uniform mat4 inv_proj; - -VARYING vec4 vary_fragcoord; - -vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); -vec3 srgb_to_linear(vec3 c); - -void main() -{ -#if defined(LOCAL_LIGHT_KILL) - discard; // Bail immediately -#endif - - vec3 out_col = vec3(0, 0, 0); - vec2 frag = (vary_fragcoord.xy * 0.5 + 0.5) * screen_res; - vec3 pos = getPosition(frag.xy).xyz; - if (pos.z < far_z) - { - discard; - } - - vec3 norm = getNorm(frag.xy); - - vec4 spec = texture2DRect(specularRect, frag.xy); - vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; - - float noise = texture2D(noiseMap, frag.xy / 128.0).b; - vec3 npos = normalize(-pos); - - // As of OSX 10.6.7 ATI Apple's crash when using a variable size loop - for (int i = 0; i < LIGHT_COUNT; ++i) - { - vec3 lv = light[i].xyz - pos; - float dist = length(lv); - dist /= light[i].w; - if (dist <= 1.0) - { - float da = dot(norm, lv); - if (da > 0.0) - { - lv = normalize(lv); - da = dot(norm, lv); - - float fa = light_col[i].a + 1.0; - float dist_atten = clamp(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 0.0, 1.0); - dist_atten *= dist_atten; - - // Tweak falloff slightly to match pre-EEP attenuation - // NOTE: this magic number also shows up in a great many other places, search for dist_atten *= to audit - dist_atten *= 2.0; - - dist_atten *= noise; - - float lit = da * dist_atten; - - vec3 col = light_col[i].rgb * lit * diff; - - if (spec.a > 0.0) - { - lit = min(da * 6.0, 1.0) * dist_atten; - 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 * light_col[i].rgb * spec.rgb; - } - } - - out_col += col; - } - } - } - - frag_color.rgb = out_col; - frag_color.a = 0.0; - -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage - // awawy which leads to unfun crashes and artifacts. - vec4 dummy1 = light[0]; - vec4 dummy2 = light_col[0]; - vec4 dummy3 = light[LIGHT_COUNT - 1]; - vec4 dummy4 = light_col[LIGHT_COUNT - 1]; -#endif -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl deleted file mode 100644 index ec3fb9c543..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ /dev/null @@ -1,284 +0,0 @@ -/** - * @file multiSpotLightF.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$ - */ - - - -//class 1 -- no shadows - -#extension GL_ARB_texture_rectangle : enable -#extension GL_ARB_shader_texture_lod : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -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 -uniform vec3 proj_p; //plane projection is emitting from (in screen space) -uniform vec3 proj_n; -uniform float proj_focus; //distance from plane to begin blurring -uniform float proj_lod; //(number of mips in proj map) -uniform float proj_range; //range between near clip and far clip plane of projection -uniform float proj_ambient_lod; -uniform float proj_ambiance; -uniform float near_clip; -uniform float far_clip; - -uniform vec3 proj_origin; //origin of projection to be used for angular attenuation -uniform float sun_wash; - -uniform vec3 center; -uniform vec3 color; -uniform float falloff; -uniform float size; - -VARYING vec4 vary_fragcoord; -uniform vec2 screen_res; - -uniform mat4 inv_proj; -vec3 getNorm(vec2 pos_screen); -vec3 srgb_to_linear(vec3 c); - -vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - -vec4 getPosition(vec2 pos_screen); - -void main() -{ - vec3 col = vec3(0,0,0); - -#if defined(LOCAL_LIGHT_KILL) - discard; -#else - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = center.xyz-pos.xyz; - float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } - - float envIntensity = texture2DRect(normalMap, frag.xy).z; - vec3 norm = getNorm(frag.xy); - - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - - 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; - - - if (dist_atten <= 0.0) - { - discard; - } - - float noise = texture2D(noiseMap, frag.xy/128.0).b; - dist_atten *= noise; - - lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(norm, lv); - - - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - - vec3 dlit = vec3(0, 0, 0); - - - if (proj_tc.z > 0.0 && - proj_tc.x < 1.0 && - proj_tc.y < 1.0 && - proj_tc.x > 0.0 && - proj_tc.y > 0.0) - { - float lit = 0.0; - float amb_da = proj_ambiance; - - if (da > 0.0) - { - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; - - lit = da * dist_atten; - - 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); - - amb_da += (da*da*0.5+0.5)*proj_ambiance; - - amb_da *= dist_atten * noise; - - amb_da = min(amb_da, 1.0-lit); - col += amb_da*color.rgb*diff_tex*amb_plcol.rgb*amb_plcol.a; - } - - - vec4 spec = texture2DRect(specularRect, frag.xy); - - if (spec.a > 0.0) - { - dlit *= min(da*6.0, 1.0) * dist_atten; - - 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 += dlit*scol*spec.rgb; - //col += spec.rgb; - } - } - - if (envIntensity > 0.0) - { - vec3 ref = reflect(normalize(pos), norm); - - //project from point pos in direction ref to plane proj_p, proj_n - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - - if (stc.z > 0.0) - { - stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * envIntensity; - } - } - } - } -#endif - - //output linear, sum of lights will be gamma corrected later - frag_color.rgb = col; - frag_color.a = 0.0; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl b/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl index 7a941674b8..05dced0026 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/normgenF.glsl @@ -23,19 +23,13 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform sampler2D alphaMap; -VARYING vec2 vary_texcoord0; +in vec2 vary_texcoord0; uniform float stepX; uniform float stepY; @@ -43,12 +37,12 @@ uniform float norm_scale; void main() { - float c = texture2D(alphaMap, vary_texcoord0).r; + float c = texture(alphaMap, vary_texcoord0).r; - vec3 right = vec3(norm_scale, 0, (texture2D(alphaMap, vary_texcoord0+vec2(stepX, 0)).r-c)*255); - vec3 left = vec3(-norm_scale, 0, (texture2D(alphaMap, vary_texcoord0-vec2(stepX, 0)).r-c)*255); - vec3 up = vec3(0, -norm_scale, (texture2D(alphaMap, vary_texcoord0-vec2(0, stepY)).r-c)*255); - vec3 down = vec3(0, norm_scale, (texture2D(alphaMap, vary_texcoord0+vec2(0, stepY)).r-c)*255); + vec3 right = vec3(norm_scale, 0, (texture(alphaMap, vary_texcoord0+vec2(stepX, 0)).r-c)*255); + vec3 left = vec3(-norm_scale, 0, (texture(alphaMap, vary_texcoord0-vec2(stepX, 0)).r-c)*255); + vec3 up = vec3(0, -norm_scale, (texture(alphaMap, vary_texcoord0-vec2(0, stepY)).r-c)*255); + vec3 down = vec3(0, norm_scale, (texture(alphaMap, vary_texcoord0+vec2(0, stepY)).r-c)*255); vec3 norm = cross(right, down) + cross(down, left) + cross(left,up) + cross(up, right); diff --git a/indra/newview/app_settings/shaders/class1/deferred/normgenV.glsl b/indra/newview/app_settings/shaders/class1/deferred/normgenV.glsl index 9bceae05b7..7896659ad3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/normgenV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/normgenV.glsl @@ -23,11 +23,11 @@ * $/LicenseInfo$ */ -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec2 texcoord0; -VARYING vec2 vary_fragcoord; -VARYING vec2 vary_texcoord0; +out vec2 vary_fragcoord; +out vec2 vary_texcoord0; void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaBlendF.glsl index 44f2a73e1f..79425ad716 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaBlendF.glsl @@ -1,9 +1,9 @@ /** - * @file shadowAlphaMaskF.glsl + * @file pbrShadowAlphaBlendF.glsl * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2011, Linden Research, Inc. + * Copyright (C) 2023, 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 @@ -23,33 +23,34 @@ * $/LicenseInfo$ */ -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform sampler2D diffuseMap; -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - -VARYING float target_pos_x; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec4 post_pos; +in float target_pos_x; +in vec4 vertex_color; +in vec2 vary_texcoord0; +uniform float minimum_alpha; void main() { - float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + float alpha = texture(diffuseMap,vary_texcoord0.xy).a; + + alpha *= vertex_color.a; + + if (alpha < 0.05) // treat as totally transparent + { + discard; + } + + if (alpha < 0.88) // treat as semi-transparent + { + if (fract(0.5*floor(target_pos_x / post_pos.w )) < 0.25) + { + discard; + } + } - frag_color = vec4(alpha, alpha, alpha, 1); - -#if !defined(DEPTH_CLAMP) - gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); -#endif + frag_color = vec4(1,1,1,1); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl index 473d6df8fa..1d1545be7e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl @@ -1,9 +1,9 @@ /** - * @file sunLightF.glsl + * @file pbrShadowAlphaMaskF.glsl * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. + * Copyright (C) 2023, 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 @@ -23,19 +23,24 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; +out vec4 frag_color; -VARYING vec2 vary_fragcoord; +uniform sampler2D diffuseMap; -uniform vec2 screen_res; +in vec4 post_pos; +in float target_pos_x; +in vec4 vertex_color; +in vec2 vary_texcoord0; +uniform float minimum_alpha; -void main() +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; + float alpha = texture(diffuseMap,vary_texcoord0.xy).a; + + if (alpha < minimum_alpha) + { + discard; + } + + frag_color = vec4(1,1,1,1); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskV.glsl new file mode 100644 index 0000000000..4fb5fbcf06 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskV.glsl @@ -0,0 +1,75 @@ +/** + * @file pbrShadowAlphaMaskV.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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; +#if defined(HAS_SKIN) +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else +uniform mat4 modelview_projection_matrix; +#endif + +uniform vec4[2] texture_base_color_transform; +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + +uniform float shadow_target_width; + +in vec3 position; +in vec4 diffuse_color; +in vec2 texcoord0; + +out vec4 post_pos; +out float target_pos_x; +out vec4 vertex_color; +out vec2 vary_texcoord0; + +void passTextureIndex(); + +void main() +{ + //transform vertex +#if defined(HAS_SKIN) + vec4 pre_pos = vec4(position.xyz, 1.0); + mat4 mat = getObjectSkinnedTransform(); + mat = modelview_matrix * mat; + vec4 pos = mat * pre_pos; + pos = projection_matrix * pos; +#else + vec4 pre_pos = vec4(position.xyz, 1.0); + vec4 pos = modelview_projection_matrix * pre_pos; +#endif + + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; + + post_pos = pos; + + gl_Position = pos; + + passTextureIndex(); + + vary_texcoord0 = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/indirect.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl index 49bfa660f8..2ccd3fd962 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/indirect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl @@ -1,9 +1,9 @@ /** - * @file class1/deferred/indirect.glsl + * @file pbralphaF.glsl * - * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. + * Copyright (C) 2023, 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 @@ -23,8 +23,11 @@ * $/LicenseInfo$ */ -vec3 getIndirect(vec3 ambient, vec3 norm, vec3 pos, vec2 pos_screen) + // debug stub + +out vec4 frag_color; + +void main() { - return ambient; + frag_color = vec4(1.0, 0, 0.5, 0.5); } - diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl new file mode 100644 index 0000000000..6b960fae33 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl @@ -0,0 +1,159 @@ +/** + * @file class1\deferred\pbralphaV.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + + +#ifndef IS_HUD + +// default alpha implementation + +#ifdef HAS_SKIN +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else +uniform mat3 normal_matrix; +uniform mat4 modelview_projection_matrix; +#endif +uniform mat4 texture_matrix0; + +#if !defined(HAS_SKIN) +uniform mat4 modelview_matrix; +#endif + +out vec3 vary_position; + +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_normal_transform; +uniform vec4[2] texture_metallic_roughness_transform; +uniform vec4[2] texture_emissive_transform; + +out vec3 vary_fragcoord; + +uniform float near_clip; + +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec4 tangent; +in vec2 texcoord0; + +out vec2 base_color_texcoord; +out vec2 normal_texcoord; +out vec2 metallic_roughness_texcoord; +out vec2 emissive_texcoord; + +out vec4 vertex_color; + +out vec3 vary_tangent; +flat out float vary_sign; +out vec3 vary_normal; + +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + + +void main() +{ +#ifdef HAS_SKIN + mat4 mat = getObjectSkinnedTransform(); + mat = modelview_matrix * mat; + vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; + vary_position = pos; + vec4 vert = projection_matrix * vec4(pos,1.0); +#else + //transform vertex + vec4 vert = modelview_projection_matrix * vec4(position.xyz, 1.0); +#endif + gl_Position = vert; + + vary_fragcoord.xyz = vert.xyz + vec3(0,0,near_clip); + + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0); + metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + +#ifdef HAS_SKIN + vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; + vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; +#else //HAS_SKIN + vec3 n = normal_matrix * normal; + vec3 t = normal_matrix * tangent.xyz; +#endif //HAS_SKIN + + n = normalize(n); + + vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0)); + vary_sign = tangent.w; + vary_normal = n; + + vertex_color = diffuse_color; + +#if !defined(HAS_SKIN) + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; +#endif +} + +#else + +// fullbright HUD alpha implementation + +uniform mat4 modelview_projection_matrix; + +uniform mat4 texture_matrix0; + +uniform mat4 modelview_matrix; + +out vec3 vary_position; + +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_emissive_transform; + +in vec3 position; +in vec4 diffuse_color; +in vec2 texcoord0; + +out vec2 base_color_texcoord; +out vec2 emissive_texcoord; + +out vec4 vertex_color; + +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + + +void main() +{ + //transform vertex + vec4 vert = modelview_projection_matrix * vec4(position.xyz, 1.0); + gl_Position = vert; + vary_position = vert.xyz; + + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + + vertex_color = diffuse_color; +} + +#endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrglowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrglowF.glsl new file mode 100644 index 0000000000..b74b2e6a83 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrglowF.glsl @@ -0,0 +1,67 @@ +/** + * @file pbrglowF.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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]*/ + +// forward fullbright implementation for HUDs + +uniform sampler2D diffuseMap; //always in sRGB space + +uniform vec3 emissiveColor; +uniform sampler2D emissiveMap; + +out vec4 frag_color; + +in vec3 vary_position; +in vec4 vertex_emissive; + +in vec2 base_color_texcoord; +in vec2 emissive_texcoord; + +uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() + +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); + +void main() +{ + vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; + + if (basecolor.a < minimum_alpha) + { + discard; + } + + vec3 emissive = emissiveColor; + emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); + + float lum = max(max(emissive.r, emissive.g), emissive.b); + lum *= vertex_emissive.a; + + // HUDs are rendered after gamma correction, output in sRGB space + frag_color.rgb = vec3(0); + frag_color.a = lum; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrglowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrglowV.glsl new file mode 100644 index 0000000000..82a50a115c --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrglowV.glsl @@ -0,0 +1,72 @@ +/** + * @file pbgglowV.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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 HAS_SKIN +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else +uniform mat4 modelview_projection_matrix; +#endif + +uniform mat4 texture_matrix0; + +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_emissive_transform; + +in vec3 position; +in vec4 emissive; + +in vec2 texcoord0; + +out vec2 base_color_texcoord; +out vec2 emissive_texcoord; + +out vec4 vertex_emissive; + +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + +void main() +{ +#ifdef 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 + + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + + vertex_emissive = emissive; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl new file mode 100644 index 0000000000..faa273b834 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -0,0 +1,153 @@ +/** + * @file pbropaqueF.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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]*/ + + +#ifndef IS_HUD + +// deferred opaque implementation + +uniform sampler2D diffuseMap; //always in sRGB space + +uniform float metallicFactor; +uniform float roughnessFactor; +uniform vec3 emissiveColor; +uniform sampler2D bumpMap; +uniform sampler2D emissiveMap; +uniform sampler2D specularMap; // Packed: Occlusion, Metal, Roughness + +out vec4 frag_data[4]; + +in vec3 vary_position; +in vec4 vertex_color; +in vec3 vary_normal; +in vec3 vary_tangent; +flat in float vary_sign; + +in vec2 base_color_texcoord; +in vec2 normal_texcoord; +in vec2 metallic_roughness_texcoord; +in vec2 emissive_texcoord; + +uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() + +vec2 encode_normal(vec3 n); +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); + +uniform mat3 normal_matrix; + +void main() +{ + vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; + if (basecolor.a < minimum_alpha) + { + discard; + } + + vec3 col = vertex_color.rgb * srgb_to_linear(basecolor.rgb); + + // from mikktspace.com + vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; + float sign = vary_sign; + vec3 vN = vary_normal; + vec3 vT = vary_tangent.xyz; + + vec3 vB = sign * cross(vN, vT); + vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); + + // RGB = Occlusion, Roughness, Metal + // default values, see LLViewerTexture::sDefaultPBRORMImagep + // occlusion 1.0 + // roughness 0.0 + // metal 0.0 + vec3 spec = texture(specularMap, metallic_roughness_texcoord.xy).rgb; + + spec.g *= roughnessFactor; + spec.b *= metallicFactor; + + vec3 emissive = emissiveColor; + emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); + + tnorm *= gl_FrontFacing ? 1.0 : -1.0; + + //spec.rgb = vec3(1,1,0); + //col = vec3(0,0,0); + //emissive = vary_tangent.xyz*0.5+0.5; + //emissive = vec3(sign*0.5+0.5); + //emissive = vNt * 0.5 + 0.5; + //emissive = tnorm*0.5+0.5; + // See: C++: addDeferredAttachments(), GLSL: softenLightF + frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse + frag_data[1] = max(vec4(spec.rgb,vertex_color.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. + frag_data[2] = max(vec4(encode_normal(tnorm), vertex_color.a, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags + frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive +} + +#else + +// forward fullbright implementation for HUDs + +uniform sampler2D diffuseMap; //always in sRGB space + +uniform vec3 emissiveColor; +uniform sampler2D emissiveMap; + +out vec4 frag_color; + +in vec3 vary_position; +in vec4 vertex_color; + +in vec2 base_color_texcoord; +in vec2 emissive_texcoord; + +uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() + +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); + +void main() +{ + vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; + if (basecolor.a < minimum_alpha) + { + discard; + } + + vec3 col = vertex_color.rgb * srgb_to_linear(basecolor.rgb); + + vec3 emissive = emissiveColor; + emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb); + + col += emissive; + + // HUDs are rendered after gamma correction, output in sRGB space + frag_color.rgb = linear_to_srgb(col); + frag_color.a = 0.0; +} + +#endif + diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl new file mode 100644 index 0000000000..160ae7a215 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -0,0 +1,139 @@ +/** + * @file pbropaqueV.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + + +#ifndef IS_HUD + +//deferred opaque implementation + +#ifdef HAS_SKIN +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else +uniform mat3 normal_matrix; +uniform mat4 modelview_projection_matrix; +#endif +uniform mat4 texture_matrix0; + +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_normal_transform; +uniform vec4[2] texture_metallic_roughness_transform; +uniform vec4[2] texture_emissive_transform; + +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec4 tangent; +in vec2 texcoord0; + +out vec2 base_color_texcoord; +out vec2 normal_texcoord; +out vec2 metallic_roughness_texcoord; +out vec2 emissive_texcoord; + +out vec4 vertex_color; + +out vec3 vary_tangent; +flat out float vary_sign; +out vec3 vary_normal; + +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + +void main() +{ +#ifdef 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 + + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + normal_texcoord = texture_transform(texcoord0, texture_normal_transform, texture_matrix0); + metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + +#ifdef HAS_SKIN + vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; + vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; +#else //HAS_SKIN + vec3 n = normal_matrix * normal; + vec3 t = normal_matrix * tangent.xyz; +#endif + + n = normalize(n); + + vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0)); + vary_sign = tangent.w; + vary_normal = n; + + vertex_color = diffuse_color; +} + +#else + +// fullbright HUD implementation + +uniform mat4 modelview_projection_matrix; + +uniform mat4 texture_matrix0; + +uniform vec4[2] texture_base_color_transform; +uniform vec4[2] texture_emissive_transform; + +in vec3 position; +in vec4 diffuse_color; +in vec2 texcoord0; + +out vec2 base_color_texcoord; +out vec2 emissive_texcoord; + +out vec4 vertex_color; + +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); + +void main() +{ + //transform vertex + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + + base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + + vertex_color = diffuse_color; +} + +#endif + + diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl deleted file mode 100644 index 18616a9bb3..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ /dev/null @@ -1,132 +0,0 @@ -/** - * @file pointLightF.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 - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; -uniform samplerCube environmentMap; -uniform sampler2D noiseMap; -uniform sampler2D lightFunc; -uniform sampler2DRect depthMap; - -uniform vec3 env_mat[3]; -uniform float sun_wash; - -uniform vec3 color; -uniform float falloff; -uniform float size; - -VARYING vec4 vary_fragcoord; -VARYING vec3 trans_center; - -uniform vec2 screen_res; - -uniform mat4 inv_proj; -uniform vec4 viewport; - -vec3 getNorm(vec2 pos_screen); -vec4 getPosition(vec2 pos_screen); -vec3 srgb_to_linear(vec3 c); - -void main() -{ - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = trans_center.xyz-pos; - float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } - - vec3 norm = getNorm(frag.xy); - - float da = dot(norm, lv); - if (da < 0.0) - { - discard; - } - - lv = normalize(lv); - da = dot(norm, lv); - - float noise = texture2D(noiseMap, frag.xy/128.0).b; - - vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; - - 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; - - float lit = da * dist_atten * noise; - - col = color.rgb*lit*col; - - 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); - 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; - } - } - - if (dot(col, col) <= 0.0) - { - discard; - } - - frag_color.rgb = col; - frag_color.a = 0.0; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl deleted file mode 100644 index 3da8531442..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightV.glsl +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @file pointLightV.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 modelview_projection_matrix; -uniform mat4 modelview_matrix; - -ATTRIBUTE vec3 position; - -uniform vec3 center; -uniform float size; - -VARYING vec4 vary_fragcoord; -VARYING vec3 trans_center; - -void main() -{ - //transform vertex - vec3 p = position*size+center; - vec4 pos = modelview_projection_matrix * vec4(p.xyz, 1.0); - vary_fragcoord = pos; - trans_center = (modelview_matrix*vec4(center.xyz, 1.0)).xyz; - gl_Position = pos; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl index f06f8c870b..86e3f1acda 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl @@ -23,28 +23,22 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2DRect diffuseRect; +uniform sampler2D diffuseRect; uniform mat4 inv_proj; uniform vec2 screen_res; uniform float max_cof; uniform float res_scale; -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; void dofSample(inout vec4 diff, inout float w, float min_sc, vec2 tc) { - vec4 s = texture2DRect(diffuseRect, tc); + vec4 s = texture(diffuseRect, tc); float sc = abs(s.a*2.0-1.0)*max_cof; @@ -63,7 +57,7 @@ void dofSample(inout vec4 diff, inout float w, float min_sc, vec2 tc) void dofSampleNear(inout vec4 diff, inout float w, float min_sc, vec2 tc) { - vec4 s = texture2DRect(diffuseRect, tc); + vec4 s = texture(diffuseRect, tc); float wg = 0.25; @@ -79,7 +73,7 @@ void main() { vec2 tc = vary_fragcoord.xy; - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); + vec4 diff = texture(diffuseRect, vary_fragcoord.xy); { float w = 1.0; @@ -93,14 +87,14 @@ void main() { while (sc > 0.5) { - int its = int(max(1.0,(sc*3.7))); + int its = int(max(1.0,(sc*3.7))); for (int i=0; i<its; ++i) { float ang = sc+i*2*PI/its; // sc is added for rotary perturbance float samp_x = sc*sin(ang); float samp_y = sc*cos(ang); // you could test sample coords against an interesting non-circular aperture shape here, if desired. - dofSampleNear(diff, w, sc, vary_fragcoord.xy + vec2(samp_x,samp_y)); + dofSampleNear(diff, w, sc, vary_fragcoord.xy + (vec2(samp_x,samp_y) / screen_res)); } sc -= 1.0; } @@ -117,7 +111,7 @@ void main() float samp_x = sc*sin(ang); float samp_y = sc*cos(ang); // you could test sample coords against an interesting non-circular aperture shape here, if desired. - dofSample(diff, w, sc, vary_fragcoord.xy + vec2(samp_x,samp_y)); + dofSample(diff, w, sc, vary_fragcoord.xy + (vec2(samp_x,samp_y) / screen_res)); } sc -= 1.0; } @@ -125,6 +119,6 @@ void main() diff /= w; } - + 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 index cd37a34e0d..53e4f02314 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -23,30 +23,163 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2DRect diffuseRect; +uniform sampler2D diffuseRect; +uniform sampler2D exposureMap; uniform vec2 screen_res; -VARYING vec2 vary_fragcoord; -uniform float display_gamma; +in vec2 vary_fragcoord; vec3 linear_to_srgb(vec3 cl); +//=============================================================== +// tone mapping taken from Khronos sample implementation +//=============================================================== + +// sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT +const mat3 ACESInputMat = mat3 +( + 0.59719, 0.07600, 0.02840, + 0.35458, 0.90834, 0.13383, + 0.04823, 0.01566, 0.83777 +); + + +// ODT_SAT => XYZ => D60_2_D65 => sRGB +const mat3 ACESOutputMat = mat3 +( + 1.60475, -0.10208, -0.00327, + -0.53108, 1.10813, -0.07276, + -0.07367, -0.00605, 1.07602 +); + +// ACES tone map (faster approximation) +// see: https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ +vec3 toneMapACES_Narkowicz(vec3 color) +{ + const float A = 2.51; + const float B = 0.03; + const float C = 2.43; + const float D = 0.59; + const float E = 0.14; + return clamp((color * (A * color + B)) / (color * (C * color + D) + E), 0.0, 1.0); +} + + +// ACES filmic tone map approximation +// see https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl +vec3 RRTAndODTFit(vec3 color) +{ + vec3 a = color * (color + 0.0245786) - 0.000090537; + vec3 b = color * (0.983729 * color + 0.4329510) + 0.238081; + return a / b; +} + + +// tone mapping +vec3 toneMapACES_Hill(vec3 color) +{ + color = ACESInputMat * color; + + // Apply RRT and ODT + color = RRTAndODTFit(color); + + color = ACESOutputMat * color; + + // Clamp to [0, 1] + color = clamp(color, 0.0, 1.0); + + return color; +} + +uniform float exposure; +uniform float gamma; + +vec3 toneMap(vec3 color) +{ +#ifndef NO_POST + float exp_scale = texture(exposureMap, vec2(0.5,0.5)).r; + + color *= exposure * exp_scale; + + color = toneMapACES_Hill(color); +#endif + + 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; +} + +//============================= + + +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 = texture2DRect(diffuseRect, vary_fragcoord); - //diff.rgb = pow(diff.rgb, vec3(display_gamma)); + vec4 diff = texture(diffuseRect, vary_fragcoord); + +#ifdef LEGACY_GAMMA + diff.rgb = linear_to_srgb(diff.rgb); + diff.rgb = legacyGamma(diff.rgb); +#else +#ifndef NO_POST + diff.rgb = toneMap(diff.rgb); +#endif diff.rgb = linear_to_srgb(diff.rgb); - frag_color = diff; +#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; + + 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 058941bfb2..bace9b8c90 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl @@ -23,27 +23,22 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2DRect diffuseRect; -uniform sampler2D bloomMap; +uniform sampler2D diffuseRect; +uniform sampler2D depthMap; uniform vec2 screen_res; -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; void main() { - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); + vec4 diff = texture(diffuseRect, vary_fragcoord.xy); - vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res); - frag_color = diff + bloom; + frag_color = diff; + + gl_FragDepth = texture(depthMap, vary_fragcoord.xy).r; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl index bd0cb50464..7e8a5d68d4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl @@ -23,18 +23,16 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; +in vec3 position; -ATTRIBUTE vec3 position; - -VARYING vec2 vary_fragcoord; +out vec2 vary_fragcoord; uniform vec2 screen_res; 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; + vec4 pos = vec4(position.xyz, 1.0); + gl_Position = pos; + vary_fragcoord = (pos.xy*0.5+0.5); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl index 8edf5b2723..10b4b3e76c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl @@ -23,12 +23,10 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; +in vec3 position; -ATTRIBUTE vec3 position; - -VARYING vec2 vary_fragcoord; -VARYING vec2 vary_tc; +out vec2 vary_fragcoord; +out vec2 vary_tc; uniform vec2 tc_scale; @@ -37,8 +35,8 @@ uniform vec2 screen_res; void main() { //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 pos = vec4(position.xyz, 1.0); gl_Position = pos; vary_tc = (pos.xy*0.5+0.5)*tc_scale; - vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; + vary_fragcoord = (pos.xy*0.5+0.5); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredVisualizeBuffers.glsl index 8e9a5fcd41..2c17de311c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredVisualizeBuffers.glsl @@ -1,5 +1,6 @@ /** - * @file avatarShadowF.glsl + * @file postDeferredNoDoFF.glsl + * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. @@ -21,21 +22,20 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2D diffuseMap; +uniform sampler2D diffuseRect; +uniform float mipLevel; -VARYING vec2 vary_texcoord0; +in vec2 vary_fragcoord; void main() { - frag_color = vec4(1,1,1,1); + vec4 diff = textureLod(diffuseRect, vary_fragcoord.xy, mipLevel); + + frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl deleted file mode 100644 index cf994d3547..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ /dev/null @@ -1,99 +0,0 @@ -/** - * @file postgiF.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]*/ - - #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DRect giLightMap; -uniform sampler2D noiseMap; - -uniform vec2 kern[32]; -uniform float dist_factor; -uniform float blur_size; -uniform vec2 delta; -uniform int kern_length; -uniform float kern_scale; -uniform vec3 blur_quad; - -VARYING vec2 vary_fragcoord; - -uniform mat4 inv_proj; -uniform vec2 screen_res; - -vec4 getPosition(vec2 pos_screen); - -void main() -{ - vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz; - norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm - vec3 pos = getPosition(vary_fragcoord.xy).xyz; - - vec3 ccol = texture2DRect(giLightMap, vary_fragcoord.xy).rgb; - vec2 dlt = kern_scale * delta/(1.0+norm.xy*norm.xy); - dlt /= max(-pos.z*dist_factor, 1.0); - float defined_weight = kern[0].x; - vec3 col = vec3(0.0); - - for (int i = 0; i < kern_length; i++) - { - vec2 tc = vary_fragcoord.xy + kern[i].y*dlt; - vec3 sampNorm = texture2DRect(normalMap, tc.xy).xyz; - sampNorm = vec3((sampNorm.xy-0.5)*2.0,sampNorm.z); // unpack norm - - float d = dot(norm.xyz, sampNorm); - - if (d > 0.8) - { - vec3 samppos = getPosition(tc.xy).xyz; - samppos -= pos; - if (dot(samppos,samppos) < -0.05*pos.z) - { - col += texture2DRect(giLightMap, tc).rgb*kern[i].x; - defined_weight += kern[i].x; - } - } - } - - col /= defined_weight; - - //col = ccol; - - col = col*col*blur_quad.x + col*blur_quad.y + blur_quad.z; - - frag_color.rgb = col; - -#ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - vec2 dummy1 = kern[0]; - vec2 dummy2 = kern[31]; -#endif -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl index 7329efe3f7..1a85d70256 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl @@ -1,41 +1,37 @@ -/** - * @file sunLightF.glsl +/** + * @file class3/deferred/screenSpaceReflUtil.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$ */ - -//class 1, no shadow, no SSAO, should never be called -#extension GL_ARB_texture_rectangle : enable +// debug stub -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif +float random (vec2 uv) +{ + return 0; +} -void main() +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness) { - frag_color = vec4(0,0,0,0); + collectedColor = vec4(0); + return 0; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl deleted file mode 100644 index f45c343066..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @file shadowAlphaMaskV.glsl - * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2011, 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; -uniform float shadow_target_width; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; - -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - -VARYING float target_pos_x; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -void passTextureIndex(); - -void main() -{ - //transform vertex - 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 !defined(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(); - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - 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 9b8df0a5a4..a8febabcc6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -25,26 +25,21 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform sampler2D diffuseMap; -VARYING vec4 post_pos; -VARYING float target_pos_x; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec4 post_pos; +in float target_pos_x; +in vec4 vertex_color; +in vec2 vary_texcoord0; uniform float minimum_alpha; void main() { float alpha = diffuseLookup(vary_texcoord0.xy).a; - // mask cutoff 0 -> no shadow SL-11051 - if (minimum_alpha == 0) + if (alpha < minimum_alpha) { discard; } @@ -53,22 +48,18 @@ void main() alpha *= vertex_color.a; #endif - if (alpha < 0.05) // treat as totally transparent - { - discard; - } + if (alpha < 0.05) // treat as totally transparent + { + discard; + } - if (alpha < 0.88) // treat as semi-transparent - { - if (fract(0.5*floor(target_pos_x / post_pos.w )) < 0.25) - { - discard; - } - } + if (alpha < 0.88) // treat as semi-transparent + { + if (fract(0.5*floor(target_pos_x / post_pos.w )) < 0.25) + { + discard; + } + } frag_color = vec4(1,1,1,1); - -#if !defined(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/shadowAlphaMaskSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskSkinnedV.glsl deleted file mode 100644 index 2b17aea75a..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskSkinnedV.glsl +++ /dev/null @@ -1,70 +0,0 @@ -/** - * @file shadowAlphaMaskSkinnedV.glsl - * - * $LicenseInfo:firstyear=2021&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2011, 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_matrix; -uniform mat4 projection_matrix; -uniform float shadow_target_width; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; - -VARYING vec4 post_pos; -VARYING float target_pos_x; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -void passTextureIndex(); - -mat4 getObjectSkinnedTransform(); - -void main() -{ - //transform vertex - vec4 pre_pos = vec4(position.xyz, 1.0); - - mat4 mat = getObjectSkinnedTransform(); - - mat = modelview_matrix * mat; - - vec4 pos = mat * pre_pos; - pos = projection_matrix * pos; - - target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; - - post_pos = pos; - -#if !defined(DEPTH_CLAMP) - gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); -#else - gl_Position = pos; -#endif - - passTextureIndex(); - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - vertex_color = diffuse_color; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl index b6a0f0b165..26db1a5d4d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl @@ -24,34 +24,46 @@ */ uniform mat4 texture_matrix0; +#if defined(HAS_SKIN) +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else uniform mat4 modelview_projection_matrix; +#endif + uniform float shadow_target_width; -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec4 diffuse_color; +in vec2 texcoord0; -VARYING vec4 post_pos; -VARYING float target_pos_x; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +out vec4 post_pos; +out float target_pos_x; +out vec4 vertex_color; +out vec2 vary_texcoord0; void passTextureIndex(); void main() { //transform vertex +#if defined(HAS_SKIN) + vec4 pre_pos = vec4(position.xyz, 1.0); + mat4 mat = getObjectSkinnedTransform(); + mat = modelview_matrix * mat; + vec4 pos = mat * pre_pos; + pos = projection_matrix * pos; +#else vec4 pre_pos = vec4(position.xyz, 1.0); vec4 pos = modelview_projection_matrix * pre_pos; +#endif + target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; post_pos = pos; -#if !defined(DEPTH_CLAMP) - 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 0e74d2eb8a..0f5f9ed289 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl @@ -25,11 +25,7 @@ uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; - -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif +in vec3 position; uniform vec3 box_center; uniform vec3 box_size; @@ -40,11 +36,5 @@ void main() vec3 p = position*box_size+box_center; vec4 pos = modelview_projection_matrix*vec4(p.xyz, 1.0); -#if !defined(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 1ea96918bb..370aa75d04 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -23,22 +23,9 @@ * $/LicenseInfo$ */ -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -VARYING vec4 post_pos; void main() { frag_color = vec4(1,1,1,1); - -#if !defined(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/shadowSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowSkinnedV.glsl index bdf8e0854d..9bbc63bce1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowSkinnedV.glsl @@ -26,9 +26,7 @@ uniform mat4 modelview_matrix; uniform mat4 projection_matrix; -ATTRIBUTE vec3 position; - -VARYING vec4 post_pos; +in vec3 position; mat4 getObjectSkinnedTransform(); @@ -41,12 +39,5 @@ void main() vec4 pos = (mat*vec4(position.xyz, 1.0)); pos = projection_matrix*pos; - post_pos = pos; - -#if !defined(DEPTH_CLAMP) - 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/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 4134220306..ee3a5f1f31 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -23,14 +23,20 @@ * $/LicenseInfo$ */ -uniform sampler2DRect normalMap; -uniform sampler2DRect depthMap; +uniform sampler2D normalMap; +uniform sampler2D depthMap; + +#if defined(SUN_SHADOW) uniform sampler2DShadow shadowMap0; uniform sampler2DShadow shadowMap1; uniform sampler2DShadow shadowMap2; uniform sampler2DShadow shadowMap3; +#endif + +#if defined(SPOT_SHADOW) uniform sampler2DShadow shadowMap4; uniform sampler2DShadow shadowMap5; +#endif uniform vec3 sun_dir; uniform vec3 moon_dir; @@ -48,40 +54,49 @@ uniform int sun_up_factor; float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { +#if defined(SUN_SHADOW) float offset = shadow_bias * bias_mul; stc.xyz /= stc.w; stc.z += offset * 2.0; stc.x = floor(stc.x*shadow_res.x + fract(pos_screen.y*shadow_res.y))/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 cs = texture(shadowMap, stc.xyz); float shadow = cs * 4.0; - shadow += shadow2D(shadowMap, stc.xyz+vec3( 1.5/shadow_res.x, 0.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3( 0.5/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.5/shadow_res.x, -0.5/shadow_res.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-0.5/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; + shadow += texture(shadowMap, stc.xyz+vec3( 1.5/shadow_res.x, 0.5/shadow_res.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3( 0.5/shadow_res.x, -1.5/shadow_res.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(-1.5/shadow_res.x, -0.5/shadow_res.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(-0.5/shadow_res.x, 1.5/shadow_res.y, 0.0)); return clamp(shadow * 0.125, 0.0, 1.0); +#else + return 1.0; +#endif } float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) { +#if defined(SPOT_SHADOW) stc.xyz /= stc.w; stc.z += spot_shadow_bias * bias_scale; stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - float cs = shadow2D(shadowMap, stc.xyz).x; + float cs = texture(shadowMap, stc.xyz); float shadow = cs; vec2 off = 1.0/proj_shadow_res; off.y *= 1.5; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; - shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; + shadow += texture(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)); + shadow += texture(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)); return shadow*0.2; +#else + return 1.0; +#endif } float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { +#if defined(SUN_SHADOW) float shadow = 0.0f; vec3 light_dir = normalize((sun_up_factor == 1) ? sun_dir : moon_dir); @@ -175,10 +190,14 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) } //shadow = min(dp_directional_light,shadow); return shadow; +#else + return 1.0; +#endif } float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) { +#if defined(SPOT_SHADOW) float shadow = 0.0f; pos += norm * spot_shadow_offset; @@ -217,5 +236,8 @@ float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) shadow = 1.0f; } return shadow; +#else + return 1.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 72bd0f0f34..bd62954ff8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowV.glsl @@ -25,21 +25,10 @@ uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; - -VARYING vec4 post_pos; +in vec3 position; void main() { //transform vertex - vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0); - - post_pos = pos; - -#if !defined(DEPTH_CLAMP) - gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); -#else - gl_Position = pos; -#endif - + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index de22312d3c..9d9ba49d82 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -22,12 +22,10 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - -/*[EXTRA_CODE_HERE]*/ // Inputs -VARYING vec4 vary_HazeColor; -VARYING float vary_LightNormPosDot; +in vec3 vary_HazeColor; +in float vary_LightNormPosDot; uniform sampler2D rainbow_map; uniform sampler2D halo_map; @@ -36,16 +34,15 @@ uniform float moisture_level; uniform float droplet_radius; uniform float ice_level; -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; + +vec3 srgb_to_linear(vec3 c); ///////////////////////////////////////////////////////////////////////// // The fragment shader for the sky ///////////////////////////////////////////////////////////////////////// + vec3 rainbow(float d) { // 'Interesting' values of d are -0.75 .. -0.825, i.e. when view vec nearly opposite of sun vec @@ -62,19 +59,16 @@ vec3 rainbow(float d) d = clamp(d, 0.0, 0.25) + interior_coord; float rad = (droplet_radius - 5.0f) / 1024.0f; - return pow(texture2D(rainbow_map, vec2(rad+0.5, d)).rgb, vec3(1.8)) * moisture_level; + return pow(texture(rainbow_map, vec2(rad+0.5, d)).rgb, vec3(1.8)) * moisture_level; } vec3 halo22(float d) { d = clamp(d, 0.1, 1.0); float v = sqrt(clamp(1 - (d * d), 0, 1)); - return texture2D(halo_map, vec2(0, v)).rgb * ice_level; + return texture(halo_map, vec2(0, v)).rgb * ice_level; } -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light); - void main() { // Potential Fill-rate optimization. Add cloud calculation @@ -82,7 +76,7 @@ void main() // the fragment) if the sky wouldn't show up because the clouds // are fully opaque. - vec4 color = vary_HazeColor; + vec3 color = vary_HazeColor; float rel_pos_lightnorm = vary_LightNormPosDot; float optic_d = rel_pos_lightnorm; @@ -90,13 +84,11 @@ void main() color.rgb += rainbow(optic_d); color.rgb += halo_22; color.rgb *= 2.; - color.rgb = scaleSoftClip(color.rgb); - - // Gamma correct for WL (soft clip effect). - frag_data[0] = vec4(color.rgb, 1.0); - frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0.0,0.0,0.0,1.0); //1.0 in norm.w masks off fog + color.rgb = clamp(color.rgb, vec3(0), vec3(5)); - gl_FragDepth = 0.99999f; + frag_data[0] = vec4(0); + frag_data[1] = vec4(0); + frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); //1.0 in norm.w masks off fog + frag_data[3] = vec4(color.rgb, 1.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 6db4690bff..17ce2dee5b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -25,26 +25,26 @@ uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; +in vec3 position; // SKY //////////////////////////////////////////////////////////////////////// // The vertex shader for creating the atmospheric sky /////////////////////////////////////////////////////////////////////////////// // Output parameters -VARYING vec4 vary_HazeColor; -VARYING float vary_LightNormPosDot; +out vec3 vary_HazeColor; +out float vary_LightNormPosDot; // Inputs uniform vec3 camPosLocal; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; +uniform vec3 lightnorm; +uniform vec3 sunlight_color; +uniform vec3 moonlight_color; uniform int sun_up_factor; -uniform vec4 ambient_color; -uniform vec4 blue_horizon; -uniform vec4 blue_density; +uniform vec3 ambient_color; +uniform vec3 blue_horizon; +uniform vec3 blue_density; uniform float haze_horizon; uniform float haze_density; @@ -53,10 +53,10 @@ uniform float density_multiplier; uniform float distance_multiplier; uniform float max_y; -uniform vec4 glow; +uniform vec3 glow; uniform float sun_moon_glow_factor; -uniform vec4 cloud_color; +uniform int cube_snapshot; // NOTE: Keep these in sync! // indra\newview\app_settings\shaders\class1\deferred\skyV.glsl @@ -91,16 +91,16 @@ void main() vary_LightNormPosDot = rel_pos_lightnorm_dot; // Initialize temp variables - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; - + vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color * 0.7; //magic 0.7 to match legacy color + // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - vec4 light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); + vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights - vec4 combined_haze = abs(blue_density) + vec4(abs(haze_density)); - vec4 blue_weight = blue_density / combined_haze; - vec4 haze_weight = haze_density / combined_haze; + vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density)); + vec3 blue_weight = blue_density / combined_haze; + vec3 haze_weight = haze_density / combined_haze; // Compute sunlight from rel_pos & lightnorm (for long rays like sky) float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y); @@ -129,20 +129,20 @@ void main() haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (sun_moon_glow_factor * (haze_glow + 0.25)); // Haze color above cloud - vec4 color = (blue_horizon * blue_weight * (sunlight + ambient_color) + vec3 color = (blue_horizon * blue_weight * (sunlight + ambient_color) + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient_color)); // Final atmosphere additive color *= (1. - combined_haze); // Increase ambient when there are more clouds - vec4 ambient = ambient_color + max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5; + vec3 ambient = ambient_color + max(vec3(0), (1. - ambient_color)) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage sunlight *= max(0.0, (1. - cloud_shadow)); // Haze color below cloud - vec4 add_below_cloud = (blue_horizon * blue_weight * (sunlight + ambient) + vec3 add_below_cloud = (blue_horizon * blue_weight * (sunlight + ambient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient)); // Attenuate cloud color by atmosphere diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl deleted file mode 100644 index 7f2c603f87..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ /dev/null @@ -1,170 +0,0 @@ -/** - * @file class1/deferred/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 -#extension GL_ARB_shader_texture_lod : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -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 mat3 env_mat; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -uniform int sun_up_factor; -VARYING vec2 vary_fragcoord; - -uniform mat4 inv_proj; -uniform vec2 screen_res; - -vec3 getNorm(vec2 pos_screen); -vec4 getPositionWithDepth(vec2 pos_screen, float depth); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); -float getAmbientClamp(); -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClip(vec3 light); - -vec3 linear_to_srgb(vec3 c); -vec3 srgb_to_linear(vec3 c); - -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - -void main() -{ - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec4 pos = getPositionWithDepth(tc, depth); - vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = getNorm(tc); - - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); - float light_gamma = 1.0/1.3; - da = pow(da, light_gamma); - - vec4 diffuse = texture2DRect(diffuseRect, tc); - - //convert to gamma space - diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 - - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 color = vec3(0); - float bloom = 0.0; - { - float ambocc = 1.0; // no AO... - - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - - calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, false); - - color.rgb = amblit; - - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - - color.rgb *= ambient; - - vec3 sun_contrib = da * sunlit; - - color.rgb += sun_contrib; - - color.rgb *= diffuse.rgb; - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - if (spec.a > 0.0) // specular reflection - { - float sa = dot(refnormpersp, light_dir.xyz); - vec3 dumbshiny = sunlit * (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; - color.rgb += spec_contrib; - } - - color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); - - if (envIntensity > 0.0) - { //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - color = mix(color.rgb, reflected_color, envIntensity); - } - - if (norm.w < 0.5) - { - color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); - color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); - } - - #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz,vec4(color, bloom)); - color = fogged.rgb; - bloom = fogged.a; - #endif - - } - -// linear debuggables -//color.rgb = vec3(final_da); -//color.rgb = vec3(ambient); -//color.rgb = vec3(scol); -//color.rgb = diffuse_srgb.rgb; - - // convert to linear as fullscreen lights need to sum in linear colorspace - // and will be gamma (re)corrected downstream... - - frag_color.rgb = srgb_to_linear(color.rgb); - frag_color.a = bloom; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl deleted file mode 100644 index 8891315e15..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @file softenLightV.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 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - -uniform vec2 screen_res; - -void setAtmosAttenuation(vec3 c); -void setAdditiveColor(vec3 c); - -VARYING vec2 vary_fragcoord; -void main() -{ - //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); - gl_Position = pos; - // appease OSX GLSL compiler/linker by touching all the varyings we said we would - setAtmosAttenuation(vec3(1)); - setAdditiveColor(vec3(0)); - 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 deleted file mode 100644 index 694b19cdfb..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ /dev/null @@ -1,279 +0,0 @@ -/** - * @file spotLightF.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 -#extension GL_ARB_shader_texture_lod : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -//class 1 -- no shadows - -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -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 -uniform vec3 proj_p; //plane projection is emitting from (in screen space) -uniform vec3 proj_n; -uniform float proj_focus; //distance from plane to begin blurring -uniform float proj_lod; //(number of mips in proj map) -uniform float proj_range; //range between near clip and far clip plane of projection -uniform float proj_ambient_lod; -uniform float proj_ambiance; -uniform float near_clip; -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; - -VARYING vec3 trans_center; -VARYING vec4 vary_fragcoord; -uniform vec2 screen_res; - -uniform mat4 inv_proj; - -vec3 getNorm(vec2 pos_screen); -vec3 srgb_to_linear(vec3 c); - -vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - -vec4 getPosition(vec2 pos_screen); - -void main() -{ - vec3 col = vec3(0,0,0); - -#if defined(LOCAL_LIGHT_KILL) - discard; -#else - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = trans_center.xyz-pos.xyz; - float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } - - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - float envIntensity = norm.z; - norm = getNorm(frag.xy); - norm = normalize(norm); - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - - 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; - - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(norm, lv); - - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - //light shaders output linear and are gamma corrected later in postDeferredGammaCorrectF.glsl - diff_tex.rgb = srgb_to_linear(diff_tex.rgb); - - vec4 spec = texture2DRect(specularRect, frag.xy); - - 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 && - proj_tc.x > 0.0 && - proj_tc.y > 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; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - dlit = color.rgb * plcol.rgb * plcol.a; - - 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); - - amb_da += (da*da*0.5+0.5)*proj_ambiance; - - 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*diff_tex.rgb; - } - - if (spec.a > 0.0) - { - dlit *= min(da*6.0, 1.0) * dist_atten; - 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 += dlit*scol*spec.rgb; - //col += spec.rgb; - } - } - - if (envIntensity > 0.0) - { - vec3 ref = reflect(normalize(pos), norm); - - //project from point pos in direction ref to plane proj_p, proj_n - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - - if (stc.z > 0.0) - { - stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * envIntensity; - } - } - } - } -#endif - - //col.r = 1.0; - frag_color.rgb = col; - frag_color.a = 0.0; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index bac79a9fdc..b35d10c8a0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -25,18 +25,13 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; -VARYING vec2 screenpos; +in vec4 vertex_color; +in vec2 vary_texcoord0; +in vec2 screenpos; uniform sampler2D diffuseMap; -uniform sampler2D altDiffuseMap; uniform float blend_factor; uniform float custom_alpha; uniform float time; @@ -46,10 +41,15 @@ float twinkle(){ return abs(d); } +// See: +// ALM off: class1/environment/starsF.glsl +// ALM on : class1/deferred/starsF.glsl void main() { - vec4 col_a = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy); + // camera above water: class1\deferred\starsF.glsl + // camera below water: class1\environment\starsF.glsl + vec4 col_a = texture(diffuseMap, vary_texcoord0.xy); + vec4 col_b = texture(diffuseMap, vary_texcoord0.xy); vec4 col = mix(col_b, col_a, blend_factor); col.rgb *= vertex_color.rgb; @@ -58,10 +58,9 @@ void main() col.a = (col.a * factor) * 32.0f; col.a *= twinkle(); - frag_data[0] = col; + frag_data[0] = vec4(0); frag_data[1] = vec4(0.0f); - frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); - - gl_FragDepth = 0.99995f; + frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); + frag_data[3] = col; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl index bb2a2ee72b..726508607d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsV.glsl @@ -27,21 +27,23 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; uniform float time; -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec4 diffuse_color; +in vec2 texcoord0; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; -VARYING vec2 screenpos; +out vec4 vertex_color; +out vec2 vary_texcoord0; +out vec2 screenpos; void main() { //transform vertex vec4 pos = modelview_projection_matrix * vec4(position, 1.0); -// bias z to fix SL-9806 and get stars to depth test against clouds - pos.z += 0.001f; + + // smash to far clip plane to + // avoid rendering on top of moon (do NOT write to gl_FragDepth, it's slow) + pos.z = pos.w; gl_Position = pos; diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index b2fa5d8a25..fd343ed2dc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -23,42 +23,31 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; vec3 srgb_to_linear(vec3 c); -vec3 fullbrightAtmosTransport(vec3 light); -vec3 fullbrightScaleSoftClip(vec3 light); uniform sampler2D diffuseMap; uniform sampler2D altDiffuseMap; uniform float blend_factor; // interp factor between sunDisc A/B -VARYING vec2 vary_texcoord0; -VARYING float sun_fade; +in vec2 vary_texcoord0; +in float sun_fade; void main() { - vec4 sunDiscA = texture2D(diffuseMap, vary_texcoord0.xy); - vec4 sunDiscB = texture2D(altDiffuseMap, vary_texcoord0.xy); + vec4 sunDiscA = texture(diffuseMap, vary_texcoord0.xy); + vec4 sunDiscB = texture(altDiffuseMap, vary_texcoord0.xy); vec4 c = mix(sunDiscA, sunDiscB, blend_factor); - //c.rgb = fullbrightAtmosTransport(c.rgb); - c.rgb = fullbrightScaleSoftClip(c.rgb); // SL-9806 stars poke through //c.a *= sun_fade; - frag_data[0] = c; + frag_data[0] = vec4(0); frag_data[1] = vec4(0.0f); - frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); - - gl_FragDepth = 0.999988f; + frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); + frag_data[3] = c; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl index 0d117c6bc7..9a8d791a1d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscV.glsl @@ -27,11 +27,11 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec2 texcoord0; -VARYING vec2 vary_texcoord0; -VARYING float sun_fade; +out vec2 vary_texcoord0; +out float sun_fade; void calcAtmospherics(vec3 eye_pos); @@ -44,6 +44,8 @@ void main() sun_fade = smoothstep(0.3, 1.0, (position.z + 50) / 512.0f); + // smash to *almost* far clip plane -- behind clouds but in front of stars + pos.z = pos.w*0.999999; gl_Position = pos; calcAtmospherics(pos.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightNoFragCoordV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightNoFragCoordV.glsl deleted file mode 100644 index 47e9d15fbc..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightNoFragCoordV.glsl +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @file sunLightF.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 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - -uniform vec2 screen_res; - -void main() -{ - //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); - gl_Position = pos; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 6b6eed9db8..f6d509e2c6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -25,11 +25,7 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; uniform sampler2D detail_0; uniform sampler2D detail_1; @@ -37,10 +33,10 @@ uniform sampler2D detail_2; uniform sampler2D detail_3; uniform sampler2D alpha_ramp; -VARYING vec3 pos; -VARYING vec3 vary_normal; -VARYING vec4 vary_texcoord0; -VARYING vec4 vary_texcoord1; +in vec3 pos; +in vec3 vary_normal; +in vec4 vary_texcoord0; +in vec4 vary_texcoord1; vec2 encode_normal(vec3 n); @@ -48,14 +44,14 @@ void main() { /// Note: This should duplicate the blending functionality currently used for the terrain rendering. - vec4 color0 = texture2D(detail_0, vary_texcoord0.xy); - vec4 color1 = texture2D(detail_1, vary_texcoord0.xy); - vec4 color2 = texture2D(detail_2, vary_texcoord0.xy); - vec4 color3 = texture2D(detail_3, vary_texcoord0.xy); + vec4 color0 = texture(detail_0, vary_texcoord0.xy); + vec4 color1 = texture(detail_1, vary_texcoord0.xy); + vec4 color2 = texture(detail_2, vary_texcoord0.xy); + vec4 color3 = texture(detail_3, vary_texcoord0.xy); - float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; - float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; - float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; + float alpha1 = texture(alpha_ramp, vary_texcoord0.zw).a; + float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a; + float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a; vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); outColor.a = 0.0; // yes, downstream atmospherics @@ -63,6 +59,7 @@ void main() frag_data[0] = outColor; frag_data[1] = vec4(0.0,0.0,0.0,-1.0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl index f42cb6ff6d..f6d3b59e85 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl @@ -27,16 +27,16 @@ uniform mat3 normal_matrix; uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec2 texcoord1; +in vec3 position; +in vec3 normal; +in vec4 diffuse_color; +in vec2 texcoord0; +in vec2 texcoord1; -VARYING vec3 pos; -VARYING vec3 vary_normal; -VARYING vec4 vary_texcoord0; -VARYING vec4 vary_texcoord1; +out vec3 pos; +out vec3 vary_normal; +out vec4 vary_texcoord0; +out vec4 vary_texcoord1; uniform vec4 object_plane_s; uniform vec4 object_plane_t; diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl new file mode 100644 index 0000000000..636dfed4ba --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -0,0 +1,122 @@ +/** + * @file class1/deferred/textureUtilV.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, 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$ + */ + +// This shader code is taken from the sample code on the KHR_texture_transform +// spec page page, plus or minus some sign error corrections (I think because the GLSL +// matrix constructor is backwards?): +// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform +// Previously (6494eed242b1), we passed in a single, precalculated matrix +// uniform per transform into the shaders. However, that was found to produce +// small-but-noticeable discrepancies with the GLTF sample model +// "TextureTransformTest", likely due to numerical precision differences. In +// the interest of parity with other renderers, calculate the transform +// directly in the shader. -Cosmic,2023-02-24 +vec2 khr_texture_transform(vec2 texcoord, vec2 scale, float rotation, vec2 offset) +{ + mat3 scale_mat = mat3(scale.x,0,0, 0,scale.y,0, 0,0,1); + mat3 offset_mat = mat3(1,0,0, 0,1,0, offset.x, offset.y, 1); + mat3 rotation_mat = mat3( + cos(rotation),-sin(rotation), 0, + sin(rotation), cos(rotation), 0, + 0, 0, 1 + ); + + mat3 transform = offset_mat * rotation_mat * scale_mat; + + return (transform * vec3(texcoord, 1)).xy; +} + +// vertex_texcoord - The UV texture coordinates sampled from the vertex at +// runtime. Per SL convention, this is in a right-handed UV coordinate +// system. Collada models also have right-handed UVs. +// khr_gltf_transform - The texture transform matrix as defined in the +// KHR_texture_transform GLTF extension spec. It assumes a left-handed UV +// coordinate system. GLTF models also have left-handed UVs. +// sl_animation_transform - The texture transform matrix for texture +// animations, available through LSL script functions such as +// LlSetTextureAnim. It assumes a right-handed UV coordinate system. +// texcoord - The final texcoord to use for image sampling +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform) +{ + vec2 texcoord = vertex_texcoord; + + // Apply texture animation first to avoid shearing and other artifacts + texcoord = (sl_animation_transform * vec4(texcoord, 0, 1)).xy; + // Convert to left-handed coordinate system. The offset of 1 is necessary + // for rotations to be applied correctly. + texcoord.y = 1.0 - texcoord.y; + texcoord = khr_texture_transform(texcoord, khr_gltf_transform[0].xy, khr_gltf_transform[0].z, khr_gltf_transform[1].xy); + // Convert back to right-handed coordinate system + texcoord.y = 1.0 - texcoord.y; + + // To make things more confusing, all SL image assets are upside-down + // We may need an additional sign flip here when we implement a Vulkan backend + + return texcoord; +} + +// Take the rotation only from both transforms and apply to the tangent. This +// accounts for the change of the topology of the normal texture when a texture +// rotation is applied to it. +// *HACK: Assume the imported GLTF model did not have both normal texture +// transforms and tangent vertices. The use of this function is inconsistent +// with the GLTF sample viewer when that is the case. See getNormalInfo in +// https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Viewer/47a191931461a6f2e14de48d6da0f0eb6ec2d147/source/Renderer/shaders/material_info.glsl +// We may want to account for this case during GLTF model import. +// -Cosmic,2023-06-06 +vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform) +{ + vec2 weights = vec2(0, 1); + + // Apply texture animation first to avoid shearing and other artifacts (rotation only) + mat2 sl_rot_scale; + sl_rot_scale[0][0] = sl_animation_transform[0][0]; + sl_rot_scale[0][1] = sl_animation_transform[0][1]; + sl_rot_scale[1][0] = sl_animation_transform[1][0]; + sl_rot_scale[1][1] = sl_animation_transform[1][1]; + weights = sl_rot_scale * weights; + // Remove scale + weights = normalize(weights); + + // Convert to left-handed coordinate system + weights.y = -weights.y; + + // Apply KHR_texture_transform (rotation only) + float khr_rotation = khr_gltf_transform[0].z; + mat2 khr_rotation_mat = mat2( + cos(khr_rotation),-sin(khr_rotation), + sin(khr_rotation), cos(khr_rotation) + ); + weights = khr_rotation_mat * weights; + + // Convert back to right-handed coordinate system + weights.y = -weights.y; + + // Similar to the MikkTSpace-compatible method of extracting the binormal + // from the normal and tangent, as seen in the fragment shader + vec3 vertex_binormal = vertex_tangent.w * cross(vertex_normal, vertex_tangent.xyz); + + return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz); +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index 89e354558a..e2d87e68fa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -25,17 +25,13 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif +out vec4 frag_data[4]; uniform sampler2D diffuseMap; -VARYING vec4 vertex_color; -VARYING vec3 vary_normal; -VARYING vec2 vary_texcoord0; +in vec4 vertex_color; +in vec3 vary_normal; +in vec2 vary_texcoord0; uniform float minimum_alpha; @@ -43,7 +39,7 @@ vec2 encode_normal(vec3 n); void main() { - vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 col = texture(diffuseMap, vary_texcoord0.xy); if (col.a < minimum_alpha) { discard; @@ -52,5 +48,6 @@ 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(encode_normal(nvn.xyz), 0.0, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl index e34d75ba1d..7dcab640f2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl @@ -25,22 +25,18 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR + out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform float minimum_alpha; uniform sampler2D diffuseMap; -VARYING vec4 post_pos; -VARYING vec2 vary_texcoord0; +in vec2 vary_texcoord0; void main() { - float alpha = texture2D(diffuseMap, vary_texcoord0.xy).a; + float alpha = texture(diffuseMap, vary_texcoord0.xy).a; if (alpha < minimum_alpha) { @@ -48,6 +44,4 @@ void main() } frag_color = vec4(1,1,1,1); - - gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeShadowSkinnedV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowSkinnedV.glsl index d9ca6d3a46..f5192c3009 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowSkinnedV.glsl @@ -27,11 +27,10 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_matrix; uniform mat4 projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec2 texcoord0; -VARYING vec4 post_pos; -VARYING vec2 vary_texcoord0; +out vec2 vary_texcoord0; mat4 getObjectSkinnedTransform(); @@ -43,11 +42,7 @@ void main() mat = modelview_matrix * mat; vec4 pos = mat * vec4(position.xyz, 1.0); - pos = projection_matrix * pos; - - post_pos = pos; - - gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); + gl_Position = projection_matrix * pos; vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl index e472a75304..3102c870fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowV.glsl @@ -26,20 +26,15 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec2 texcoord0; -VARYING vec4 post_pos; -VARYING vec2 vary_texcoord0; +out vec2 vary_texcoord0; void main() { //transform vertex - vec4 pos = modelview_projection_matrix*vec4(position.xyz, 1.0); - - post_pos = pos; - - gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); + gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl index 3b6571a24a..ce8a10712c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl @@ -27,13 +27,13 @@ uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; uniform mat3 normal_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; +in vec3 position; +in vec3 normal; +in vec2 texcoord0; -VARYING vec3 vary_normal; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +out vec3 vary_normal; +out vec4 vertex_color; +out vec2 vary_texcoord0; void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl deleted file mode 100644 index 9a5debb3c1..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file underWaterF.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]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif - -uniform sampler2D diffuseMap; -uniform sampler2D bumpMap; -uniform sampler2D screenTex; -uniform sampler2D refTex; -uniform sampler2D screenDepth; - -uniform vec4 fogCol; -uniform vec3 lightDir; -uniform vec3 specular; -uniform float lightExp; -uniform vec2 fbScale; -uniform float refScale; -uniform float znear; -uniform float zfar; -uniform float kd; -uniform vec4 waterPlane; -uniform vec3 eyeVec; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; -uniform vec2 screenRes; - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; - -vec2 encode_normal(vec3 n); - -void main() -{ - vec4 color; - - //get detail normals - vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - vec3 wavef = normalize(wave1+wave2+wave3); - - //figure out distortion vector (ripply) - vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - distort = distort+wavef.xy*refScale; - - vec4 fb = texture2D(screenTex, distort); - - frag_data[0] = vec4(fb.rgb, 1.0); // diffuse - frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec - frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, env intens, atmo kill -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl deleted file mode 100644 index a157e9c017..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ /dev/null @@ -1,184 +0,0 @@ -/** - * @file class1/deferred/waterF.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 - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif - -vec3 scaleSoftClip(vec3 inColor); -vec3 atmosTransport(vec3 inColor); - -uniform sampler2D bumpMap; -uniform sampler2D bumpMap2; -uniform float blend_factor; -uniform sampler2D screenTex; -uniform sampler2D refTex; -uniform float sunAngle; -uniform float sunAngle2; -uniform vec3 lightDir; -uniform vec3 specular; -uniform float lightExp; -uniform float refScale; -uniform float kd; -uniform vec2 screenRes; -uniform vec3 normScale; -uniform float fresnelScale; -uniform float fresnelOffset; -uniform float blurMultiplier; -uniform vec2 screen_res; -uniform mat4 norm_mat; //region space to screen space -uniform int water_edge; - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; -VARYING vec4 vary_position; - -vec2 encode_normal(vec3 n); -vec3 scaleSoftClip(vec3 l); -vec3 srgb_to_linear(vec3 c); -vec3 linear_to_srgb(vec3 c); - -vec3 BlendNormal(vec3 bump1, vec3 bump2) -{ - vec3 n = mix(bump1, bump2, blend_factor); - return n; -} - -void main() -{ - vec4 color; - float dist = length(view.xyz); - - //normalize view vector - vec3 viewVec = normalize(view.xyz); - - //get wave normals - vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - - - vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; - vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; - - vec3 wave1 = BlendNormal(wave1_a, wave1_b); - vec3 wave2 = BlendNormal(wave2_a, wave2_b); - vec3 wave3 = BlendNormal(wave3_a, wave3_b); - - //get base fresnel components - - vec3 df = vec3( - dot(viewVec, wave1), - dot(viewVec, (wave2 + wave3) * 0.5), - dot(viewVec, wave3) - ) * fresnelScale + fresnelOffset; - df *= df; - - vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - - float dist2 = dist; - dist = max(dist, 5.0); - - float dmod = sqrt(dist); - - vec2 dmod_scale = vec2(dmod*dmod, dmod); - - //get reflected color - vec2 refdistort1 = wave1.xy*normScale.x; - vec2 refvec1 = distort+refdistort1/dmod_scale; - vec4 refcol1 = texture2D(refTex, refvec1); - - vec2 refdistort2 = wave2.xy*normScale.y; - vec2 refvec2 = distort+refdistort2/dmod_scale; - vec4 refcol2 = texture2D(refTex, refvec2); - - vec2 refdistort3 = wave3.xy*normScale.z; - vec2 refvec3 = distort+refdistort3/dmod_scale; - vec4 refcol3 = texture2D(refTex, refvec3); - - vec4 refcol = refcol1 + refcol2 + refcol3; - float df1 = df.x + df.y + df.z; - refcol *= df1 * 0.333; - - vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; - wavef.z *= max(-viewVec.z, 0.1); - wavef = normalize(wavef); - - float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; - - vec2 refdistort4 = wavef.xy*0.125; - refdistort4.y -= abs(refdistort4.y); - vec2 refvec4 = distort+refdistort4/dmod; - float dweight = min(dist2*blurMultiplier, 1.0); - vec4 baseCol = texture2D(refTex, refvec4); - - refcol = mix(baseCol*df2, refcol, dweight); - - //get specular component - float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); - - //harden specular - spec = pow(spec, 128.0); - - //figure out distortion vector (ripply) - vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); - - vec4 fb = texture2D(screenTex, distort2); - - //mix with reflection - // Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999f); - - vec4 pos = vary_position; - - color.rgb += spec * specular; - - color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClip(color.rgb); - - color.a = spec * sunAngle2; - - vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - - //frag_data[0] = color; - - // TODO: The non-obvious assignment below is copied from the pre-EEP WL shader code - // Unfortunately, fixing it causes a mismatch for EEP, and so it remains... for now - // SL-12975 (unfix pre-EEP broken alpha) - frag_data[0] = vec4(color.rgb, color); // Effectively, color.rgbr - - - frag_data[1] = vec4(0); // speccolor, spec - frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 0 -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl deleted file mode 100644 index 8863869e44..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl +++ /dev/null @@ -1,99 +0,0 @@ -/** - * @file waterV.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 modelview_matrix; -uniform mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - - -void calcAtmospherics(vec3 inPositionEye); - -uniform vec2 waveDir1; -uniform vec2 waveDir2; -uniform float time; -uniform vec3 eyeVec; -uniform float waterHeight; - -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; - -VARYING vec4 vary_position; - -float wave(vec2 v, float t, float f, vec2 d, float s) -{ - return (dot(d, v)*f + t*s)*f; -} - -void main() -{ - //transform vertex - vec4 pos = vec4(position.xyz, 1.0); - mat4 modelViewProj = modelview_projection_matrix; - - vec4 oPosition; - - //get view vector - vec3 oEyeVec; - oEyeVec.xyz = pos.xyz-eyeVec; - - float d = length(oEyeVec.xy); - float ld = min(d, 2560.0); - - pos.xy = eyeVec.xy + oEyeVec.xy/d*ld; - view.xyz = oEyeVec; - - d = clamp(ld/1536.0-0.5, 0.0, 1.0); - d *= d; - - oPosition = vec4(position, 1.0); - oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); - vary_position = modelview_matrix * oPosition; - oPosition = modelViewProj * oPosition; - - refCoord.xyz = oPosition.xyz + vec3(0,0,0.2); - - //get wave position parameter (create sweeping horizontal waves) - vec3 v = pos.xyz; - v.x += (cos(v.x*0.08/*+time*0.01*/)+sin(v.y*0.02))*6.0; - - //push position for further horizon effect. - pos.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z); - pos.w = 1.0; - pos = modelview_matrix*pos; - - calcAtmospherics(pos.xyz); - - //pass wave parameters to pixel shader - vec2 bigWave = (v.xy) * vec2(0.04,0.04) + waveDir1 * time * 0.055; - //get two normal map (detail map) texture coordinates - littleWave.xy = (v.xy) * vec2(0.45, 0.9) + waveDir2 * time * 0.13; - littleWave.zw = (v.xy) * vec2(0.1, 0.2) + waveDir1 * time * 0.1; - view.w = bigWave.y; - refCoord.w = bigWave.x; - - gl_Position = oPosition; -} |