diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class1')
116 files changed, 2247 insertions, 2601 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 02b2daf0ac..f4ec1ec532 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -25,305 +25,11 @@ //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() +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; + frag_color = vec4(1,0,1,0.5); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl index 23adbded5e..37fe8287be 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 = texture2D(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 = texture2D(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/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/avatarAlphaMaskShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaMaskShadowF.glsl index b8ce54bcb1..44f67899e4 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 @@ -32,10 +32,6 @@ out vec4 frag_color; 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; @@ -58,8 +54,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..9a0024ede9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl @@ -33,10 +33,6 @@ 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; @@ -60,9 +56,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..dfe7077db5 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 @@ -34,9 +34,6 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP -VARYING vec4 post_pos; -#endif VARYING float pos_w; VARYING float target_pos_x; VARYING vec2 vary_texcoord0; @@ -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/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index 60d83cc623..22b3bd1463 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -52,6 +52,6 @@ void main() frag_data[0] = vec4(diff.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(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..ac8a483a6a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarShadowV.glsl @@ -31,10 +31,6 @@ ATTRIBUTE vec3 position; ATTRIBUTE vec3 normal; ATTRIBUTE vec2 texcoord0; -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif - void main() { vec4 pos; @@ -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/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 596d0274af..93a85cad40 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -33,12 +33,13 @@ out vec4 frag_color; #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; @@ -52,8 +53,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,41 +65,55 @@ 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; diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl index 212f7e56ad..5e0f01981b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl @@ -23,8 +23,6 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; - ATTRIBUTE vec3 position; VARYING vec2 vary_fragcoord; @@ -33,7 +31,7 @@ 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..749ec3a6ac 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -64,5 +64,5 @@ void main() frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(tnorm); - frag_data[2] = vec4(encode_normal(nvn), vertex_color.a, 0.0); + frag_data[2] = vec4(encode_normal(nvn), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); } 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..b45dfcd550 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -34,15 +34,15 @@ out vec4 frag_data[3]; // The fragment shader for the sky ///////////////////////////////////////////////////////////////////////// -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; +VARYING vec3 vary_CloudColorSun; +VARYING vec3 vary_CloudColorAmbient; VARYING 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; @@ -69,8 +69,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,7 +115,7 @@ 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 *= 2.0; @@ -124,8 +124,8 @@ void main() /// Gamma correct for WL (soft clip effect). frag_data[0] = vec4(color.rgb, alpha1); frag_data[1] = vec4(0.0,0.0,0.0,0.0); - frag_data[2] = vec4(0,0,0,1); + frag_data[2] = vec4(0,0,0,GBUFFER_FLAG_SKIP_ATMOS); - gl_FragDepth = 0.99995f; + gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; // SL-14113 Stars and Clouds need same depth } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 8e0a001403..5ca210863e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -33,8 +33,8 @@ ATTRIBUTE vec2 texcoord0; /////////////////////////////////////////////////////////////////////////////// // Output parameters -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; +VARYING vec3 vary_CloudColorSun; +VARYING vec3 vary_CloudColorAmbient; VARYING float vary_CloudDensity; VARYING vec2 vary_texcoord0; @@ -46,13 +46,13 @@ VARYING 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,14 +155,14 @@ 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 @@ -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..1e640d95ae 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl @@ -33,8 +33,8 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect depthMap; +uniform sampler2D diffuseRect; +uniform sampler2D depthMap; uniform sampler2D bloomMap; uniform float depth_cutoff; @@ -69,19 +69,19 @@ void main() { vec2 tc = vary_fragcoord.xy; - float z = texture2DRect(depthMap, tc).r; + float z = texture2D(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 = texture2D(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); + vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy); frag_color.rgb = diff.rgb + bloom.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..c87e754eca 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -23,25 +23,129 @@ * $/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); +vec3 scaleSoftClipFragLinear(vec3 light); + +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 = texture2D(normalMap, screenpos.xy).xy; vec2 fenc = enc*4-2; float f = dot(fenc,fenc); float g = sqrt(1-f/4); @@ -51,12 +155,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 = texture2D(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 = texture2D(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 = texture2D(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 = texture2D(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 = texture2D(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 +320,249 @@ 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) +{ + // 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); + + return (diffuse + specular*0.5) * ao; //reduce by half to place in appropriate color space for atmospherics +} + +// 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 +{ + // 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); + + const vec3 u_LightColor = vec3(1.0); + + // Calculation of analytical lighting contribution + vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs); + vec3 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 * u_LightColor * (diffuseContrib + specContrib); + + return color; +} + +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) +{ + vec3 color = vec3(0); + + float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); + + color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); + + color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir)) * sunlit * 2.75 * scol; + color += colorEmissive*0.5; + + color = atmosFragLightingLinear(color, additive, atten); + color = scaleSoftClipFragLinear(color); + + return color; +} + +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.1) + { + discard; + } + } + else + { + if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) > -0.1) + { + 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..3bf148502c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -53,6 +53,6 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(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/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index fc5c86b4d6..e15239b59d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -52,5 +52,5 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(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/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index 1bb8eb8bd0..b0ff233414 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -52,6 +52,6 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(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/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 8319e61242..b2d2e2fa71 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -46,6 +46,6 @@ void main() frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); + frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index ccd1df84f9..b4bc114dd5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -48,5 +48,5 @@ 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); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl b/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl index 8d48bb016b..d9c0e590c8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl @@ -33,8 +33,8 @@ out vec4 frag_color; #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; @@ -46,12 +46,12 @@ uniform float dof_height; VARYING 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 texture2D(tex, tc); } void main() @@ -60,7 +60,7 @@ void main() vec4 dof = dofSample(diffuseRect, vary_fragcoord.xy*res_scale); - vec4 diff = texture2DRect(lightMap, vary_fragcoord.xy); + vec4 diff = texture2D(lightMap, vary_fragcoord.xy); float a = min(abs(diff.a*2.0-1.0) * max_cof*res_scale*res_scale, 1.0); @@ -69,10 +69,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 = texture2D(lightMap, vary_fragcoord.xy+vec2(sc,sc)/screen_res); + col += texture2D(lightMap, vary_fragcoord.xy+vec2(-sc,sc)/screen_res); + col += texture2D(lightMap, vary_fragcoord.xy+vec2(sc,-sc)/screen_res); + col += texture2D(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/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 57420158ca..73e5b401c0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -54,35 +54,44 @@ vec3 fullbrightScaleSoftClip(vec3 light); 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 = texture2D(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; #ifdef WATER_FOG - vec3 pos = vary_position; - vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha)); - color.rgb = fogged.rgb; - color.a = fogged.a; + vec3 pos = vary_position; + 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; + frag_color.rgb = srgb_to_linear(color.rgb); + frag_color.a = color.a; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index 9fcee04c32..f693323d45 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -38,7 +38,7 @@ uniform sampler2D diffuseMap; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; VARYING vec3 vary_texcoord1; -VARYING vec4 vary_position; +VARYING vec3 vary_position; uniform samplerCube environmentMap; @@ -74,7 +74,7 @@ void main() vec3 amblit; vec3 additive; vec3 atten; - vec3 pos = vary_position.xyz/vary_position.w; + vec3 pos = vary_position.xyz; calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl index 3bd6b693fa..0e461b4004 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl @@ -45,7 +45,7 @@ ATTRIBUTE vec2 texcoord0; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; VARYING vec3 vary_texcoord1; -VARYING vec4 vary_position; +VARYING 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..e565722164 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -38,9 +38,7 @@ void calcAtmospherics(vec3 inPositionEye); vec3 atmosAmbient(); vec3 atmosAffectDirectionalLight(float lightIntensity); -#ifdef WATER_FOG VARYING vec3 vary_position; -#endif VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; @@ -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..50d697ae12 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,6 +2088,7 @@ half4 FxaaPixelShader( #endif uniform sampler2D diffuseMap; +uniform sampler2D depthMap; uniform vec2 rcp_screen_res; uniform vec4 rcp_frame_opt; @@ -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..9e6c853015 --- /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]*/ + +VARYING 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/genbrdflutV.glsl b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutV.glsl new file mode 100644 index 0000000000..682244478b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutV.glsl @@ -0,0 +1,39 @@ +/** + * @file class3\deferred\genbrdflutV.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$ + */ + +uniform mat4 modelview_projection_matrix; + +ATTRIBUTE vec3 position; + +VARYING vec2 vary_uv; + +void main() +{ + //transform vertex + vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_uv = position.xy*0.5+0.5; + + 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..75f914cb02 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl @@ -38,5 +38,5 @@ void main() { frag_data[0] = color*texture2D(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); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index a58cc3d12d..51afda2791 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -41,6 +41,7 @@ uniform sampler2D specularMap; VARYING vec2 vary_texcoord0; vec3 linear_to_srgb(vec3 c); +vec2 encode_normal (vec3 n); void main() { @@ -56,5 +57,5 @@ void main() 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); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index be1003a7e0..185c1150ef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -31,10 +31,10 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseMap; +uniform sampler2D diffuseMap; VARYING vec2 vary_fragcoord; void main() { - frag_color = texture2DRect(diffuseMap, vary_fragcoord.xy); + frag_color = texture2D(diffuseMap, vary_fragcoord.xy); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl index f2dc60aa5d..5488a63c6a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl @@ -39,7 +39,7 @@ void main() vec4 pos = modelview_projection_matrix * 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); 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..51a36935f2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -23,431 +23,30 @@ * $/LicenseInfo$ */ + /*[EXTRA_CODE_HERE]*/ //class1/deferred/materialF.glsl -// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. +// Debug stub for non-pbr material -#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; + frag_color = vec4(1, 0, 0, 0.5); #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); - -#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. + // emissive red PBR material + frag_data[0] = vec4(0, 0, 0, 0); + frag_data[1] = vec4(0, 0, 0, 0); + frag_data[2] = vec4(1, 0, 0, GBUFFER_FLAG_HAS_PBR); + frag_data[3] = vec4(1, 0, 0, 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..a1cab87092 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 diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 35068899ee..7032c45603 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -34,8 +34,7 @@ out vec4 frag_data[3]; #endif uniform vec4 color; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; +uniform vec3 moonlight_color; uniform vec3 moon_dir; uniform float moon_brightness; uniform sampler2D diffuseMap; @@ -55,6 +54,12 @@ void main() fade = clamp( moon_dir.z*moon_dir.z*4.0, 0.0, 1.0 ); vec4 c = texture2D(diffuseMap, vary_texcoord0.xy); + + // 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 = srgb_to_linear(c.rgb); c.rgb *= moonlight_color.rgb; c.rgb *= moon_brightness; @@ -66,8 +71,8 @@ void main() frag_data[0] = vec4(c.rgb, c.a); frag_data[1] = vec4(0.0); - frag_data[2] = vec4(0.0f); + frag_data[2] = vec4(0.0, 0.0, 0.0, GBUFFER_FLAG_HAS_ATMOS); - gl_FragDepth = 0.999985f; + gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; // SL-14113 } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 09c47165dd..8fdb5e7154 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -23,123 +23,11 @@ * $/LicenseInfo$ */ -#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 - -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 + frag_color = vec4(0.5, 0.5, 0.0, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl index eefefa640d..d71dc76423 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl @@ -23,8 +23,6 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; - ATTRIBUTE vec3 position; VARYING vec4 vary_fragcoord; @@ -32,7 +30,7 @@ VARYING vec4 vary_fragcoord; void main() { //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 pos = vec4(position.xyz, 1.0); vary_fragcoord = pos; gl_Position = pos; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index ec3fb9c543..e9dac711c3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -38,11 +38,10 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform samplerCube environmentMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D depthMap; +uniform sampler2D normalMap; uniform sampler2D noiseMap; uniform sampler2D projectionMap; uniform sampler2D lightFunc; @@ -73,6 +72,7 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 getNorm(vec2 pos_screen); vec3 srgb_to_linear(vec3 c); +float getDepth(vec2 tc); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { @@ -138,7 +138,6 @@ 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 = center.xyz-pos.xyz; @@ -149,7 +148,7 @@ void main() discard; } - float envIntensity = texture2DRect(normalMap, frag.xy).z; + float envIntensity = texture2D(normalMap, frag.xy).z; vec3 norm = getNorm(frag.xy); float l_dist = -dot(lv, proj_n); @@ -173,7 +172,7 @@ void main() discard; } - float noise = texture2D(noiseMap, frag.xy/128.0).b; + float noise = texture2D(noiseMap, frag.xy).b; dist_atten *= noise; lv = proj_origin-pos.xyz; @@ -181,7 +180,7 @@ void main() float da = dot(norm, lv); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + vec3 diff_tex = texture2D(diffuseRect, frag.xy).rgb; vec3 dlit = vec3(0, 0, 0); @@ -221,7 +220,7 @@ void main() } - vec4 spec = texture2DRect(specularRect, frag.xy); + vec4 spec = texture2D(specularRect, frag.xy); if (spec.a > 0.0) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl new file mode 100644 index 0000000000..fc1024f4f1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl @@ -0,0 +1,34 @@ +/** + * @file class1\deferred\pbralphaF.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]*/ + +out vec4 frag_color; + +void main() +{ + frag_color = vec4(0,1,0,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..a2ad1b70fb --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl @@ -0,0 +1,120 @@ +/** + * @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$ + */ + +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +#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 (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + #if !defined(HAS_SKIN) + uniform mat4 modelview_matrix; + #endif + VARYING vec3 vary_position; +#endif + +uniform mat3 texture_basecolor_matrix; +uniform mat3 texture_normal_matrix; +uniform mat3 texture_metallic_roughness_matrix; +uniform mat3 texture_emissive_matrix; + +#ifdef HAS_SUN_SHADOW +out vec3 vary_fragcoord; +uniform float near_clip; +#endif + +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec4 tangent; +in vec2 texcoord0; + +out vec2 basecolor_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; + + +void main() +{ +#ifdef HAS_SKIN + mat4 mat = getObjectSkinnedTransform(); + mat = modelview_matrix * mat; + vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vary_position = pos; +#endif + 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; + +#ifdef HAS_SUN_SHADOW + vary_fragcoord.xyz = vert.xyz + vec3(0,0,near_clip); +#endif + + basecolor_texcoord = (texture_matrix0 * vec4(texture_basecolor_matrix * vec3(texcoord0,1), 1)).xy; + normal_texcoord = (texture_matrix0 * vec4(texture_normal_matrix * vec3(texcoord0,1), 1)).xy; + metallic_roughness_texcoord = (texture_matrix0 * vec4(texture_metallic_roughness_matrix * vec3(texcoord0,1), 1)).xy; + emissive_texcoord = (texture_matrix0 * vec4(texture_emissive_matrix * vec3(texcoord0,1), 1)).xy; + +#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 + + vary_tangent = normalize(t); + vary_sign = tangent.w; + vary_normal = normalize(n); + + vertex_color = diffuse_color; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + #if !defined(HAS_SKIN) + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; + #endif +#endif +} 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..39419e9d78 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -0,0 +1,103 @@ +/** + * @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]*/ + +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 basecolor_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 = texture2D(diffuseMap, basecolor_texcoord.xy).rgba; + if (basecolor.a < minimum_alpha) + { + discard; + } + + vec3 col = vertex_color.rgb * srgb_to_linear(basecolor.rgb); + + // from mikktspace.com + vec3 vNt = texture2D(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 = texture2D(specularMap, metallic_roughness_texcoord.xy).rgb; + + spec.g *= roughnessFactor; + spec.b *= metallicFactor; + + vec3 emissive = emissiveColor; + emissive *= srgb_to_linear(texture2D(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] = vec4(col, 0.0); // Diffuse + frag_data[1] = vec4(spec.rgb,vertex_color.a); // PBR linear packed Occlusion, Roughness, Metal. + frag_data[2] = vec4(encode_normal(tnorm), vertex_color.a, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags + frag_data[3] = vec4(emissive,0); // PBR sRGB Emissive +} 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..5a69da641a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -0,0 +1,97 @@ +/** + * @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$ + */ + +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +#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 mat3 texture_basecolor_matrix; +uniform mat3 texture_normal_matrix; +uniform mat3 texture_metallic_roughness_matrix; +uniform mat3 texture_emissive_matrix; + +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec4 tangent; +in vec2 texcoord0; + +out vec2 basecolor_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; + +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 + + basecolor_texcoord = (texture_matrix0 * vec4(texture_basecolor_matrix * vec3(texcoord0,1), 1)).xy; + normal_texcoord = (texture_matrix0 * vec4(texture_normal_matrix * vec3(texcoord0,1), 1)).xy; + metallic_roughness_texcoord = (texture_matrix0 * vec4(texture_metallic_roughness_matrix * vec3(texcoord0,1), 1)).xy; + emissive_texcoord = (texture_matrix0 * vec4(texture_emissive_matrix * vec3(texcoord0,1), 1)).xy; + +#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 + + vary_tangent = normalize(t); + vary_sign = tangent.w; + vary_normal = normalize(n); + + vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 18616a9bb3..a025c4a1b4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -1,5 +1,5 @@ /** - * @file pointLightF.glsl + * @file class1\deferred\pointLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -22,111 +22,11 @@ * 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 +// debug stub 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; + frag_color = vec4(0.0, 0.5, 0.5, 0.0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl index f06f8c870b..5ca39d6966 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; +uniform sampler2D diffuseRect; uniform mat4 inv_proj; uniform vec2 screen_res; @@ -44,7 +44,7 @@ VARYING vec2 vary_fragcoord; void dofSample(inout vec4 diff, inout float w, float min_sc, vec2 tc) { - vec4 s = texture2DRect(diffuseRect, tc); + vec4 s = texture2D(diffuseRect, tc); float sc = abs(s.a*2.0-1.0)*max_cof; @@ -63,7 +63,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 = texture2D(diffuseRect, tc); float wg = 0.25; @@ -79,7 +79,7 @@ void main() { vec2 tc = vary_fragcoord.xy; - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); + vec4 diff = texture2D(diffuseRect, vary_fragcoord.xy); { float w = 1.0; @@ -93,14 +93,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 +117,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 +125,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..987b2d1fe8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; +uniform sampler2D diffuseRect; uniform vec2 screen_res; VARYING vec2 vary_fragcoord; @@ -41,12 +41,55 @@ uniform float display_gamma; vec3 linear_to_srgb(vec3 cl); +//================================= +// borrowed noise from: +// <https://www.shadertoy.com/view/4dS3Wd> +// By Morgan McGuire @morgan3d, http://graphicscodex.com +// +float hash(float n) { return fract(sin(n) * 1e4); } +float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); } + +float noise(float x) { + float i = floor(x); + float f = fract(x); + float u = f * f * (3.0 - 2.0 * f); + return mix(hash(i), hash(i + 1.0), u); +} + +float noise(vec2 x) { + vec2 i = floor(x); + vec2 f = fract(x); + + // Four corners in 2D of a tile + float a = hash(i); + float b = hash(i + vec2(1.0, 0.0)); + float c = hash(i + vec2(0.0, 1.0)); + float d = hash(i + vec2(1.0, 1.0)); + + // Simple 2D lerp using smoothstep envelope between the values. + // return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)), + // mix(c, d, smoothstep(0.0, 1.0, f.x)), + // smoothstep(0.0, 1.0, f.y))); + + // Same code, with the clamps in smoothstep and common subexpressions + // optimized away. + vec2 u = f * f * (3.0 - 2.0 * f); + return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; +} + +//============================= + void main() { //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 = texture2D(diffuseRect, vary_fragcoord); diff.rgb = linear_to_srgb(diff.rgb); + vec2 tc = vary_fragcoord.xy*screen_res; + + 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.008; + //diff.rgb = nz; frag_color = diff; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl index 058941bfb2..a79f644aef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; +uniform sampler2D diffuseRect; uniform sampler2D bloomMap; uniform vec2 screen_res; @@ -41,9 +41,9 @@ VARYING vec2 vary_fragcoord; void main() { - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); + vec4 diff = texture2D(diffuseRect, vary_fragcoord.xy); - vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res); + vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy); frag_color = diff + bloom; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl index bd0cb50464..4d24b4de9a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl @@ -23,8 +23,6 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; - ATTRIBUTE vec3 position; VARYING vec2 vary_fragcoord; @@ -34,7 +32,7 @@ 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/postDeferredV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl index 8edf5b2723..86f0077edb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl @@ -23,8 +23,6 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; - ATTRIBUTE vec3 position; VARYING vec2 vary_fragcoord; @@ -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/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index cf994d3547..8111f43c28 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl @@ -31,9 +31,9 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DRect giLightMap; +uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D giLightMap; uniform sampler2D noiseMap; uniform vec2 kern[32]; @@ -53,11 +53,11 @@ vec4 getPosition(vec2 pos_screen); void main() { - vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz; + vec3 norm = texture2D(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; + vec3 ccol = texture2D(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; @@ -66,7 +66,7 @@ void main() for (int i = 0; i < kern_length; i++) { vec2 tc = vary_fragcoord.xy + kern[i].y*dlt; - vec3 sampNorm = texture2DRect(normalMap, tc.xy).xyz; + vec3 sampNorm = texture2D(normalMap, tc.xy).xyz; sampNorm = vec3((sampNorm.xy-0.5)*2.0,sampNorm.z); // unpack norm float d = dot(norm.xyz, sampNorm); @@ -77,7 +77,7 @@ void main() samppos -= pos; if (dot(samppos,samppos) < -0.05*pos.z) { - col += texture2DRect(giLightMap, tc).rgb*kern[i].x; + col += texture2D(giLightMap, tc).rgb*kern[i].x; defined_weight += kern[i].x; } } diff --git a/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl new file mode 100644 index 0000000000..2ffe688524 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl @@ -0,0 +1,64 @@ +/** + * @file class1/deferred/reflectionProbeF.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$ + */ + +// fallback stub -- will be used if actual reflection probe shader failed to load (output pink so it's obvious) +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) +{ + ambenv = vec3(1,0,1); + glossenv = vec3(1,0,1); +} + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness) +{ + sampleReflectionProbes(ambenv, glossenv, + pos, norm, glossiness, false); +} + +vec4 sampleReflectionProbesDebug(vec3 pos) +{ + //output green to debug display + return vec4(0, 1, 0, 0.5); +} + +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec3 pos, vec3 norm, float glossiness, float envIntensity) +{ + ambenv = vec3(1,0,1); + glossenv = vec3(1,0,1); + legacyenv = vec3(1,0,1); +} + +void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) +{ + +} + +void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) +{ + +} + diff --git a/indra/newview/app_settings/shaders/class1/objects/indexedTextureF.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostF.glsl index 254c1d4fc2..df16e7f0e7 100644 --- a/indra/newview/app_settings/shaders/class1/objects/indexedTextureF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostF.glsl @@ -1,33 +1,33 @@ -/** - * @file fullbrightF.glsl +/** + * @file class3/deferred/screenSpaceReflPostF.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$ */ - - + // debug stub + +out vec4 frag_color; void main() { - fullbright_lighting(); + frag_color = vec4(0.5, 0.4, 0.1, 0); } - diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostV.glsl index 0fa0edfd67..966e7e1cbb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostV.glsl @@ -1,50 +1,39 @@ -/** - * @file attachmentShadowV.glsl +/** + * @file class3/deferred/screenSpaceReflPostV.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(); +uniform vec2 screen_res; + +VARYING vec2 vary_fragcoord; 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 + 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/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl new file mode 100644 index 0000000000..d054305767 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl @@ -0,0 +1,37 @@ +/** + * @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$ + */ + +// debug stub + +float random (vec2 uv) +{ + return 0; +} + +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source) +{ + 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..68e9addc1b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -43,32 +43,30 @@ 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; } +#if !defined(GLTF) + #if !defined(IS_FULLBRIGHT) 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; + } + } +#endif 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 index 2b17aea75a..61c9e60744 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskSkinnedV.glsl @@ -57,11 +57,7 @@ void main() 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/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl index b6a0f0b165..40f8fc9894 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskV.glsl @@ -47,11 +47,7 @@ void main() 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..9608e89169 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowCubeV.glsl @@ -27,10 +27,6 @@ uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif - 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..406a7ef3b3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowF.glsl @@ -25,20 +25,9 @@ /*[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..186ba49969 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowSkinnedV.glsl @@ -28,8 +28,6 @@ uniform mat4 projection_matrix; ATTRIBUTE vec3 position; -VARYING vec4 post_pos; - mat4 getObjectSkinnedTransform(); void main() @@ -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..cd49202f89 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,6 +54,7 @@ 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; @@ -59,10 +66,14 @@ float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, 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; 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 @@ -78,10 +89,14 @@ float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 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; 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..849e1c4893 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -46,6 +46,8 @@ out vec4 frag_data[3]; // The fragment shader for the sky ///////////////////////////////////////////////////////////////////////// +VARYING vec3 vary_HazeColor; + vec3 rainbow(float d) { // 'Interesting' values of d are -0.75 .. -0.825, i.e. when view vec nearly opposite of sun vec @@ -82,7 +84,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; @@ -95,7 +97,7 @@ void main() // 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 + frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); //1.0 in norm.w masks off fog gl_FragDepth = 0.99999f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 6db4690bff..3b24311f2b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -32,19 +32,19 @@ ATTRIBUTE vec3 position; /////////////////////////////////////////////////////////////////////////////// // Output parameters -VARYING vec4 vary_HazeColor; +VARYING vec3 vary_HazeColor; VARYING 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,11 +53,9 @@ 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; - // NOTE: Keep these in sync! // indra\newview\app_settings\shaders\class1\deferred\skyV.glsl // indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl @@ -91,16 +89,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; // 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) + vec4(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 +127,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 index 7f2c603f87..152402907b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -34,11 +34,11 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; -uniform sampler2DRect lightMap; -uniform sampler2DRect depthMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D normalMap; +uniform sampler2D lightMap; +uniform sampler2D depthMap; uniform samplerCube environmentMap; uniform sampler2D lightFunc; @@ -58,6 +58,7 @@ uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); vec4 getPositionWithDepth(vec2 pos_screen, float depth); +float getDepth(vec2 pos_screen); 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(); @@ -76,9 +77,9 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); void main() { vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; + float depth = getDepth(tc); vec4 pos = getPositionWithDepth(tc, depth); - vec4 norm = texture2DRect(normalMap, tc); + vec4 norm = texture2D(normalMap, tc); float envIntensity = norm.z; norm.xyz = getNorm(tc); @@ -87,12 +88,12 @@ void main() float light_gamma = 1.0/1.3; da = pow(da, light_gamma); - vec4 diffuse = texture2DRect(diffuseRect, tc); + vec4 diffuse = texture2D(diffuseRect, tc); //convert to gamma space diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); + vec4 spec = texture2D(specularRect, vary_fragcoord.xy); vec3 color = vec3(0); float bloom = 0.0; { @@ -142,7 +143,7 @@ void main() color = mix(color.rgb, reflected_color, envIntensity); } - if (norm.w < 0.5) + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); @@ -156,12 +157,6 @@ void main() } -// 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... diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index 8891315e15..23ad332db4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -22,8 +22,6 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - -uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; @@ -36,10 +34,10 @@ VARYING vec2 vary_fragcoord; void main() { //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec4 pos = 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; + vary_fragcoord = (pos.xy*0.5+0.5); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 694b19cdfb..0376f42319 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -36,10 +36,10 @@ out vec4 frag_color; //class 1 -- no shadows -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D depthMap; +uniform sampler2D normalMap; uniform samplerCube environmentMap; uniform sampler2D noiseMap; uniform sampler2D projectionMap; @@ -137,7 +137,6 @@ 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.xyz; @@ -148,7 +147,7 @@ void main() discard; } - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + vec3 norm = texture2D(normalMap, frag.xy).xyz; float envIntensity = norm.z; norm = getNorm(frag.xy); norm = normalize(norm); @@ -176,13 +175,13 @@ void main() lv = normalize(lv); float da = dot(norm, lv); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; + vec3 diff_tex = texture2D(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); + vec4 spec = texture2D(specularRect, frag.xy); - float noise = texture2D(noiseMap, frag.xy/128.0).b; + float noise = texture2D(noiseMap, frag.xy).b; vec3 dlit = vec3(0, 0, 0); if (proj_tc.z > 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..152316c117 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -36,7 +36,6 @@ VARYING vec2 vary_texcoord0; VARYING vec2 screenpos; uniform sampler2D diffuseMap; -uniform sampler2D altDiffuseMap; uniform float blend_factor; uniform float custom_alpha; uniform float time; @@ -46,8 +45,13 @@ float twinkle(){ return abs(d); } +// See: +// ALM off: class1/environment/starsF.glsl +// ALM on : class1/deferred/starsF.glsl void main() { + // camera above water: class1\deferred\starsF.glsl + // camera below water: class1\environment\starsF.glsl vec4 col_a = texture2D(diffuseMap, vary_texcoord0.xy); vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy); vec4 col = mix(col_b, col_a, blend_factor); @@ -60,8 +64,8 @@ void main() frag_data[0] = col; frag_data[1] = vec4(0.0f); - 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); - gl_FragDepth = 0.99995f; + gl_FragDepth = LL_SHADER_CONST_STAR_DEPTH; // SL-14113 Moon Haze -- Stars need to depth test behind the moon } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index b2fa5d8a25..4ab8747629 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -57,7 +57,7 @@ void main() frag_data[0] = c; frag_data[1] = vec4(0.0f); - 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); gl_FragDepth = 0.999988f; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 15f141cbe5..d9a0b6c702 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -35,7 +35,7 @@ out vec4 frag_color; //class 1 -- no shadow, SSAO only -uniform sampler2DRect normalMap; +uniform sampler2D normalMap; // Inputs VARYING vec2 vary_fragcoord; diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl index 473d6df8fa..9d70b9d98d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl @@ -22,8 +22,6 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - -uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; @@ -34,8 +32,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_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/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 6b6eed9db8..d6c14c48c9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -63,6 +63,6 @@ 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); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index 89e354558a..dc0e5b0ce3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -52,5 +52,5 @@ void main() frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(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/treeShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl index e34d75ba1d..c850a39d6f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowF.glsl @@ -25,18 +25,14 @@ /*[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() { @@ -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..5a7cf369b5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeShadowSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeShadowSkinnedV.glsl @@ -30,8 +30,7 @@ uniform mat4 projection_matrix; ATTRIBUTE vec3 position; ATTRIBUTE 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/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 9a5debb3c1..14c337e608 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -78,5 +78,5 @@ void main() 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 + frag_data[2] = vec4(encode_normal(wavef), 0.0, GBUFFER_FLAG_HAS_ATMOS); // normalxyz, env intens, flags (atmo kill) } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index a157e9c017..876422f86b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -22,163 +22,15 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - -#extension GL_ARB_texture_rectangle : enable -/*[EXTRA_CODE_HERE]*/ +// debug stub +out vec4 frag_data[4]; -#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) +void main() { - 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 + // emissive blue PBR material + frag_data[0] = vec4(0, 0, 0, 0); + frag_data[1] = vec4(0, 0, 0, 0); + frag_data[2] = vec4(1, 0, 0, GBUFFER_FLAG_HAS_PBR); + frag_data[3] = vec4(0, 0, 1, 0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl index 8863869e44..38276859a0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl @@ -70,7 +70,7 @@ void main() d *= d; oPosition = vec4(position, 1.0); - oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); +// oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); // SL-11589 remove "U" shaped horizon vary_position = modelview_matrix * oPosition; oPosition = modelViewProj * oPosition; diff --git a/indra/newview/app_settings/shaders/class1/effects/glowExtractF.glsl b/indra/newview/app_settings/shaders/class1/effects/glowExtractF.glsl index 36563982ba..4e535f7e18 100644 --- a/indra/newview/app_settings/shaders/class1/effects/glowExtractF.glsl +++ b/indra/newview/app_settings/shaders/class1/effects/glowExtractF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseMap; +uniform sampler2D diffuseMap; uniform float minLuminance; uniform float maxExtractAlpha; uniform vec3 lumWeights; @@ -44,7 +44,7 @@ VARYING vec2 vary_texcoord0; void main() { - vec4 col = texture2DRect(diffuseMap, vary_texcoord0.xy); + vec4 col = texture2D(diffuseMap, vary_texcoord0.xy); /// CALCULATING LUMINANCE (Using NTSC lum weights) /// http://en.wikipedia.org/wiki/Luma_%28video%29 float lum = smoothstep(minLuminance, minLuminance+1.0, dot(col.rgb, lumWeights ) ); diff --git a/indra/newview/app_settings/shaders/class1/effects/glowExtractV.glsl b/indra/newview/app_settings/shaders/class1/effects/glowExtractV.glsl index 1396dc6973..db0662ad89 100644 --- a/indra/newview/app_settings/shaders/class1/effects/glowExtractV.glsl +++ b/indra/newview/app_settings/shaders/class1/effects/glowExtractV.glsl @@ -32,7 +32,7 @@ VARYING vec2 vary_texcoord0; void main() { - gl_Position = modelview_projection_matrix * vec4(position, 1.0); + gl_Position = vec4(position, 1.0); - vary_texcoord0.xy = texcoord0; + vary_texcoord0.xy = position.xy * 0.5 + 0.5; } diff --git a/indra/newview/app_settings/shaders/class1/effects/glowV.glsl b/indra/newview/app_settings/shaders/class1/effects/glowV.glsl index cdb2281578..ea66e8271b 100644 --- a/indra/newview/app_settings/shaders/class1/effects/glowV.glsl +++ b/indra/newview/app_settings/shaders/class1/effects/glowV.glsl @@ -37,7 +37,7 @@ VARYING vec4 vary_texcoord3; void main() { - gl_Position = modelview_projection_matrix * vec4(position, 1.0); + gl_Position = vec4(position, 1.0); vary_texcoord0.xy = texcoord0 + glowDelta*(-3.5); vary_texcoord1.xy = texcoord0 + glowDelta*(-2.5); diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaMaskShadowF.glsl b/indra/newview/app_settings/shaders/class1/environment/moonF.glsl index c64b6ba240..a220971f06 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaMaskShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/moonF.glsl @@ -1,9 +1,9 @@ /** - * @file attachmentAlphaMaskShadowF.glsl + * @file class1/environment/moonF.glsl * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ + * $LicenseInfo:firstyear=2021&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2005, Linden Research, Inc. + * Copyright (C) 2021, 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 @@ -29,36 +29,23 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform float minimum_alpha; +uniform sampler2D tex0; -uniform sampler2D diffuseMap; - -VARYING vec4 post_pos; VARYING vec2 vary_texcoord0; -VARYING float pos_w; -VARYING float target_pos_x; -VARYING vec4 vertex_color; +// See: +// AS off: class1/environment/moonF.glsl +// ALM off: class1/windlight/moonF.glsl +// ALM on : class1/deferred/moonF.glsl void main() { - float alpha = texture2D(diffuseMap, vary_texcoord0.xy).a; - - if (alpha < 0.05) // treat as totally transparent - { - discard; - } + vec4 color = texture2D(tex0, vary_texcoord0.xy); - if (alpha < minimum_alpha) // treat as semi-transparent - { - //if (fract(0.5*floor(target_pos_x / pos_w )) < 0.25) - { - discard; - } - } + // 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 (color.a <= 2./255.) // 0.00784 + 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 + frag_color = color; + gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; // SL-14113 Moon is infront of stars } diff --git a/indra/newview/app_settings/shaders/class1/environment/moonV.glsl b/indra/newview/app_settings/shaders/class1/environment/moonV.glsl new file mode 100644 index 0000000000..c00f202c23 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/moonV.glsl @@ -0,0 +1,38 @@ +/** + * @file class1\environment\moonV.glsl + * + * $LicenseInfo:firstyear=2021&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2021, 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 vec2 texcoord0; + +VARYING vec2 vary_texcoord0; + +void main() +{ + gl_Position = modelview_projection_matrix * vec4(position, 1); + vary_texcoord0 = texcoord0; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class1/environment/starsF.glsl index 44f2a73e1f..e1a9cc6387 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/starsF.glsl @@ -1,9 +1,9 @@ /** - * @file shadowAlphaMaskF.glsl + * @file class1/environment/starsF.glsl * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * $LicenseInfo:firstyear=2021&license=viewerlgpl$ * Second Life Viewer Source Code - * Copyright (C) 2011, Linden Research, Inc. + * Copyright (C) 2021, 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,6 @@ * $/LicenseInfo$ */ -/*[EXTRA_CODE_HERE]*/ - #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -33,23 +31,21 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING float pos_w; +uniform float custom_alpha; -VARYING float target_pos_x; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; +// See: +// ALM off: class1/environment/starsF.glsl +// ALM on : class1/deferred/starsF.glsl void main() { - float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; + vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); + color.rgb = pow(color.rgb, vec3(0.45)); + color.rgb *= vertex_color.rgb; + color.a *= max(custom_alpha, vertex_color.a); - 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 = color; + gl_FragDepth = LL_SHADER_CONST_STAR_DEPTH; // SL-14113 Moon Haze -- Stars need to depth test behind the moon } diff --git a/indra/newview/app_settings/shaders/class1/environment/starsV.glsl b/indra/newview/app_settings/shaders/class1/environment/starsV.glsl new file mode 100644 index 0000000000..6fcfec6b6a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/environment/starsV.glsl @@ -0,0 +1,41 @@ +/** + * @file class1/environment/starsV.glsl + * + * $LicenseInfo:firstyear=2021&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2021, 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; +ATTRIBUTE vec2 texcoord0; + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; + +void main() +{ + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_texcoord0 = texcoord0; + vertex_color = diffuse_color; +} + diff --git a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl index 8c8bd6d0d5..ad105c616c 100644 --- a/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/underWaterF.glsl @@ -23,55 +23,10 @@ * $/LicenseInfo$ */ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#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 waterFogKS; -uniform vec2 screenRes; - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; - -vec4 applyWaterFogView(vec3 pos, vec4 color); +// debug stub 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_color = applyWaterFogView(view.xyz, fb); + frag_color = vec4(0, 1, 1, 0); } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index d370997123..46a6c2021d 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -23,146 +23,9 @@ * $/LicenseInfo$ */ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#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; - - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; - -vec3 BlendNormal(vec3 bump1, vec3 bump2) +void main() { - vec3 n = mix(bump1, bump2, blend_factor); - return n; + frag_color = vec4(0, 0, 1, 0); } - - -void main() -{ - vec4 color; - - float dist = length(view.xy); - - //normalize view vector - vec3 viewVec = normalize(view.xyz); - - //get wave normals - vec2 bigwave = vec2(refCoord.w, view.w); - vec3 wave1_a = texture2D(bumpMap, bigwave ).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, bigwave ).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 and nvidia compiler bug - color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); - color.rgb += spec * specular; - - color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClip(color.rgb); - color.a = spec * sunAngle2; - - frag_color = color; - -#if defined(WATER_EDGE) - gl_FragDepth = 0.9999847f; -#endif - -} - diff --git a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl index df640cba05..e1cdeddcea 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterFogF.glsl @@ -32,6 +32,8 @@ uniform float waterFogKS; vec3 getPositionEye(); +vec3 srgb_to_linear(vec3 col); + vec4 applyWaterFogView(vec3 pos, vec4 color) { vec3 view = normalize(pos); @@ -66,14 +68,64 @@ vec4 applyWaterFogView(vec3 pos, vec4 color) float D = pow(0.98, l*kd); color.rgb = color.rgb * D + kc.rgb * L; - color.a = kc.a + color.a; return color; } +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit) +{ + if (dot(pos, waterPlane.xyz) + waterPlane.w > 0.0) + { + return color; + } + + vec3 view = normalize(pos); + //normalize view vector + float es = -(dot(view, waterPlane.xyz)); + + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w / es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(pos - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + kc.rgb = srgb_to_linear(kc.rgb); // TODO -- pass in waterFogColor linear + kc.rgb *= sunlit; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2 * l) - 1.0; + + float L = min(t1 / t2 * t3, 1.0); + + float D = pow(0.98, l * kd); + + color.rgb = color.rgb * D + kc.rgb * L; + + return color; +} + +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color) +{ + return applyWaterFogViewLinear(pos, color, vec3(1)); +} + vec4 applyWaterFog(vec4 color) { //normalize view vector - return applyWaterFogView(getPositionEye(), color); + return applyWaterFogViewLinear(getPositionEye(), color); } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl index cc41e3f740..ac400aa2a6 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl @@ -24,6 +24,7 @@ */ uniform mat4 modelview_matrix; +uniform mat3 normal_matrix; uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; @@ -36,10 +37,16 @@ uniform vec2 waveDir2; uniform float time; uniform vec3 eyeVec; uniform float waterHeight; +uniform vec3 lightDir; VARYING vec4 refCoord; VARYING vec4 littleWave; VARYING vec4 view; +out vec3 vary_position; +out vec3 vary_light_dir; +out vec3 vary_tangent; +out vec3 vary_normal; +out vec2 vary_fragcoord; float wave(vec2 v, float t, float f, vec2 d, float s) { @@ -52,6 +59,11 @@ void main() vec4 pos = vec4(position.xyz, 1.0); mat4 modelViewProj = modelview_projection_matrix; + vary_position = (modelview_matrix * pos).xyz; + vary_light_dir = normal_matrix * lightDir; + vary_normal = normal_matrix * vec3(0, 0, 1); + vary_tangent = normal_matrix * vec3(1, 0, 0); + vec4 oPosition; //get view vector @@ -63,12 +75,13 @@ void main() 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); +// oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); // SL-11589 remove "U" shaped horizon + oPosition = modelViewProj * oPosition; refCoord.xyz = oPosition.xyz + vec3(0,0,0.2); @@ -83,8 +96,7 @@ void main() 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 diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl b/indra/newview/app_settings/shaders/class1/interface/copyF.glsl index 8e9a5fcd41..65d3c20091 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/copyF.glsl @@ -1,8 +1,9 @@ /** - * @file avatarShadowF.glsl - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * @file copyF.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,20 +23,18 @@ * $/LicenseInfo$ */ -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif +in vec2 tc; +uniform sampler2D depthMap; uniform sampler2D diffuseMap; -VARYING vec2 vary_texcoord0; +out vec4 frag_color; void main() { - frag_color = vec4(1,1,1,1); + frag_color = texture(diffuseMap, tc); +#if defined(COPY_DEPTH) + gl_FragDepth = texture(depthMap, tc).r; +#endif } diff --git a/indra/newview/app_settings/shaders/class1/interface/copyV.glsl b/indra/newview/app_settings/shaders/class1/interface/copyV.glsl new file mode 100644 index 0000000000..ace5da6578 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/copyV.glsl @@ -0,0 +1,34 @@ +/** + * @file copyV.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$ + */ + + +in vec3 position; +out vec2 tc; + +void main() +{ + tc = position.xy * 0.5 + 0.5; + gl_Position = vec4(position, 1.0); +} diff --git a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl index cff8d9d50f..99662097bb 100644 --- a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthRectF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect depthMap; +uniform sampler2D depthMap; VARYING vec2 tc0; VARYING vec2 tc1; @@ -48,22 +48,22 @@ VARYING vec2 tc8; void main() { vec4 depth1 = - vec4(texture2DRect(depthMap, tc0).r, - texture2DRect(depthMap, tc1).r, - texture2DRect(depthMap, tc2).r, - texture2DRect(depthMap, tc3).r); + vec4(texture2D(depthMap, tc0).r, + texture2D(depthMap, tc1).r, + texture2D(depthMap, tc2).r, + texture2D(depthMap, tc3).r); vec4 depth2 = - vec4(texture2DRect(depthMap, tc4).r, - texture2DRect(depthMap, tc5).r, - texture2DRect(depthMap, tc6).r, - texture2DRect(depthMap, tc7).r); + vec4(texture2D(depthMap, tc4).r, + texture2D(depthMap, tc5).r, + texture2D(depthMap, tc6).r, + texture2D(depthMap, tc7).r); depth1 = min(depth1, depth2); float depth = min(depth1.x, depth1.y); depth = min(depth, depth1.z); depth = min(depth, depth1.w); - depth = min(depth, texture2DRect(depthMap, tc8).r); + depth = min(depth, texture2D(depthMap, tc8).r); gl_FragDepth = depth; } diff --git a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthV.glsl b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthV.glsl index 71d80911d6..e104377037 100644 --- a/indra/newview/app_settings/shaders/class1/interface/downsampleDepthV.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/downsampleDepthV.glsl @@ -45,7 +45,7 @@ void main() { gl_Position = vec4(position, 1.0); - vec2 tc = (position.xy*0.5+0.5)*screen_res; + vec2 tc = (position.xy*0.5+0.5); tc0 = tc+vec2(-delta.x,-delta.y); tc1 = tc+vec2(0,-delta.y); tc2 = tc+vec2(delta.x,-delta.y); diff --git a/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl b/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl index b5bbbb5c73..3ead2149f5 100644 --- a/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/glowcombineF.glsl @@ -27,20 +27,18 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2D glowMap; -uniform sampler2DRect screenMap; +uniform sampler2D emissiveRect; +uniform sampler2D diffuseRect; +uniform sampler2D depthMap; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; +in vec2 tc; void main() { - frag_color = texture2D(glowMap, vary_texcoord0.xy) + - texture2DRect(screenMap, vary_texcoord1.xy); + frag_color = texture2D(emissiveRect, tc) + + texture2D(diffuseRect, tc); + + gl_FragDepth = texture(depthMap, tc).r; } diff --git a/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAF.glsl b/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAF.glsl index a9e7ea1de8..c50548d528 100644 --- a/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAF.glsl @@ -27,20 +27,17 @@ /*[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 vec2 screen_res; -VARYING vec2 vary_tc; + +in vec2 vary_tc; void main() { - vec3 col = texture2DRect(diffuseRect, vary_tc*screen_res).rgb; - - frag_color = vec4(col.rgb, dot(col.rgb, vec3(0.299, 0.587, 0.144))); + vec3 col = texture(diffuseRect, vary_tc).rgb; + + frag_color = vec4(col.rgb, dot(col.rgb, vec3(0.299, 0.587, 0.144))); } diff --git a/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAV.glsl b/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAV.glsl index 058f3b1b82..48aab1ce21 100644 --- a/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAV.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/glowcombineFXAAV.glsl @@ -23,7 +23,6 @@ * $/LicenseInfo$ */ -uniform mat4 modelview_projection_matrix; ATTRIBUTE vec3 position; @@ -31,7 +30,7 @@ VARYING vec2 vary_tc; void main() { - 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; diff --git a/indra/newview/app_settings/shaders/class1/interface/glowcombineV.glsl b/indra/newview/app_settings/shaders/class1/interface/glowcombineV.glsl index f7970b7f78..8fa08a18c3 100644 --- a/indra/newview/app_settings/shaders/class1/interface/glowcombineV.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/glowcombineV.glsl @@ -25,17 +25,13 @@ uniform mat4 modelview_projection_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec2 texcoord1; +in vec3 position; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; +out vec2 tc; void main() { - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - vary_texcoord0 = texcoord0; - vary_texcoord1 = texcoord1; + gl_Position = vec4(position.xyz, 1.0); + tc = position.xy * 0.5 + 0.5; } diff --git a/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl new file mode 100644 index 0000000000..2b1e794b52 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl @@ -0,0 +1,33 @@ +/** + * @file irradianceGenF.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$ + */ + +// debug stub + +out vec4 frag_color; + +void main() +{ + frag_color = vec4(0.5, 0, 0.5, 0); +} diff --git a/indra/newview/app_settings/shaders/class1/interface/irradianceGenV.glsl b/indra/newview/app_settings/shaders/class1/interface/irradianceGenV.glsl new file mode 100644 index 0000000000..5190abf17c --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/irradianceGenV.glsl @@ -0,0 +1,38 @@ +/** + * @file irradianceGenV.glsl + * + * $LicenseInfo:firstyear=2022&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 modelview_matrix; + +ATTRIBUTE vec3 position; + +VARYING vec3 vary_dir; + +void main() +{ + gl_Position = vec4(position, 1.0); + + vary_dir = vec3(modelview_matrix * vec4(position, 1.0)).xyz; +} + diff --git a/indra/newview/app_settings/shaders/class1/interface/occlusionF.glsl b/indra/newview/app_settings/shaders/class1/interface/occlusionF.glsl index db130e456c..f5d2804c7f 100644 --- a/indra/newview/app_settings/shaders/class1/interface/occlusionF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/occlusionF.glsl @@ -23,13 +23,13 @@ * $/LicenseInfo$ */ -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif +out vec4 frag_data[4]; void main() { - frag_color = vec4(1,1,1,1); + // emissive red PBR material for debugging + frag_data[0] = vec4(0, 0, 0, 0); + frag_data[1] = vec4(0, 0, 0, 0); + frag_data[2] = vec4(1, 0, 0, GBUFFER_FLAG_HAS_PBR); + frag_data[3] = vec4(1, 0, 0, 0); } diff --git a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl new file mode 100644 index 0000000000..e60ddcd569 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl @@ -0,0 +1,172 @@ +/** + * @file radianceGenF.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]*/ + +out vec4 frag_color; + +uniform samplerCubeArray reflectionProbes; +uniform int sourceIdx; + +VARYING vec3 vary_dir; + +//uniform float roughness; + +uniform float mipLevel; +uniform int u_width; +uniform float max_probe_lod; + + +// ============================================================================================================= +// Parts of this file are (c) 2018 Sascha Willems +// SNIPPED FROM https://github.com/SaschaWillems/Vulkan-glTF-PBR/blob/master/data/shaders/prefilterenvmap.frag +/* +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. +*/ +// ============================================================================================================= + +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); +} + +// Normal Distribution function +float D_GGX(float dotNH, float roughness) +{ + float alpha = roughness * roughness; + float alpha2 = alpha * alpha; + float denom = dotNH * dotNH * (alpha2 - 1.0) + 1.0; + return (alpha2)/(PI * denom*denom); +} + +vec4 prefilterEnvMap(vec3 R) +{ + vec3 N = R; + vec3 V = R; + vec4 color = vec4(0.0); + float totalWeight = 0.0; + float envMapDim = u_width; + int numSamples = 4; + + float numMips = max_probe_lod; + + float roughness = mipLevel/numMips; + + numSamples = max(int(numSamples*roughness), 1); + + for(uint i = 0u; i < numSamples; i++) { + vec2 Xi = hammersley2d(i, numSamples); + vec3 H = importanceSample_GGX(Xi, roughness, N); + vec3 L = 2.0 * dot(V, H) * H - V; + float dotNL = clamp(dot(N, L), 0.0, 1.0); + if(dotNL > 0.0) { + // Filtering based on https://placeholderart.wordpress.com/2015/07/28/implementation-notes-runtime-environment-map-filtering-for-image-based-lighting/ + + float dotNH = clamp(dot(N, H), 0.0, 1.0); + float dotVH = clamp(dot(V, H), 0.0, 1.0); + + // Probability Distribution Function + float pdf = D_GGX(dotNH, roughness) * dotNH / (4.0 * dotVH) + 0.0001; + // Slid angle of current smple + float omegaS = 1.0 / (float(numSamples) * pdf); + // Solid angle of 1 pixel across all cube faces + float omegaP = 4.0 * PI / (6.0 * envMapDim * envMapDim); + // Biased (+1.0) mip level for better result + float mip = roughness == 0.0 ? 0.0 : clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, numMips); + //float mip = clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, 7.f); + color += textureLod(reflectionProbes, vec4(L,sourceIdx), mip) * dotNL; + totalWeight += dotNL; + + } + } + return (color / totalWeight); +} + +void main() +{ + vec3 N = normalize(vary_dir); + frag_color = prefilterEnvMap(N); +} +// ============================================================================================================= diff --git a/indra/newview/app_settings/shaders/class1/interface/radianceGenV.glsl b/indra/newview/app_settings/shaders/class1/interface/radianceGenV.glsl new file mode 100644 index 0000000000..5f5d9396ff --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/radianceGenV.glsl @@ -0,0 +1,38 @@ +/** + * @file radianceGenV.glsl + * + * $LicenseInfo:firstyear=2022&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 modelview_matrix; + +ATTRIBUTE vec3 position; + +VARYING vec3 vary_dir; + +void main() +{ + gl_Position = vec4(position, 1.0); + + vary_dir = vec3(modelview_matrix * vec4(position, 1.0)).xyz; +} + diff --git a/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl b/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl new file mode 100644 index 0000000000..a9c28b2974 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl @@ -0,0 +1,100 @@ +/** + * @file reflectionmipF.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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +// NOTE screenMap should always be texture channel 0 and +// depthmap should always be channel 1 +uniform sampler2D diffuseRect; +uniform sampler2D depthMap; + +uniform float resScale; +uniform float znear; +uniform float zfar; + +VARYING vec2 vary_texcoord0; + +// get linear depth value given a depth buffer sample d and znear and zfar values +float linearDepth(float d, float znear, float zfar); + +void main() +{ +#if 0 + float w[9]; + + float c = 1.0/16.0; //corner weight + float e = 1.0/8.0; //edge weight + float m = 1.0/4.0; //middle weight + + //float wsum = c*4+e*4+m; + + w[0] = c; w[1] = e; w[2] = c; + w[3] = e; w[4] = m; w[5] = e; + w[6] = c; w[7] = e; w[8] = c; + + vec2 tc[9]; + + float ed = 1; + float cd = 1; + + + tc[0] = vec2(-cd, cd); tc[1] = vec2(0, ed); tc[2] = vec2(cd, cd); + tc[3] = vec2(-ed, 0); tc[4] = vec2(0, 0); tc[5] = vec2(ed, 0); + tc[6] = vec2(-cd, -cd); tc[7] = vec2(0, -ed); tc[8] = vec2(cd, -1); + + vec3 color = vec3(0,0,0); + + for (int i = 0; i < 9; ++i) + { + color += texture2D(screenMap, vary_texcoord0.xy+tc[i]).rgb * w[i]; + //color += texture2D(screenMap, vary_texcoord0.xy+tc[i]*2.0).rgb * w[i]*0.5; + } + + //color /= wsum; + + frag_color = vec4(color, 1.0); +#else + float depth = texture(depthMap, vary_texcoord0.xy).r; + float dist = linearDepth(depth, znear, zfar); + + // convert linear depth to distance + vec3 v; + v.xy = vary_texcoord0.xy / 512.0 * 2.0 - 1.0; + v.z = 1.0; + v = normalize(v); + dist /= v.z; + + vec3 col = texture2D(diffuseRect, vary_texcoord0.xy).rgb; + frag_color = vec4(col, dist/256.0); +#endif +} diff --git a/indra/newview/app_settings/shaders/class1/interface/reflectionprobeF.glsl b/indra/newview/app_settings/shaders/class1/interface/reflectionprobeF.glsl new file mode 100644 index 0000000000..e2e0a2002b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/reflectionprobeF.glsl @@ -0,0 +1,32 @@ +/** + * @file reflectionprobeF.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$ + */ + +// debug stub +out vec4 frag_color; + +void main() +{ + frag_color = vec4(0,1,0,0.5); +} diff --git a/indra/newview/app_settings/shaders/class1/interface/reflectionprobeV.glsl b/indra/newview/app_settings/shaders/class1/interface/reflectionprobeV.glsl new file mode 100644 index 0000000000..0efbd63944 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/interface/reflectionprobeV.glsl @@ -0,0 +1,34 @@ +/** + * @file reflectionprobeV.glsl + * + * $LicenseInfo:firstyear=2022&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$ + */ + + // Debug stub + +ATTRIBUTE vec3 position; + +void main() +{ + gl_Position = vec4(position, 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class1/interface/splattexturerectF.glsl b/indra/newview/app_settings/shaders/class1/interface/splattexturerectF.glsl index 7614075cfd..bf6c1b355c 100644 --- a/indra/newview/app_settings/shaders/class1/interface/splattexturerectF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/splattexturerectF.glsl @@ -33,12 +33,12 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect screenMap; +uniform sampler2D screenMap; VARYING vec4 vertex_color; VARYING vec2 vary_texcoord0; void main() { - frag_color = texture2DRect(screenMap, vary_texcoord0.xy) * vertex_color; + frag_color = texture2D(screenMap, vary_texcoord0.xy) * vertex_color; } diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl index ea2690ba09..12f500e224 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl @@ -22,113 +22,26 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; -uniform int sun_up_factor; -uniform vec4 ambient_color; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -uniform float haze_horizon; -uniform float haze_density; -uniform float cloud_shadow; -uniform float density_multiplier; -uniform float distance_multiplier; -uniform float max_y; -uniform vec4 glow; -uniform float scene_light_strength; -uniform mat3 ssao_effect_mat; -uniform int no_atmo; -uniform float sun_moon_glow_factor; + +// debug stub float getAmbientClamp() { return 1.0f; } +// Returns colors in sRGB 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 rel_pos = inPositionEye; - - //(TERRAIN) limit altitude - if (abs(rel_pos.y) > max_y) rel_pos *= (max_y / rel_pos.y); - - vec3 rel_pos_norm = normalize(rel_pos); - float rel_pos_len = length(rel_pos); - vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_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); - // I had thought blue_density and haze_density should have equal weighting, - // but attenuation due to haze_density tends to seem too strong - - vec4 combined_haze = blue_density + vec4(haze_density); - vec4 blue_weight = blue_density / combined_haze; - vec4 haze_weight = vec4(haze_density) / combined_haze; - - //(TERRAIN) compute sunlight from lightnorm y component. Factor is roughly cosecant(sun elevation) (for short rays like terrain) - float above_horizon_factor = 1.0 / max(1e-6, lightnorm.y); - sunlight *= exp(-light_atten * above_horizon_factor); // for sun [horizon..overhead] this maps to an exp curve [0..1] - - // main atmospheric scattering line integral - float density_dist = rel_pos_len * density_multiplier; - - // Transparency (-> combined_haze) - // ATI Bugfix -- can't store combined_haze*density_dist*distance_multiplier in a variable because the ati - // compiler gets confused. - combined_haze = exp(-combined_haze * density_dist * distance_multiplier); - - // final atmosphere attenuation factor - atten = combined_haze.rgb; - - // compute haze glow - float haze_glow = dot(rel_pos_norm, lightnorm.xyz); - - // dampen sun additive contrib when not facing it... - // SL-13539: This "if" clause causes an "additive" white artifact at roughly 77 degreees. - // if (length(light_dir) > 0.01) - haze_glow *= max(0.0f, dot(light_dir, rel_pos_norm)); - - haze_glow = 1. - haze_glow; - // haze_glow is 0 at the sun and increases away from sun - haze_glow = max(haze_glow, .001); // set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - haze_glow *= glow.x; - // higher glow.x gives dimmer glow (because next step is 1 / "angle") - haze_glow = pow(haze_glow, glow.z); - // glow.z should be negative, so we're doing a sort of (1 / "angle") function - - // add "minimum anti-solar illumination" - haze_glow += .25; - - haze_glow *= sun_moon_glow_factor; - - vec4 amb_color = ambient_color; - - // increase ambient when there are more clouds - vec4 tmpAmbient = amb_color + (vec4(1.) - amb_color) * cloud_shadow * 0.5; - - /* decrease value and saturation (that in HSV, not HSL) for occluded areas - * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, - * ambAlpha); - */ - if (use_ao) - { - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - } - - // Similar/Shared Algorithms: - // indra\llinventory\llsettingssky.cpp -- LLSettingsSky::calculateLightSettings() - // indra\newview\app_settings\shaders\class1\windlight\atmosphericsFuncs.glsl -- calcAtmosphericVars() - // haze color - vec3 cs = sunlight.rgb * (1. - cloud_shadow); - additive = (blue_horizon.rgb * blue_weight.rgb) * (cs + tmpAmbient.rgb) + (haze_horizon * haze_weight.rgb) * (cs * haze_glow + tmpAmbient.rgb); + amblit = vec3(0.2, 0, 0.2); + sunlit = vec3(1,0,1); + additive = vec3(0.5,0.5,0.5); + atten = vec3(1,0,1); +} - // brightness of surface both sunlight and ambient - sunlit = sunlight.rgb * 0.5; - amblit = tmpAmbient.rgb * .25; - additive *= vec3(1.0 - combined_haze); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 additive, + out vec3 atten) +{ + amblit = vec3(0.2, 0, 0.2); + sunlit = vec3(1,0,1); + additive = vec3(0.5,0.5,0.5); + atten = vec3(1,0,1); } diff --git a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl deleted file mode 100644 index 82fad4db5a..0000000000 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowF.glsl +++ /dev/null @@ -1,127 +0,0 @@ -/** - * @file class1/windlight/cloudShadowF.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() -{ - if (cloud_scale >= 0.0001) - { - // 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); - - 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/windlight/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl deleted file mode 100644 index 09b6004481..0000000000 --- a/indra/newview/app_settings/shaders/class1/windlight/cloudShadowV.glsl +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @file class1\windlight\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; - -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; -} diff --git a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl index 2425a2ad04..c4ab0c95dc 100644 --- a/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/windlight/moonF.glsl @@ -34,8 +34,7 @@ out vec4 frag_color; #endif uniform vec4 color; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; +uniform vec3 moonlight_color; uniform vec3 moon_dir; uniform float moon_brightness; uniform sampler2D diffuseMap; @@ -52,6 +51,12 @@ void main() fade = clamp( moon_dir.z*moon_dir.z*4.0, 0.0, 1.0 ); vec4 c = texture2D(diffuseMap, vary_texcoord0.xy); + + // 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 = pow(c.rgb, vec3(0.7f)); // can't use "srgb_to_linear(color.rgb)" as that is a deferred only function c.rgb *= moonlight_color.rgb; c.rgb *= moon_brightness; @@ -62,5 +67,6 @@ void main() c.rgb = scaleSoftClip(c.rgb); frag_color = vec4(c.rgb, c.a); + gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; // SL-14113 } |