From 0940e8871894e08da80730d11c31cbd252a05b35 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 24 May 2022 10:34:47 -0500 Subject: SL-17472 Add checkbox to preferences for enabling "PBR" that uses "class3" deferred shaders. Move reflection probe shaders to class3 and restore class2 shaders to non-reflection probe versions. --- .../shaders/class3/deferred/attachmentShadowF.glsl | 44 -- .../shaders/class3/deferred/attachmentShadowV.glsl | 49 --- .../shaders/class3/deferred/avatarShadowF.glsl | 52 --- .../shaders/class3/deferred/avatarShadowV.glsl | 68 --- .../shaders/class3/deferred/cloudShadowF.glsl | 119 ------ .../shaders/class3/deferred/cloudShadowV.glsl | 63 --- .../shaders/class3/deferred/cloudsF.glsl | 166 ------- .../shaders/class3/deferred/cloudsV.glsl | 70 --- .../shaders/class3/deferred/deferredUtil.glsl | 79 ---- .../class3/deferred/depthToShadowVolumeG.glsl | 202 --------- .../shaders/class3/deferred/fullbrightShinyF.glsl | 122 ++++++ .../shaders/class3/deferred/gatherSkyShF.glsl | 70 --- .../shaders/class3/deferred/gatherSkyShV.glsl | 40 -- .../shaders/class3/deferred/genSkyShF.glsl | 111 ----- .../shaders/class3/deferred/genSkyShV.glsl | 37 -- .../shaders/class3/deferred/indirect.glsl | 44 -- .../shaders/class3/deferred/materialF.glsl | 455 ++++++++++++++++++++ .../shaders/class3/deferred/multiSpotLightF.glsl | 291 ------------- .../shaders/class3/deferred/pointShadowBlurF.glsl | 37 -- .../shaders/class3/deferred/reflectionProbeF.glsl | 476 +++++++++++++++++++++ .../shaders/class3/deferred/shVisF.glsl | 73 ---- .../shaders/class3/deferred/shVisV.glsl | 33 -- .../shaders/class3/deferred/shadowAlphaBlendF.glsl | 58 --- .../shaders/class3/deferred/shadowAlphaBlendV.glsl | 66 --- .../shaders/class3/deferred/shadowAlphaMaskF.glsl | 74 ---- .../shaders/class3/deferred/shadowAlphaMaskV.glsl | 67 --- .../shaders/class3/deferred/shadowCubeV.glsl | 50 --- .../shaders/class3/deferred/shadowF.glsl | 49 --- .../shaders/class3/deferred/shadowUtil.glsl | 157 ------- .../shaders/class3/deferred/shadowV.glsl | 62 --- .../app_settings/shaders/class3/deferred/skyF.glsl | 126 ------ .../app_settings/shaders/class3/deferred/skyV.glsl | 37 -- .../shaders/class3/deferred/softenLightF.glsl | 239 ++++++----- .../shaders/class3/deferred/softenLightV.glsl | 38 -- .../shaders/class3/deferred/spotLightF.glsl | 287 ------------- .../shaders/class3/deferred/sunLightF.glsl | 57 --- .../shaders/class3/deferred/sunLightSSAOF.glsl | 61 --- .../shaders/class3/deferred/sunLightV.glsl | 41 -- .../shaders/class3/deferred/treeShadowF.glsl | 59 --- .../shaders/class3/deferred/treeShadowV.glsl | 43 -- .../shaders/class3/deferred/underWaterF.glsl | 115 ----- .../shaders/class3/deferred/waterF.glsl | 174 -------- .../shaders/class3/deferred/waterV.glsl | 95 ---- 43 files changed, 1180 insertions(+), 3476 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/indirect.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/materialF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/skyF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/skyV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/waterF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/waterV.glsl (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl deleted file mode 100644 index d973326f93..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowF.glsl +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @file avatarShadowF.glsl - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2D diffuseMap; - -VARYING vec4 pos; -VARYING vec2 vary_texcoord0; - -vec4 computeMoments(float depth, float a); - -void main() -{ - frag_color = computeMoments(length(pos), 1.0); -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl deleted file mode 100644 index 1a655e6467..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/attachmentShadowV.glsl +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file attachmentShadowV.glsl - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -uniform mat4 projection_matrix; -uniform mat4 modelview_matrix; -uniform mat4 texture_matrix0; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -mat4 getObjectSkinnedTransform(); - -VARYING vec4 pos; - -void main() -{ - //transform vertex - mat4 mat = getObjectSkinnedTransform(); - - mat = modelview_matrix * mat; - pos = (mat*vec4(position.xyz, 1.0)); - pos = projection_matrix * vec4(pos.xyz, 1.0); - -#if !defined(DEPTH_CLAMP) - pos.z = max(pos.z, -pos.w+0.01); -#endif - gl_Position = pos; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl deleted file mode 100644 index 48eefc7a73..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowF.glsl +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @file avatarShadowF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2D diffuseMap; - -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif - -VARYING vec4 pos; - -vec4 computeMoments(float depth, float a); - -void main() -{ - frag_color = computeMoments(length(pos), 1.0); - -#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/class3/deferred/avatarShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl deleted file mode 100644 index 164b355f20..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/avatarShadowV.glsl +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @file avatarShadowV.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; - -mat4 getSkinnedTransform(); - -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; - -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif - -VARYING vec4 pos; - -void main() -{ - vec3 norm; - - vec4 pos_in = vec4(position.xyz, 1.0); - mat4 trans = getSkinnedTransform(); - - 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); - - 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/class3/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl deleted file mode 100644 index 32210f60dc..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowF.glsl +++ /dev/null @@ -1,119 +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 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; - -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); -} - -vec4 computeMoments(float depth, float alpha); - -void main() -{ - if (cloud_scale >= 0.001) - { - // 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 = computeMoments(length(pos), alpha1); - } - else - { - frag_color = vec4(0); - } -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudShadowV.glsl deleted file mode 100644 index effb070f93..0000000000 --- a/indra/newview/app_settings/shaders/class3/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/class3/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl deleted file mode 100644 index e40d7e7c75..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsF.glsl +++ /dev/null @@ -1,166 +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_data[3]; -#else -#define frag_data gl_FragData -#endif - -///////////////////////////////////////////////////////////////////////// -// The fragment shader for the sky -///////////////////////////////////////////////////////////////////////// - -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; -VARYING float vary_CloudDensity; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; -VARYING vec3 vary_pos; - -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 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; - -uniform sampler2D transmittance_texture; -uniform sampler3D scattering_texture; -uniform sampler3D single_mie_scattering_texture; -uniform sampler2D irradiance_texture; -uniform sampler2D sh_input_r; -uniform sampler2D sh_input_g; -uniform sampler2D sh_input_b; - -vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); - -/// Soft clips the light with a gamma correction -vec3 scaleSoftClip(vec3 light); - -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 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.001) - { - discard; - } - - vec2 uv4 = vary_texcoord3.xy; - - vec2 disturbance = vec2(cloudNoise(uv1 / 16.0f).x, cloudNoise((uv3 + uv1) / 16.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) * 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; - - vec3 view_ray = vary_pos.xyz + camPosLocal; - - vec3 view_direction = normalize(view_ray); - vec3 sun_direction = normalize(sun_dir); - vec3 earth_center = vec3(0, 0, -6360.0f); - vec3 camPos = (camPosLocal / 1000.0f) - earth_center; - - vec3 transmittance; - vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 1.0 - alpha1, sun_direction, transmittance); - - vec3 sun_color = vec3(1.0) - exp(-radiance_sun * 0.0001); - - // Combine - vec4 color; - - vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); - - vec4 l1r = texture2D(sh_input_r, vec2(0,0)); - vec4 l1g = texture2D(sh_input_g, vec2(0,0)); - vec4 l1b = texture2D(sh_input_b, vec2(0,0)); - - vec3 sun_indir = vec3(-view_direction.xy, view_direction.z); - vec3 amb = vec3(dot(l1r, l1tap * vec4(1, sun_indir)), - dot(l1g, l1tap * vec4(1, sun_indir)), - dot(l1b, l1tap * vec4(1, sun_indir))); - - - amb = max(vec3(0), amb); - - color.rgb = sun_color * cloud_color.rgb * (1. - alpha2); - color.rgb = pow(color.rgb, vec3(1.0 / 2.2)); - color.rgb += amb; - - frag_data[0] = vec4(color.rgb, alpha1); - frag_data[1] = vec4(0); - frag_data[2] = vec4(0,1,0,1); -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl deleted file mode 100644 index 71e422ddf0..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/cloudsV.glsl +++ /dev/null @@ -1,70 +0,0 @@ -/** - * @file WLCloudsV.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$ - */ - -uniform mat4 modelview_projection_matrix; -uniform mat4 modelview_matrix; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -////////////////////////////////////////////////////////////////////////// -// The vertex shader for creating the atmospheric sky -/////////////////////////////////////////////////////////////////////////////// - -// Output parameters -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; -VARYING vec3 vary_pos; - -// Inputs -uniform float cloud_scale; -uniform vec4 lightnorm; -uniform vec3 camPosLocal; - -void main() -{ - vary_pos = position; - - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - - // Texture coords - vary_texcoord0 = texcoord0; - vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= max(0.001, cloud_scale); - vary_texcoord0.xy += 0.5; - - vary_texcoord1 = vary_texcoord0; - vary_texcoord1.x += lightnorm.x * 0.0125; - vary_texcoord1.y += lightnorm.z * 0.0125; - - vary_texcoord2 = vary_texcoord0 * 16.; - vary_texcoord3 = vary_texcoord1 * 16.; - - // END CLOUDS -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl deleted file mode 100644 index e27bbce094..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/deferredUtil.glsl +++ /dev/null @@ -1,79 +0,0 @@ -/** - * @file class1/deferred/deferredUtil.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 sampler2DRect normalMap; -uniform sampler2DRect depthMap; - -uniform mat4 inv_proj; -uniform vec2 screen_res; - -vec2 getScreenCoordinate(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); -} - -vec3 getNorm(vec2 screenpos) -{ - vec2 enc = texture2DRect(normalMap, screenpos.xy).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 n; -} - -float getDepth(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen).r; - return depth; -} - -vec4 getPosition(vec2 pos_screen) -{ - float depth = getDepth(pos_screen); - 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; -} - -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; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl b/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl deleted file mode 100644 index cdaff4b09f..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/depthToShadowVolumeG.glsl +++ /dev/null @@ -1,202 +0,0 @@ -/** - * @file depthToShadowVolumeG.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$ - */ -#extension GL_ARB_geometry_shader4 : enable -#extension GL_ARB_texture_rectangle : enable - -/*[EXTRA_CODE_HERE]*/ - -layout (triangles) in; -layout (triangle_strip, max_vertices = 128) out; - -uniform sampler2DRect depthMap; -uniform mat4 shadowMatrix[6]; -uniform vec4 lightpos; - -VARYING vec2 vary_texcoord0; - -out vec3 to_vec; - -void cross_products(out vec4 ns[3], int a, int b, int c) -{ - ns[0] = cross(gl_PositionIn[b].xyz - gl_PositionIn[a].xyz, gl_PositionIn[c].xyz - gl_PositionIn[a].xyz); - ns[1] = cross(gl_PositionIn[c].xyz - gl_PositionIn[b].xyz, gl_PositionIn[a].xyz - gl_PositionIn[b].xyz); - ns[2] = cross(gl_PositionIn[a].xyz - gl_PositionIn[c].xyz, gl_PositionIn[b].xyz - gl_PositionIn[c].xyz); -} - -vec3 getLightDirection(vec4 lightpos, vec3 pos) -{ - - vec3 lightdir = lightpos.xyz - lightpos.w * pos; - return lightdir; -} - -void emitTri(vec4 v[3]) -{ - gl_Position = proj_matrix * v[0]; - EmitVertex(); - - gl_Position = proj_matrix * v[1]; - EmitVertex(); - - gl_Position = proj_matrix * v[2]; - EmitVertex(); - - EndPrimitive(); -} - -void emitQuad(vec4 v[4] -{ - // Emit a quad as a triangle strip. - gl_Position = proj_matrix*v[0]; - EmitVertex(); - - gl_Position = proj_matrix*v[1]; - EmitVertex(); - - gl_Position = proj_matrix*v[2]; - EmitVertex(); - - gl_Position = proj_matrix*v[3]; - EmitVertex(); - - EndPrimitive(); -} - -void emitPrimitives(int layer) -{ - int i = layer; - gl_Layer = i; - - vec4 depth1 = vec4(texture2DRect(depthMap, tc0).rg, texture2DRect(depthMap, tc1).rg)); - vec3 depth2 = vec4(texture2DRect(depthMap, tc2).rg, texture2DRect(depthMap, tc3).rg)); - vec3 depth3 = vec4(texture2DRect(depthMap, tc4).rg, texture2DRect(depthMap, tc5).rg)); - vec3 depth4 = vec4(texture2DRect(depthMap, tc6).rg, texture2DRect(depthMap, tc7).rg)); - - depth1 = min(depth1, depth2); - depth1 = min(depth1, depth3); - depth1 = min(depth1, depth4); - - vec2 depth = min(depth1.xy, depth1.zw); - - int side = sqrt(gl_VerticesIn); - - for (int j = 0; j < side; j++) - { - for (int k = 0; k < side; ++k) - { - vec3 pos = gl_PositionIn[(j * side) + k].xyz; - vec4 v = shadowMatrix[i] * vec4(pos, 1.0); - gl_Position = v; - to_vec = pos - light_position.xyz * depth; - EmitVertex(); - } - - EndPrimitive(); - } - - vec3 norms[3]; // Normals - vec3 lightdir3]; // Directions toward light - - vec4 v[4]; // Temporary vertices - - vec4 or_pos[3] = - { // Triangle oriented toward light source - gl_PositionIn[0], - gl_PositionIn[2], - gl_PositionIn[4] - }; - - // Compute normal at each vertex. - cross_products(n, 0, 2, 4); - - // Compute direction from vertices to light. - lightdir[0] = getLightDirection(lightpos, gl_PositionIn[0].xyz); - lightdir[1] = getLightDirection(lightpos, gl_PositionIn[2].xyz); - lightdir[2] = getLightDirection(lightpos, gl_PositionIn[4].xyz); - - // Check if the main triangle faces the light. - bool faces_light = true; - if (!(dot(ns[0],d[0]) > 0 - |dot(ns[1],d[1]) > 0 - |dot(ns[2],d[2]) > 0)) - { - // Flip vertex winding order in or_pos. - or_pos[1] = gl_PositionIn[4]; - or_pos[2] = gl_PositionIn[2]; - faces_light = false; - } - - // Near cap: simply render triangle. - emitTri(or_pos); - - // Far cap: extrude positions to infinity. - v[0] =vec4(lightpos.w * or_pos[0].xyz - lightpos.xyz,0); - v[1] =vec4(lightpos.w * or_pos[2].xyz - lightpos.xyz,0); - v[2] =vec4(lightpos.w * or_pos[1].xyz - lightpos.xyz,0); - - emitTri(v); - - // Loop over all edges and extrude if needed. - for ( int i=0; i<3; i++ ) - { - // Compute indices of neighbor triangle. - int v0 = i*2; - int nb = (i*2+1); - int v1 = (i*2+2) % 6; - cross_products(n, v0, nb, v1); - - // Compute direction to light, again as above. - d[0] =lightpos.xyz-lightpos.w*gl_PositionIn[v0].xyz; - d[1] =lightpos.xyz-lightpos.w*gl_PositionIn[nb].xyz; - d[2] =lightpos.xyz-lightpos.w*gl_PositionIn[v1].xyz; - - bool is_parallel = gl_PositionIn[nb].w < 1e-5; - - // Extrude the edge if it does not have a - // neighbor, or if it's a possible silhouette. - if (is_parallel || - ( faces_light != (dot(ns[0],d[0])>0 || - dot(ns[1],d[1])>0 || - dot(ns[2],d[2])>0) )) - { - // Make sure sides are oriented correctly. - int i0 = faces_light ? v0 : v1; - int i1 = faces_light ? v1 : v0; - - v[0] = gl_PositionIn[i0]; - v[1] = vec4(lightpos.w*gl_PositionIn[i0].xyz - lightpos.xyz, 0); - v[2] = gl_PositionIn[i1]; - v[3] = vec4(lightpos.w*gl_PositionIn[i1].xyz - lightpos.xyz, 0); - - emitQuad(v); - } - } -} - -void main() -{ - // Output - emitPrimitives(0); -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl new file mode 100644 index 0000000000..a04f611440 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -0,0 +1,122 @@ +/** + * @file fullbrightShinyF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +#ifndef HAS_DIFFUSE_LOOKUP +uniform sampler2D diffuseMap; +#endif + + +VARYING vec4 vertex_color; +VARYING vec2 vary_texcoord0; +VARYING vec3 vary_texcoord1; +VARYING vec3 vary_position; + +uniform samplerCube environmentMap; + +// render_hud_attachments() -> HUD objects set LLShaderMgr::NO_ATMO; used in LLDrawPoolAlpha::beginRenderPass() +uniform int no_atmo; + +vec3 fullbrightShinyAtmosTransport(vec3 light); +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClip(vec3 light); + +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); + +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); + +#ifdef HAS_REFLECTION_PROBES +// reflection probe interface +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, + vec3 pos, vec3 norm, float glossiness, float envIntensity); +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); +#endif + +// See: +// class1\deferred\fullbrightShinyF.glsl +// class1\lighting\lightFullbrightShinyF.glsl +void main() +{ +#ifdef HAS_DIFFUSE_LOOKUP + vec4 color = diffuseLookup(vary_texcoord0.xy); +#else + vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); +#endif + + color.rgb *= vertex_color.rgb; + + // SL-9632 HUDs are affected by Atmosphere + if (no_atmo == 0) + { + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + vec3 pos = vary_position; + calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); + + float env_intensity = vertex_color.a; +#ifndef HAS_REFLECTION_PROBES + vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; + color.rgb = mix(color.rgb, envColor.rgb, env_intensity); +#else + vec3 ambenv; + vec3 glossenv; + vec3 legacyenv; + vec3 norm = normalize(vary_texcoord1.xyz); + vec4 spec = vec4(0,0,0,0); + sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, env_intensity); + legacyenv *= 1.5; // fudge brighter + applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); +#endif + color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); + color.rgb = fullbrightScaleSoftClip(color.rgb); + } + +/* + // NOTE: HUD objects will be full bright. Uncomment if you want "some" environment lighting effecting these HUD objects. + else + { + vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; + float env_intensity = vertex_color.a; + color.rgb = mix(color.rgb, envColor.rgb, env_intensity); + } +*/ + + color.a = 1.0; + //color.rgb = linear_to_srgb(color.rgb); + + frag_color = color; +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl deleted file mode 100644 index 34d26cddea..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShF.glsl +++ /dev/null @@ -1,70 +0,0 @@ -/** - * @file class3/deferred/gatherSkyShF.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_data[3]; -#else -#define frag_data gl_FragData -#endif - -VARYING vec2 vary_frag; - -uniform vec2 screen_res; -uniform sampler2D sh_input_r; -uniform sampler2D sh_input_g; -uniform sampler2D sh_input_b; - -void main() -{ - vec2 offset = vec2(2.0) / screen_res; - - vec4 r = vec4(0); - vec4 g = vec4(0); - vec4 b = vec4(0); - - vec2 tc = vary_frag * 2.0; - - r += texture2D(sh_input_r, tc + vec2(0, 0)); - r += texture2D(sh_input_r, tc + vec2(offset.x, 0)); - r += texture2D(sh_input_r, tc + vec2(0, offset.y)); - r += texture2D(sh_input_r, tc + vec2(offset.x, offset.y)); - r /= 4.0f; - - g += texture2D(sh_input_g, tc + vec2(0, 0)); - g += texture2D(sh_input_g, tc + vec2(offset.x, 0)); - g += texture2D(sh_input_g, tc + vec2(0, offset.y)); - g += texture2D(sh_input_g, tc + vec2(offset.x, offset.y)); - g /= 4.0f; - - b += texture2D(sh_input_b, tc + vec2(0, 0)); - b += texture2D(sh_input_b, tc + vec2(offset.x, 0)); - b += texture2D(sh_input_b, tc + vec2(0, offset.y)); - b += texture2D(sh_input_b, tc + vec2(offset.x, offset.y)); - b /= 4.0f; - - frag_data[0] = r; - frag_data[1] = g; - frag_data[2] = b; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl b/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl deleted file mode 100644 index 337c8a50fe..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/gatherSkyShV.glsl +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file gatherSkyShV.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$ - */ - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -VARYING vec2 vary_frag; -uniform vec2 screen_res; - -void main() -{ - // pass through untransformed fullscreen pos - float oo_divisor = screen_res.x / 64.0; - vec3 pos = (position.xyz * oo_divisor) + vec3(oo_divisor - 1, oo_divisor - 1, 0); - gl_Position = vec4(pos.xyz, 1.0); - vary_frag = texcoord0 * oo_divisor; -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl b/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl deleted file mode 100644 index d5d91c88f0..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/genSkyShF.glsl +++ /dev/null @@ -1,111 +0,0 @@ -/** - * @file class3/deferred/genSkyShF.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_data[3]; -#else -#define frag_data gl_FragData -#endif - -VARYING vec2 vary_frag; - -uniform vec3 sun_dir; - -uniform sampler2D transmittance_texture; -uniform sampler3D scattering_texture; -uniform sampler3D single_mie_scattering_texture; -uniform sampler2D irradiance_texture; - -vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); - -vec3 calcDirection(vec2 tc) -{ - float phi = tc.y * 2.0 * 3.14159265; - float cosTheta = sqrt(1.0 - tc.x); - float sinTheta = sqrt(1.0 - cosTheta * cosTheta); - return vec3(cos(phi) * sinTheta, sin(phi) * sinTheta, cosTheta); -} - -// reverse mapping above to convert a hemisphere direction into phi/theta values -void getPhiAndThetaFromDirection(vec3 dir, out float phi, out float theta) -{ - float sin_theta; - float cos_theta; - cos_theta = dir.z; - theta = acos(cos_theta); - sin_theta = sin(theta); - phi = abs(sin_theta) > 0.0001 ? acos(dir.x / sin_theta) : 1.0; -} - -// reverse mapping above to convert a hemisphere direction into an SH texture sample pos -vec2 calcShUvFromDirection(vec3 dir) -{ - vec2 uv; - float phi; - float theta; - getPhiAndThetaFromDirection(dir, phi, theta); - uv.y = phi / 2.0 * 3.14159265; - uv.x = theta / 2.0 * 3.14159265; - return uv; -} - -void projectToL1(vec3 n, vec3 c, vec4 basis, out vec4 coeffs[3]) -{ - coeffs[0] = vec4(basis.x, n * basis.yzw * c.r); - coeffs[1] = vec4(basis.x, n * basis.yzw * c.g); - coeffs[2] = vec4(basis.x, n * basis.yzw * c.b); -} - -void main() -{ - float Y00 = sqrt(1.0 / 3.14159265) * 0.5; - float Y1x = sqrt(3.0 / 3.14159265) * 0.5; - float Y1y = Y1x; - float Y1z = Y1x; - - vec4 L1 = vec4(Y00, Y1x, Y1y, Y1z); - - vec3 view_direction = calcDirection(vary_frag); - vec3 sun_direction = normalize(sun_dir); - vec3 cam_pos = vec3(0, 0, 6360); - - vec3 transmittance; - vec3 radiance = GetSkyLuminance(cam_pos, view_direction, 0.0f, sun_direction, transmittance); - - vec3 color = vec3(1.0) - exp(-radiance * 0.0001); - - color = pow(color, vec3(1.0/2.2)); - - vec4 coeffs[3]; - coeffs[0] = vec4(0); - coeffs[1] = vec4(0); - coeffs[2] = vec4(0); - - projectToL1(view_direction, color.rgb, L1, coeffs); - - frag_data[0] = coeffs[0]; - frag_data[1] = coeffs[1]; - frag_data[2] = coeffs[2]; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl b/indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl deleted file mode 100644 index b466883dc7..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/genSkyShV.glsl +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @file genSkyShV.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$ - */ - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -VARYING vec2 vary_frag; - -void main() -{ - // pass through untransformed fullscreen pos - gl_Position = vec4(position.xyz, 1.0); - vary_frag = texcoord0; -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/indirect.glsl b/indra/newview/app_settings/shaders/class3/deferred/indirect.glsl deleted file mode 100644 index 33c5667cae..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/indirect.glsl +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @file class3/deferred/indirect.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$ - */ - -/*[EXTRA_CODE_HERE]*/ - -uniform sampler2D sh_input_r; -uniform sampler2D sh_input_g; -uniform sampler2D sh_input_b; - -vec3 GetIndirect(vec3 norm) -{ - vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); - vec4 l1r = texture2D(sh_input_r, vec2(0,0)); - vec4 l1g = texture2D(sh_input_g, vec2(0,0)); - vec4 l1b = texture2D(sh_input_b, vec2(0,0)); - vec3 indirect = vec3(dot(l1r, l1tap * vec4(1, norm.xyz)), - dot(l1g, l1tap * vec4(1, norm.xyz)), - dot(l1b, l1tap * vec4(1, norm.xyz))); - indirect = clamp(indirect, vec3(0), vec3(1.0)); - return indirect; -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl new file mode 100644 index 0000000000..c5b1937cfb --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -0,0 +1,455 @@ +/** +* @file materialF.glsl +* +* $LicenseInfo:firstyear=2007&license=viewerlgpl$ +* Second Life Viewer Source Code +* Copyright (C) 2007, Linden Research, Inc. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* +* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA +* $/LicenseInfo$ +*/ + +/*[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. + +#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); +#endif + +#ifdef HAS_REFLECTION_PROBES +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec3 pos, vec3 norm, float glossiness, float envIntensity); +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); +#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 + if (diffcol.a < minimum_alpha-bias) + { + discard; + } +#endif + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + vec3 gamma_diff = diffcol.rgb; + diffcol.rgb = srgb_to_linear(diffcol.rgb); +#endif + +#ifdef HAS_SPECULAR_MAP + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + spec.rgb *= specular_color.rgb; +#else + vec4 spec = vec4(specular_color.rgb, 1.0); +#endif + +#ifdef HAS_NORMAL_MAP + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + + norm.xyz = norm.xyz * 2 - 1; + + vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2)); +#else + vec4 norm = vec4(0,0,0,1.0); + vec3 tnorm = vary_normal; +#endif + + norm.xyz = normalize(tnorm.xyz); + + vec2 abnormal = encode_normal(norm.xyz); + + vec4 final_color = diffcol; + +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) + final_color.a = emissive_brightness; +#else + final_color.a = max(final_color.a, emissive_brightness); +#endif + + vec4 final_specular = spec; + +#ifdef HAS_SPECULAR_MAP + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); + final_specular.a = specular_color.a * norm.a; +#else + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + final_specular.a = specular_color.a; +#endif + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + + //forward rendering, output just lit sRGBA + vec3 pos = vary_position; + + float shadow = 1.0f; + +#ifdef HAS_SUN_SHADOW + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); +#endif + + spec = final_specular; + vec4 diffuse = final_color; + float envIntensity = final_normal.z; + + vec3 color = vec3(0,0,0); + + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + + float bloom = 0.0; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + + // This call breaks the Mac GLSL compiler/linker for unknown reasons (17Mar2020) + // The call is either a no-op or a pure (pow) gamma adjustment, depending on GPU level + // TODO: determine if we want to re-apply the gamma adjustment, and if so understand & fix Mac breakage + //color = fullbrightScaleSoftClip(color); + + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + + //we're in sRGB space, so gamma correct this dot product so + // lighting from the sun stays sharp + float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); + da = pow(da, 1.0 / 1.3); + vec3 sun_contrib = min(da, shadow) * sunlit; + +#ifdef HAS_REFLECTION_PROBES + vec3 ambenv; + vec3 glossenv; + vec3 legacyenv; + sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + amblit = max(ambenv, amblit); + color.rgb = amblit; +#else + + 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); + + color *= ambient; +#endif + + color += sun_contrib; + + color *= gamma_diff.rgb; + + float glare = 0.0; + + if (spec.a > 0.0) // specular reflection + { + 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; + +#ifdef HAS_REFLECTION_PROBES + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); +#endif + } + + + color = mix(color.rgb, diffcol.rgb, diffuse.a); + +#ifdef HAS_REFLECTION_PROBES + if (envIntensity > 0.0) + { // add environmentmap + //fudge darker + legacyenv *= 0.5*diffuse.a+0.5; + + applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + } +#else + 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; + } +#endif + + 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. +#endif +} + diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl deleted file mode 100644 index 9d62b9d180..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ /dev/null @@ -1,291 +0,0 @@ -/** - * @file multiSpotLightF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable -#extension GL_ARB_shader_texture_lod : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform samplerCube environmentMap; -uniform sampler2DRect lightMap; -uniform sampler2D noiseMap; -uniform sampler2D projectionMap; -uniform sampler2D lightFunc; - -uniform mat4 proj_mat; //screen space to light space -uniform float proj_near; //near clip for projection -uniform vec3 proj_p; //plane projection is emitting from (in screen space) -uniform vec3 proj_n; -uniform float proj_focus; //distance from plane to begin blurring -uniform float proj_lod; //(number of mips in proj map) -uniform float proj_range; //range between near clip and far clip plane of projection -uniform float proj_ambient_lod; -uniform float proj_ambiance; -uniform float near_clip; -uniform float far_clip; - -uniform vec3 proj_origin; //origin of projection to be used for angular attenuation -uniform float sun_wash; -uniform int proj_shadow_idx; -uniform float shadow_fade; - -uniform vec3 center; -uniform float size; -uniform vec3 color; -uniform float falloff; - -VARYING vec4 vary_fragcoord; -uniform vec2 screen_res; - -uniform mat4 inv_proj; - -vec3 getNorm(vec2 pos_screen); - -vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - - -vec4 getPosition(vec2 pos_screen); - -void main() -{ - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = center.xyz-pos.xyz; - float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } - - float shadow = 1.0; - - if (proj_shadow_idx >= 0) - { - vec4 shd = texture2DRect(lightMap, frag.xy); - shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; - shadow += shadow_fade; - shadow = clamp(shadow, 0.0, 1.0); - } - - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - - float envIntensity = norm.z; - - norm = getNorm(frag.xy); - - norm = normalize(norm); - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - - float fa = (falloff*0.5)+1.0; - float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(norm, lv); - - vec3 col = vec3(0,0,0); - - vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb); - - vec4 spec = texture2DRect(specularRect, frag.xy); - - vec3 dlit = vec3(0, 0, 0); - - float noise = texture2D(noiseMap, frag.xy/128.0).b; - if (proj_tc.z > 0.0 && - proj_tc.x < 1.0 && - proj_tc.y < 1.0 && - proj_tc.x > 0.0 && - proj_tc.y > 0.0) - { - float amb_da = proj_ambiance; - float lit = 0.0; - - if (da > 0.0) - { - lit = da * dist_atten * noise; - - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; - - col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; - } - - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; - - amb_da *= dist_atten * noise; - - amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; - } - - - if (spec.a > 0.0) - { - vec3 npos = -normalize(pos); - dlit *= min(da*6.0, 1.0) * dist_atten; - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += dlit*scol*spec.rgb*shadow; - //col += spec.rgb; - } - } - - if (envIntensity > 0.0) - { - vec3 ref = reflect(normalize(pos), norm); - - //project from point pos in direction ref to plane proj_p, proj_n - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - - if (stc.z > 0.0) - { - stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; - } - } - } - } - - //not sure why, but this line prevents MATBUG-194 - col = max(col, vec3(0.0)); - - col = scaleDownLight(col); - - //output linear space color as gamma correction happens down stream - frag_color.rgb = col; - frag_color.a = 0.0; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl deleted file mode 100644 index ca9ce3a2e1..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/pointShadowBlurF.glsl +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @file pointShadowBlur.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 samplerCube cube_map; - -in vec3 to_vec; - -out vec4 fragColor; - -void main() -{ - vec4 vcol = texture(cube_map, to_vec); - fragColor = vec4(vcol.rgb, 1.0); -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl new file mode 100644 index 0000000000..8c1323ba1a --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -0,0 +1,476 @@ +/** + * @file class2/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$ + */ + +#extension GL_ARB_shader_texture_lod : enable + +#define FLT_MAX 3.402823466e+38 + +#define REFMAP_COUNT 256 +#define REF_SAMPLE_COUNT 64 //maximum number of samples to consider + +uniform samplerCubeArray reflectionProbes; + +layout (std140, binding = 1) uniform ReflectionProbes +{ + // list of OBBs for user override probes + // box is a set of 3 planes outward facing planes and the depth of the box along that plane + // for each box refBox[i]... + /// box[0..2] - plane 0 .. 2 in [A,B,C,D] notation + // box[3][0..2] - plane thickness + mat4 refBox[REFMAP_COUNT]; + // list of bounding spheres for reflection probes sorted by distance to camera (closest first) + vec4 refSphere[REFMAP_COUNT]; + // index of cube map in reflectionProbes for a corresponding reflection probe + // e.g. cube map channel of refSphere[2] is stored in refIndex[2] + // refIndex.x - cubemap channel in reflectionProbes + // refIndex.y - index in refNeighbor of neighbor list (index is ivec4 index, not int index) + // refIndex.z - number of neighbors + // refIndex.w - priority, if negative, this probe has a box influence + ivec4 refIndex[REFMAP_COUNT]; + + // neighbor list data (refSphere indices, not cubemap array layer) + ivec4 refNeighbor[1024]; + + // number of reflection probes present in refSphere + int refmapCount; + + // intensity of ambient light from reflection probes + float reflectionAmbiance; +}; + +// Inputs +uniform mat3 env_mat; + +// list of probeIndexes shader will actually use after "getRefIndex" is called +// (stores refIndex/refSphere indices, NOT rerflectionProbes layer) +int probeIndex[REF_SAMPLE_COUNT]; + +// number of probes stored in probeIndex +int probeInfluences = 0; + +bool isAbove(vec3 pos, vec4 plane) +{ + return (dot(plane.xyz, pos) + plane.w) > 0; +} + +// return true if probe at index i influences position pos +bool shouldSampleProbe(int i, vec3 pos) +{ + if (refIndex[i].w < 0) + { + vec4 v = refBox[i] * vec4(pos, 1.0); + if (abs(v.x) > 1 || + abs(v.y) > 1 || + abs(v.z) > 1) + { + return false; + } + } + else + { + vec3 delta = pos.xyz - refSphere[i].xyz; + float d = dot(delta, delta); + float r2 = refSphere[i].w; + r2 *= r2; + + if (d > r2) + { //outside bounding sphere + return false; + } + } + + return true; +} + +// call before sampleRef +// populate "probeIndex" with N probe indices that influence pos where N is REF_SAMPLE_COUNT +// overall algorithm -- +void preProbeSample(vec3 pos) +{ + // TODO: make some sort of structure that reduces the number of distance checks + + for (int i = 0; i < refmapCount; ++i) + { + // found an influencing probe + if (shouldSampleProbe(i, pos)) + { + probeIndex[probeInfluences] = i; + ++probeInfluences; + + int neighborIdx = refIndex[i].y; + if (neighborIdx != -1) + { + int neighborCount = min(refIndex[i].z, REF_SAMPLE_COUNT-1); + + int count = 0; + while (count < neighborCount) + { + // check up to REF_SAMPLE_COUNT-1 neighbors (neighborIdx is ivec4 index) + + int idx = refNeighbor[neighborIdx].x; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + idx = refNeighbor[neighborIdx].y; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + idx = refNeighbor[neighborIdx].z; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + idx = refNeighbor[neighborIdx].w; + if (shouldSampleProbe(idx, pos)) + { + probeIndex[probeInfluences++] = idx; + if (probeInfluences == REF_SAMPLE_COUNT) + { + return; + } + } + count++; + if (count == neighborCount) + { + return; + } + + ++neighborIdx; + } + + return; + } + } + } +} + +// from https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection + +// original reference implementation: +/* +bool intersect(const Ray &ray) const +{ + float t0, t1; // solutions for t if the ray intersects +#if 0 + // geometric solution + Vec3f L = center - orig; + float tca = L.dotProduct(dir); + // if (tca < 0) return false; + float d2 = L.dotProduct(L) - tca * tca; + if (d2 > radius2) return false; + float thc = sqrt(radius2 - d2); + t0 = tca - thc; + t1 = tca + thc; +#else + // analytic solution + Vec3f L = orig - center; + float a = dir.dotProduct(dir); + float b = 2 * dir.dotProduct(L); + float c = L.dotProduct(L) - radius2; + if (!solveQuadratic(a, b, c, t0, t1)) return false; +#endif + if (t0 > t1) std::swap(t0, t1); + + if (t0 < 0) { + t0 = t1; // if t0 is negative, let's use t1 instead + if (t0 < 0) return false; // both t0 and t1 are negative + } + + t = t0; + + return true; +} */ + +// adapted -- assume that origin is inside sphere, return distance from origin to edge of sphere +vec3 sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) +{ + float t0, t1; // solutions for t if the ray intersects + + vec3 L = center - origin; + float tca = dot(L,dir); + + float d2 = dot(L,L) - tca * tca; + + float thc = sqrt(radius2 - d2); + t0 = tca - thc; + t1 = tca + thc; + + vec3 v = origin + dir * t1; + return v; +} + +// from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ +/* +vec3 DirectionWS = normalize(PositionWS - CameraWS); +vec3 ReflDirectionWS = reflect(DirectionWS, NormalWS); + +// Intersection with OBB convertto unit box space +// Transform in local unit parallax cube space (scaled and rotated) +vec3 RayLS = MulMatrix( float(3x3)WorldToLocal, ReflDirectionWS); +vec3 PositionLS = MulMatrix( WorldToLocal, PositionWS); + +vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); +vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; +vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; +vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); +float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); + +// Use Distance in WS directly to recover intersection +vec3 IntersectPositionWS = PositionWS + ReflDirectionWS * Distance; +vec3 ReflDirectionWS = IntersectPositionWS - CubemapPositionWS; + +return texCUBE(envMap, ReflDirectionWS); +*/ + +// get point of intersection with given probe's box influence volume +// origin - ray origin in clip space +// dir - ray direction in clip space +// i - probe index in refBox/refSphere +vec3 boxIntersect(vec3 origin, vec3 dir, int i) +{ + // Intersection with OBB convertto unit box space + // Transform in local unit parallax cube space (scaled and rotated) + mat4 clipToLocal = refBox[i]; + + vec3 RayLS = mat3(clipToLocal) * dir; + vec3 PositionLS = (clipToLocal * vec4(origin, 1.0)).xyz; + + vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); + vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; + vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; + vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); + float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); + + // Use Distance in CS directly to recover intersection + vec3 IntersectPositionCS = origin + dir * Distance; + + return IntersectPositionCS; +} + + + +// Tap a sphere based reflection probe +// pos - position of pixel +// dir - pixel normal +// lod - which mip to bias towards (lower is higher res, sharper reflections) +// c - center of probe +// r2 - radius of probe squared +// i - index of probe +// vi - point at which reflection vector struck the influence volume, in clip space +vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) +{ + //lod = max(lod, 1); + // parallax adjustment + + vec3 v; + if (refIndex[i].w < 0) + { + v = boxIntersect(pos, dir, i); + } + else + { + v = sphereIntersect(pos, dir, c, r2); + } + + v -= c; + v = env_mat * v; + { + float min_lod = textureQueryLod(reflectionProbes,v).y; // lower is higher res + return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), max(min_lod, lod)).rgb; + //return texture(reflectionProbes, vec4(v.xyz, refIndex[i].x)).rgb; + } +} + +vec3 sampleProbes(vec3 pos, vec3 dir, float lod) +{ + float wsum = 0.0; + vec3 col = vec3(0,0,0); + float vd2 = dot(pos,pos); // view distance squared + + for (int idx = 0; idx < probeInfluences; ++idx) + { + int i = probeIndex[idx]; + float r = refSphere[i].w; // radius of sphere volume + float p = float(abs(refIndex[i].w)); // priority + float rr = r*r; // radius squred + float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) + vec3 delta = pos.xyz-refSphere[i].xyz; + float d2 = dot(delta,delta); + float r2 = r1*r1; + + { + vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, rr, i); + + float w = 1.0/d2; + + float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); + w *= atten; + w *= p; // boost weight based on priority + col += refcol*w; + + wsum += w; + } + } + + if (probeInfluences <= 1) + { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera + for (int idx = 0; idx < 8; ++idx) + { + if (refIndex[idx].w < 0) + { // don't fallback to box probes, they are *very* specific + continue; + } + int i = idx; + vec3 delta = pos.xyz-refSphere[i].xyz; + float d2 = dot(delta,delta); + + { + vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, d2, i); + + float w = 1.0/d2; + w *= w; + col += refcol*w; + wsum += w; + } + } + } + + if (wsum > 0.0) + { + col *= 1.0/wsum; + } + + return col; +} + +vec3 sampleProbeAmbient(vec3 pos, vec3 dir, float lod) +{ + vec3 col = sampleProbes(pos, dir, lod); + + //desaturate + vec3 hcol = col *0.5; + + col *= 2.0; + col = vec3( + col.r + hcol.g + hcol.b, + col.g + hcol.r + hcol.b, + col.b + hcol.r + hcol.g + ); + + col *= 0.333333; + + return col*reflectionAmbiance; + +} + +// brighten a color so that at least one component is 1 +vec3 brighten(vec3 c) +{ + float m = max(max(c.r, c.g), c.b); + + if (m == 0) + { + return vec3(1,1,1); + } + + return c * 1.0/m; +} + + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec3 pos, vec3 norm, float glossiness, float envIntensity) +{ + // TODO - don't hard code lods + float reflection_lods = 8; + preProbeSample(pos); + + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); + + ambenv = sampleProbeAmbient(pos, norm, reflection_lods-1); + + if (glossiness > 0.0) + { + float lod = (1.0-glossiness)*reflection_lods; + glossenv = sampleProbes(pos, normalize(refnormpersp), lod); + } + + if (envIntensity > 0.0) + { + legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0); + } +} + +void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) +{ + glossenv *= 0.35; // fudge darker + float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); + float minf = spec.a * 0.1; + fresnel = fresnel * (1.0-minf) + minf; + glossenv *= spec.rgb*min(fresnel, 1.0); + color.rgb += glossenv; +} + + void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) + { + vec3 reflected_color = legacyenv; //*0.5; //fudge darker + vec3 lookAt = normalize(pos); + float fresnel = 1.0+dot(lookAt, norm.xyz); + fresnel *= fresnel; + fresnel = min(fresnel+envIntensity, 1.0); + reflected_color *= (envIntensity*fresnel)*brighten(spec.rgb); + color = mix(color.rgb, reflected_color, envIntensity); + } \ No newline at end of file diff --git a/indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl deleted file mode 100644 index c8991f7a18..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shVisF.glsl +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @file class3/deferred/shVisF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifdef DEFINE_GL_FRAGCOLOR - out vec4 frag_color; -#else - #define frag_color gl_FragColor -#endif - -///////////////////////////////////////////////////////////////////////// -// Fragment shader for L1 SH debug rendering -///////////////////////////////////////////////////////////////////////// - -uniform sampler2D sh_input_r; -uniform sampler2D sh_input_g; -uniform sampler2D sh_input_b; - -uniform mat3 inv_modelviewprojection; - -VARYING vec4 vary_pos; - -void main(void) -{ - vec2 coord = vary_pos.xy + vec2(0.5,0.5); - - coord.x *= (1.6/0.9); - - if (dot(coord, coord) > 0.25) - { - discard; - } - - vec4 n = vec4(coord*2.0, 0.0, 1); - //n.y = -n.y; - n.z = sqrt(max(1.0-n.x*n.x-n.y*n.y, 0.0)); - //n.xyz = inv_modelviewprojection * n.xyz; - - vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); - vec4 l1r = texture2D(sh_input_r, vec2(0,0)); - vec4 l1g = texture2D(sh_input_g, vec2(0,0)); - vec4 l1b = texture2D(sh_input_b, vec2(0,0)); - vec3 indirect = vec3( - dot(l1r, l1tap * n), - dot(l1g, l1tap * n), - dot(l1b, l1tap * n)); - - //indirect = pow(indirect, vec3(0.45)); - indirect *= 3.0; - - frag_color = vec4(indirect, 1.0); -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl deleted file mode 100644 index 8f32dfde79..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shVisV.glsl +++ /dev/null @@ -1,33 +0,0 @@ -/** - * @file class3/deferred/shVisV.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$ - */ -ATTRIBUTE vec3 position; -VARYING vec4 vary_pos; - -void main() -{ - // Output - vary_pos = vec4(position, 1); - gl_Position = vary_pos; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl deleted file mode 100644 index 345c07a354..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendF.glsl +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file shadowAlphaMaskF.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$ - */ - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2D diffuseMap; - -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - -VARYING float target_pos_x; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; -VARYING vec3 pos; - -vec4 computeMoments(float depth, float a); - -void main() -{ - float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; - - frag_color = computeMoments(length(pos), float a); - -#if !defined(DEPTH_CLAMP) - gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); -#endif -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl deleted file mode 100644 index af1461c297..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaBlendV.glsl +++ /dev/null @@ -1,66 +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 target_pos_x; -VARYING vec4 pos; -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/class3/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl deleted file mode 100644 index 50f1ffd626..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskF.glsl +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @file class3/deferred/shadowAlphaMaskF.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$ - */ - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2D diffuseMap; - -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - -VARYING float target_pos_x; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -vec4 getPosition(vec2 screen_coord); -vec4 computeMoments(float depth, float a); - -void main() -{ - vec4 pos = getPosition(vary_texcoord0.xy); - - float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; - - if (alpha < 0.05) // treat as totally transparent - { - discard; - } - - if (alpha < 0.88) // treat as semi-transparent - { - if (fract(0.5*floor(target_pos_x / pos_w )) < 0.25) - { - discard; - } - } - - frag_color = computeMoments(length(pos.xyz), alpha); - -#if !defined(DEPTH_CLAMP) - gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); -#endif - -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl deleted file mode 100644 index 6a646f5e9e..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowAlphaMaskV.glsl +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @file class3/deferred/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 vec4 pos; -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); - - 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/class3/deferred/shadowCubeV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl deleted file mode 100644 index db8c75fb8a..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowCubeV.glsl +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @file class3/deferred/shadowCubeV.glsl - * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -uniform mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif - -uniform vec3 box_center; -uniform vec3 box_size; - -void main() -{ - //transform vertex - 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/class3/deferred/shadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl deleted file mode 100644 index 3350267130..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowF.glsl +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file class3/deferred/shadowF.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$ - */ - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2D diffuseMap; - -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING vec4 pos; -VARYING float target_pos_x; - -vec4 computeMoments(float depth, float a); - -void main() -{ - frag_color = computeMoments(length(pos), 1.0); -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl deleted file mode 100644 index 2f69a353e8..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowUtil.glsl +++ /dev/null @@ -1,157 +0,0 @@ -/** - * @file class3/deferred/shadowUtil.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 sampler2D shadowMap0; -uniform sampler2D shadowMap1; -uniform sampler2D shadowMap2; -uniform sampler2D shadowMap3; -uniform sampler2D shadowMap4; -uniform sampler2D shadowMap5; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -uniform vec2 shadow_res; -uniform vec2 proj_shadow_res; -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float shadow_bias; - -uniform float spot_shadow_bias; -uniform float spot_shadow_offset; - -float getDepth(vec2 screenpos); -vec3 getNorm(vec2 screenpos); -vec4 getPosition(vec2 pos_screen); - -float ReduceLightBleeding(float p_max, float Amount) -{ - return smoothstep(Amount, 1, p_max); -} - -float ChebyshevUpperBound(vec2 m, float t, float min_v, float Amount) -{ - float p = (t <= m.x) ? 1.0 : 0.0; - - float v = m.y - (m.x*m.x); - v = max(v, min_v); - - float d = t - m.x; - - float p_max = v / (v + d*d); - - p_max = ReduceLightBleeding(p_max, Amount); - - return max(p, p_max); -} - -vec4 computeMoments(float depth, float a) -{ - float m1 = depth; - float dx = dFdx(depth); - float dy = dFdy(depth); - float m2 = m1*m1 + 0.25 * a * (dx*dx + dy*dy); - return vec4(m1, m2, a, max(dx, dy)); -} - -float vsmDirectionalSample(vec4 stc, float depth, sampler2D shadowMap, mat4 shadowMatrix) -{ - vec4 lpos = shadowMatrix * stc; - vec4 moments = texture2D(shadowMap, lpos.xy); - return ChebyshevUpperBound(moments.rg, depth - shadow_bias * 256.0f, 0.125, 0.9); -} - -float vsmSpotSample(vec4 stc, float depth, sampler2D shadowMap, mat4 shadowMatrix) -{ - vec4 lpos = shadowMatrix * stc; - vec4 moments = texture2D(shadowMap, lpos.xy); - lpos.xyz /= lpos.w; - lpos.xy *= 0.5; - lpos.xy += 0.5; - return ChebyshevUpperBound(moments.rg, depth - spot_shadow_bias * 16.0f, 0.125, 0.9); -} - -#if VSM_POINT_SHADOWS -float vsmPointSample(float lightDistance, vec3 lightDirection, samplerCube shadow_cube_map) -{ - vec4 moments = textureCube(shadow_cube_map, light_direction); - return ChebyshevUpperBound(moments.rg, light_distance, 0.01, 0.25); -} -#endif - -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) -{ - if (pos.z < -shadow_clip.w) - { - discard; - } - - float depth = getDepth(pos_screen); - - vec4 spos = vec4(pos,1.0); - vec4 near_split = shadow_clip*-0.75; - vec4 far_split = shadow_clip*-1.25; - - float shadow = 0.0f; - float weight = 1.0; - - if (spos.z < near_split.z) - { - shadow += vsmDirectionalSample(spos, depth, shadowMap3, shadow_matrix[3]); - weight += 1.0f; - } - if (spos.z < near_split.y) - { - shadow += vsmDirectionalSample(spos, depth, shadowMap2, shadow_matrix[2]); - weight += 1.0f; - } - if (spos.z < near_split.x) - { - shadow += vsmDirectionalSample(spos, depth, shadowMap1, shadow_matrix[1]); - weight += 1.0f; - } - if (spos.z > far_split.x) - { - shadow += vsmDirectionalSample(spos, depth, shadowMap0, shadow_matrix[0]); - weight += 1.0f; - } - - shadow /= weight; - - return shadow; -} - -float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) -{ - if (pos.z < -shadow_clip.w) - { - discard; - } - - float depth = getDepth(pos_screen); - - pos += norm * spot_shadow_offset; - return vsmSpotSample(vec4(pos, 1.0), depth, (index == 0) ? shadowMap4 : shadowMap5, shadow_matrix[4 + index]); -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl deleted file mode 100644 index 6577fe0ecf..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/shadowV.glsl +++ /dev/null @@ -1,62 +0,0 @@ -/** - * @file class3/deferred/shadowV.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 modelview_projection_matrix; -uniform float shadow_target_width; -uniform mat4 texture_matrix0; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING vec4 pos; -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); - - 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 - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl deleted file mode 100644 index a0b082ed7c..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/skyF.glsl +++ /dev/null @@ -1,126 +0,0 @@ -/** - * @file class3/deferred/skyF.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_data[3]; -#else -#define frag_data gl_FragData -#endif - -VARYING vec2 vary_frag; - -uniform vec3 camPosLocal; -uniform vec3 sun_dir; -uniform float sun_size; -uniform float far_z; -uniform mat4 inv_proj; -uniform mat4 inv_modelview; - -uniform sampler2D transmittance_texture; -uniform sampler3D scattering_texture; -uniform sampler3D single_mie_scattering_texture; -uniform sampler2D irradiance_texture; -uniform sampler2D rainbow_map; -uniform sampler2D halo_map; - -uniform float moisture_level; -uniform float droplet_radius; -uniform float ice_level; - -vec3 GetSolarLuminance(); -vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); -vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); - -vec3 ColorFromRadiance(vec3 radiance); -vec3 rainbow(float d) -{ - // d is the dot product of view and sun directions, so ranging -1.0..1.0 - // 'interesting' values of d are the range -0.75..-0.825, when view is nearly opposite of sun vec - // Rainbox texture mode is GL_REPEAT, so tc of -.75 is equiv to 0.25, -0.825 equiv to 0.175. - - // SL-13629 Rainbow texture has colors within the correct .175...250 range, but order is inverted. - // Rather than replace the texture, we mirror and translate the y tc to keep the colors within the - // interesting range, but in reversed order: i.e. d = (1 - d) - 1.575 - d = clamp(-0.575 - d, 0.0, 1.0); - - // With the colors in the lower 1/4 of the texture, inverting the coords leaves most of it inaccessible. - // So, we can stretch the texcoord above the colors (ie > 0.25) to fill the entire remaining coordinate - // space. This improves gradation, reduces banding within the rainbow interior. (1-0.25) / (0.425/0.25) = 4.2857 - float interior_coord = max(0.0, d - 0.25) * 4.2857; - d = clamp(d, 0.0, 0.25) + interior_coord; - - float rad = (droplet_radius - 5.0f) / 1024.0f; - return pow(texture2D(rainbow_map, vec2(rad, d)).rgb, vec3(1.8)) * moisture_level; -} - -vec3 halo22(float d) -{ - float v = sqrt(max(0, 1 - (d*d))); - return texture2D(halo_map, vec2(0, v)).rgb * ice_level; -} - -void main() -{ - vec3 pos = vec3((vary_frag * 2.0) - vec2(1.0, 1.0f), 1.0); - vec4 view_pos = (inv_proj * vec4(pos, 1.0f)); - - view_pos /= view_pos.w; - - vec3 view_ray = (inv_modelview * vec4(view_pos.xyz, 0.0f)).xyz + camPosLocal; - - vec3 view_direction = normalize(view_ray); - vec3 sun_direction = normalize(sun_dir); - vec3 earth_center = vec3(0, 0, -6360.0f); - vec3 camPos = (camPosLocal / 1000.0f) - earth_center; - - vec3 transmittance; - vec3 radiance_sun = GetSkyLuminance(camPos, view_direction, 0.0f, sun_direction, transmittance); - vec3 solar_luminance = GetSolarLuminance(); - - // If the view ray intersects the Sun, add the Sun radiance. - float s = dot(view_direction, sun_direction); - - // cheesy solar disc... - if (s >= (sun_size * 0.999)) - { - radiance_sun += pow(smoothstep(0.0, 1.3, (s - (sun_size * 0.9))), 2.0) * solar_luminance * transmittance; - } - s = smoothstep(0.9, 1.0, s) * 16.0f; - - vec3 color = ColorFromRadiance(radiance_sun); - - float optic_d = dot(view_direction, sun_direction); - vec3 halo_22 = halo22(optic_d); - - color.rgb += rainbow(optic_d) * optic_d; - color.rgb += halo_22; - - color = pow(color, vec3(1.0/2.2)); - - frag_data[0] = vec4(color, 1.0 + s); - frag_data[1] = vec4(0.0); - frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl deleted file mode 100644 index 2eb222ada4..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/skyV.glsl +++ /dev/null @@ -1,37 +0,0 @@ -/** - * @file class3/deferred/skyV.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$ - */ - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -VARYING vec2 vary_frag; - -void main() -{ - // pass through untransformed fullscreen pos at back of frustum for proper sky depth testing - gl_Position = vec4(position.xy, 1.0f, 1.0); - vary_frag = texcoord0; -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 7ed9e7b4fc..61757882bb 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -1,31 +1,35 @@ -/** - * @file class3/deferred/softenLightF.glsl +/** + * @file class2/deferred/softenLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable -/*[EXTRA_CODE_HERE]*/ +#define FLT_MAX 3.402823466e+38 + +#define REFMAP_COUNT 256 +#define REF_SAMPLE_COUNT 64 //maximum number of samples to consider #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -36,142 +40,153 @@ out vec4 frag_color; uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; + +#if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) uniform sampler2DRect lightMap; +#endif + uniform sampler2DRect depthMap; uniform sampler2D lightFunc; -uniform samplerCube environmentMap; uniform float blur_size; uniform float blur_fidelity; // Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -uniform float cloud_shadow; -uniform float max_y; -uniform vec4 glow; uniform mat3 env_mat; -uniform vec4 shadow_clip; uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform int sun_up_factor; VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; -uniform mat4 inv_modelview; - uniform vec2 screen_res; -uniform sampler2D transmittance_texture; -uniform sampler3D scattering_texture; -uniform sampler3D single_mie_scattering_texture; -uniform sampler2D irradiance_texture; +vec3 getNorm(vec2 pos_screen); +vec4 getPositionWithDepth(vec2 pos_screen, float depth); -uniform sampler2D sh_input_r; -uniform sampler2D sh_input_g; -uniform sampler2D sh_input_b; +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +float getAmbientClamp(); +vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFrag(vec3 l); +vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); +vec3 fullbrightScaleSoftClip(vec3 light); -vec3 GetSunAndSkyIrradiance(vec3 camPos, vec3 norm, vec3 dir, out vec3 sky_irradiance); -vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 dir, out vec3 transmittance); -vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 dir, out vec3 transmittance); +// reflection probe interface +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, + vec3 pos, vec3 norm, float glossiness, float envIntensity); +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); -vec3 ColorFromRadiance(vec3 radiance); -vec4 getPositionWithDepth(vec2 pos_screen, float depth); -vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -void main() +void main() { - vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; - vec3 pos = getPositionWithDepth(tc, depth).xyz; - vec4 norm = texture2DRect(normalMap, tc); + vec2 tc = vary_fragcoord.xy; + float depth = texture2DRect(depthMap, tc.xy).r; + vec4 pos = getPositionWithDepth(tc, depth); + vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; - norm.xyz = getNorm(tc); + norm.xyz = getNorm(tc); + + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); + float light_gamma = 1.0 / 1.3; + da = pow(da, light_gamma); - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + vec4 diffuse = texture2DRect(diffuseRect, tc); + diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14025 + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec4 diffuse = texture2DRect(diffuseRect, tc); // sRGB - diffuse.rgb = srgb_to_linear(diffuse.rgb); - vec3 col; +#if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) + vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; + scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); + float scol = max(scol_ambocc.r, diffuse.a); + float ambocc = scol_ambocc.g; +#else + float scol = 1.0; + float ambocc = 1.0; +#endif + + vec3 color = vec3(0); float bloom = 0.0; + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); + + //vec3 amb_vec = env_mat * norm.xyz; + + vec3 ambenv; + vec3 glossenv; + vec3 legacyenv; + sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + + amblit = max(ambenv, amblit); + color.rgb = amblit*ambocc; + + //float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + //ambient *= 0.5; + //ambient *= ambient; + //ambient = (1.0 - ambient); + //color.rgb *= ambient; + + vec3 sun_contrib = min(da, scol) * sunlit; + color.rgb += sun_contrib; + color.rgb = min(color.rgb, vec3(1,1,1)); + color.rgb *= diffuse.rgb; + + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); + + if (spec.a > 0.0) // specular reflection { - vec3 camPos = (camPosLocal / 1000.0f) + vec3(0, 0, 6360.0f); - - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - - vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; - - float scol = max(scol_ambocc.r, diffuse.a); - - float ambocc = scol_ambocc.g; - - vec4 l1tap = vec4(1.0/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265), sqrt(3)/sqrt(4*3.14159265)); - vec4 l1r = texture2D(sh_input_r, vec2(0,0)); - vec4 l1g = texture2D(sh_input_g, vec2(0,0)); - vec4 l1b = texture2D(sh_input_b, vec2(0,0)); - - vec3 indirect = vec3(dot(l1r, l1tap * vec4(1, norm.xyz)), - dot(l1g, l1tap * vec4(1, norm.xyz)), - dot(l1b, l1tap * vec4(1, norm.xyz))); - - indirect = clamp(indirect, vec3(0), vec3(1.0)); - - vec3 transmittance; - vec3 sky_irradiance; - vec3 sun_irradiance = GetSunAndSkyIrradiance(camPos, norm.xyz, sun_dir, sky_irradiance); - vec3 inscatter = GetSkyLuminanceToPoint(camPos, (pos / 1000.f) + vec3(0, 0, 6360.0f), scol, sun_dir, transmittance); - - vec3 radiance = scol * (sun_irradiance + sky_irradiance) + inscatter; - vec3 atmo_color = ColorFromRadiance(radiance); - - col = atmo_color + indirect; - col *= transmittance; - col *= diffuse.rgb; - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - if (spec.a > 0.0) // specular reflection - { - // the old infinite-sky shiny reflection - // - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = scol * texture2D(lightFunc, vec2(sa, spec.a)).r * atmo_color; - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb * 0.25; - bloom = dot(spec_contrib, spec_contrib); - col += spec_contrib; - } - - col = mix(col, diffuse.rgb, diffuse.a); - - if (envIntensity > 0.0) - { //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - vec3 sun_direction = (inv_modelview * vec4(sun_dir, 1.0)).xyz; - vec3 radiance_sun = GetSkyLuminance(camPos, env_vec, 0.0f, sun_direction, transmittance); - vec3 refcol = ColorFromRadiance(radiance_sun); - col = mix(col.rgb, refcol, envIntensity); - } - - /*if (norm.w < 0.5) - { - col = scaleSoftClipFrag(col); - }*/ - - #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos,vec4(col, bloom)); - col = fogged.rgb; - bloom = fogged.a; - #endif + float sa = dot(normalize(refnormpersp), light_dir.xyz); + vec3 dumbshiny = sunlit * scol * (texture2D(lightFunc, vec2(sa, spec.a)).r); + + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + color.rgb += spec_contrib; + + // add reflection map - EXPERIMENTAL WORK IN PROGRESS + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } - //output linear since gamma correction happens down stream - frag_color.rgb = col; + color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); + + if (envIntensity > 0.0) + { // add environmentmap + //fudge darker + legacyenv *= 0.5*diffuse.a+0.5;; + applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + } + + if (norm.w < 0.5) + { + color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); + color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); + } + +#ifdef WATER_FOG + vec4 fogged = applyWaterFogView(pos.xyz, vec4(color, bloom)); + color = fogged.rgb; + bloom = fogged.a; +#endif + + // convert to linear as fullscreen lights need to sum in linear colorspace + // and will be gamma (re)corrected downstream... + //color = vec3(ambocc); + //color = ambenv; + //color.b = diffuse.a; + frag_color.rgb = srgb_to_linear(color.rgb); frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl deleted file mode 100644 index 9d872b8df8..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightV.glsl +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @file class3/deferred/softenLightV.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ -ATTRIBUTE vec3 position; - -VARYING vec2 vary_fragcoord; - -uniform mat4 modelview_projection_matrix; -uniform vec2 screen_res; - -void main() -{ - //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); - gl_Position = pos; - vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl deleted file mode 100644 index 56b0f4e5ce..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ /dev/null @@ -1,287 +0,0 @@ -/** - * @file spotLightF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable -#extension GL_ARB_shader_texture_lod : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform samplerCube environmentMap; -uniform sampler2DRect lightMap; -uniform sampler2D noiseMap; -uniform sampler2D projectionMap; -uniform sampler2D lightFunc; - -uniform mat4 proj_mat; //screen space to light space -uniform float proj_near; //near clip for projection -uniform vec3 proj_p; //plane projection is emitting from (in screen space) -uniform vec3 proj_n; -uniform float proj_focus; //distance from plane to begin blurring -uniform float proj_lod; //(number of mips in proj map) -uniform float proj_range; //range between near clip and far clip plane of projection -uniform float proj_ambient_lod; -uniform float proj_ambiance; -uniform float near_clip; -uniform float far_clip; - -uniform vec3 proj_origin; //origin of projection to be used for angular attenuation -uniform float sun_wash; -uniform int proj_shadow_idx; -uniform float shadow_fade; - -uniform float size; -uniform vec3 color; -uniform float falloff; - -VARYING vec3 trans_center; -VARYING vec4 vary_fragcoord; -uniform vec2 screen_res; - -uniform mat4 inv_proj; - -vec3 getNorm(vec2 pos_screen); - -vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - - -vec4 getPosition(vec2 pos_screen); - -void main() -{ - vec4 frag = vary_fragcoord; - frag.xyz /= frag.w; - frag.xyz = frag.xyz*0.5+0.5; - frag.xy *= screen_res; - - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = trans_center.xyz-pos.xyz; - float dist = length(lv); - dist /= size; - if (dist > 1.0) - { - discard; - } - - float shadow = 1.0; - - if (proj_shadow_idx >= 0) - { - vec4 shd = texture2DRect(lightMap, frag.xy); - shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; - shadow += shadow_fade; - shadow = clamp(shadow, 0.0, 1.0); - } - - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - float envIntensity = norm.z; - norm = getNorm(frag.xy); - - norm = normalize(norm); - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - - float fa = (falloff*0.5) + 1.0; - float dist_atten = min(1.0 - (dist - 1.0 * (1.0 - fa)) / fa, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; - - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(norm, lv); - - vec3 col = vec3(0,0,0); - - vec3 diff_tex = srgb_to_linear(texture2DRect(diffuseRect, frag.xy).rgb); - - vec4 spec = texture2DRect(specularRect, frag.xy); - - vec3 dlit = vec3(0, 0, 0); - - float noise = texture2D(noiseMap, frag.xy/128.0).b; - if (proj_tc.z > 0.0 && - proj_tc.x < 1.0 && - proj_tc.y < 1.0 && - proj_tc.x > 0.0 && - proj_tc.y > 0.0) - { - float amb_da = proj_ambiance; - float lit = 0.0; - - if (da > 0.0) - { - lit = da * dist_atten * noise; - - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; - - col = dlit*lit*diff_tex*shadow; - amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance; - } - - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - amb_da += (da*da*0.5+0.5)*(1.0-shadow)*proj_ambiance; - - amb_da *= dist_atten * noise; - - amb_da = min(amb_da, 1.0-lit); - - col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a; - } - - - if (spec.a > 0.0) - { - dlit *= min(da*6.0, 1.0) * dist_atten; - vec3 npos = -normalize(pos); - - //vec3 ref = dot(pos+lv, norm); - vec3 h = normalize(lv+npos); - float nh = dot(norm, h); - float nv = dot(norm, npos); - float vh = dot(npos, h); - float sa = nh; - float fres = pow(1 - dot(h, npos), 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - - if (nh > 0.0) - { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); - col += dlit*scol*spec.rgb*shadow; - } - } - - - if (envIntensity > 0.0) - { - vec3 ref = reflect(normalize(pos), norm); - - //project from point pos in direction ref to plane proj_p, proj_n - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - - if (stc.z > 0.0) - { - stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - col += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; - } - } - } - } - - //not sure why, but this line prevents MATBUG-194 - col = max(col, vec3(0.0)); - - frag_color.rgb = col; - frag_color.a = 0.0; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl deleted file mode 100644 index 112b498c90..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightF.glsl +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file class3\deferred\sunLightF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -//class 2, shadows, no SSAO - -// Inputs -VARYING vec2 vary_fragcoord; - -vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); - -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen); - -void main() -{ - vec2 pos_screen = vary_fragcoord.xy; - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); - - frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); - frag_color.g = 1.0f; - frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); - frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl deleted file mode 100644 index 342a2ff3ed..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightSSAOF.glsl +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @file class3\deferred\sunLightSSAOF.glsl - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -//class 2 -- shadows and SSAO - -// Inputs -VARYING vec2 vary_fragcoord; - -uniform vec3 sun_dir; - -vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); - -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen); - -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); - -void main() -{ - vec2 pos_screen = vary_fragcoord.xy; - vec4 pos = getPosition(pos_screen); - vec3 norm = getNorm(pos_screen); - - frag_color.r = sampleDirectionalShadow(pos.xyz, norm, pos_screen); - frag_color.b = calcAmbientOcclusion(pos, norm, pos_screen); - frag_color.b = sampleSpotShadow(pos.xyz, norm, 0, pos_screen); - frag_color.a = sampleSpotShadow(pos.xyz, norm, 1, pos_screen); -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl deleted file mode 100644 index bc5eb5181d..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/sunLightV.glsl +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @file sunLightV.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -uniform mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - -VARYING vec2 vary_fragcoord; - -uniform vec2 screen_res; - -void main() -{ - //transform vertex - vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); - gl_Position = pos; - - vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl b/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl deleted file mode 100644 index 41673d1669..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/treeShadowF.glsl +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @file treeShadowF.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$ - */ - -/*[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 pos; -VARYING vec2 vary_texcoord0; - -vec4 computeMoments(float d, float a); - -void main() -{ - float alpha = texture2D(diffuseMap, vary_texcoord0.xy).a; - - if (alpha < minimum_alpha) - { - discard; - } - - frag_color = computeMoments(length(pos), 1.0); - -#if !defined(DEPTH_CLAMP) - gl_FragDepth = max(pos.z/pos.w*0.5+0.5, 0.0); -#endif - -} - diff --git a/indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl b/indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl deleted file mode 100644 index 15e769ac10..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/treeShadowV.glsl +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file treeShadowV.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -uniform mat4 texture_matrix0; -uniform mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec2 texcoord0; - -VARYING vec4 pos; -VARYING vec2 vary_texcoord0; - -void main() -{ - //transform vertex - pos = modelview_projection_matrix*vec4(position.xyz, 1.0); - - gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl deleted file mode 100644 index 540226e672..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/underWaterF.glsl +++ /dev/null @@ -1,115 +0,0 @@ -/** - * @file underWaterF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif - -uniform sampler2D diffuseMap; -uniform sampler2D bumpMap; -uniform sampler2D screenTex; -uniform sampler2D refTex; -uniform sampler2D screenDepth; - -uniform vec4 fogCol; -uniform vec3 lightDir; -uniform vec3 specular; -uniform float lightExp; -uniform vec2 fbScale; -uniform float refScale; -uniform float znear; -uniform float zfar; -uniform float kd; -uniform vec4 waterPlane; -uniform vec3 eyeVec; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; -uniform vec2 screenRes; - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; - -vec2 encode_normal(vec3 n); - -vec4 applyWaterFog(vec4 color, vec3 viewVec) -{ - //normalize view vector - vec3 view = normalize(viewVec); - float es = -view.z; - - //find intersection point with water plane and eye vector - - //get eye depth - float e0 = max(-waterPlane.w, 0.0); - - //get object depth - float depth = length(viewVec); - - //get "thickness" of water - float l = max(depth, 0.1); - - float kd = waterFogDensity; - float ks = waterFogKS; - vec4 kc = waterFogColor; - - 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); - return color * D + kc * L; -} - -void main() -{ - vec4 color; - - //get detail normals - vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; - vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; - vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - vec3 wavef = normalize(wave1+wave2+wave3); - - //figure out distortion vector (ripply) - vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; - distort = distort+wavef.xy*refScale; - - vec4 fb = texture2D(screenTex, distort); - - frag_data[0] = vec4(fb.rgb, 1.0); // diffuse - frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec - frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl deleted file mode 100644 index c65cf48c67..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/waterF.glsl +++ /dev/null @@ -1,174 +0,0 @@ -/** - * @file waterF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif - -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 - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; -VARYING vec4 vary_position; - -vec3 scaleSoftClip(vec3 c); -vec2 encode_normal(vec3 n); - -vec3 BlendNormal(vec3 bump1, vec3 bump2) -{ - //vec3 normal = bump1.xyz * vec3( 2.0, 2.0, 2.0) - vec3(1.0, 1.0, 0.0); - //vec3 normal2 = bump2.xyz * vec3(-2.0, -2.0, 2.0) + vec3(1.0, 1.0, -1.0); - //vec3 n = normalize(normal * dot(normal, normal2) - (normal2 * normal.z)); - vec3 n = normalize(mix(bump1, bump2, blend_factor)); - return n; -} - -void main() -{ - vec4 color; - float dist = length(view.xy); - - //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.99999); - - color.rgb *= 2.0f; - color.rgb = scaleSoftClip(color.rgb); - - vec4 pos = vary_position; - - color.rgb += spec * specular; - color.a = spec * sunAngle2; - - vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - - frag_data[0] = vec4(color.rgb, color); // diffuse - frag_data[1] = vec4(spec * specular, spec); // speccolor, spec - frag_data[2] = vec4(encode_normal(wavef.xyz), 0.05, 0);// normalxy, 0, 0 -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class3/deferred/waterV.glsl deleted file mode 100644 index 02000d90ca..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/waterV.glsl +++ /dev/null @@ -1,95 +0,0 @@ -/** - * @file waterV.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -uniform mat4 modelview_matrix; -uniform mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - - -uniform vec2 d1; -uniform vec2 d2; -uniform float time; -uniform vec3 eyeVec; -uniform float waterHeight; - -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; - -VARYING vec4 vary_position; - -float wave(vec2 v, float t, float f, vec2 d, float s) -{ - return (dot(d, v)*f + t*s)*f; -} - -void main() -{ - //transform vertex - vec4 pos = vec4(position.xyz, 1.0); - mat4 modelViewProj = modelview_projection_matrix; - - vec4 oPosition; - - //get view vector - vec3 oEyeVec; - oEyeVec.xyz = pos.xyz-eyeVec; - - float d = length(oEyeVec.xy); - float ld = min(d, 2560.0); - - pos.xy = eyeVec.xy + oEyeVec.xy/d*ld; - view.xyz = oEyeVec; - - d = clamp(ld/1536.0-0.5, 0.0, 1.0); - d *= d; - - oPosition = vec4(position, 1.0); - oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); - vary_position = modelview_matrix * oPosition; - oPosition = modelViewProj * oPosition; - - refCoord.xyz = oPosition.xyz + vec3(0,0,0.2); - - //get wave position parameter (create sweeping horizontal waves) - vec3 v = pos.xyz; - v.x += (cos(v.x*0.08/*+time*0.01*/)+sin(v.y*0.02))*6.0; - - //push position for further horizon effect. - pos.xyz = oEyeVec.xyz*(waterHeight/oEyeVec.z); - pos.w = 1.0; - pos = modelview_matrix*pos; - - //pass wave parameters to pixel shader - vec2 bigWave = (v.xy) * vec2(0.04,0.04) + d1 * time * 0.055; - //get two normal map (detail map) texture coordinates - littleWave.xy = (v.xy) * vec2(0.45, 0.9) + d2 * time * 0.13; - littleWave.zw = (v.xy) * vec2(0.1, 0.2) + d1 * time * 0.1; - view.w = bigWave.y; - refCoord.w = bigWave.x; - - gl_Position = oPosition; -} -- cgit v1.2.3 From 220afbcda0961df86ad08bbd51d96b8c868b2e62 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 2 Jun 2022 18:42:38 -0500 Subject: SL-17285 Add proper reflection probe support to LLVOVolume, LLPrimitive, and LLPanelVolume --- .../shaders/class3/deferred/reflectionProbeF.glsl | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 8c1323ba1a..eb9d3f485b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -1,5 +1,5 @@ /** - * @file class2/deferred/reflectionProbeF.glsl + * @file class3/deferred/reflectionProbeF.glsl * * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Second Life Viewer Source Code @@ -42,6 +42,8 @@ layout (std140, binding = 1) uniform ReflectionProbes mat4 refBox[REFMAP_COUNT]; // list of bounding spheres for reflection probes sorted by distance to camera (closest first) vec4 refSphere[REFMAP_COUNT]; + // extra parameters (currently only .x used for probe ambiance) + vec4 refParams[REFMAP_COUNT]; // index of cube map in reflectionProbes for a corresponding reflection probe // e.g. cube map channel of refSphere[2] is stored in refIndex[2] // refIndex.x - cubemap channel in reflectionProbes @@ -55,9 +57,6 @@ layout (std140, binding = 1) uniform ReflectionProbes // number of reflection probes present in refSphere int refmapCount; - - // intensity of ambient light from reflection probes - float reflectionAmbiance; }; // Inputs @@ -335,7 +334,7 @@ vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) } } -vec3 sampleProbes(vec3 pos, vec3 dir, float lod) +vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) { float wsum = 0.0; vec3 col = vec3(0,0,0); @@ -360,7 +359,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod) float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); w *= atten; w *= p; // boost weight based on priority - col += refcol*w; + col += refcol*w*max(minweight, refParams[i].x); wsum += w; } @@ -383,7 +382,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod) float w = 1.0/d2; w *= w; - col += refcol*w; + col += refcol*w*max(minweight, refParams[i].x); wsum += w; } } @@ -399,7 +398,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod) vec3 sampleProbeAmbient(vec3 pos, vec3 dir, float lod) { - vec3 col = sampleProbes(pos, dir, lod); + vec3 col = sampleProbes(pos, dir, lod, 0.f); //desaturate vec3 hcol = col *0.5; @@ -413,7 +412,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir, float lod) col *= 0.333333; - return col*reflectionAmbiance; + return col; } @@ -445,12 +444,12 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 l if (glossiness > 0.0) { float lod = (1.0-glossiness)*reflection_lods; - glossenv = sampleProbes(pos, normalize(refnormpersp), lod); + glossenv = sampleProbes(pos, normalize(refnormpersp), lod, 1.f); } if (envIntensity > 0.0) { - legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0); + legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, 1.f); } } -- cgit v1.2.3 From 619fb2eed5d6c6e341a9ab179bb94aa33ec7fcd0 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 3 Jun 2022 10:14:45 -0500 Subject: SL-17285 Build fix (coding policy needs last line to be blank). --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index eb9d3f485b..edb78f114b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -472,4 +472,4 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no fresnel = min(fresnel+envIntensity, 1.0); reflected_color *= (envIntensity*fresnel)*brighten(spec.rgb); color = mix(color.rgb, reflected_color, envIntensity); - } \ No newline at end of file + } -- cgit v1.2.3 From a185fae28d7e035226d4b5f7c350f94830001b06 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 3 Jun 2022 11:36:37 -0500 Subject: SL-17285 Build fix take two. --- indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index edb78f114b..3fd001e7f5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -473,3 +473,4 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no reflected_color *= (envIntensity*fresnel)*brighten(spec.rgb); color = mix(color.rgb, reflected_color, envIntensity); } + -- cgit v1.2.3 From 509476f95ed75ce8289ecd69b4c94d9912e1d3df Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 10 Jun 2022 01:13:41 -0500 Subject: SL-17574 Add probe detail combo box to advanced graphics preferences. Fix spot light shadows not working in probes. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 3fd001e7f5..b3396baeba 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -74,6 +74,8 @@ bool isAbove(vec3 pos, vec4 plane) return (dot(plane.xyz, pos) + plane.w) > 0; } +int max_priority = 0; + // return true if probe at index i influences position pos bool shouldSampleProbe(int i, vec3 pos) { @@ -86,6 +88,8 @@ bool shouldSampleProbe(int i, vec3 pos) { return false; } + + max_priority = max(max_priority, -refIndex[i].w); } else { @@ -98,6 +102,8 @@ bool shouldSampleProbe(int i, vec3 pos) { //outside bounding sphere return false; } + + max_priority = max(max_priority, refIndex[i].w); } return true; @@ -343,8 +349,13 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) for (int idx = 0; idx < probeInfluences; ++idx) { int i = probeIndex[idx]; + if (refIndex[i].w < max_priority) + { + continue; + } float r = refSphere[i].w; // radius of sphere volume float p = float(abs(refIndex[i].w)); // priority + float rr = r*r; // radius squred float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz-refSphere[i].xyz; @@ -358,7 +369,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); w *= atten; - w *= p; // boost weight based on priority + //w *= p; // boost weight based on priority col += refcol*w*max(minweight, refParams[i].x); wsum += w; -- cgit v1.2.3 From 5eb6591d0a5252f0bdd1db9ef551a526099b5a99 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 10 Jun 2022 11:52:32 -0500 Subject: SL-17574 Fix for box probes not applying. --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index b3396baeba..4a40f691be 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -349,7 +349,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) for (int idx = 0; idx < probeInfluences; ++idx) { int i = probeIndex[idx]; - if (refIndex[i].w < max_priority) + if (abs(refIndex[i].w) < max_priority) { continue; } -- cgit v1.2.3 From 36d9fa90150d30a0a0851cc0da87531014c1d93d Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 21 Jun 2022 16:31:35 -0700 Subject: SL-17274: Add view_dir uniform --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 61757882bb..4dd5c88211 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -1,5 +1,5 @@ /** - * @file class2/deferred/softenLightF.glsl + * @file class3/deferred/softenLightF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code @@ -85,6 +85,8 @@ vec3 srgb_to_linear(vec3 c); vec4 applyWaterFogView(vec3 pos, vec4 color); #endif +uniform vec3 view_dir; // PBR + void main() { vec2 tc = vary_fragcoord.xy; -- cgit v1.2.3 From 31e2fa5e50bc5aad265e8ec12613223eeb3ae3e1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 21 Jun 2022 22:44:30 -0500 Subject: SL-17600 WIP -- Proper radiance maps (not just mipped cubemaps). --- .../app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 4a40f691be..40378b49ea 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -334,8 +334,9 @@ vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) v -= c; v = env_mat * v; { - float min_lod = textureQueryLod(reflectionProbes,v).y; // lower is higher res - return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), max(min_lod, lod)).rgb; + //float min_lod = textureQueryLod(reflectionProbes,v).y; // lower is higher res + //return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), max(min_lod, lod)).rgb; + return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod).rgb; //return texture(reflectionProbes, vec4(v.xyz, refIndex[i].x)).rgb; } } @@ -450,7 +451,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 l vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - ambenv = sampleProbeAmbient(pos, norm, reflection_lods-1); + ambenv = sampleProbeAmbient(pos, norm, reflection_lods-2); if (glossiness > 0.0) { -- cgit v1.2.3 From 77b96114c30232c1d3f3b548bf982f89f11d09da Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 21 Jun 2022 22:00:12 -0700 Subject: SL-17274 Cleanup hard-coded gbuffer atmos flag for softenlight --- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index c5b1937cfb..13369d09fd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -446,10 +446,10 @@ void main() #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer - // deferred path - frag_data[0] = final_color; //gbuffer is sRGB + // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl + 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. + frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) #endif } -- cgit v1.2.3 From 27ca7760cc4126c8c45a5c22edafee5d2984a742 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 21 Jun 2022 22:23:38 -0700 Subject: SL-17274: Remove hard-coded magic number checking if G-Buffer flag is set --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 61757882bb..ea89a7626f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -170,7 +170,7 @@ void main() applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, 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); -- cgit v1.2.3 From d0d1b832d4983f35ab29947eb6fda54a8aa48f8a Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 22 Jun 2022 13:25:50 -0500 Subject: SL-17600 Proper irradiance probes. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 120 +++++++++++++++++---- 1 file changed, 99 insertions(+), 21 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 40378b49ea..83348077d7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -31,6 +31,7 @@ #define REF_SAMPLE_COUNT 64 //maximum number of samples to consider uniform samplerCubeArray reflectionProbes; +uniform samplerCubeArray irradianceProbes; layout (std140, binding = 1) uniform ReflectionProbes { @@ -308,7 +309,7 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i) -// Tap a sphere based reflection probe +// Tap a reflection probe // pos - position of pixel // dir - pixel normal // lod - which mip to bias towards (lower is higher res, sharper reflections) @@ -334,10 +335,36 @@ vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) v -= c; v = env_mat * v; { - //float min_lod = textureQueryLod(reflectionProbes,v).y; // lower is higher res - //return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), max(min_lod, lod)).rgb; return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod).rgb; - //return texture(reflectionProbes, vec4(v.xyz, refIndex[i].x)).rgb; + } +} + +// Tap an irradiance map +// pos - position of pixel +// dir - pixel normal +// c - center of probe +// r2 - radius of probe squared +// i - index of probe +// vi - point at which reflection vector struck the influence volume, in clip space +vec3 tapIrradianceMap(vec3 pos, vec3 dir, vec3 c, float r2, int i) +{ + //lod = max(lod, 1); + // parallax adjustment + + vec3 v; + if (refIndex[i].w < 0) + { + v = boxIntersect(pos, dir, i); + } + else + { + v = sphereIntersect(pos, dir, c, r2); + } + + v -= c; + v = env_mat * v; + { + return texture(irradianceProbes, vec4(v.xyz, refIndex[i].x)).rgb * refParams[i].x; } } @@ -371,7 +398,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); w *= atten; //w *= p; // boost weight based on priority - col += refcol*w*max(minweight, refParams[i].x); + col += refcol*w; wsum += w; } @@ -394,7 +421,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) float w = 1.0/d2; w *= w; - col += refcol*w*max(minweight, refParams[i].x); + col += refcol*w; wsum += w; } } @@ -408,24 +435,75 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) return col; } -vec3 sampleProbeAmbient(vec3 pos, vec3 dir, float lod) +vec3 sampleProbeAmbient(vec3 pos, vec3 dir) { - vec3 col = sampleProbes(pos, dir, lod, 0.f); + // modified copy/paste of sampleProbes follows, will likely diverge from sampleProbes further + // as irradiance map mixing is tuned independently of radiance map mixing + float wsum = 0.0; + vec3 col = vec3(0,0,0); + float vd2 = dot(pos,pos); // view distance squared - //desaturate - vec3 hcol = col *0.5; - - col *= 2.0; - col = vec3( - col.r + hcol.g + hcol.b, - col.g + hcol.r + hcol.b, - col.b + hcol.r + hcol.g - ); - - col *= 0.333333; + float minweight = 1.0; - return col; + for (int idx = 0; idx < probeInfluences; ++idx) + { + int i = probeIndex[idx]; + if (abs(refIndex[i].w) < max_priority) + { + continue; + } + float r = refSphere[i].w; // radius of sphere volume + float p = float(abs(refIndex[i].w)); // priority + + float rr = r*r; // radius squred + float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) + vec3 delta = pos.xyz-refSphere[i].xyz; + float d2 = dot(delta,delta); + float r2 = r1*r1; + + { + vec3 refcol = tapIrradianceMap(pos, dir, refSphere[i].xyz, rr, i); + + float w = 1.0/d2; + + float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); + w *= atten; + //w *= p; // boost weight based on priority + col += refcol*w; + + wsum += w; + } + } + if (probeInfluences <= 1) + { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera + for (int idx = 0; idx < 8; ++idx) + { + if (refIndex[idx].w < 0) + { // don't fallback to box probes, they are *very* specific + continue; + } + int i = idx; + vec3 delta = pos.xyz-refSphere[i].xyz; + float d2 = dot(delta,delta); + + { + vec3 refcol = tapIrradianceMap(pos, dir, refSphere[i].xyz, d2, i); + + float w = 1.0/d2; + w *= w; + col += refcol*w; + wsum += w; + } + } + } + + if (wsum > 0.0) + { + col *= 1.0/wsum; + } + + return col; } // brighten a color so that at least one component is 1 @@ -451,7 +529,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 l vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - ambenv = sampleProbeAmbient(pos, norm, reflection_lods-2); + ambenv = sampleProbeAmbient(pos, norm); if (glossiness > 0.0) { -- cgit v1.2.3 From 661f554886511a4062c91b0ce656bb0130937244 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 23 Jun 2022 16:18:11 -0700 Subject: SL-17274: Add WIP PBR Shader --- .../shaders/class3/deferred/softenLightF.glsl | 180 ++++++++++++++++++++- 1 file changed, 179 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 56fa4d0c4e..f2ae699130 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -23,6 +23,28 @@ * $/LicenseInfo$ */ +#define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 +#define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 +#define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 + +#define DEBUG_PBR_RAW_DIFF 0 // Output: use diffuse in G-Buffer +#define DEBUG_PBR_RAW_SPEC 0 // Output: use spec in G-Buffer +#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance +#define DEBUG_PBR_DIFFUSE 0 // Output: Radiance Lambertian +#define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal +#define DEBUG_PBR_ROUGH 0 // Output: grayscale roughenss +#define DEBUG_PBR_METAL 0 // Output: grayscale metal +#define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance +#define DEBUG_PBR_SPEC 0 // Output: Final spec +#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: reflection +#define DEBUG_PBR_NORMAL 0 // Output: passed in normal +#define DEBUG_PBR_VIEW 0 // Output: view_dir +#define DEBUG_PBR_BRDF 0 // Output: Environment BRDF +#define DEBUG_PBR_DOT_NV 0 // Output: +#define DEBUG_PBR_DOT_TV 0 // Output: +#define DEBUG_PBR_DOT_BV 0 // Output: +#define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel + #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -87,6 +109,32 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); uniform vec3 view_dir; // PBR +#define getDiffuseLightPBR(n) ambenv +#define getSpecularPBR(reflection) glossenv + +// Approximate Environment BRDF +vec2 getGGXApprox( vec2 uv ) +{ + vec2 st = vec2(1.) - uv; + float d = (st.x * st.x * 0.5) * (st.y * st.y); + float scale = 1.0 - d; + float bias = d; + return vec2( scale, bias ); +} + +vec2 getGGX( vec2 brdfPoint ) +{ + // TODO: use GGXLUT + // texture2D(GGXLUT, brdfPoint).rg; + return getGGXApprox( brdfPoint); +} + +vec3 calcBaseReflect0(float ior) +{ + vec3 reflect0 = vec3(pow((ior - 1.0) / (ior + 1.0), 2.0)); + return reflect0; +} + void main() { vec2 tc = vary_fragcoord.xy; @@ -133,6 +181,136 @@ void main() vec3 legacyenv; sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + bool hasPBR = GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR); + if (hasPBR) + { + vec3 colorDiffuse = vec3(0); + vec3 colorEmissive = vec3(0); + vec3 colorSpec = vec3(0); +// vec3 colorClearCoat = vec3(0); +// vec3 colorSheen = vec3(0); +// vec3 colorTransmission = vec3(0); + + vec3 packedORM = spec.rgb; // Packed: Occlusion Roughness Metal +#if DEBUG_PBR_PACK_ORM0 + packedORM = vec3(0,0,0); +#endif +#if DEBUG_PBR_PACK_ORM1 + packedORM = vec3(1,1,1); +#endif + float IOR = 1.5; // default Index Of Reflection 1.5 + vec3 reflect0 = vec3(0.04); // -> incidence reflectance 0.04 + + IOR = 0.0; // TODO: Set from glb + reflect0 = calcBaseReflect0(IOR); + + float metal = packedORM.b; + vec3 reflect90 = vec3(0); + vec3 v = view_dir; + vec3 n = norm.xyz; +// vec3 t = texture2DRect(tangentMap, tc).rgb; +#if DEBUG_PBR_TANGENT1 + vec3 t = vec3(1,0,0); +#endif + vec3 b = cross( n,t); + vec3 reflectVN = normalize(reflect(-v,n)); + + float dotNV = clamp(dot(n,v),0,1); + float dotTV = clamp(dot(n,t),0,1); + float dotBV = clamp(dot(n,b),0,1); + + // Reference: getMetallicRoughnessInfo + float perceptualRough = packedORM.g; + float alphaRough = perceptualRough * perceptualRough; + vec3 colorDiff = mix( diffuse.rgb, vec3(0) , metal); + reflect0 = mix( reflect0 , diffuse.rgb, metal); // reflect at 0 degrees + reflect90 = vec3(1); // reflect at 90 degrees + float reflectance = max( max( reflect0.r, reflect0.g ), reflect0.b ); + + // Common to RadianceGGX and RadianceLambertian + float specWeight = 1.0; + vec2 brdfPoint = clamp(vec2(dotNV, perceptualRough), vec2(0,0), vec2(1,1)); + vec2 vScaleBias = getGGX( brdfPoint); // Environment BRDF: scale and bias applied to reflect0 + vec3 fresnelR = max(vec3(1.0 - perceptualRough), reflect0) - reflect0; // roughness dependent fresnel + vec3 kSpec = reflect0 + fresnelR*pow(1.0 - dotNV, 5.0); + + // Reference: getIBLRadianceGGX + vec3 specLight = getSpecularPBR(reflection); +#if HAS_IBL + kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); +#endif + vec3 FssEssRadiance = kSpec*vScaleBias.x + vScaleBias.y; + colorSpec += specWeight * specLight * FssEssRadiance; + + // Reference: getIBLRadianceLambertian + vec3 irradiance = getDiffuseLightPBR(n); + vec3 FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term + float Ems = (1.0 - vScaleBias.x + vScaleBias.y); + vec3 avg = specWeight * (reflect0 + (1.0 - reflect0) / 21.0); + vec3 AvgEms = avg * Ems; + vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms); + vec3 kDiffuse = colorDiffuse * (1.0 - FssEssLambert + FmsEms); + colorDiffuse += (FmsEms + kDiffuse) * irradiance; + + color.rgb = colorDiffuse + colorEmissive + colorSpec; + + #if DEBUG_PBR_BRDF + color.rgb = vec3(vScaleBias,0); + #endif + #if DEBUG_PBR_FRESNEL + color.rgb = fresnelR; + #endif + #if DEBUG_PBR_RAW_DIFF + color.rgb = diffuse.rgb; + #endif + #if DEBUG_PBR_RAW_SPEC + color.rgb = spec.rgb; + #endif + #if DEBUG_PBR_REFLECTANCE + color.rgb = vec3(reflectance); + #endif + #if DEBUG_PBR_IRRADIANCE + color.rgb = irradiance; + #endif + #if DEBUG_PBR_DIFFUSE + color.rgb = colorDiffuse; + #endif + #if DEBUG_PBR_EMISSIVE + color.rgb = colorEmissive; + #endif + #if DEBUG_PBR_METAL + color.rgb = vec3(metal); + #endif + #if DEBUG_PBR_ROUGH + color.rgb = vec3(perceptualRough); + #endif + #if DEBUG_PBR_SPEC + color.rgb = colorSpec; + #endif + #if DEBUG_PBR_SPEC_REFLECTION + color.rgb = specLight; + #endif + #if DEBUG_PBR_ORM + color.rgb = packedORM; + #endif + #if DEBUG_PBR_NORMAL + color.rgb = norm.xyz; + #endif + #if DEBUG_PBR_VIEW + color.rgb = view_dir; + #endif + #if DEBUG_PBR_DOT_NV + color.rgb = vec3(dotNV); + #endif + #if DEBUG_PBR_DOT_TV + color.rgb = vec3(dotTV); + #endif + #if DEBUG_PBR_DOT_BV + color.rgb = vec3(dotBV); + #endif + } +else +{ amblit = max(ambenv, amblit); color.rgb = amblit*ambocc; @@ -183,7 +361,7 @@ void main() color = fogged.rgb; bloom = fogged.a; #endif - +} // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... //color = vec3(ambocc); -- cgit v1.2.3 From 668be68dd1285698d0f0131d2d6a568d913eecaf Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 24 Jun 2022 14:38:34 -0700 Subject: SL-17274: PBR: Add roughness alpha debug --- .../shaders/class3/deferred/softenLightF.glsl | 40 ++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index f2ae699130..d2176130dc 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -27,23 +27,24 @@ #define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 #define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 -#define DEBUG_PBR_RAW_DIFF 0 // Output: use diffuse in G-Buffer -#define DEBUG_PBR_RAW_SPEC 0 // Output: use spec in G-Buffer -#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance -#define DEBUG_PBR_DIFFUSE 0 // Output: Radiance Lambertian -#define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal -#define DEBUG_PBR_ROUGH 0 // Output: grayscale roughenss -#define DEBUG_PBR_METAL 0 // Output: grayscale metal -#define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance -#define DEBUG_PBR_SPEC 0 // Output: Final spec -#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: reflection -#define DEBUG_PBR_NORMAL 0 // Output: passed in normal -#define DEBUG_PBR_VIEW 0 // Output: view_dir -#define DEBUG_PBR_BRDF 0 // Output: Environment BRDF -#define DEBUG_PBR_DOT_NV 0 // Output: -#define DEBUG_PBR_DOT_TV 0 // Output: -#define DEBUG_PBR_DOT_BV 0 // Output: -#define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel +#define DEBUG_PBR_RAW_DIFF 0 // Output: use diffuse in G-Buffer +#define DEBUG_PBR_RAW_SPEC 0 // Output: use spec in G-Buffer +#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance +#define DEBUG_PBR_DIFFUSE 0 // Output: Radiance Lambertian +#define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal +#define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughenss +#define DEBUG_PBR_ROUGH_ALPHA 0 // Output: grayscale Alpha Roughness +#define DEBUG_PBR_METAL 0 // Output: grayscale metal +#define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance +#define DEBUG_PBR_SPEC 0 // Output: Final spec +#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: reflection +#define DEBUG_PBR_NORMAL 0 // Output: passed in normal +#define DEBUG_PBR_VIEW 0 // Output: view_dir +#define DEBUG_PBR_BRDF 0 // Output: Environment BRDF +#define DEBUG_PBR_DOT_NV 0 // Output: +#define DEBUG_PBR_DOT_TV 0 // Output: +#define DEBUG_PBR_DOT_BV 0 // Output: +#define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -281,9 +282,12 @@ void main() #if DEBUG_PBR_METAL color.rgb = vec3(metal); #endif - #if DEBUG_PBR_ROUGH + #if DEBUG_PBR_ROUGH_PERCEPTUAL color.rgb = vec3(perceptualRough); #endif + #if DEBUG_PBR_ROUGH_ALPHA + color.rgb = vec3(alphaRough); + #endif #if DEBUG_PBR_SPEC color.rgb = colorSpec; #endif -- cgit v1.2.3 From 11a67c57b8816c1a1141313301721fd4e0998b17 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 24 Jun 2022 15:10:09 -0700 Subject: SL-17274: PBR: Add BRDF debug --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index d2176130dc..8b82d544cd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -36,12 +36,14 @@ #define DEBUG_PBR_ROUGH_ALPHA 0 // Output: grayscale Alpha Roughness #define DEBUG_PBR_METAL 0 // Output: grayscale metal #define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance +#define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) +#define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) #define DEBUG_PBR_SPEC 0 // Output: Final spec #define DEBUG_PBR_SPEC_REFLECTION 0 // Output: reflection #define DEBUG_PBR_NORMAL 0 // Output: passed in normal #define DEBUG_PBR_VIEW 0 // Output: view_dir #define DEBUG_PBR_BRDF 0 // Output: Environment BRDF -#define DEBUG_PBR_DOT_NV 0 // Output: +#define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal,ViewDir) #define DEBUG_PBR_DOT_TV 0 // Output: #define DEBUG_PBR_DOT_BV 0 // Output: #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel @@ -255,8 +257,11 @@ void main() color.rgb = colorDiffuse + colorEmissive + colorSpec; - #if DEBUG_PBR_BRDF - color.rgb = vec3(vScaleBias,0); + #if DEBUG_PBR_BRDF_UV + color.rgb = vec3(brdfPoint,0.0); + #endif + #if DEBUG_PBR_BRDF_SCALE_BIAS + color.rgb = vec3(vScaleBias,0.0); #endif #if DEBUG_PBR_FRESNEL color.rgb = fresnelR; -- cgit v1.2.3 From 4e1a4e80e4913fbe4161560591513333106b2658 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 24 Jun 2022 15:38:35 -0700 Subject: SL-17274: PBR: Add note about DEBUG_PBR_NORMAL --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8b82d544cd..243f1c4498 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -40,7 +40,7 @@ #define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) #define DEBUG_PBR_SPEC 0 // Output: Final spec #define DEBUG_PBR_SPEC_REFLECTION 0 // Output: reflection -#define DEBUG_PBR_NORMAL 0 // Output: passed in normal +#define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_RAW_DIFF 1, and in pbropaqueF set DEBUG_NORMAL_RAW #define DEBUG_PBR_VIEW 0 // Output: view_dir #define DEBUG_PBR_BRDF 0 // Output: Environment BRDF #define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal,ViewDir) -- cgit v1.2.3 From 46c817d8511428662f4e325976887e1b4f669f75 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Mon, 27 Jun 2022 15:07:40 -0700 Subject: SL-17274: PBR: Fix v, dotTV, dotBV --- .../shaders/class3/deferred/softenLightF.glsl | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 243f1c4498..0ca7391e32 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -26,6 +26,7 @@ #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 #define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 #define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 +#define DEBUG_PBR_VERT2CAM1 0 // vertex2camera = 0,0,1 #define DEBUG_PBR_RAW_DIFF 0 // Output: use diffuse in G-Buffer #define DEBUG_PBR_RAW_SPEC 0 // Output: use spec in G-Buffer @@ -41,7 +42,10 @@ #define DEBUG_PBR_SPEC 0 // Output: Final spec #define DEBUG_PBR_SPEC_REFLECTION 0 // Output: reflection #define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_RAW_DIFF 1, and in pbropaqueF set DEBUG_NORMAL_RAW -#define DEBUG_PBR_VIEW 0 // Output: view_dir +#define DEBUG_PBR_TANGENT 0 // Output: Tangent +#define DEBUG_PBR_BITANGET 0 // Output: Bitangnet +#define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera +#define DEBUG_PBR_V2C_REMAP 0 // Output: vertex2camera (remap [-1,1] -> [0,1]) #define DEBUG_PBR_BRDF 0 // Output: Environment BRDF #define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal,ViewDir) #define DEBUG_PBR_DOT_TV 0 // Output: @@ -209,7 +213,10 @@ void main() float metal = packedORM.b; vec3 reflect90 = vec3(0); - vec3 v = view_dir; + vec3 v = -normalize(pos.xyz); +#if DEBUG_PBR_VERT2CAM1 + v = vec3(0,0,1); +#endif vec3 n = norm.xyz; // vec3 t = texture2DRect(tangentMap, tc).rgb; #if DEBUG_PBR_TANGENT1 @@ -219,8 +226,8 @@ void main() vec3 reflectVN = normalize(reflect(-v,n)); float dotNV = clamp(dot(n,v),0,1); - float dotTV = clamp(dot(n,t),0,1); - float dotBV = clamp(dot(n,b),0,1); + float dotTV = clamp(dot(t,v),0,1); + float dotBV = clamp(dot(b,v),0,1); // Reference: getMetallicRoughnessInfo float perceptualRough = packedORM.g; @@ -305,8 +312,17 @@ void main() #if DEBUG_PBR_NORMAL color.rgb = norm.xyz; #endif - #if DEBUG_PBR_VIEW - color.rgb = view_dir; + #if DEBUG_PBR_TANGENT + color.rgb = t; + #endif + #if DEBUG_PBR_BITANGENT + color.rgb = b; + #endif + #if DEBUG_PBR_V2C_RAW + color.rgb = v; + #endif + #if DEBUG_PBR_V2C_REMAP + color.rgb = v*0.5 + vec3(0.5); #endif #if DEBUG_PBR_DOT_NV color.rgb = vec3(dotNV); -- cgit v1.2.3 From 5462ac5d3b20aeefbe750ab10780346c9238bdff Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Mon, 27 Jun 2022 16:45:06 -0700 Subject: SL-17274: PBR: Fix IOR --- .../shaders/class3/deferred/softenLightF.glsl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 0ca7391e32..9b21c7a3cb 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -51,6 +51,7 @@ #define DEBUG_PBR_DOT_TV 0 // Output: #define DEBUG_PBR_DOT_BV 0 // Output: #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel +#define DEBUG_PBR_IOR 0 // Output: grayscale IOR #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -205,11 +206,14 @@ void main() #if DEBUG_PBR_PACK_ORM1 packedORM = vec3(1,1,1); #endif - float IOR = 1.5; // default Index Of Reflection 1.5 + float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics) vec3 reflect0 = vec3(0.04); // -> incidence reflectance 0.04 - - IOR = 0.0; // TODO: Set from glb - reflect0 = calcBaseReflect0(IOR); +#if HAS_IOR + reflect0 = calcBaseReflect0(IOR); +#endif +#if DEBUG_PBR_REFLECT0_BASE + vec3 debug_reflect0 = reflect0; +#endif float metal = packedORM.b; vec3 reflect90 = vec3(0); @@ -273,6 +277,12 @@ void main() #if DEBUG_PBR_FRESNEL color.rgb = fresnelR; #endif + #if DEBUG_PBR_IOR + color.rgb = vec3(IOR); + #endif + #if DEBUG_PBR_KSPEC + color.rgb = kSpec; + #endif #if DEBUG_PBR_RAW_DIFF color.rgb = diffuse.rgb; #endif -- cgit v1.2.3 From 00e5a546702c6234d5c8df8b7056bf009b46bf5e Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 10:33:39 -0700 Subject: SL-17274: PBR: Cleanup: Only calc reflectance if debugging --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 9b21c7a3cb..b628a0265f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -239,7 +239,9 @@ void main() vec3 colorDiff = mix( diffuse.rgb, vec3(0) , metal); reflect0 = mix( reflect0 , diffuse.rgb, metal); // reflect at 0 degrees reflect90 = vec3(1); // reflect at 90 degrees +#if DEBUG_PBR_REFLECTANCE float reflectance = max( max( reflect0.r, reflect0.g ), reflect0.b ); +#endif // Common to RadianceGGX and RadianceLambertian float specWeight = 1.0; -- cgit v1.2.3 From c69d7bab9955172393ff0cc3223077154f23b4b2 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 10:34:32 -0700 Subject: SL-17274: PBR: Move amblit to before PBR shading --- .../shaders/class3/deferred/softenLightF.glsl | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index b628a0265f..bb14ca471d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -189,6 +189,8 @@ void main() vec3 legacyenv; sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + amblit = max(ambenv, amblit); + bool hasPBR = GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR); if (hasPBR) { @@ -345,10 +347,24 @@ void main() #if DEBUG_PBR_DOT_BV color.rgb = vec3(dotBV); #endif + #if DEBUG_PBR_FE_GGX + color.rgb = FssEssGGX; // spec + #endif + #if DEBUG_PBR_FE_LAMBERT + color.rgb = FssEssLambert; // diffuse + #endif +color.rgb = vec3(dotNV); +color.rgb = vec3(brdfPoint,0.0); +color.rgb = vec3(vScaleBias,0.0); +color.rgb = fresnelR; +color.rgb = kSpec; +color.rgb = reflection; +color.rgb = specLight; +//color.rgb = FssEssGGX; + } else { - amblit = max(ambenv, amblit); color.rgb = amblit*ambocc; //float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); -- cgit v1.2.3 From 4de6e8808586fe1b806f955d3ddd785c6d827a16 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 10:37:33 -0700 Subject: SL-17274: PBR: Add reflection vec --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index bb14ca471d..758b267b40 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -253,6 +253,7 @@ void main() vec3 kSpec = reflect0 + fresnelR*pow(1.0 - dotNV, 5.0); // Reference: getIBLRadianceGGX + vec3 reflection = normalize(reflect(-v,n)); vec3 specLight = getSpecularPBR(reflection); #if HAS_IBL kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); -- cgit v1.2.3 From 39092990b712342a5327f3dbdd63f634d4f0d847 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 10:39:48 -0700 Subject: SL-17274: PBR: Add reflect0 debugging --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 758b267b40..c83fa3615e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -52,6 +52,8 @@ #define DEBUG_PBR_DOT_BV 0 // Output: #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel #define DEBUG_PBR_IOR 0 // Output: grayscale IOR +#define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior +#define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -294,6 +296,12 @@ void main() #if DEBUG_PBR_RAW_SPEC color.rgb = spec.rgb; #endif + #if DEBUG_PBR_REFLECT0_BASE + color.rgb = vec3(debug_reflect0); + #endif + #if DEBUG_PBR_REFLECT0_MIX + color.rgb = vec3(reflect0); + #endif #if DEBUG_PBR_REFLECTANCE color.rgb = vec3(reflectance); #endif -- cgit v1.2.3 From ea48b194237ce8a8f38bc2f3fd54808c0c32df2a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 10:42:14 -0700 Subject: SL-17274: PBR: Remove manual debug --- .../shaders/class3/deferred/softenLightF.glsl | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index c83fa3615e..15a3775569 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -54,6 +54,8 @@ #define DEBUG_PBR_IOR 0 // Output: grayscale IOR #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior #define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior +#define DEBUG_PBR_FE_GGX 0 // Output: FssEssGGX +#define DEBUG_PBR_FE_LAMBERT 0 // Output: FssEssLambert #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -260,8 +262,8 @@ void main() #if HAS_IBL kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); #endif - vec3 FssEssRadiance = kSpec*vScaleBias.x + vScaleBias.y; - colorSpec += specWeight * specLight * FssEssRadiance; + vec3 FssEssGGX = kSpec*vScaleBias.x + vScaleBias.y; + colorSpec += specWeight * specLight * FssEssGGX; // Reference: getIBLRadianceLambertian vec3 irradiance = getDiffuseLightPBR(n); @@ -362,15 +364,6 @@ void main() #if DEBUG_PBR_FE_LAMBERT color.rgb = FssEssLambert; // diffuse #endif -color.rgb = vec3(dotNV); -color.rgb = vec3(brdfPoint,0.0); -color.rgb = vec3(vScaleBias,0.0); -color.rgb = fresnelR; -color.rgb = kSpec; -color.rgb = reflection; -color.rgb = specLight; -//color.rgb = FssEssGGX; - } else { -- cgit v1.2.3 From 626ef903b272fe8636d5e18d9b9b573d9bd22321 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 10:43:50 -0700 Subject: SL-17274: PBR: Add kDiffuse debugging --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 15a3775569..a0a2f95651 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -56,6 +56,7 @@ #define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior #define DEBUG_PBR_FE_GGX 0 // Output: FssEssGGX #define DEBUG_PBR_FE_LAMBERT 0 // Output: FssEssLambert +#define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -313,6 +314,9 @@ void main() #if DEBUG_PBR_DIFFUSE color.rgb = colorDiffuse; #endif + #if DEBUG_PBR_DIFFUSE_K + color.rgb = kDiffuse; + #endif #if DEBUG_PBR_EMISSIVE color.rgb = colorEmissive; #endif -- cgit v1.2.3 From c55634a046b3ac2999b8dbef1a08ec5974951410 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 10:45:08 -0700 Subject: SL-17274: PBR: Cleanup dot() vertex2camera --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index a0a2f95651..4688d946de 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -47,9 +47,9 @@ #define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera #define DEBUG_PBR_V2C_REMAP 0 // Output: vertex2camera (remap [-1,1] -> [0,1]) #define DEBUG_PBR_BRDF 0 // Output: Environment BRDF -#define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal,ViewDir) -#define DEBUG_PBR_DOT_TV 0 // Output: -#define DEBUG_PBR_DOT_BV 0 // Output: +#define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal ,Vertex2Camera) +#define DEBUG_PBR_DOT_TV 0 // Output: grayscale dot(Tangent ,Vertex2Camera) +#define DEBUG_PBR_DOT_BV 0 // Output: graysacle dot(Bitangent,Vertex2Camera) #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel #define DEBUG_PBR_IOR 0 // Output: grayscale IOR #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior -- cgit v1.2.3 From c90fb9b14c61a81c2cebfaa7d92c09d98bfd06da Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 10:45:55 -0700 Subject: SL-17274: PBR: Add kSpec debugging --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 4688d946de..c97a09ab1d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -51,6 +51,7 @@ #define DEBUG_PBR_DOT_TV 0 // Output: grayscale dot(Tangent ,Vertex2Camera) #define DEBUG_PBR_DOT_BV 0 // Output: graysacle dot(Bitangent,Vertex2Camera) #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel +#define DEBUG_PBR_KSPEC 0 // Output: K spec #define DEBUG_PBR_IOR 0 // Output: grayscale IOR #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior #define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior -- cgit v1.2.3 From 7fdb05d7ef449d2cc9b96c77c7bfa41bf7c15ede Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 11:11:40 -0700 Subject: SL-17274: PBR: Add occlusion --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index c97a09ab1d..ff2b87b9df 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -33,6 +33,7 @@ #define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance #define DEBUG_PBR_DIFFUSE 0 // Output: Radiance Lambertian #define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal +#define DEBUG_PBR_OCCLUSION 0 // Output: Occlusion map #define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughenss #define DEBUG_PBR_ROUGH_ALPHA 0 // Output: grayscale Alpha Roughness #define DEBUG_PBR_METAL 0 // Output: grayscale metal @@ -277,7 +278,11 @@ void main() vec3 kDiffuse = colorDiffuse * (1.0 - FssEssLambert + FmsEms); colorDiffuse += (FmsEms + kDiffuse) * irradiance; - color.rgb = colorDiffuse + colorEmissive + colorSpec; + float occlusion_strength = 1.0; // TODO: From glb + float ao = packedORM.r; + colorDiffuse = mix(colorDiffuse, colorDiffuse * ao, occlusion_strength); + + color.rgb = colorDiffuse + colorEmissive + colorSpec; #if DEBUG_PBR_BRDF_UV color.rgb = vec3(brdfPoint,0.0); @@ -336,6 +341,9 @@ void main() #if DEBUG_PBR_SPEC_REFLECTION color.rgb = specLight; #endif + #if DEBUG_PBR_OCCLUSION + color.rgb = vec3(packedORM.r); + #endif #if DEBUG_PBR_ORM color.rgb = packedORM; #endif -- cgit v1.2.3 From 254bbc86e5d1d3ec094779f46619c109d027da18 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 28 Jun 2022 15:39:04 -0500 Subject: Add emissiveRect to softenLightF.glsl --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index ff2b87b9df..295cf5f743 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -77,6 +77,7 @@ out vec4 frag_color; uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; +uniform sampler2DRect emissiveRect; #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) uniform sampler2DRect lightMap; -- cgit v1.2.3 From 9f75a535ad22e1a87a607b797db0c416be7236ec Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 14:05:16 -0700 Subject: SL-17274: PBR: Add Emissive --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 295cf5f743..aa146b4bcc 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -32,6 +32,7 @@ #define DEBUG_PBR_RAW_SPEC 0 // Output: use spec in G-Buffer #define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance #define DEBUG_PBR_DIFFUSE 0 // Output: Radiance Lambertian +#define DEBUG_PBR_EMISSIVE 0 // Output: Emissive #define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal #define DEBUG_PBR_OCCLUSION 0 // Output: Occlusion map #define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughenss @@ -203,7 +204,7 @@ void main() if (hasPBR) { vec3 colorDiffuse = vec3(0); - vec3 colorEmissive = vec3(0); + vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; vec3 colorSpec = vec3(0); // vec3 colorClearCoat = vec3(0); // vec3 colorSheen = vec3(0); -- cgit v1.2.3 From 93dfd8173047bcbcce142fc196e64acbfd115c82 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 15:43:12 -0700 Subject: SL-17274: PBR: Fix reflection --- .../shaders/class3/deferred/softenLightF.glsl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index aa146b4bcc..e50d3604c7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -126,9 +126,6 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); uniform vec3 view_dir; // PBR -#define getDiffuseLightPBR(n) ambenv -#define getSpecularPBR(reflection) glossenv - // Approximate Environment BRDF vec2 getGGXApprox( vec2 uv ) { @@ -196,9 +193,6 @@ void main() vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); - - amblit = max(ambenv, amblit); bool hasPBR = GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR); if (hasPBR) @@ -262,8 +256,13 @@ void main() vec3 kSpec = reflect0 + fresnelR*pow(1.0 - dotNV, 5.0); // Reference: getIBLRadianceGGX - vec3 reflection = normalize(reflect(-v,n)); - vec3 specLight = getSpecularPBR(reflection); + // https://forum.substance3d.com/index.php?topic=3243.0 + // Glossiness + // This map is the inverse of the roughness map. + vec3 irradiance = vec3(0); + vec3 specLight = vec3(0); + float gloss = 1.0 - perceptualRough; + sampleReflectionProbes(irradiance, specLight, legacyenv, pos.xyz, norm.xyz, gloss, 0.0); #if HAS_IBL kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); #endif @@ -271,7 +270,6 @@ void main() colorSpec += specWeight * specLight * FssEssGGX; // Reference: getIBLRadianceLambertian - vec3 irradiance = getDiffuseLightPBR(n); vec3 FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term float Ems = (1.0 - vScaleBias.x + vScaleBias.y); vec3 avg = specWeight * (reflect0 + (1.0 - reflect0) / 21.0); @@ -382,6 +380,9 @@ void main() } else { + sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + + amblit = max(ambenv, amblit); color.rgb = amblit*ambocc; //float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); -- cgit v1.2.3 From d42d0d9bc0c38e1669e2caa75a7da848f974c8e2 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 15:59:44 -0700 Subject: SL-17274: PBR: Cleanup: Put primary channels Diffuse,Emissive,Metal,Occlusion,Roughness first --- .../shaders/class3/deferred/softenLightF.glsl | 61 ++++++++++------------ 1 file changed, 29 insertions(+), 32 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index e50d3604c7..54ccb9eeae 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -28,27 +28,26 @@ #define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 #define DEBUG_PBR_VERT2CAM1 0 // vertex2camera = 0,0,1 -#define DEBUG_PBR_RAW_DIFF 0 // Output: use diffuse in G-Buffer -#define DEBUG_PBR_RAW_SPEC 0 // Output: use spec in G-Buffer -#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance #define DEBUG_PBR_DIFFUSE 0 // Output: Radiance Lambertian #define DEBUG_PBR_EMISSIVE 0 // Output: Emissive -#define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal -#define DEBUG_PBR_OCCLUSION 0 // Output: Occlusion map -#define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughenss +#define DEBUG_PBR_METAL 0 // Output: grayscale Metal map +#define DEBUG_PBR_OCCLUSION 0 // Output: grayscale Occlusion map +#define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughenss map #define DEBUG_PBR_ROUGH_ALPHA 0 // Output: grayscale Alpha Roughness -#define DEBUG_PBR_METAL 0 // Output: grayscale metal -#define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance + +#define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer +#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance +#define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal +#define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance -- NOT USED #define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) #define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) #define DEBUG_PBR_SPEC 0 // Output: Final spec -#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: reflection +#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection #define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_RAW_DIFF 1, and in pbropaqueF set DEBUG_NORMAL_RAW #define DEBUG_PBR_TANGENT 0 // Output: Tangent #define DEBUG_PBR_BITANGET 0 // Output: Bitangnet #define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera #define DEBUG_PBR_V2C_REMAP 0 // Output: vertex2camera (remap [-1,1] -> [0,1]) -#define DEBUG_PBR_BRDF 0 // Output: Environment BRDF #define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal ,Vertex2Camera) #define DEBUG_PBR_DOT_TV 0 // Output: grayscale dot(Tangent ,Vertex2Camera) #define DEBUG_PBR_DOT_BV 0 // Output: graysacle dot(Bitangent,Vertex2Camera) @@ -284,6 +283,25 @@ void main() color.rgb = colorDiffuse + colorEmissive + colorSpec; + #if DEBUG_PBR_DIFFUSE + color.rgb = colorDiffuse; + #endif + #if DEBUG_PBR_EMISSIVE + color.rgb = colorEmissive; + #endif + #if DEBUG_PBR_METAL + color.rgb = vec3(metal); + #endif + #if DEBUG_PBR_OCCLUSION + color.rgb = vec3(ao); + #endif + #if DEBUG_PBR_ROUGH_PERCEPTUAL + color.rgb = vec3(perceptualRough); + #endif + #if DEBUG_PBR_ROUGH_ALPHA + color.rgb = vec3(alphaRough); + #endif + #if DEBUG_PBR_BRDF_UV color.rgb = vec3(brdfPoint,0.0); #endif @@ -299,12 +317,9 @@ void main() #if DEBUG_PBR_KSPEC color.rgb = kSpec; #endif - #if DEBUG_PBR_RAW_DIFF + #if DEBUG_PBR_DIFFUSE_MAP color.rgb = diffuse.rgb; #endif - #if DEBUG_PBR_RAW_SPEC - color.rgb = spec.rgb; - #endif #if DEBUG_PBR_REFLECT0_BASE color.rgb = vec3(debug_reflect0); #endif @@ -317,33 +332,15 @@ void main() #if DEBUG_PBR_IRRADIANCE color.rgb = irradiance; #endif - #if DEBUG_PBR_DIFFUSE - color.rgb = colorDiffuse; - #endif #if DEBUG_PBR_DIFFUSE_K color.rgb = kDiffuse; #endif - #if DEBUG_PBR_EMISSIVE - color.rgb = colorEmissive; - #endif - #if DEBUG_PBR_METAL - color.rgb = vec3(metal); - #endif - #if DEBUG_PBR_ROUGH_PERCEPTUAL - color.rgb = vec3(perceptualRough); - #endif - #if DEBUG_PBR_ROUGH_ALPHA - color.rgb = vec3(alphaRough); - #endif #if DEBUG_PBR_SPEC color.rgb = colorSpec; #endif #if DEBUG_PBR_SPEC_REFLECTION color.rgb = specLight; #endif - #if DEBUG_PBR_OCCLUSION - color.rgb = vec3(packedORM.r); - #endif #if DEBUG_PBR_ORM color.rgb = packedORM; #endif -- cgit v1.2.3 From 4257bf7bc882dd59400abff6740aa3649b5e4392 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 16:07:24 -0700 Subject: SL-17274 PBR: Cleanup: Alphabetize and categorize debugging flags --- .../shaders/class3/deferred/softenLightF.glsl | 109 +++++++++++---------- 1 file changed, 55 insertions(+), 54 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 54ccb9eeae..6f7f4976f3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -32,34 +32,34 @@ #define DEBUG_PBR_EMISSIVE 0 // Output: Emissive #define DEBUG_PBR_METAL 0 // Output: grayscale Metal map #define DEBUG_PBR_OCCLUSION 0 // Output: grayscale Occlusion map +#define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal #define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughenss map #define DEBUG_PBR_ROUGH_ALPHA 0 // Output: grayscale Alpha Roughness -#define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer -#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance -#define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal -#define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance -- NOT USED -#define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) -#define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) -#define DEBUG_PBR_SPEC 0 // Output: Final spec -#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection -#define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_RAW_DIFF 1, and in pbropaqueF set DEBUG_NORMAL_RAW +#define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_DIFFUSE_MAP 1, and in pbropaqueF set DEBUG_NORMAL_RAW #define DEBUG_PBR_TANGENT 0 // Output: Tangent -#define DEBUG_PBR_BITANGET 0 // Output: Bitangnet -#define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera -#define DEBUG_PBR_V2C_REMAP 0 // Output: vertex2camera (remap [-1,1] -> [0,1]) +#define DEBUG_PBR_BITANGENT 0 // Output: Bitangent +#define DEBUG_PBR_DOT_BV 0 // Output: graysacle dot(Bitangent,Vertex2Camera) #define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal ,Vertex2Camera) #define DEBUG_PBR_DOT_TV 0 // Output: grayscale dot(Tangent ,Vertex2Camera) -#define DEBUG_PBR_DOT_BV 0 // Output: graysacle dot(Bitangent,Vertex2Camera) + +#define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) +#define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) +#define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms +#define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer +#define DEBUG_PBR_FE_GGX 0 // Output: FssEssGGX +#define DEBUG_PBR_FE_LAMBERT 0 // Output: FssEssLambert #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel -#define DEBUG_PBR_KSPEC 0 // Output: K spec #define DEBUG_PBR_IOR 0 // Output: grayscale IOR +#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance +#define DEBUG_PBR_KSPEC 0 // Output: K spec #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior #define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior -#define DEBUG_PBR_FE_GGX 0 // Output: FssEssGGX -#define DEBUG_PBR_FE_LAMBERT 0 // Output: FssEssLambert -#define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms - +#define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance -- NOT USED +#define DEBUG_PBR_SPEC 0 // Output: Final spec +#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection +#define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera +#define DEBUG_PBR_V2C_REMAP 0 // Output: vertex2camera (remap [-1,1] -> [0,1]) #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -295,6 +295,9 @@ void main() #if DEBUG_PBR_OCCLUSION color.rgb = vec3(ao); #endif + #if DEBUG_PBR_ORM + color.rgb = packedORM; + #endif #if DEBUG_PBR_ROUGH_PERCEPTUAL color.rgb = vec3(perceptualRough); #endif @@ -302,24 +305,55 @@ void main() color.rgb = vec3(alphaRough); #endif + #if DEBUG_PBR_NORMAL + color.rgb = norm.xyz; + #endif + #if DEBUG_PBR_TANGENT + color.rgb = t; + #endif + #if DEBUG_PBR_BITANGENT + color.rgb = b; + #endif + #if DEBUG_PBR_DOT_NV + color.rgb = vec3(dotNV); + #endif + #if DEBUG_PBR_DOT_TV + color.rgb = vec3(dotTV); + #endif + #if DEBUG_PBR_DOT_BV + color.rgb = vec3(dotBV); + #endif + #if DEBUG_PBR_BRDF_UV color.rgb = vec3(brdfPoint,0.0); #endif #if DEBUG_PBR_BRDF_SCALE_BIAS color.rgb = vec3(vScaleBias,0.0); #endif + #if DEBUG_PBR_DIFFUSE_K + color.rgb = kDiffuse; + #endif + #if DEBUG_PBR_DIFFUSE_MAP + color.rgb = diffuse.rgb; + #endif + #if DEBUG_PBR_FE_GGX + color.rgb = FssEssGGX; // spec + #endif + #if DEBUG_PBR_FE_LAMBERT + color.rgb = FssEssLambert; // diffuse + #endif #if DEBUG_PBR_FRESNEL color.rgb = fresnelR; #endif #if DEBUG_PBR_IOR color.rgb = vec3(IOR); #endif + #if DEBUG_PBR_IRRADIANCE + color.rgb = irradiance; + #endif #if DEBUG_PBR_KSPEC color.rgb = kSpec; #endif - #if DEBUG_PBR_DIFFUSE_MAP - color.rgb = diffuse.rgb; - #endif #if DEBUG_PBR_REFLECT0_BASE color.rgb = vec3(debug_reflect0); #endif @@ -329,51 +363,18 @@ void main() #if DEBUG_PBR_REFLECTANCE color.rgb = vec3(reflectance); #endif - #if DEBUG_PBR_IRRADIANCE - color.rgb = irradiance; - #endif - #if DEBUG_PBR_DIFFUSE_K - color.rgb = kDiffuse; - #endif #if DEBUG_PBR_SPEC color.rgb = colorSpec; #endif #if DEBUG_PBR_SPEC_REFLECTION color.rgb = specLight; #endif - #if DEBUG_PBR_ORM - color.rgb = packedORM; - #endif - #if DEBUG_PBR_NORMAL - color.rgb = norm.xyz; - #endif - #if DEBUG_PBR_TANGENT - color.rgb = t; - #endif - #if DEBUG_PBR_BITANGENT - color.rgb = b; - #endif #if DEBUG_PBR_V2C_RAW color.rgb = v; #endif #if DEBUG_PBR_V2C_REMAP color.rgb = v*0.5 + vec3(0.5); #endif - #if DEBUG_PBR_DOT_NV - color.rgb = vec3(dotNV); - #endif - #if DEBUG_PBR_DOT_TV - color.rgb = vec3(dotTV); - #endif - #if DEBUG_PBR_DOT_BV - color.rgb = vec3(dotBV); - #endif - #if DEBUG_PBR_FE_GGX - color.rgb = FssEssGGX; // spec - #endif - #if DEBUG_PBR_FE_LAMBERT - color.rgb = FssEssLambert; // diffuse - #endif } else { -- cgit v1.2.3 From 7e901e559658833b78a4ed24971a350ccc7ea691 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 28 Jun 2022 16:09:33 -0700 Subject: SL-17274: PBR: Cleanup alignment --- .../shaders/class3/deferred/softenLightF.glsl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 6f7f4976f3..5c62c3bc4a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -239,12 +239,12 @@ void main() // Reference: getMetallicRoughnessInfo float perceptualRough = packedORM.g; - float alphaRough = perceptualRough * perceptualRough; - vec3 colorDiff = mix( diffuse.rgb, vec3(0) , metal); - reflect0 = mix( reflect0 , diffuse.rgb, metal); // reflect at 0 degrees - reflect90 = vec3(1); // reflect at 90 degrees + float alphaRough = perceptualRough * perceptualRough; + vec3 colorDiff = mix( diffuse.rgb, vec3(0) , metal); + reflect0 = mix( reflect0 , diffuse.rgb, metal); // reflect at 0 degrees + reflect90 = vec3(1); // reflect at 90 degrees #if DEBUG_PBR_REFLECTANCE - float reflectance = max( max( reflect0.r, reflect0.g ), reflect0.b ); + float reflectance = max( max( reflect0.r, reflect0.g ), reflect0.b ); #endif // Common to RadianceGGX and RadianceLambertian @@ -270,12 +270,12 @@ void main() // Reference: getIBLRadianceLambertian vec3 FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term - float Ems = (1.0 - vScaleBias.x + vScaleBias.y); - vec3 avg = specWeight * (reflect0 + (1.0 - reflect0) / 21.0); - vec3 AvgEms = avg * Ems; - vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms); - vec3 kDiffuse = colorDiffuse * (1.0 - FssEssLambert + FmsEms); - colorDiffuse += (FmsEms + kDiffuse) * irradiance; + float Ems = (1.0 - vScaleBias.x + vScaleBias.y); + vec3 avg = specWeight * (reflect0 + (1.0 - reflect0) / 21.0); + vec3 AvgEms = avg * Ems; + vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms); + vec3 kDiffuse = colorDiffuse * (1.0 - FssEssLambert + FmsEms); + colorDiffuse += (FmsEms + kDiffuse) * irradiance; float occlusion_strength = 1.0; // TODO: From glb float ao = packedORM.r; -- cgit v1.2.3 From 2ec7a9af8212211a15a65e5301e44807e2e4e53d Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 08:43:33 -0700 Subject: SL-17274: Fix typo in reference to SL-14035 --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 5c62c3bc4a..7eba8689b3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -163,7 +163,7 @@ void main() da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); - diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14025 + diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); -- cgit v1.2.3 From 7515353d8ea17c433b08f1fdc05cc7a812babff4 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 09:02:50 -0700 Subject: SL-17274: Simplify occlusion and make not about future occlusion_strength --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 7eba8689b3..bd6ba4bf15 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -277,9 +277,7 @@ void main() vec3 kDiffuse = colorDiffuse * (1.0 - FssEssLambert + FmsEms); colorDiffuse += (FmsEms + kDiffuse) * irradiance; - float occlusion_strength = 1.0; // TODO: From glb - float ao = packedORM.r; - colorDiffuse = mix(colorDiffuse, colorDiffuse * ao, occlusion_strength); + colorDiffuse *= packedORM.r; // Occlusion -- NOTE: pbropaque will need occlusion_strength pre-multiplied into spec.r color.rgb = colorDiffuse + colorEmissive + colorSpec; @@ -293,7 +291,7 @@ void main() color.rgb = vec3(metal); #endif #if DEBUG_PBR_OCCLUSION - color.rgb = vec3(ao); + color.rgb = vec3(packedORM.r); #endif #if DEBUG_PBR_ORM color.rgb = packedORM; -- cgit v1.2.3 From 714667847edb406523405c06d18daa9bc1bcf1d3 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 13:24:21 -0700 Subject: SL-17274: Fix typo --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index bd6ba4bf15..dc22511bb3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -33,7 +33,7 @@ #define DEBUG_PBR_METAL 0 // Output: grayscale Metal map #define DEBUG_PBR_OCCLUSION 0 // Output: grayscale Occlusion map #define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal -#define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughenss map +#define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughness map #define DEBUG_PBR_ROUGH_ALPHA 0 // Output: grayscale Alpha Roughness #define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_DIFFUSE_MAP 1, and in pbropaqueF set DEBUG_NORMAL_RAW -- cgit v1.2.3 From d9ce24309d5f6537a526e233e1b6a6f6f4da4bc5 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 13:55:26 -0700 Subject: SL-17274: Add reflection dir debugging --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index dc22511bb3..4c082dcd98 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -56,6 +56,7 @@ #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior #define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior #define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance -- NOT USED +#define DEBUG_PBR_REFLECTION 0 // Output: reflection dir #define DEBUG_PBR_SPEC 0 // Output: Final spec #define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection #define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera @@ -361,6 +362,9 @@ void main() #if DEBUG_PBR_REFLECTANCE color.rgb = vec3(reflectance); #endif + #if DEBUG_PBR_REFLECTION + color.rgb = reflect(-v, n); // NOTE: equivalent to normalize(reflect(pos.xyz, norm.xyz)); + #endif #if DEBUG_PBR_SPEC color.rgb = colorSpec; #endif -- cgit v1.2.3 From 78e3edba6e998d8e97a1bff952073f62e58fd379 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 14:00:17 -0700 Subject: SL-17274: Cleanup order of diffuse debug flags --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 4c082dcd98..a64d059d06 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -28,7 +28,8 @@ #define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 #define DEBUG_PBR_VERT2CAM1 0 // vertex2camera = 0,0,1 -#define DEBUG_PBR_DIFFUSE 0 // Output: Radiance Lambertian +// Pass input through "as is" +#define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer #define DEBUG_PBR_EMISSIVE 0 // Output: Emissive #define DEBUG_PBR_METAL 0 // Output: grayscale Metal map #define DEBUG_PBR_OCCLUSION 0 // Output: grayscale Occlusion map @@ -36,6 +37,7 @@ #define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughness map #define DEBUG_PBR_ROUGH_ALPHA 0 // Output: grayscale Alpha Roughness +#define DEBUG_PBR_DIFFUSE 0 // Output: Radiance Lambertian #define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_DIFFUSE_MAP 1, and in pbropaqueF set DEBUG_NORMAL_RAW #define DEBUG_PBR_TANGENT 0 // Output: Tangent #define DEBUG_PBR_BITANGENT 0 // Output: Bitangent @@ -46,7 +48,6 @@ #define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) #define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) #define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms -#define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer #define DEBUG_PBR_FE_GGX 0 // Output: FssEssGGX #define DEBUG_PBR_FE_LAMBERT 0 // Output: FssEssLambert #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel -- cgit v1.2.3 From 251b75ea2ed5e652c245f9bed33ff96092b830fe Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 17:49:10 -0700 Subject: SL-17274: PBR: Add c_diff and fix kDiffuse --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index a64d059d06..2749dfed30 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -222,6 +222,7 @@ void main() #endif float metal = packedORM.b; + vec3 c_diff = mix(diffuse.rgb,vec3(0),metal); vec3 reflect90 = vec3(0); vec3 v = -normalize(pos.xyz); #if DEBUG_PBR_VERT2CAM1 @@ -276,7 +277,7 @@ void main() vec3 avg = specWeight * (reflect0 + (1.0 - reflect0) / 21.0); vec3 AvgEms = avg * Ems; vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms); - vec3 kDiffuse = colorDiffuse * (1.0 - FssEssLambert + FmsEms); + vec3 kDiffuse = c_diff * (1.0 - FssEssLambert + FmsEms); colorDiffuse += (FmsEms + kDiffuse) * irradiance; colorDiffuse *= packedORM.r; // Occlusion -- NOTE: pbropaque will need occlusion_strength pre-multiplied into spec.r @@ -330,6 +331,9 @@ void main() #if DEBUG_PBR_BRDF_SCALE_BIAS color.rgb = vec3(vScaleBias,0.0); #endif + #if DEBUG_PBR_DIFFUSE_C + color.rgb = c_diff; + #endif #if DEBUG_PBR_DIFFUSE_K color.rgb = kDiffuse; #endif -- cgit v1.2.3 From d1e078a1229fa61ba697e382fb42b6a6b11e8f97 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 17:50:03 -0700 Subject: SL-17274: PBR: Fix EMS being zero when using GGX approximation --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 2749dfed30..44884e780f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -23,6 +23,7 @@ * $/LicenseInfo$ */ +#define PBR_GGX_APPROX 1 #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 #define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 #define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 @@ -141,7 +142,9 @@ vec2 getGGX( vec2 brdfPoint ) { // TODO: use GGXLUT // texture2D(GGXLUT, brdfPoint).rg; +#if PBR_GGX_APPROX return getGGXApprox( brdfPoint); +#endif } vec3 calcBaseReflect0(float ior) @@ -274,6 +277,9 @@ void main() // Reference: getIBLRadianceLambertian vec3 FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term float Ems = (1.0 - vScaleBias.x + vScaleBias.y); +#if PBR_GGX_APPROX + Ems = alphaRough; // With GGX approximation Ems = 0 so use substitute +#endif vec3 avg = specWeight * (reflect0 + (1.0 - reflect0) / 21.0); vec3 AvgEms = avg * Ems; vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms); -- cgit v1.2.3 From 76caf9fe0ede7ded0bf348872be34891a0571c56 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 17:50:45 -0700 Subject: SL-17274: PBR: Group diffuse debugging --- .../shaders/class3/deferred/softenLightF.glsl | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 44884e780f..3c12e55d6a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -48,12 +48,20 @@ #define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) #define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) + +// Diffuse +#define DEBUG_PBR_DIFFUSE_C 0 // Output: diffuse non metal mix +#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance +#define DEBUG_PBR_FE_LAMBERT 0 // Output: FssEssLambert +#define DEBUG_PBR_EMS 0 // Output: Ems +#define DEBUG_PBR_AVG 0 // Output: Avg +#define DEBUG_PBR_EMS_FMS 0 // Output: FmsEms #define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms +#define DEBUG_PBR_DIFFUSE_PRE_AO 0 // Output: diffuse pre AO + #define DEBUG_PBR_FE_GGX 0 // Output: FssEssGGX -#define DEBUG_PBR_FE_LAMBERT 0 // Output: FssEssLambert #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel #define DEBUG_PBR_IOR 0 // Output: grayscale IOR -#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance #define DEBUG_PBR_KSPEC 0 // Output: K spec #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior #define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior @@ -285,7 +293,9 @@ void main() vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms); vec3 kDiffuse = c_diff * (1.0 - FssEssLambert + FmsEms); colorDiffuse += (FmsEms + kDiffuse) * irradiance; - + #if DEBUG_PBR_DIFFUSE_PRE_AO + vec3 debug_diffuse = colorDiffuse; + #endif colorDiffuse *= packedORM.r; // Occlusion -- NOTE: pbropaque will need occlusion_strength pre-multiplied into spec.r color.rgb = colorDiffuse + colorEmissive + colorSpec; @@ -331,6 +341,9 @@ void main() color.rgb = vec3(dotBV); #endif + #if DEBUG_PBR_AVG + color.rgb = avg; + #endif #if DEBUG_PBR_BRDF_UV color.rgb = vec3(brdfPoint,0.0); #endif @@ -346,6 +359,18 @@ void main() #if DEBUG_PBR_DIFFUSE_MAP color.rgb = diffuse.rgb; #endif + #if DEBUG_PBR_DIFFUSE_PRE_AO + color.rgb = debug_diffuse; + #endif + #if DEBUG_PBR_EMS + color.rgb = vec3(Ems); + #endif + #if DEBUG_PBR_EMS_AVG + color.rgb = AvgEms; + #endif + #if DEBUG_PBR_EMS_FMS + color.rgb = FmsEms; + #endif #if DEBUG_PBR_FE_GGX color.rgb = FssEssGGX; // spec #endif -- cgit v1.2.3 From 9432edaba7d073cd3f22ecda1f2cfc3093d9bcb7 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 29 Jun 2022 17:51:19 -0700 Subject: SL-17274: PBR: Add spec weight debugging --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 3c12e55d6a..14ba06741b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -69,6 +69,7 @@ #define DEBUG_PBR_REFLECTION 0 // Output: reflection dir #define DEBUG_PBR_SPEC 0 // Output: Final spec #define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection +#define DEBUG_PBR_SPEC_WEIGHT 0 // Output: specWeight #define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera #define DEBUG_PBR_V2C_REMAP 0 // Output: vertex2camera (remap [-1,1] -> [0,1]) #extension GL_ARB_texture_rectangle : enable @@ -407,6 +408,9 @@ void main() #if DEBUG_PBR_SPEC_REFLECTION color.rgb = specLight; #endif + #if DEBUG_PBR_SPEC_WEIGHT + color.rgb = vec3(specWeight); + #endif #if DEBUG_PBR_V2C_RAW color.rgb = v; #endif -- cgit v1.2.3 From 38b6f10717918643c1169a4007dc92cfe36fc4d5 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 30 Jun 2022 12:50:22 -0700 Subject: SL-17682: Fix diffuse, and emissive being in sRGB which also fixes fresnelR --- .../shaders/class3/deferred/softenLightF.glsl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 14ba06741b..0030405b2b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -177,7 +177,6 @@ void main() da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); - diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); @@ -210,8 +209,17 @@ void main() bool hasPBR = GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR); if (hasPBR) { + // 5.22.2. material.pbrMetallicRoughness.baseColorTexture + // The first three components (RGB) MUST be encoded with the sRGB transfer function. + // + // 5.19.7. material.emissiveTexture + // This texture contains RGB components encoded with the sRGB transfer function. + // + // 5.22.5. material.pbrMetallicRoughness.metallicRoughnessTexture + // These values MUST be encoded with a linear transfer function. + vec3 colorDiffuse = vec3(0); - vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 colorEmissive = srgb_to_linear(texture2DRect(emissiveRect, tc).rgb); vec3 colorSpec = vec3(0); // vec3 colorClearCoat = vec3(0); // vec3 colorSheen = vec3(0); @@ -417,9 +425,12 @@ void main() #if DEBUG_PBR_V2C_REMAP color.rgb = v*0.5 + vec3(0.5); #endif + frag_color.rgb = color.rgb; // PBR is done in linear } else { + diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 + sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); amblit = max(ambenv, amblit); @@ -472,12 +483,12 @@ else color = fogged.rgb; bloom = fogged.a; #endif -} // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... //color = vec3(ambocc); //color = ambenv; //color.b = diffuse.a; frag_color.rgb = srgb_to_linear(color.rgb); +} frag_color.a = bloom; } -- cgit v1.2.3 From d047b3f46b7db0b5c27690a2d5b39af592631860 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 1 Jul 2022 14:36:52 -0700 Subject: SL-17682: Cleanup GGX flags --- .../shaders/class3/deferred/softenLightF.glsl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 0030405b2b..f89c910dcf 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -23,11 +23,13 @@ * $/LicenseInfo$ */ -#define PBR_GGX_APPROX 1 -#define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 -#define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 -#define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 -#define DEBUG_PBR_VERT2CAM1 0 // vertex2camera = 0,0,1 +#define PBR_USE_GGX_APPROX 1 +#define PBR_USE_GGX_EMS_HACK 1 + +#define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 +#define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 +#define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 +#define DEBUG_PBR_VERT2CAM1 0 // vertex2camera = 0,0,1 // Pass input through "as is" #define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer @@ -151,7 +153,7 @@ vec2 getGGX( vec2 brdfPoint ) { // TODO: use GGXLUT // texture2D(GGXLUT, brdfPoint).rg; -#if PBR_GGX_APPROX +#if PBR_USE_GGX_APPROX return getGGXApprox( brdfPoint); #endif } @@ -294,7 +296,7 @@ void main() // Reference: getIBLRadianceLambertian vec3 FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term float Ems = (1.0 - vScaleBias.x + vScaleBias.y); -#if PBR_GGX_APPROX +#if PBR_USE_GGX_EMS_HACK Ems = alphaRough; // With GGX approximation Ems = 0 so use substitute #endif vec3 avg = specWeight * (reflect0 + (1.0 - reflect0) / 21.0); -- cgit v1.2.3 From 20a7dd5b50b28e2f78d8cca433ef863a462cd327 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 1 Jul 2022 14:55:30 -0700 Subject: SL-17682: PBR: Fix irradiance to use amblit --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index f89c910dcf..d9a3310a07 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -287,6 +287,7 @@ void main() vec3 specLight = vec3(0); float gloss = 1.0 - perceptualRough; sampleReflectionProbes(irradiance, specLight, legacyenv, pos.xyz, norm.xyz, gloss, 0.0); + irradiance = max(amblit,irradiance); #if HAS_IBL kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); #endif -- cgit v1.2.3 From 9ae6859b80e36a52007ac5381e0f7e9d645de208 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 1 Jul 2022 15:27:02 -0700 Subject: SL-17682: PBR: Cleanup FE_LAMBERT debug name --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index d9a3310a07..9d928198d9 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -54,7 +54,7 @@ // Diffuse #define DEBUG_PBR_DIFFUSE_C 0 // Output: diffuse non metal mix #define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance -#define DEBUG_PBR_FE_LAMBERT 0 // Output: FssEssLambert +#define DEBUG_PBR_FSS_ESS_LAMBERT 0 // Output: FssEssLambert #define DEBUG_PBR_EMS 0 // Output: Ems #define DEBUG_PBR_AVG 0 // Output: Avg #define DEBUG_PBR_EMS_FMS 0 // Output: FmsEms @@ -386,7 +386,7 @@ void main() #if DEBUG_PBR_FE_GGX color.rgb = FssEssGGX; // spec #endif - #if DEBUG_PBR_FE_LAMBERT + #if DEBUG_PBR_FSS_ESS_LAMBERT color.rgb = FssEssLambert; // diffuse #endif #if DEBUG_PBR_FRESNEL -- cgit v1.2.3 From c7f5cb7c631c5b6a06fa0da88318608b9c09fc87 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 1 Jul 2022 15:27:43 -0700 Subject: SL-17682: PBR: Cleanup EMS_FMS debug name --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 9d928198d9..89c4eb1b11 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -57,7 +57,7 @@ #define DEBUG_PBR_FSS_ESS_LAMBERT 0 // Output: FssEssLambert #define DEBUG_PBR_EMS 0 // Output: Ems #define DEBUG_PBR_AVG 0 // Output: Avg -#define DEBUG_PBR_EMS_FMS 0 // Output: FmsEms +#define DEBUG_PBR_FMS_EMS 0 // Output: FmsEms #define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms #define DEBUG_PBR_DIFFUSE_PRE_AO 0 // Output: diffuse pre AO @@ -380,7 +380,7 @@ void main() #if DEBUG_PBR_EMS_AVG color.rgb = AvgEms; #endif - #if DEBUG_PBR_EMS_FMS + #if DEBUG_PBR_FMS_EMS color.rgb = FmsEms; #endif #if DEBUG_PBR_FE_GGX -- cgit v1.2.3 From 56a0a30e03787d3e0545bce0d76772e7fbf70ad2 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 1 Jul 2022 16:07:52 -0700 Subject: SL-17682: PBR: Group IBL Spec and Diffuse debug flags --- .../shaders/class3/deferred/softenLightF.glsl | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 89c4eb1b11..a7d2ea0b9b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -40,18 +40,25 @@ #define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughness map #define DEBUG_PBR_ROUGH_ALPHA 0 // Output: grayscale Alpha Roughness -#define DEBUG_PBR_DIFFUSE 0 // Output: Radiance Lambertian -#define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_DIFFUSE_MAP 1, and in pbropaqueF set DEBUG_NORMAL_RAW #define DEBUG_PBR_TANGENT 0 // Output: Tangent #define DEBUG_PBR_BITANGENT 0 // Output: Bitangent #define DEBUG_PBR_DOT_BV 0 // Output: graysacle dot(Bitangent,Vertex2Camera) -#define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal ,Vertex2Camera) #define DEBUG_PBR_DOT_TV 0 // Output: grayscale dot(Tangent ,Vertex2Camera) -#define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) +// IBL Spec +#define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_DIFFUSE_MAP 1, and in pbropaqueF set DEBUG_NORMAL_RAW +#define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera +#define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal ,Vertex2Camera) #define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) +#define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) +#define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel +#define DEBUG_PBR_KSPEC 0 // Output: K spec +#define DEBUG_PBR_REFLECTION_DIR 0 // Output: reflection dir +#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection +#define DEBUG_PBR_FSS_ESS_GGX 0 // Output: FssEssGGX +#define DEBUG_PBR_SPEC 0 // Output: Final spec -// Diffuse +// IBL Diffuse #define DEBUG_PBR_DIFFUSE_C 0 // Output: diffuse non metal mix #define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance #define DEBUG_PBR_FSS_ESS_LAMBERT 0 // Output: FssEssLambert @@ -60,19 +67,13 @@ #define DEBUG_PBR_FMS_EMS 0 // Output: FmsEms #define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms #define DEBUG_PBR_DIFFUSE_PRE_AO 0 // Output: diffuse pre AO +#define DEBUG_PBR_DIFFUSE 0 // Output: diffuse post AO -#define DEBUG_PBR_FE_GGX 0 // Output: FssEssGGX -#define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel #define DEBUG_PBR_IOR 0 // Output: grayscale IOR -#define DEBUG_PBR_KSPEC 0 // Output: K spec #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior #define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior #define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance -- NOT USED -#define DEBUG_PBR_REFLECTION 0 // Output: reflection dir -#define DEBUG_PBR_SPEC 0 // Output: Final spec -#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection #define DEBUG_PBR_SPEC_WEIGHT 0 // Output: specWeight -#define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera #define DEBUG_PBR_V2C_REMAP 0 // Output: vertex2camera (remap [-1,1] -> [0,1]) #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -383,7 +384,7 @@ void main() #if DEBUG_PBR_FMS_EMS color.rgb = FmsEms; #endif - #if DEBUG_PBR_FE_GGX + #if DEBUG_PBR_FSS_ESS_GGX color.rgb = FssEssGGX; // spec #endif #if DEBUG_PBR_FSS_ESS_LAMBERT @@ -410,7 +411,7 @@ void main() #if DEBUG_PBR_REFLECTANCE color.rgb = vec3(reflectance); #endif - #if DEBUG_PBR_REFLECTION + #if DEBUG_PBR_REFLECTION_DIR color.rgb = reflect(-v, n); // NOTE: equivalent to normalize(reflect(pos.xyz, norm.xyz)); #endif #if DEBUG_PBR_SPEC -- cgit v1.2.3 From c25717cb353b64f0c9e68e0baaa56a8654e21e0f Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 1 Jul 2022 16:09:39 -0700 Subject: SL-17682: PBR: Fix spec reflection being blown out --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index a7d2ea0b9b..2990797c9b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -289,6 +289,7 @@ void main() float gloss = 1.0 - perceptualRough; sampleReflectionProbes(irradiance, specLight, legacyenv, pos.xyz, norm.xyz, gloss, 0.0); irradiance = max(amblit,irradiance); + specLight = srgb_to_linear(specLight); #if HAS_IBL kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); #endif -- cgit v1.2.3 From 49c923bf3ce941b62110a537709b9bf5a368be7a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 5 Jul 2022 08:22:36 -0700 Subject: SL-17682: PBR: Fix debug normal output to match glTF Sample Viewer --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 2990797c9b..e5f5901e18 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -337,7 +337,8 @@ void main() #endif #if DEBUG_PBR_NORMAL - color.rgb = norm.xyz; + color.rgb = norm.xyz*0.5 + vec3(0.5); + color.rgb = srgb_to_linear(color.rgb); #endif #if DEBUG_PBR_TANGENT color.rgb = t; -- cgit v1.2.3 From e2879eaf99cf4ce46bddebe1fc6b38b72f000bad Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 5 Jul 2022 08:22:58 -0700 Subject: SL-17682: PBR: Fix debug BRDF uv output to match glTF Sample Viewer --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index e5f5901e18..e787b5d41d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -361,6 +361,7 @@ void main() #endif #if DEBUG_PBR_BRDF_UV color.rgb = vec3(brdfPoint,0.0); + color.rgb = linear_to_srgb(color.rgb); #endif #if DEBUG_PBR_BRDF_SCALE_BIAS color.rgb = vec3(vScaleBias,0.0); -- cgit v1.2.3 From 36a7a424a9008ff3b29aafc172969bc17bf1d024 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 5 Jul 2022 08:23:17 -0700 Subject: SL-17682: PBR: Fix debug fresnel roughness output to match glTF Sample Viewer --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index e787b5d41d..643b9ea20b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -395,6 +395,7 @@ void main() #endif #if DEBUG_PBR_FRESNEL color.rgb = fresnelR; + color.rgb = srgb_to_linear(color.rgb); #endif #if DEBUG_PBR_IOR color.rgb = vec3(IOR); -- cgit v1.2.3 From e5ef64b74aa4bdbb67bf2e1bf4cfce79cfb79b70 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 5 Jul 2022 20:03:29 -0700 Subject: SL-17682: PBR: Fix occlusion debug output to match glTF Sample Viewer --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 643b9ea20b..ca0306b24a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -325,6 +325,7 @@ void main() #endif #if DEBUG_PBR_OCCLUSION color.rgb = vec3(packedORM.r); + color.rgb = linear_to_srgb(color.rgb); #endif #if DEBUG_PBR_ORM color.rgb = packedORM; -- cgit v1.2.3 From bcd630cad91cdcf5f188d3ea9ad69bb7df1eb86c Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 5 Jul 2022 20:03:54 -0700 Subject: SL-17682: PBR: Fix roughness debug output to match glTF Sample Viewer --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index ca0306b24a..8b9c8aff92 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -332,6 +332,7 @@ void main() #endif #if DEBUG_PBR_ROUGH_PERCEPTUAL color.rgb = vec3(perceptualRough); + color.rgb = linear_to_srgb(color.rgb); #endif #if DEBUG_PBR_ROUGH_ALPHA color.rgb = vec3(alphaRough); -- cgit v1.2.3 From 7537b3d5456f989859142d1d3340dae65d407cef Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 5 Jul 2022 20:05:09 -0700 Subject: SL-17682: PBR: Fix metal debug output to match glTF Sample Viewer --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8b9c8aff92..139a1c274e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -322,6 +322,7 @@ void main() #endif #if DEBUG_PBR_METAL color.rgb = vec3(metal); + color.rgb = linear_to_srgb(color.rgb); #endif #if DEBUG_PBR_OCCLUSION color.rgb = vec3(packedORM.r); -- cgit v1.2.3 From f49579ad25128b643f62115d9df249788d77d435 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 5 Jul 2022 20:06:37 -0700 Subject: SL-17682: PBR: Cleanup debug flags to view raw normal map as-is --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 139a1c274e..fbcc69586a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -35,6 +35,7 @@ #define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer #define DEBUG_PBR_EMISSIVE 0 // Output: Emissive #define DEBUG_PBR_METAL 0 // Output: grayscale Metal map +#define DEBUG_PBR_NORMAL_MAP 0 // Output: Normal -- also need to set DEBUG_NORMAL_MAP in pbropaqueF #define DEBUG_PBR_OCCLUSION 0 // Output: grayscale Occlusion map #define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal #define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughness map @@ -46,7 +47,7 @@ #define DEBUG_PBR_DOT_TV 0 // Output: grayscale dot(Tangent ,Vertex2Camera) // IBL Spec -#define DEBUG_PBR_NORMAL 0 // Output: passed in normal. To see raw normal map: set DEBUG_PBR_DIFFUSE_MAP 1, and in pbropaqueF set DEBUG_NORMAL_RAW +#define DEBUG_PBR_NORMAL 0 // Output: passed in normal #define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera #define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal ,Vertex2Camera) #define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) @@ -324,6 +325,9 @@ void main() color.rgb = vec3(metal); color.rgb = linear_to_srgb(color.rgb); #endif + #if DEBUG_PBR_NORMAL_MAP + color.rgb = diffuse.rgb; + #endif #if DEBUG_PBR_OCCLUSION color.rgb = vec3(packedORM.r); color.rgb = linear_to_srgb(color.rgb); -- cgit v1.2.3 From 6369180eae30f2a4dfa7dc4a10149c632d69c4c3 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 6 Jul 2022 12:29:19 -0700 Subject: SL-17682 PBR: Fix Occlusion Roughness Metal not being in linear space; removes need for redundant linear/sRGB conversions. --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index fbcc69586a..2bf2183f29 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -223,13 +223,13 @@ void main() // These values MUST be encoded with a linear transfer function. vec3 colorDiffuse = vec3(0); - vec3 colorEmissive = srgb_to_linear(texture2DRect(emissiveRect, tc).rgb); + vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 colorSpec = vec3(0); // vec3 colorClearCoat = vec3(0); // vec3 colorSheen = vec3(0); // vec3 colorTransmission = vec3(0); - vec3 packedORM = spec.rgb; // Packed: Occlusion Roughness Metal + vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl #if DEBUG_PBR_PACK_ORM0 packedORM = vec3(0,0,0); #endif @@ -323,21 +323,18 @@ void main() #endif #if DEBUG_PBR_METAL color.rgb = vec3(metal); - color.rgb = linear_to_srgb(color.rgb); #endif #if DEBUG_PBR_NORMAL_MAP color.rgb = diffuse.rgb; #endif #if DEBUG_PBR_OCCLUSION color.rgb = vec3(packedORM.r); - color.rgb = linear_to_srgb(color.rgb); #endif #if DEBUG_PBR_ORM color.rgb = packedORM; #endif #if DEBUG_PBR_ROUGH_PERCEPTUAL color.rgb = vec3(perceptualRough); - color.rgb = linear_to_srgb(color.rgb); #endif #if DEBUG_PBR_ROUGH_ALPHA color.rgb = vec3(alphaRough); -- cgit v1.2.3 From 873f70cff74c316d081e86c7296cc70013db6d05 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 6 Jul 2022 12:40:37 -0700 Subject: SL-17682: PBR: Remove incorret redundant sRGB/linear from debug fresnel roughness output --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 2bf2183f29..bba1dd3902 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -399,7 +399,6 @@ void main() #endif #if DEBUG_PBR_FRESNEL color.rgb = fresnelR; - color.rgb = srgb_to_linear(color.rgb); #endif #if DEBUG_PBR_IOR color.rgb = vec3(IOR); -- cgit v1.2.3 From 5862d15068373adaf76c83024582999ed940ab16 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 6 Jul 2022 20:48:06 -0700 Subject: SL-17736: PBR: Add irradiance raw debugging --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index bba1dd3902..c5b27ec52c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -61,6 +61,7 @@ // IBL Diffuse #define DEBUG_PBR_DIFFUSE_C 0 // Output: diffuse non metal mix +#define DEBUG_PBR_IRRADIANCE_RAW 0 // Output: Diffuse Irradiance pre-mix #define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance #define DEBUG_PBR_FSS_ESS_LAMBERT 0 // Output: FssEssLambert #define DEBUG_PBR_EMS 0 // Output: Ems @@ -289,6 +290,9 @@ void main() vec3 specLight = vec3(0); float gloss = 1.0 - perceptualRough; sampleReflectionProbes(irradiance, specLight, legacyenv, pos.xyz, norm.xyz, gloss, 0.0); +#if DEBUG_PBR_IRRADIANCE_RAW + vec3 debug_irradiance = irradiance; +#endif irradiance = max(amblit,irradiance); specLight = srgb_to_linear(specLight); #if HAS_IBL @@ -403,6 +407,9 @@ void main() #if DEBUG_PBR_IOR color.rgb = vec3(IOR); #endif + #if DEBUG_PBR_IRRADIANCE_RAW + color.rgb = debug_irradiance; + #endif #if DEBUG_PBR_IRRADIANCE color.rgb = irradiance; #endif -- cgit v1.2.3 From 9b956c774c373f058ee64fe60ab1fadfd7c8fa21 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 6 Jul 2022 20:50:00 -0700 Subject: SL-17736: PBR: Add irradiance hack to have more even lighting and not lose details --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index c5b27ec52c..3b1003f83b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -25,6 +25,8 @@ #define PBR_USE_GGX_APPROX 1 #define PBR_USE_GGX_EMS_HACK 1 +#define PBR_USE_IRRADIANCE_HACK 1 + #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 #define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 @@ -294,6 +296,9 @@ void main() vec3 debug_irradiance = irradiance; #endif irradiance = max(amblit,irradiance); +#if PBR_USE_IRRADIANCE_HACK + irradiance += amblit*0.5*vec3(dot(n, light_dir)); +#endif specLight = srgb_to_linear(specLight); #if HAS_IBL kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); -- cgit v1.2.3 From 77df86620182b042e7c02ade26859558650a5bc2 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 6 Jul 2022 20:51:22 -0700 Subject: SL-17703: PBR: Add sun/moon debugging --- .../shaders/class3/deferred/softenLightF.glsl | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 3b1003f83b..82aecdfce1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -73,6 +73,14 @@ #define DEBUG_PBR_DIFFUSE_PRE_AO 0 // Output: diffuse pre AO #define DEBUG_PBR_DIFFUSE 0 // Output: diffuse post AO +// Atmospheric Lighting +#define DEBUG_PBR_AMBOCC 0 // Output: ambient occlusion +#define DEBUG_PBR_DIRECT_AMBIENT 0 // Output: da +#define DEBUG_PBR_SUN_LIT 0 // Ouput: sunlit +#define DEBUG_PBR_SUN_CONTRIB 0 // Output: sun_contrib +#define DEBUG_PBR_SKY_ADDITIVE 0 // Output: additive +#define DEBUG_PBR_SKY_ATTEN 0 // Output: atten + #define DEBUG_PBR_IOR 0 // Output: grayscale IOR #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior #define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior @@ -442,6 +450,27 @@ void main() #if DEBUG_PBR_SPEC_WEIGHT color.rgb = vec3(specWeight); #endif + +#if DEBUG_PBR_AMBOCC + color.rgb = vec3(ambocc); +#endif +#if DEBUG_PBR_DIRECT_AMBIENT + color.rgb = vec3(da); +#endif +#if DEBUG_PBR_SKY_ADDITIVE + color.rgb = additive; +#endif +#if DEBUG_PBR_SKY_ATTEN + color.rgb = atten; +#endif + +#if DEBUG_PBR_SUN_LIT + color.rgb = sunlit; +color = srgb_to_linear(color); +#endif +#if DEBUG_PBR_SUN_CONTRIB + color.rgb = sun_contrib; +#endif #if DEBUG_PBR_V2C_RAW color.rgb = v; #endif -- cgit v1.2.3 From 2e8d2feb47e2375726e9d9f740592275e096f46a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 6 Jul 2022 21:14:10 -0700 Subject: SL-17274: PBR: Add missing GBuffer flags to class3 materialF --- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 13369d09fd..7f8536cdab 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -284,10 +284,10 @@ void main() vec4 final_specular = spec; #ifdef HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, GBUFFER_FLAG_HAS_ATMOS); final_specular.a = specular_color.a * norm.a; #else - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); + vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, GBUFFER_FLAG_HAS_ATMOS); final_specular.a = specular_color.a; #endif -- cgit v1.2.3 From c40bf62f959f41df9bb7fbbccef4f2163e249813 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 7 Jul 2022 19:06:19 -0700 Subject: SL-17703: PBR: Cleanup atmos debugging --- .../shaders/class3/deferred/softenLightF.glsl | 49 ++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 82aecdfce1..ac7b5938fd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -75,11 +75,12 @@ // Atmospheric Lighting #define DEBUG_PBR_AMBOCC 0 // Output: ambient occlusion -#define DEBUG_PBR_DIRECT_AMBIENT 0 // Output: da +#define DEBUG_PBR_DA_RAW 0 // Output: da pre pow() +#define DEBUG_PBR_DA_POW 0 // Output: da post pow() #define DEBUG_PBR_SUN_LIT 0 // Ouput: sunlit #define DEBUG_PBR_SUN_CONTRIB 0 // Output: sun_contrib #define DEBUG_PBR_SKY_ADDITIVE 0 // Output: additive -#define DEBUG_PBR_SKY_ATTEN 0 // Output: atten +#define DEBUG_PBR_SKY_ATTEN 0 // Output: greyscale atten.r #define DEBUG_PBR_IOR 0 // Output: grayscale IOR #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior @@ -188,6 +189,9 @@ void main() vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); +#if DEBUG_PBR_DA_RAW + float debug_da = da; +#endif float light_gamma = 1.0 / 1.3; da = pow(da, light_gamma); @@ -450,32 +454,33 @@ void main() #if DEBUG_PBR_SPEC_WEIGHT color.rgb = vec3(specWeight); #endif + #if DEBUG_PBR_V2C_RAW + color.rgb = v; + #endif + #if DEBUG_PBR_V2C_REMAP + color.rgb = v*0.5 + vec3(0.5); + #endif -#if DEBUG_PBR_AMBOCC + #if DEBUG_PBR_AMBOCC color.rgb = vec3(ambocc); -#endif -#if DEBUG_PBR_DIRECT_AMBIENT + #endif + #if DEBUG_PBR_DA_RAW + color.rgb = vec3(debug_da); + #endif + #if DEBUG_PBR_DA_POW color.rgb = vec3(da); -#endif -#if DEBUG_PBR_SKY_ADDITIVE + #endif + #if DEBUG_PBR_SKY_ADDITIVE color.rgb = additive; -#endif -#if DEBUG_PBR_SKY_ATTEN - color.rgb = atten; -#endif - -#if DEBUG_PBR_SUN_LIT + #endif + #if DEBUG_PBR_SKY_ATTEN + color.rgb = vec3(atten.r); + #endif + #if DEBUG_PBR_SUN_LIT color.rgb = sunlit; -color = srgb_to_linear(color); -#endif -#if DEBUG_PBR_SUN_CONTRIB - color.rgb = sun_contrib; -#endif - #if DEBUG_PBR_V2C_RAW - color.rgb = v; #endif - #if DEBUG_PBR_V2C_REMAP - color.rgb = v*0.5 + vec3(0.5); + #if DEBUG_PBR_SUN_CONTRIB + color.rgb = sun_contrib; #endif frag_color.rgb = color.rgb; // PBR is done in linear } -- cgit v1.2.3 From daf3f4f7365137852f952f6fd2a484c81791165a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 7 Jul 2022 19:07:00 -0700 Subject: SL-17703: PBR: Add sun/moon to output --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index ac7b5938fd..822b3e473d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -23,6 +23,7 @@ * $/LicenseInfo$ */ +#define PBR_USE_ATMOS 1 #define PBR_USE_GGX_APPROX 1 #define PBR_USE_GGX_EMS_HACK 1 #define PBR_USE_IRRADIANCE_HACK 1 @@ -336,6 +337,14 @@ void main() color.rgb = colorDiffuse + colorEmissive + colorSpec; + vec3 sun_contrib = min(da, scol) * sunlit; +#if PBR_USE_ATMOS + color += sun_contrib; + color *= atten.r; + color += 0.5*additive; + color = scaleSoftClipFrag(color); +#endif // PBR_USE_ATMOS + #if DEBUG_PBR_DIFFUSE color.rgb = colorDiffuse; #endif -- cgit v1.2.3 From bae0fc077b8bebfd159d8426223129581c9cf520 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 8 Jul 2022 07:52:19 -0700 Subject: SL-17703: PBR: Sun/Moon lighting is in sRGB --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 822b3e473d..6c70781bee 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -339,10 +339,12 @@ void main() vec3 sun_contrib = min(da, scol) * sunlit; #if PBR_USE_ATMOS - color += sun_contrib; + color = linear_to_srgb(color); + color += 2.0*sun_contrib; // 2x = Undo legacy hack of calcAtmosphericVars() returning sunlight.rgb * 0.5; color *= atten.r; - color += 0.5*additive; + color += 2.0*additive; color = scaleSoftClipFrag(color); + color = srgb_to_linear(color); #endif // PBR_USE_ATMOS #if DEBUG_PBR_DIFFUSE -- cgit v1.2.3 From 2e1c9046dc48208c5bc86dfec8c7d4f0fc294b48 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 8 Jul 2022 14:26:15 -0700 Subject: DRTVWR-559: Add fake constant color HDRi color for testing --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 6c70781bee..906a1de951 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -28,11 +28,11 @@ #define PBR_USE_GGX_EMS_HACK 1 #define PBR_USE_IRRADIANCE_HACK 1 - #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 #define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 #define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 #define DEBUG_PBR_VERT2CAM1 0 // vertex2camera = 0,0,1 +#define DEBUG_PBR_SPECLIGHT051 1 // Force specLigh to be 0,0.5,1 // Pass input through "as is" #define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer @@ -313,6 +313,10 @@ void main() irradiance += amblit*0.5*vec3(dot(n, light_dir)); #endif specLight = srgb_to_linear(specLight); +#if DEBUG_PBR_SPECLIGHT051 + specLight = vec3(0,0.5,1.0); + irradiance = specLight; +#endif #if HAS_IBL kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); #endif -- cgit v1.2.3 From 32efb52cd1d7b3f4907efb1b4f8dc151e8a1a5d0 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 14 Jul 2022 18:12:19 -0700 Subject: SL-17764: PBR: Add light shaders to class 3 deferred --- .../shaders/class3/deferred/multiPointLightF.glsl | 157 +++++++++++ .../shaders/class3/deferred/multiPointLightV.glsl | 39 +++ .../shaders/class3/deferred/multiSpotLightF.glsl | 300 +++++++++++++++++++++ .../shaders/class3/deferred/pointLightF.glsl | 145 ++++++++++ .../shaders/class3/deferred/pointLightV.glsl | 45 ++++ .../shaders/class3/deferred/spotLightF.glsl | 287 ++++++++++++++++++++ 6 files changed, 973 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/pointLightV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl new file mode 100644 index 0000000000..5aec75ff3d --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -0,0 +1,157 @@ +/** + * @file class3\deferred\multiPointLightF.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 + +uniform sampler2DRect depthMap; +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +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; + +void calcHalfVectors(vec3 h, vec3 n, vec3 npos, out float nh, out float nv, out float vh); +vec4 getPosition(vec2 pos_screen); +vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec2 getScreenXY(vec4 clip); +vec3 srgb_to_linear(vec3 c); + +void main() +{ +#if defined(LOCAL_LIGHT_KILL) + discard; // Bail immediately +#else + vec3 final_color = vec3(0, 0, 0); + vec2 tc = getScreenXY(vary_fragcoord); + vec3 pos = getPosition(tc).xyz; + if (pos.z < far_z) + { + discard; + } + + float envIntensity; // not used for this shader + vec3 n; + vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() + + vec4 spec = texture2DRect(specularRect, tc); + vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; + + float noise = texture2D(noiseMap, tc/128.0).b; + vec3 v = -normalize(pos); + + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + { + vec3 colorDiffuse = vec3(0); + vec3 colorSpec = vec3(0); + + final_color = colorDiffuse + colorSpec; + } + else + { + // 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(n, lv); + if (da > 0.0) + { + lv = normalize(lv); + da = dot(n, 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 * diffuse; + + if (spec.a > 0.0) + { + lit = min(da * 6.0, 1.0) * dist_atten; + vec3 h = normalize(lv + v); + float nh, nv, vh; + calcHalfVectors(h, n, v, nh, nv, vh); + float sa = nh; + float fres = pow(1 - dot(h, v), 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; + } + } + + final_color += col; + } + } + } + } + + frag_color.rgb = final_color; + frag_color.a = 0.0; +#endif // LOCAL_LIGHT_KILL + +#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 + // away which leads to unfun crashes and artifacts. + vec4 dummy1 = light[0]; + vec4 dummy2 = light_col[0]; + vec4 dummy3 = light[LIGHT_COUNT - 1]; + vec4 dummy4 = light_col[LIGHT_COUNT - 1]; +#endif +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl new file mode 100644 index 0000000000..ad6a0fa752 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl @@ -0,0 +1,39 @@ +/** + * @file class3\deferred\multiPointLightV.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 vec4 vary_fragcoord; + +void main() +{ + //transform vertex + vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_fragcoord = pos; + + gl_Position = pos; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl new file mode 100644 index 0000000000..f1b06fe1ad --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -0,0 +1,300 @@ +/** + * @file class3\deferred\multiSpotLightF.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 +#extension GL_ARB_shader_texture_lod : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect depthMap; +uniform sampler2DRect normalMap; +uniform samplerCube environmentMap; +uniform sampler2DRect lightMap; +uniform sampler2D noiseMap; +uniform sampler2D projectionMap; +uniform sampler2D lightFunc; + +uniform mat4 proj_mat; //screen space to light space +uniform float proj_near; //near clip for projection +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform vec3 proj_n; +uniform float proj_focus; //distance from plane to begin blurring +uniform float proj_lod; //(number of mips in proj map) +uniform float proj_range; //range between near clip and far clip plane of projection +uniform float proj_ambient_lod; +uniform float proj_ambiance; +uniform float near_clip; +uniform float far_clip; + +uniform vec3 proj_origin; //origin of projection to be used for angular attenuation +uniform float sun_wash; +uniform int proj_shadow_idx; +uniform float shadow_fade; + +uniform vec3 center; +uniform float size; +uniform vec3 color; +uniform float falloff; + +VARYING vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform mat4 inv_proj; + +void calcHalfVectors(vec3 h, vec3 n, vec3 v, out float nh, out float nv, out float vh); +vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec2 getScreenXY(vec4 clip); +vec3 srgb_to_linear(vec3 cs); + +vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) +{ + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + + float det = min(lod/(proj_lod*0.5), 1.0); + + float d = min(dist.x, dist.y); + + d *= min(1, d * (proj_lod - lod)); + + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) +{ + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + + float det = min(lod/(proj_lod*0.5), 1.0); + + float d = min(dist.x, dist.y); + + float edge = 0.25*det; + + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) +{ + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = tc-vec2(0.5); + + float d = dot(dist,dist); + + ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + + return ret; +} + +vec4 getPosition(vec2 pos_screen); + +void main() +{ +#if defined(LOCAL_LIGHT_KILL) + discard; +#else + vec3 final_color = vec3(0,0,0); + vec2 tc = getScreenXY(vary_fragcoord); + vec3 pos = getPosition(tc).xyz; + + vec3 lv = center.xyz-pos.xyz; + float dist = length(lv); + + if (dist >= size) + { + discard; + } + dist /= size; + + float shadow = 1.0; + + if (proj_shadow_idx >= 0) + { + vec4 shd = texture2DRect(lightMap, tc); + shadow = (proj_shadow_idx==0)?shd.b:shd.a; + shadow += shadow_fade; + shadow = clamp(shadow, 0.0, 1.0); + } + + float envIntensity; + vec3 n; + vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); + + float l_dist = -dot(lv, proj_n); + + vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); + if (proj_tc.z < 0.0) + { + discard; + } + + proj_tc.xyz /= proj_tc.w; + + float fa = falloff+1.0; + float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; + if (dist_atten <= 0.0) + { + discard; + } + + lv = proj_origin-pos.xyz; + lv = normalize(lv); + float da = dot(n, lv); + + vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; + vec4 spec = texture2DRect(specularRect, tc); + vec3 dlit = vec3(0, 0, 0); + + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + { + vec3 colorDiffuse = vec3(0); + vec3 colorSpec = vec3(0); + + final_color = colorDiffuse + colorSpec; + } + else + { + float noise = texture2D(noiseMap, tc/128.0).b; + if (proj_tc.z > 0.0 && + proj_tc.x < 1.0 && + proj_tc.y < 1.0 && + proj_tc.x > 0.0 && + proj_tc.y > 0.0) + { + float amb_da = proj_ambiance; + float lit = 0.0; + + if (da > 0.0) + { + lit = da * dist_atten * noise; + + float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); + float lod = diff * proj_lod; + + vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); + + dlit = color.rgb * plcol.rgb * plcol.a; + + final_color = dlit*lit*diffuse*shadow; + + // unshadowed for consistency between forward and deferred? + amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; + } + + //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); + vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); + + // use unshadowed for consistency between forward and deferred? + amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; + amb_da *= dist_atten * noise; + amb_da = min(amb_da, 1.0-lit); + + final_color += amb_da*color.rgb*diffuse.rgb*amb_plcol.rgb*amb_plcol.a; + } + + + if (spec.a > 0.0) + { + vec3 v = -normalize(pos); + dlit *= min(da*6.0, 1.0) * dist_atten; + + //vec3 ref = dot(pos+lv, n); + vec3 h = normalize(lv + v); + float nh, nv, vh; + calcHalfVectors(h, n, v, nh, nv, vh); + float sa = nh; + float fres = pow(1 - dot(h, v), 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 = dlit*scol*spec.rgb*shadow; + speccol = clamp(speccol, vec3(0), vec3(1)); + final_color += speccol; + } + } + + if (envIntensity > 0.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 ds = dot(ref, proj_n); + + if (ds < 0.0) + { + vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; + + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + + if (stc.z > 0.0) + { + stc /= stc.w; + + if (stc.x < 1.0 && + stc.y < 1.0 && + stc.x > 0.0 && + stc.y > 0.0) + { + final_color += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + } + } + } + } + } + + //not sure why, but this line prevents MATBUG-194 + final_color = max(final_color, vec3(0.0)); + + //output linear + frag_color.rgb = final_color; + frag_color.a = 0.0; +#endif // LOCAL_LIGHT_KILL +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl new file mode 100644 index 0000000000..10d8c5e87f --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -0,0 +1,145 @@ +/** + * @file class3\deferred\pointLightF.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 + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect normalMap; +uniform sampler2D noiseMap; +uniform sampler2D lightFunc; +uniform sampler2DRect depthMap; + +uniform vec3 env_mat[3]; +uniform float sun_wash; + +// light params +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; + +void calcHalfVectors(vec3 h, vec3 n, vec3 v, out float nh, out float nv, out float vh); +vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec4 getPosition(vec2 pos_screen); +vec2 getScreenXY(vec4 clip); +vec3 srgb_to_linear(vec3 c); + +void main() +{ + vec3 final_color = vec3(0); + vec2 tc = getScreenXY(vary_fragcoord); + vec3 pos = getPosition(tc).xyz; + + vec3 lv = trans_center.xyz-pos; + float dist = length(lv); + if (dist >= size) + { + discard; + } + dist /= size; + + float envIntensity; + vec3 n; + vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() + + float da = dot(n, lv); + if (da < 0.0) + { + discard; + } + + lv = normalize(lv); + da = dot(n, lv); + + float noise = texture2D(noiseMap, tc/128.0).b; + + vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; + vec4 spec = texture2DRect(specularRect, tc); + + // Common half vectors calcs + vec3 v = -normalize(pos); + vec3 h = normalize(lv + v); + float nh, nv, vh; + calcHalfVectors(h, n, v, nh, nv, vh); + + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + { + vec3 colorDiffuse = vec3(0); + vec3 colorSpec = vec3(0); + + final_color = colorDiffuse + colorSpec; + } + else + { + 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; + + final_color = color.rgb*lit*diffuse; + + if (spec.a > 0.0) + { + lit = min(da*6.0, 1.0) * dist_atten; + + float sa = nh; + float fres = pow(1 - dot(h, v), 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); + final_color += lit*scol*color.rgb*spec.rgb; + } + } + + if (dot(final_color, final_color) <= 0.0) + { + discard; + } + } + + frag_color.rgb = final_color; + frag_color.a = 0.0; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightV.glsl new file mode 100644 index 0000000000..d42c8f6cf6 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightV.glsl @@ -0,0 +1,45 @@ +/** + * @file class3\deferred\pointLightV.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; +uniform mat4 modelview_matrix; + +ATTRIBUTE vec3 position; + +uniform vec3 center; +uniform float size; + +VARYING vec4 vary_fragcoord; +VARYING vec3 trans_center; + +void main() +{ + //transform vertex + vec3 p = position*size+center; + vec4 pos = modelview_projection_matrix * vec4(p.xyz, 1.0); + vary_fragcoord = pos; + trans_center = (modelview_matrix*vec4(center.xyz, 1.0)).xyz; + gl_Position = pos; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl new file mode 100644 index 0000000000..8768500682 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -0,0 +1,287 @@ +/** + * @file class3\deferred\spotLightF.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 +#extension GL_ARB_shader_texture_lod : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect depthMap; +uniform sampler2DRect normalMap; +uniform samplerCube environmentMap; +uniform sampler2DRect lightMap; +uniform sampler2D noiseMap; +uniform sampler2D projectionMap; +uniform sampler2D lightFunc; + +uniform mat4 proj_mat; //screen space to light space +uniform float proj_near; //near clip for projection +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform vec3 proj_n; +uniform float proj_focus; //distance from plane to begin blurring +uniform float proj_lod; //(number of mips in proj map) +uniform float proj_range; //range between near clip and far clip plane of projection +uniform float proj_ambient_lod; +uniform float proj_ambiance; +uniform float near_clip; +uniform float far_clip; + +uniform vec3 proj_origin; //origin of projection to be used for angular attenuation +uniform float sun_wash; +uniform int proj_shadow_idx; +uniform float shadow_fade; + +uniform float size; +uniform vec3 color; +uniform float falloff; + +VARYING vec3 trans_center; +VARYING vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform mat4 inv_proj; + +void calcHalfVectors(vec3 h, vec3 n, vec3 v, out float nh, out float nv, out float vh); +vec2 getScreenXY(vec4 clip_point); +vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec3 srgb_to_linear(vec3 c); + +vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) +{ + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + float det = min(lod/(proj_lod*0.5), 1.0); + float d = min(dist.x, dist.y); + d *= min(1, d * (proj_lod - lod)); + float edge = 0.25*det; + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) +{ + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); + float det = min(lod/(proj_lod*0.5), 1.0); + float d = min(dist.x, dist.y); + float edge = 0.25*det; + ret *= clamp(d/edge, 0.0, 1.0); + + return ret; +} + +vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) +{ + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = tc-vec2(0.5); + float d = dot(dist,dist); + ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + + return ret; +} + +vec4 getPosition(vec2 pos_screen); + +void main() +{ +#if defined(LOCAL_LIGHT_KILL) + discard; +#else + vec3 final_color = vec3(0,0,0); + vec2 tc = getScreenXY(vary_fragcoord); + vec3 pos = getPosition(tc).xyz; + + vec3 lv = trans_center.xyz-pos.xyz; + float dist = length(lv); + if (dist >= size) + { + discard; + } + dist /= size; + + float shadow = 1.0; + + if (proj_shadow_idx >= 0) + { + vec4 shd = texture2DRect(lightMap, tc); + shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; + shadow += shadow_fade; + shadow = clamp(shadow, 0.0, 1.0); + } + + float envIntensity; + vec3 n; + vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() + + float l_dist = -dot(lv, proj_n); + + vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); + if (proj_tc.z < 0.0) + { + discard; + } + + proj_tc.xyz /= proj_tc.w; + + float fa = falloff+1.0; + float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); + dist_atten *= dist_atten; + dist_atten *= 2.0; + + if (dist_atten <= 0.0) + { + discard; + } + + lv = proj_origin-pos.xyz; + lv = normalize(lv); + float da = dot(n, lv); + + vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; + vec4 spec = texture2DRect(specularRect, tc); + vec3 dlit = vec3(0, 0, 0); + + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + { + vec3 colorDiffuse = vec3(0); + vec3 colorSpec = vec3(0); + + final_color = colorDiffuse + colorSpec; + } + else + { + float noise = texture2D(noiseMap, tc/128.0).b; + if (proj_tc.z > 0.0 && + proj_tc.x < 1.0 && + proj_tc.y < 1.0 && + proj_tc.x > 0.0 && + proj_tc.y > 0.0) + { + float amb_da = proj_ambiance; + float lit = 0.0; + + if (da > 0.0) + { + lit = da * dist_atten * noise; + + float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); + float lod = diff * proj_lod; + + vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); + + dlit = color.rgb * plcol.rgb * plcol.a; + + final_color = dlit*lit*diffuse*shadow; + + amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; + } + + //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); + vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); + + amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; + amb_da *= dist_atten * noise; + amb_da = min(amb_da, 1.0-lit); + + final_color += amb_da*color.rgb*diffuse.rgb*amb_plcol.rgb*amb_plcol.a; + } + + if (spec.a > 0.0) + { + dlit *= min(da*6.0, 1.0) * dist_atten; + vec3 v = -normalize(pos); + + //vec3 ref = dot(pos+lv, n); + vec3 h = normalize(lv + v); + float nh, nv, vh; + calcHalfVectors(h, n, v, nh, nv, vh); + float sa = nh; + float fres = pow(1 - dot(h, v), 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 = dlit*scol*spec.rgb*shadow; + speccol = clamp(speccol, vec3(0), vec3(1)); + final_color += speccol; + } + } + + if (envIntensity > 0.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 ds = dot(ref, proj_n); + + if (ds < 0.0) + { + vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; + + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); + + if (stc.z > 0.0) + { + stc /= stc.w; + + if (stc.x < 1.0 && + stc.y < 1.0 && + stc.x > 0.0 && + stc.y > 0.0) + { + final_color += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + } + } + } + } + } + + //not sure why, but this line prevents MATBUG-194 + final_color = max(final_color, vec3(0.0)); + + //output linear colors as gamma correction happens down stream + frag_color.rgb = final_color; + frag_color.a = 0.0; +#endif // LOCAL_LIGHT_KILL +} -- cgit v1.2.3 From d05ccd74d44b595d02d6032c9ed2c0f9ff21f5f0 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 14 Jul 2022 19:10:05 -0700 Subject: SL-17765: PBR: Add emissiveRect to class3 light shaders --- .../app_settings/shaders/class3/deferred/multiPointLightF.glsl | 7 +++++-- .../app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 7 +++++-- .../newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 7 +++++-- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 7 +++++-- 5 files changed, 21 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 5aec75ff3d..c33734c0bd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -36,6 +36,7 @@ out vec4 frag_color; uniform sampler2DRect depthMap; uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; +uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D noiseMap; uniform sampler2D lightFunc; @@ -82,8 +83,10 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorDiffuse = vec3(0); - vec3 colorSpec = vec3(0); + vec3 colorDiffuse = vec3(0); + vec3 colorSpec = vec3(0); + vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl + vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl final_color = colorDiffuse + colorSpec; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index f1b06fe1ad..d36ff995dd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -38,6 +38,7 @@ uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect depthMap; uniform sampler2DRect normalMap; +uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform samplerCube environmentMap; uniform sampler2DRect lightMap; uniform sampler2D noiseMap; @@ -190,8 +191,10 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorDiffuse = vec3(0); - vec3 colorSpec = vec3(0); + vec3 colorDiffuse = vec3(0); + vec3 colorSpec = vec3(0); + vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl + vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl final_color = colorDiffuse + colorSpec; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 10d8c5e87f..9db906bc5a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -36,6 +36,7 @@ out vec4 frag_color; uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; +uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D noiseMap; uniform sampler2D lightFunc; uniform sampler2DRect depthMap; @@ -102,8 +103,10 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorDiffuse = vec3(0); - vec3 colorSpec = vec3(0); + vec3 colorDiffuse = vec3(0); + vec3 colorSpec = vec3(0); + vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl + vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl final_color = colorDiffuse + colorSpec; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 906a1de951..3aef3ac8ba 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -106,7 +106,7 @@ out vec4 frag_color; uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; -uniform sampler2DRect emissiveRect; +uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) uniform sampler2DRect lightMap; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 8768500682..e70a545a7b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -38,6 +38,7 @@ uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect depthMap; uniform sampler2DRect normalMap; +uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform samplerCube environmentMap; uniform sampler2DRect lightMap; uniform sampler2D noiseMap; @@ -180,8 +181,10 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorDiffuse = vec3(0); - vec3 colorSpec = vec3(0); + vec3 colorDiffuse = vec3(0); + vec3 colorSpec = vec3(0); + vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl + vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl final_color = colorDiffuse + colorSpec; } -- cgit v1.2.3 From 53372ea8ae0654ae6065f963eabd6215f720544a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 14 Jul 2022 23:53:52 -0700 Subject: SL-17702: PBR: First pass point lights --- .../shaders/class3/deferred/pointLightF.glsl | 24 +++++++++++++++---- .../shaders/class3/deferred/softenLightF.glsl | 27 ++++------------------ 2 files changed, 24 insertions(+), 27 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 9db906bc5a..46de34e49a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -57,10 +57,13 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; +vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); +vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); void calcHalfVectors(vec3 h, vec3 n, vec3 v, out float nh, out float nv, out float vh); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec4 getPosition(vec2 pos_screen); vec2 getScreenXY(vec4 clip); +void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); void main() @@ -88,9 +91,7 @@ void main() } lv = normalize(lv); - da = dot(n, lv); - - float noise = texture2D(noiseMap, tc/128.0).b; + da = dot(n, lv); // alias for: nl vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; vec4 spec = texture2DRect(specularRect, tc); @@ -108,6 +109,20 @@ void main() vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + + vec3 l = lv; // already normalized + float nl = clamp(dot(n, l), 0.0, 1.0); + + if (nl > 0.0 || nv > 0.0) + { + vec3 intensity = size * color; + colorDiffuse += intensity * nl * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); + colorSpec += intensity * nl * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + } + final_color = colorDiffuse + colorSpec; } else @@ -116,7 +131,8 @@ void main() 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 noise = texture2D(noiseMap, tc/128.0).b; float lit = da * dist_atten * noise; final_color = color.rgb*lit*diffuse; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 3aef3ac8ba..59076d9760 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -23,16 +23,15 @@ * $/LicenseInfo$ */ -#define PBR_USE_ATMOS 1 -#define PBR_USE_GGX_APPROX 1 -#define PBR_USE_GGX_EMS_HACK 1 +#define PBR_USE_ATMOS 0 +#define PBR_USE_GGX_EMS_HACK 0 #define PBR_USE_IRRADIANCE_HACK 1 #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 #define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 #define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 #define DEBUG_PBR_VERT2CAM1 0 // vertex2camera = 0,0,1 -#define DEBUG_PBR_SPECLIGHT051 1 // Force specLigh to be 0,0.5,1 +#define DEBUG_PBR_SPECLIGHT051 0 // Force specLigh to be 0,0.5,1 // Pass input through "as is" #define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer @@ -134,6 +133,7 @@ vec4 getPositionWithDepth(vec2 pos_screen, float depth); void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); float getAmbientClamp(); +vec2 getGGX( vec2 brdfPoint ); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); @@ -154,25 +154,6 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); uniform vec3 view_dir; // PBR -// Approximate Environment BRDF -vec2 getGGXApprox( vec2 uv ) -{ - vec2 st = vec2(1.) - uv; - float d = (st.x * st.x * 0.5) * (st.y * st.y); - float scale = 1.0 - d; - float bias = d; - return vec2( scale, bias ); -} - -vec2 getGGX( vec2 brdfPoint ) -{ - // TODO: use GGXLUT - // texture2D(GGXLUT, brdfPoint).rg; -#if PBR_USE_GGX_APPROX - return getGGXApprox( brdfPoint); -#endif -} - vec3 calcBaseReflect0(float ior) { vec3 reflect0 = vec3(pow((ior - 1.0) / (ior + 1.0), 2.0)); -- cgit v1.2.3 From 9b8751a6e425f60cf8cf661b40fec6af1e11ecf8 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 15 Jul 2022 17:24:10 -0700 Subject: SL-17702: Document .w and .a point lights array --- .../app_settings/shaders/class3/deferred/multiPointLightF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index c33734c0bd..fa553cf341 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -43,8 +43,8 @@ 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 vec4 light[LIGHT_COUNT]; // .w = size; see C++ fullscreen_lights.push_back() +uniform vec4 light_col[LIGHT_COUNT]; // .a = falloff uniform vec2 screen_res; uniform float far_z; -- cgit v1.2.3 From 314f27d1b1701e0fdc4bb983d0f9fd4d4ed6573a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 15 Jul 2022 17:29:39 -0700 Subject: SL-17702: PBR: Cleanup light shaders to use calcHalfVectors, remove da alias, and unused sa --- .../shaders/class3/deferred/multiPointLightF.glsl | 43 ++++++++++-------- .../shaders/class3/deferred/multiSpotLightF.glsl | 34 +++++++------- .../shaders/class3/deferred/pointLightF.glsl | 53 ++++++++++------------ .../shaders/class3/deferred/spotLightF.glsl | 36 +++++++-------- 4 files changed, 80 insertions(+), 86 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index fa553cf341..d4e82cebf3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -52,10 +52,14 @@ uniform mat4 inv_proj; VARYING vec4 vary_fragcoord; -void calcHalfVectors(vec3 h, vec3 n, vec3 npos, out float nh, out float nv, out float vh); +vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); +vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); +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); +vec3 getLightIntensityPoint(vec3 lightColor, float lightRange, float lightDistance); vec4 getPosition(vec2 pos_screen); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec2 getScreenXY(vec4 clip); +void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); void main() @@ -66,10 +70,6 @@ void main() vec3 final_color = vec3(0, 0, 0); vec2 tc = getScreenXY(vary_fragcoord); vec3 pos = getPosition(tc).xyz; - if (pos.z < far_z) - { - discard; - } float envIntensity; // not used for this shader vec3 n; @@ -78,8 +78,8 @@ void main() vec4 spec = texture2DRect(specularRect, tc); vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; - float noise = texture2D(noiseMap, tc/128.0).b; - vec3 v = -normalize(pos); + vec3 h, l, v = -normalize(pos); + float nh, nl, nv, vh, lightDist; if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { @@ -92,6 +92,13 @@ void main() } else { + if (pos.z < far_z) + { + discard; + } + + float noise = texture2D(noiseMap, tc/128.0).b; + // As of OSX 10.6.7 ATI Apple's crash when using a variable size loop for (int i = 0; i < LIGHT_COUNT; ++i) { @@ -100,11 +107,11 @@ void main() dist /= light[i].w; if (dist <= 1.0) { - float da = dot(n, lv); - if (da > 0.0) + float nl = dot(n, lv); + if (nl > 0.0) { - lv = normalize(lv); - da = dot(n, lv); + float lightDist; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); 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); @@ -116,25 +123,21 @@ void main() dist_atten *= noise; - float lit = da * dist_atten; + float lit = nl * dist_atten; vec3 col = light_col[i].rgb * lit * diffuse; if (spec.a > 0.0) { - lit = min(da * 6.0, 1.0) * dist_atten; - vec3 h = normalize(lv + v); - float nh, nv, vh; - calcHalfVectors(h, n, v, nh, nv, vh); - float sa = nh; - float fres = pow(1 - dot(h, v), 5) * 0.4 + 0.5; + lit = min(nl * 6.0, 1.0) * dist_atten; + float fres = pow(1 - vh, 5) * 0.4 + 0.5; float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh)); if (nh > 0.0) { - float scol = fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt / (nh * da); + float scol = fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt / (nh * nl); col += lit * scol * light_col[i].rgb * spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index d36ff995dd..b86402b031 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -62,6 +62,7 @@ uniform float sun_wash; uniform int proj_shadow_idx; uniform float shadow_fade; +// Light params uniform vec3 center; uniform float size; uniform vec3 color; @@ -72,9 +73,13 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -void calcHalfVectors(vec3 h, vec3 n, vec3 v, out float nh, out float nv, out float vh); +vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); +vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); +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); +vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec2 getScreenXY(vec4 clip); +void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 cs); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) @@ -182,8 +187,9 @@ void main() } lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(n, lv); + vec3 h, l, v = -normalize(pos); + float nh, nl, nv, vh, lightDist; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; vec4 spec = texture2DRect(specularRect, tc); @@ -210,9 +216,9 @@ void main() float amb_da = proj_ambiance; float lit = 0.0; - if (da > 0.0) + if (nl > 0.0) { - lit = da * dist_atten * noise; + lit = nl * dist_atten * noise; float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); float lod = diff * proj_lod; @@ -224,14 +230,14 @@ void main() final_color = dlit*lit*diffuse*shadow; // unshadowed for consistency between forward and deferred? - amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; + amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); // use unshadowed for consistency between forward and deferred? - amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; + amb_da += (nl*nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); @@ -241,22 +247,16 @@ void main() if (spec.a > 0.0) { - vec3 v = -normalize(pos); - dlit *= min(da*6.0, 1.0) * dist_atten; + dlit *= min(nl*6.0, 1.0) * dist_atten; - //vec3 ref = dot(pos+lv, n); - vec3 h = normalize(lv + v); - float nh, nv, vh; - calcHalfVectors(h, n, v, nh, nv, vh); - float sa = nh; - float fres = pow(1 - dot(h, v), 5)*0.4+0.5; + float fres = pow(1 - vh, 5)*0.4+0.5; float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh)); if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); vec3 speccol = dlit*scol*spec.rgb*shadow; speccol = clamp(speccol, vec3(0), vec3(1)); final_color += speccol; diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 46de34e49a..ddfbafd739 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -59,7 +59,8 @@ uniform vec4 viewport; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); -void calcHalfVectors(vec3 h, vec3 n, vec3 v, out float nh, out float nv, out float vh); +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); +vec3 getLightIntensityPoint(vec3 lightColor, float lightRange, float lightDistance); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec4 getPosition(vec2 pos_screen); vec2 getScreenXY(vec4 clip); @@ -72,35 +73,18 @@ void main() vec2 tc = getScreenXY(vary_fragcoord); vec3 pos = getPosition(tc).xyz; - vec3 lv = trans_center.xyz-pos; - float dist = length(lv); - if (dist >= size) - { - discard; - } - dist /= size; - float envIntensity; vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() - float da = dot(n, lv); - if (da < 0.0) - { - discard; - } - - lv = normalize(lv); - da = dot(n, lv); // alias for: nl - vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; vec4 spec = texture2DRect(specularRect, tc); // Common half vectors calcs - vec3 v = -normalize(pos); - vec3 h = normalize(lv + v); - float nh, nv, vh; - calcHalfVectors(h, n, v, nh, nv, vh); + vec3 lv = trans_center.xyz-pos; + vec3 h, l, v = -normalize(pos); + float nh, nl, nv, vh, lightDist; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { @@ -113,9 +97,6 @@ void main() float alphaRough, specWeight; initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - vec3 l = lv; // already normalized - float nl = clamp(dot(n, l), 0.0, 1.0); - if (nl > 0.0 || nv > 0.0) { vec3 intensity = size * color; @@ -127,28 +108,40 @@ void main() } else { + float dist = lightDist; + if (dist >= size) + { + discard; + } + dist /= size; + + if (nl < 0.0) + { + discard; + } + 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 noise = texture2D(noiseMap, tc/128.0).b; - float lit = da * dist_atten * noise; + float lit = nl * dist_atten * noise; final_color = color.rgb*lit*diffuse; if (spec.a > 0.0) { - lit = min(da*6.0, 1.0) * dist_atten; + lit = min(nl*6.0, 1.0) * dist_atten; float sa = nh; - float fres = pow(1 - dot(h, v), 5) * 0.4+0.5; + float fres = pow(1 - vh, 5) * 0.4+0.5; float gtdenom = 2 * nh; - float gt = max(0,(min(gtdenom * nv / vh, gtdenom * da / vh))); + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); final_color += lit*scol*color.rgb*spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index e70a545a7b..680fcbfab3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -72,9 +72,13 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -void calcHalfVectors(vec3 h, vec3 n, vec3 v, out float nh, out float nv, out float vh); -vec2 getScreenXY(vec4 clip_point); +vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); +vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); +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); +vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec2 getScreenXY(vec4 clip_point); +void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) @@ -144,7 +148,7 @@ void main() vec4 shd = texture2DRect(lightMap, tc); shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; shadow += shadow_fade; - shadow = clamp(shadow, 0.0, 1.0); + shadow = clamp(shadow, 0.0, 1.0); } float envIntensity; @@ -172,8 +176,9 @@ void main() } lv = proj_origin-pos.xyz; - lv = normalize(lv); - float da = dot(n, lv); + vec3 h, l, v = -normalize(pos); + float nh, nl, nv, vh, lightDist; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; vec4 spec = texture2DRect(specularRect, tc); @@ -200,9 +205,9 @@ void main() float amb_da = proj_ambiance; float lit = 0.0; - if (da > 0.0) + if (nl > 0.0) { - lit = da * dist_atten * noise; + lit = nl * dist_atten * noise; float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); float lod = diff * proj_lod; @@ -213,13 +218,13 @@ void main() final_color = dlit*lit*diffuse*shadow; - amb_da += (da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; + amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - amb_da += (da*da*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; + amb_da += (nl*nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; amb_da *= dist_atten * noise; amb_da = min(amb_da, 1.0-lit); @@ -228,22 +233,15 @@ void main() if (spec.a > 0.0) { - dlit *= min(da*6.0, 1.0) * dist_atten; - vec3 v = -normalize(pos); - - //vec3 ref = dot(pos+lv, n); - vec3 h = normalize(lv + v); - float nh, nv, vh; - calcHalfVectors(h, n, v, nh, nv, vh); - float sa = nh; + dlit *= min(nl*6.0, 1.0) * dist_atten; float fres = pow(1 - dot(h, v), 5)*0.4+0.5; float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); + float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh)); if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da); + float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); vec3 speccol = dlit*scol*spec.rgb*shadow; speccol = clamp(speccol, vec3(0), vec3(1)); final_color += speccol; -- cgit v1.2.3 From 35a97efcb713db780399bb6ce1fbb38e517bd570 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 15 Jul 2022 17:31:25 -0700 Subject: SL-17702: PBR: Add PBR materials to point light shaders --- .../shaders/class3/deferred/multiPointLightF.glsl | 18 ++++++++++++++++++ .../shaders/class3/deferred/pointLightF.glsl | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index d4e82cebf3..513b748f5f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -88,6 +88,24 @@ void main() vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + + for (int light_idx = 0; light_idx < LIGHT_COUNT; ++light_idx) + { + vec3 lightColor = light_col[ light_idx ].rgb; + float lightSize = light [ light_idx ].w; + vec3 lv =(light [ light_idx ].xyz - pos); + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + + if (nl > 0.0 || nv > 0.0) + { + vec3 intensity = getLightIntensityPoint(lightColor, lightSize, lightDist); + colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); + } + } final_color = colorDiffuse + colorSpec; } else diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index ddfbafd739..8886abb7d1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -99,9 +99,9 @@ void main() if (nl > 0.0 || nv > 0.0) { - vec3 intensity = size * color; - colorDiffuse += intensity * nl * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); - colorSpec += intensity * nl * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + vec3 intensity = getLightIntensityPoint(color, size, lightDist); + colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } final_color = colorDiffuse + colorSpec; -- cgit v1.2.3 From 2bdb97613b1c1ac76c6c1eed7038e390d80594bd Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 21 Jul 2022 19:28:17 -0700 Subject: SL-17762: PBR: Add debug flag to turn off regular output and color code point lights and spot lights --- .../app_settings/shaders/class3/deferred/multiPointLightF.glsl | 6 ++++++ .../app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 6 ++++++ indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 6 ++++++ .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 ++++ indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 6 ++++++ 5 files changed, 28 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 513b748f5f..521ad33059 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -27,6 +27,8 @@ /*[EXTRA_CODE_HERE]*/ +#define DEBUG_PBR_LIGHT_TYPE 0 + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -106,6 +108,10 @@ void main() colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } } + + #if DEBUG_PBR_LIGHT_TYPE + colorDiffuse = vec3(0,0.5,0); colorSpec = vec3(0); + #endif final_color = colorDiffuse + colorSpec; } else diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index b86402b031..332cf28fb8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -28,6 +28,8 @@ /*[EXTRA_CODE_HERE]*/ +#define DEBUG_PBR_LIGHT_TYPE 0 + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -202,6 +204,10 @@ void main() vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl + #if DEBUG_PBR_LIGHT_TYPE + colorDiffuse = vec3(0.5); colorSpec = vec3(0); + #endif + final_color = colorDiffuse + colorSpec; } else diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 8886abb7d1..5d9b4bc877 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -27,6 +27,8 @@ /*[EXTRA_CODE_HERE]*/ +#define DEBUG_PBR_LIGHT_TYPE 0 + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -104,6 +106,10 @@ void main() colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } +#if DEBUG_PBR_LIGHT_TYPE + colorDiffuse = vec3(0,0,0.5); colorSpec = vec3(0); +#endif + final_color = colorDiffuse + colorSpec; } else diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 59076d9760..4e92915dc2 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -27,6 +27,7 @@ #define PBR_USE_GGX_EMS_HACK 0 #define PBR_USE_IRRADIANCE_HACK 1 +#define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 #define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 #define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 @@ -477,6 +478,9 @@ void main() #endif #if DEBUG_PBR_SUN_CONTRIB color.rgb = sun_contrib; + #endif + #if DEBUG_PBR_LIGHT_TYPE + color.rgb = vec3(0); #endif frag_color.rgb = color.rgb; // PBR is done in linear } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 680fcbfab3..b94db1b4cb 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -28,6 +28,8 @@ /*[EXTRA_CODE_HERE]*/ +#define DEBUG_PBR_LIGHT_TYPE 0 + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -191,6 +193,10 @@ void main() vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl + #if DEBUG_PBR_LIGHT_TYPE + colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0.0); + #endif + final_color = colorDiffuse + colorSpec; } else -- cgit v1.2.3 From fb29b66fcf029342959d9403964f5e3b3be89a23 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 21 Jul 2022 19:55:11 -0700 Subject: SL-17762: PBR: Cleanup code, add clipProjectedLightVars() --- .../shaders/class3/deferred/multiSpotLightF.glsl | 20 +++++--------------- .../shaders/class3/deferred/spotLightF.glsl | 19 +++++-------------- 2 files changed, 10 insertions(+), 29 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 332cf28fb8..31544cf212 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -78,6 +78,7 @@ uniform mat4 inv_proj; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); +bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec2 getScreenXY(vec4 clip); @@ -146,14 +147,13 @@ void main() vec2 tc = getScreenXY(vary_fragcoord); vec3 pos = getPosition(tc).xyz; - vec3 lv = center.xyz-pos.xyz; - float dist = length(lv); - - if (dist >= size) + vec3 lv; + vec4 proj_tc; + float dist, l_dist; + if (clipProjectedLightVars(center, pos, dist, l_dist, lv, proj_tc)) { discard; } - dist /= size; float shadow = 1.0; @@ -169,16 +169,6 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index b94db1b4cb..7a2cb84f6e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -77,6 +77,7 @@ uniform mat4 inv_proj; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); +bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec2 getScreenXY(vec4 clip_point); @@ -135,13 +136,13 @@ void main() vec2 tc = getScreenXY(vary_fragcoord); vec3 pos = getPosition(tc).xyz; - vec3 lv = trans_center.xyz-pos.xyz; - float dist = length(lv); - if (dist >= size) + vec3 lv; + vec4 proj_tc; + float dist, l_dist; + if (clipProjectedLightVars(trans_center, pos, dist, l_dist, lv, proj_tc)) { discard; } - dist /= size; float shadow = 1.0; @@ -157,16 +158,6 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() - float l_dist = -dot(lv, proj_n); - - vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0)); - if (proj_tc.z < 0.0) - { - discard; - } - - proj_tc.xyz /= proj_tc.w; - float fa = falloff+1.0; float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); dist_atten *= dist_atten; -- cgit v1.2.3 From aa5aaefd7630f69ccaaa5f600f5875bd36eab227 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 21 Jul 2022 20:09:14 -0700 Subject: SL-17762: Cleanup: Document channels in projectionMap --- indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 31544cf212..a6b09ad3ad 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -44,7 +44,7 @@ uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, M uniform samplerCube environmentMap; uniform sampler2DRect lightMap; uniform sampler2D noiseMap; -uniform sampler2D projectionMap; +uniform sampler2D projectionMap; // rgba uniform sampler2D lightFunc; uniform mat4 proj_mat; //screen space to light space diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 7a2cb84f6e..e499638991 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -44,7 +44,7 @@ uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, M uniform samplerCube environmentMap; uniform sampler2DRect lightMap; uniform sampler2D noiseMap; -uniform sampler2D projectionMap; +uniform sampler2D projectionMap; // rgba uniform sampler2D lightFunc; uniform mat4 proj_mat; //screen space to light space -- cgit v1.2.3 From 02c27b8c484f193d83dc8c1c4ed4c222e890522d Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 21 Jul 2022 20:10:14 -0700 Subject: SL-17762: PBR: Cleanup: Document specularRect for PBR --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 4e92915dc2..83fc144434 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -179,8 +179,7 @@ void main() da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR sRGB Emissive #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; -- cgit v1.2.3 From 86de20e711dd077e18f5776de1bc4b26ebd62c3d Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 26 Jul 2022 10:26:25 -0700 Subject: SL-17762L PBR: Move texture2DLodDiffuse() to defferredUtil --- .../shaders/class3/deferred/multiSpotLightF.glsl | 31 ++++------------------ .../shaders/class3/deferred/spotLightF.glsl | 23 +++------------- 2 files changed, 8 insertions(+), 46 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index a6b09ad3ad..90445cb0ef 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -81,6 +81,8 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); +vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip); void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 cs); @@ -104,24 +106,6 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) return ret; } -vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); @@ -186,6 +170,7 @@ void main() vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; vec4 spec = texture2DRect(specularRect, tc); vec3 dlit = vec3(0, 0, 0); + vec3 slit = vec3(0, 0, 0); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { @@ -216,13 +201,8 @@ void main() { lit = nl * dist_atten * noise; - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; - + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); + final_color = dlit*lit*diffuse*shadow; // unshadowed for consistency between forward and deferred? @@ -240,7 +220,6 @@ void main() final_color += amb_da*color.rgb*diffuse.rgb*amb_plcol.rgb*amb_plcol.a; } - if (spec.a > 0.0) { dlit *= min(nl*6.0, 1.0) * dist_atten; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index e499638991..c9e635ab3f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -80,6 +80,8 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); +vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip_point); void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); @@ -99,20 +101,6 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) return ret; } -vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - float det = min(lod/(proj_lod*0.5), 1.0); - float d = min(dist.x, dist.y); - float edge = 0.25*det; - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} - vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); @@ -206,12 +194,7 @@ void main() { lit = nl * dist_atten * noise; - float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0); - float lod = diff * proj_lod; - - vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod); - - dlit = color.rgb * plcol.rgb * plcol.a; + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); final_color = dlit*lit*diffuse*shadow; -- cgit v1.2.3 From d621e58ad49e1a67315da9362a404cf2b7683a99 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 26 Jul 2022 10:42:12 -0700 Subject: SL-17762: Cleanup: Move texture2DLodSpecular() to deferredUtil, remove redundant first arg --- .../shaders/class3/deferred/multiSpotLightF.glsl | 22 ++-------------------- .../shaders/class3/deferred/spotLightF.glsl | 18 ++---------------- 2 files changed, 4 insertions(+), 36 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 90445cb0ef..f8655ccf3b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -86,25 +86,7 @@ vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip); void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 cs); - -vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - - float det = min(lod/(proj_lod*0.5), 1.0); - - float d = min(dist.x, dist.y); - - d *= min(1, d * (proj_lod - lod)); - - float edge = 0.25*det; - - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} +vec4 texture2DLodSpecular(vec2 tc, float lod); vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { @@ -261,7 +243,7 @@ void main() stc.x > 0.0 && stc.y > 0.0) { - final_color += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + final_color += color.rgb * texture2DLodSpecular(stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; } } } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index c9e635ab3f..300e3b8e76 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -85,21 +85,7 @@ vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip_point); void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); - -vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); - float det = min(lod/(proj_lod*0.5), 1.0); - float d = min(dist.x, dist.y); - d *= min(1, d * (proj_lod - lod)); - float edge = 0.25*det; - ret *= clamp(d/edge, 0.0, 1.0); - - return ret; -} +vec4 texture2DLodSpecular(vec2 tc, float lod); vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { @@ -251,7 +237,7 @@ void main() stc.x > 0.0 && stc.y > 0.0) { - final_color += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; + final_color += color.rgb * texture2DLodSpecular(stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; } } } -- cgit v1.2.3 From c7d61c417b0e7c9b7f56e29b82476dfe85c39b91 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 27 Jul 2022 10:21:34 -0700 Subject: SL-17762: Cleanup dist_atten --- .../shaders/class3/deferred/multiPointLightF.glsl | 5 ++++- .../shaders/class3/deferred/multiSpotLightF.glsl | 16 ++++++++-------- .../shaders/class3/deferred/pointLightF.glsl | 7 ++++--- .../shaders/class3/deferred/spotLightF.glsl | 20 ++++++++++---------- 4 files changed, 26 insertions(+), 22 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 521ad33059..699a9c0276 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -97,13 +97,16 @@ void main() for (int light_idx = 0; light_idx < LIGHT_COUNT; ++light_idx) { vec3 lightColor = light_col[ light_idx ].rgb; + float falloff = light_col[ light_idx ].a; float lightSize = light [ light_idx ].w; vec3 lv =(light [ light_idx ].xyz - pos); calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); if (nl > 0.0 || nv > 0.0) { - vec3 intensity = getLightIntensityPoint(lightColor, lightSize, lightDist); + float dist = lightDist / lightSize; + float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + vec3 intensity = dist_atten * getLightIntensityPoint(lightColor, lightSize, lightDist); colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index f8655ccf3b..09a8dbd4f1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -135,14 +135,7 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); - float fa = falloff+1.0; - float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; - if (dist_atten <= 0.0) - { - discard; - } + float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); lv = proj_origin-pos.xyz; vec3 h, l, v = -normalize(pos); @@ -169,6 +162,13 @@ void main() } else { + dist_atten *= dist_atten; + dist_atten *= 2.0; + if (dist_atten <= 0.0) + { + discard; + } + float noise = texture2D(noiseMap, tc/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 5d9b4bc877..defd577266 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -88,6 +88,9 @@ void main() float nh, nl, nv, vh, lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + float dist = lightDist / size; + float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { vec3 colorDiffuse = vec3(0); @@ -101,7 +104,7 @@ void main() if (nl > 0.0 || nv > 0.0) { - vec3 intensity = getLightIntensityPoint(color, size, lightDist); + vec3 intensity = dist_atten * getLightIntensityPoint(color, size, lightDist); colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } @@ -126,8 +129,6 @@ void main() discard; } - float fa = falloff+1.0; - float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); dist_atten *= dist_atten; dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 300e3b8e76..72ae733622 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -132,17 +132,9 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() - float fa = falloff+1.0; - float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0); - dist_atten *= dist_atten; - dist_atten *= 2.0; + float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; + lv = proj_origin-pos.xyz; // NOTE: Re-using lv vec3 h, l, v = -normalize(pos); float nh, nl, nv, vh, lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); @@ -166,6 +158,14 @@ void main() } else { + dist_atten *= dist_atten; + dist_atten *= 2.0; + + if (dist_atten <= 0.0) + { + discard; + } + float noise = texture2D(noiseMap, tc/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && -- cgit v1.2.3 From 4c07a4a44553e29a5d54215119fcf056c62e45e8 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 27 Jul 2022 10:26:50 -0700 Subject: SL-17762: PBR: Add defines for spot light debugging --- .../shaders/class3/deferred/multiSpotLightF.glsl | 24 +++++++++++++++++++++- .../shaders/class3/deferred/spotLightF.glsl | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 09a8dbd4f1..e29e5d69a2 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -28,7 +28,15 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_PBR_LIGHT_TYPE 0 +#define DEBUG_PBR_LIGHT_TYPE 0 // Ouput gray if PBR multiSpot lights object +#define DEBUG_PBR_SPOT 0 +#define DEBUG_PBR_SPOT_DIFFUSE 0 // PBR diffuse lit +#define DEBUG_PBR_SPOT_SPECULAR 0 // PBR spec lit + +#define DEBUG_SPOT_DIFFUSE 0 +#define DEBUG_SPOT_NL 0 // monochome area effected by light +#define DEBUG_SPOT_SPEC_POS 0 +#define DEBUG_SPOT_REFLECTION 0 #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -247,7 +255,21 @@ void main() } } } + #if DEBUG_SPOT_SPEC_POS + final_color = pos + ref * dot(pdelta, proj_n)/ds; + #endif + #if DEBUG_SPOT_REFLECTION + final_color = ref; + #endif } + +#if DEBUG_SPOT_NL + final_color =vec3(nl); +#endif +#if DEBUG_SPOT_DIFFUSE + final_color = vec3(nl * dist_atten * noise); +#endif + } //not sure why, but this line prevents MATBUG-194 diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 72ae733622..f6ab0ad428 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -29,6 +29,10 @@ /*[EXTRA_CODE_HERE]*/ #define DEBUG_PBR_LIGHT_TYPE 0 +#define DEBUG_PBR_SPOT 0 +#define DEBUG_PBR_NL 0 // monochome area effected by light +#define DEBUG_PBR_SPOT_DIFFUSE 0 +#define DEBUG_PBR_SPOT_SPECULAR 0 #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -142,6 +146,7 @@ void main() vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; vec4 spec = texture2DRect(specularRect, tc); vec3 dlit = vec3(0, 0, 0); + vec3 slit = vec3(0, 0, 0); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { -- cgit v1.2.3 From 21ee88a088054d520b35e6c7e2c65b07a3899bc3 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 27 Jul 2022 10:27:21 -0700 Subject: SL-17762: PBR: Add support for spot lights --- .../shaders/class3/deferred/multiSpotLightF.glsl | 46 ++++++++++++++++++++++ .../shaders/class3/deferred/spotLightF.glsl | 42 ++++++++++++++++++++ 2 files changed, 88 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index e29e5d69a2..20309d9673 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -161,7 +161,53 @@ void main() vec3 colorSpec = vec3(0); vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl + float metal = packedORM.b; +// if (proj_tc.x > 0.0 && proj_tc.x < 1.0 +// && proj_tc.y > 0.0 && proj_tc.y < 1.0) + if (nl > 0.0) + { + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); + slit = getProjectedLightSpecularColor( pos, n ); + +// vec3 intensity = getLightIntensitySpot( color, size, lightDist, v ); + colorDiffuse = shadow * dlit * nl * dist_atten; + colorSpec = shadow * slit * nl * dist_atten; + +// colorDiffuse *= BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); +// colorSpec *= BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + + #if DEBUG_PBR_SPOT_DIFFUSE + colorDiffuse = dlit.rgb; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SPOT_SPECULAR + colorDiffuse = vec3(0); colorSpec = slit.rgb; + #endif + #if DEBUG_PBR_SPOT + colorDiffuse = dlit; colorSpec = vec3(0); + colorDiffuse *= nl; + colorDiffuse *= shadow; + #endif + + #if DEBUG_SPOT_SPEC_POS + colorDiffuse = pos + ref * dot(pdelta, proj_n)/ds; colorSpec = vec3(0); + #endif + #if DEBUG_SPOT_REFLECTION + colorDiffuse = ref; colorSpec = vec3(0); + #endif + + } + + #if DEBUG_SPOT_DIFFUSE + colorDiffuse = vec3(nl * dist_atten); + #endif + #if DEBUG_SPOT_NL + colorDiffuse = vec3(nl); colorSpec = vec3(0); + #endif #if DEBUG_PBR_LIGHT_TYPE colorDiffuse = vec3(0.5); colorSpec = vec3(0); #endif diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index f6ab0ad428..a82581d1a1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -154,7 +154,49 @@ void main() vec3 colorSpec = vec3(0); vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl + float metal = packedORM.b; +// if (proj_tc.x > 0.0 && proj_tc.x < 1.0 +// && proj_tc.y > 0.0 && proj_tc.y < 1.0) + if (nl > 0.0) + { + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); + slit = getProjectedLightSpecularColor( pos, n ); + +// vec3 intensity = getLightIntensitySpot( color, size, lightDist, v ); +// colorDiffuse = shadow * dlit * nl; +// colorSpec = shadow * slit * nl; + +// colorDiffuse *= BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); +// colorSpec *= BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + + colorDiffuse = shadow * dlit * nl * dist_atten; + colorSpec = shadow * slit * nl * dist_atten; + + #if DEBUG_PBR_SPOT_DIFFUSE + colorDiffuse = dlit.rgb; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SPOT_SPECULAR + colorDiffuse = vec3(0); colorSpec = slit.rgb; + #endif + #if DEBUG_PBR_SPOT + colorDiffuse = dlit; colorSpec = vec3(0); + colorDiffuse *= nl; + colorDiffuse *= shadow; + #endif + + } + + #if DEBUG_SPOT_DIFFUSE + colorDiffuse = vec3(nl * dist_atten); + #endif + #if DEBUG_PBR_NL + colorDiffuse = vec3(nl); colorSpec = vec3(0); + #endif #if DEBUG_PBR_LIGHT_TYPE colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0.0); #endif -- cgit v1.2.3 From 1a9d1677408bb914622b6c6a97dd7eba9895e09d Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 2 Aug 2022 19:39:37 -0700 Subject: SL-17763: PBR: Fix ems calculation --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 83fc144434..8bf44abbe3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -306,10 +306,7 @@ void main() // Reference: getIBLRadianceLambertian vec3 FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term - float Ems = (1.0 - vScaleBias.x + vScaleBias.y); -#if PBR_USE_GGX_EMS_HACK - Ems = alphaRough; // With GGX approximation Ems = 0 so use substitute -#endif + float Ems = 1.0 - (vScaleBias.x + vScaleBias.y); vec3 avg = specWeight * (reflect0 + (1.0 - reflect0) / 21.0); vec3 AvgEms = avg * Ems; vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms); -- cgit v1.2.3 From bbe2d43b7d0e64a8137075ce1390722507354538 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 2 Aug 2022 19:41:15 -0700 Subject: SL-17763: PBR: Add more BRDF debug outputs --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8bf44abbe3..c2a3e472d0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -55,6 +55,8 @@ #define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal ,Vertex2Camera) #define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) #define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) +#define DEBUG_PBR_BRDF_SCALE_ONLY 0 // Output: grayscale BRDF Scale +#define DEBUG_PBR_BRDF_BIAS_ONLY 0 // Output: grayscale BRDER Bias #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel #define DEBUG_PBR_KSPEC 0 // Output: K spec #define DEBUG_PBR_REFLECTION_DIR 0 // Output: reflection dir @@ -67,7 +69,7 @@ #define DEBUG_PBR_IRRADIANCE_RAW 0 // Output: Diffuse Irradiance pre-mix #define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance #define DEBUG_PBR_FSS_ESS_LAMBERT 0 // Output: FssEssLambert -#define DEBUG_PBR_EMS 0 // Output: Ems +#define DEBUG_PBR_EMS 0 // Output: Ems = (1 - BRDF Scale + BRDF Bias) #define DEBUG_PBR_AVG 0 // Output: Avg #define DEBUG_PBR_FMS_EMS 0 // Output: FmsEms #define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms @@ -387,6 +389,12 @@ void main() #if DEBUG_PBR_DIFFUSE_C color.rgb = c_diff; #endif + #if DEBUG_PBR_BRDF_SCALE_ONLY + color.rgb = vec3(vScaleBias.x); + #endif + #if DEBUG_PBR_BRDF_BIAS_ONLY + color.rgb = vec3(vScaleBias.y); + #endif #if DEBUG_PBR_DIFFUSE_K color.rgb = kDiffuse; #endif -- cgit v1.2.3 From 38b895162ccd15281c214dccd54bacb0c6485c5a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 9 Aug 2022 01:10:06 -0700 Subject: SL-17763: PBR: Add debug spot light vectors --- .../shaders/class3/deferred/multiSpotLightF.glsl | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 20309d9673..eed714c8db 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -38,6 +38,21 @@ #define DEBUG_SPOT_SPEC_POS 0 #define DEBUG_SPOT_REFLECTION 0 +#define DEBUG_PBR_LIGHT_H 0 // Half vector +#define DEBUG_PBR_LIHGT_L 0 // Light vector +#define DEBUG_PBR_LIGHT_NH 0 // dot(n,h) +#define DEBUG_PBR_LIGHT_NL 0 // doh(n,l) +#define DEBUG_PBR_LIGHT_NV 0 // doh(n,v) +#define DEBUG_PBR_LIGHT_VH 0 // doh(v,h) +#define DEBUG_PBR_LIGHT_DIFFUSE_COLOR 0 // non PBR spotlight +#define DEBUG_PBR_LIGHT_SPECULAR_COLOR 0 // non PBR spotlight +#define DEBUG_PBR_LIGHT_INTENSITY 0 // Light intensity +#define DEBUG_PBR_LIGHT_INTENSITY_NL 0 // Light intensity * dot(n,l) +#define DEBUG_PBR_LIGHT_BRDF_DIFFUSE 0 +#define DEBUG_PBR_LIGHT_BRDF_SPECULAR 0 +#define DEBUG_PBR_LIGHT_BRDF_FINAL 0 // BRDF Diffuse + BRDF Specular +#define DEBUG_PBR_SHADOW 0 // Show inverted shadow + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -96,6 +111,13 @@ void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 vec3 srgb_to_linear(vec3 cs); vec4 texture2DLodSpecular(vec2 tc, float lod); +vec3 colorized_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 ); +} + vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); @@ -212,6 +234,65 @@ void main() colorDiffuse = vec3(0.5); colorSpec = vec3(0); #endif + #if DEBUG_PBR_LIGHT_H + colorDiffuse = h*0.5 + 0.5; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_LIHGT_L + colorDiffuse = l*0.5 + 0.5; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_LIGHT_NH + colorDiffuse = colorized_dot(nh); colorSpec = vec3(0); + #endif + #if DEBUG_PBR_LIGHT_NL + colorDiffuse = colorized_dot(nl); colorSpec = vec3(0); + #endif + #if DEBUG_PBR_LIGHT_NV + colorDiffuse = colorized_dot(nv); colorSpec = vec3(0); + #endif + #if DEBUG_PBR_LIGHT_VH + colorDiffuse = colorized_dot(vh); colorSpec = vec3(0); + #endif + #if DEBUG_PBR_LIGHT_DIFFUSE_COLOR + colorDiffuse = dlit; + #endif + #if DEBUG_PBR_LIGHT_SPECULAR_COLOR + colorDiffuse = slit; + #endif + #if DEBUG_PBR_LIGHT_INTENSITY + colorDiffuse = getLightIntensitySpot( color, size, lightDist, v ); colorSpec = vec3(0); +// colorDiffuse = nl * dist_atten; + #endif + #if DEBUG_PBR_LIGHT_INTENSITY_NL + colorDiffuse = getLightIntensitySpot( color, size, lightDist, v ) * nl; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_LIGHT_BRDF_DIFFUSE + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + + colorDiffuse = BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); + colorSpec = vec3(0); + #endif + #if DEBUG_PBR_LIGHT_BRDF_SPECULAR + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + + colorDiffuse = vec3(0); + colorSpec = BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + #endif + #if DEBUG_PBR_LIGHT_BRDF_FINAL + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + colorDiffuse = nl * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); + colorSpec = nl * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + #endif + #if DEBUG_PBR_SHADOW + colorDiffuse = 1.0 - vec3(shadow); + colorSpec = vec3(0); + #endif + final_color = colorDiffuse + colorSpec; } else -- cgit v1.2.3 From f9615f7cffc3c9b2e9c8c4031cc81a3f6eb07afb Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 9 Aug 2022 01:15:53 -0700 Subject: SL-17763: PBR: Add BRDF to spot light --- .../app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 8 ++------ .../app_settings/shaders/class3/deferred/spotLightF.glsl | 11 ++--------- 2 files changed, 4 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index eed714c8db..371c9d88f4 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -196,12 +196,8 @@ void main() dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); slit = getProjectedLightSpecularColor( pos, n ); -// vec3 intensity = getLightIntensitySpot( color, size, lightDist, v ); - colorDiffuse = shadow * dlit * nl * dist_atten; - colorSpec = shadow * slit * nl * dist_atten; - -// colorDiffuse *= BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); -// colorSpec *= BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + colorDiffuse = shadow * dist_atten * nl * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); + colorSpec = shadow * dist_atten * nl * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); #if DEBUG_PBR_SPOT_DIFFUSE colorDiffuse = dlit.rgb; colorSpec = vec3(0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index a82581d1a1..3b028d9fae 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -167,15 +167,8 @@ void main() dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); slit = getProjectedLightSpecularColor( pos, n ); -// vec3 intensity = getLightIntensitySpot( color, size, lightDist, v ); -// colorDiffuse = shadow * dlit * nl; -// colorSpec = shadow * slit * nl; - -// colorDiffuse *= BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); -// colorSpec *= BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); - - colorDiffuse = shadow * dlit * nl * dist_atten; - colorSpec = shadow * slit * nl * dist_atten; + colorDiffuse = shadow * dist_atten * nl * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); + colorSpec = shadow * dist_atten * nl * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); #if DEBUG_PBR_SPOT_DIFFUSE colorDiffuse = dlit.rgb; colorSpec = vec3(0); -- cgit v1.2.3 From e408fb9f7c9cc0adf32a2977882fd0c741de66a9 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 9 Aug 2022 01:25:59 -0700 Subject: SL-17763: PBR: Fix point light to be consistent --- .../newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 699a9c0276..b27b171122 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -102,7 +102,7 @@ void main() vec3 lv =(light [ light_idx ].xyz - pos); calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); - if (nl > 0.0 || nv > 0.0) + if (nl > 0.0) { float dist = lightDist / lightSize; float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index defd577266..b4640187c7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -102,7 +102,7 @@ void main() float alphaRough, specWeight; initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - if (nl > 0.0 || nv > 0.0) + if (nl > 0.0) { vec3 intensity = dist_atten * getLightIntensityPoint(color, size, lightDist); colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); -- cgit v1.2.3 From 0ea71a2db2cddb2447a483d926e0cf6be84b344d Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 10 Aug 2022 14:44:22 -0700 Subject: SL-17763: PBR: Add spotlight ambiance to spotlight --- .../shaders/class3/deferred/spotLightF.glsl | 43 ++++++++++++++-------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 3b028d9fae..308d045a9b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -84,6 +84,7 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv); vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip_point); @@ -156,31 +157,43 @@ void main() vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl float metal = packedORM.b; -// if (proj_tc.x > 0.0 && proj_tc.x < 1.0 -// && proj_tc.y > 0.0 && proj_tc.y < 1.0) - if (nl > 0.0) + // We need this additional test inside a light's frustum since a spotlight's ambiance can be applied + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) { - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + float lit = 0.0; + float amb_da = 0.0; + + if (nl > 0.0) + { + amb_da += (nl*0.5 + 0.5) * proj_ambiance; + lit = nl * dist_atten; - dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - slit = getProjectedLightSpecularColor( pos, n ); + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - colorDiffuse = shadow * dist_atten * nl * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); - colorSpec = shadow * dist_atten * nl * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); + slit = getProjectedLightSpecularColor( pos, n ); + + colorDiffuse = shadow * dist_atten * nl * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); + colorSpec = shadow * dist_atten * nl * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); #if DEBUG_PBR_SPOT_DIFFUSE - colorDiffuse = dlit.rgb; colorSpec = vec3(0); + colorDiffuse = dlit.rgb; colorSpec = vec3(0); #endif #if DEBUG_PBR_SPOT_SPECULAR - colorDiffuse = vec3(0); colorSpec = slit.rgb; + colorDiffuse = vec3(0); colorSpec = slit.rgb; #endif #if DEBUG_PBR_SPOT - colorDiffuse = dlit; colorSpec = vec3(0); - colorDiffuse *= nl; - colorDiffuse *= shadow; + colorDiffuse = dlit; colorSpec = vec3(0); + colorDiffuse *= nl; + colorDiffuse *= shadow; #endif + } + + vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); + colorDiffuse += diffuse.rgb * amb_rgb; } -- cgit v1.2.3 From 2f993717dbfda56bcefcbc85312126cb47b0aa9c Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 10 Aug 2022 14:44:56 -0700 Subject: SL-17763: Cleanup legacy to use ambiance utility --- .../shaders/class3/deferred/spotLightF.glsl | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 308d045a9b..062062f976 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -92,18 +92,6 @@ void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 vec3 srgb_to_linear(vec3 c); vec4 texture2DLodSpecular(vec2 tc, float lod); -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = tc-vec2(0.5); - float d = dot(dist,dist); - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - vec4 getPosition(vec2 pos_screen); void main() @@ -240,14 +228,8 @@ void main() amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - amb_da += (nl*nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; - amb_da *= dist_atten * noise; - amb_da = min(amb_da, 1.0-lit); - - final_color += amb_da*color.rgb*diffuse.rgb*amb_plcol.rgb*amb_plcol.a; + vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); + final_color += diffuse.rgb*amb_rgb; } if (spec.a > 0.0) -- cgit v1.2.3 From 76ed0860e5c6e8a8c911279ea5d42151b5813ea3 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 10 Aug 2022 14:51:06 -0700 Subject: SL-17763: PBR: Add spotlight ambiance to multiSpotLight --- .../shaders/class3/deferred/multiSpotLightF.glsl | 61 ++++++++++++++++------ 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 371c9d88f4..d061b3984e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -104,6 +104,7 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv); vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip); @@ -185,25 +186,54 @@ void main() vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl float metal = packedORM.b; -// if (proj_tc.x > 0.0 && proj_tc.x < 1.0 -// && proj_tc.y > 0.0 && proj_tc.y < 1.0) - if (nl > 0.0) + // We need this additional test inside a light's frustum since a spotlight's ambiance can be applied + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) { - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + float lit = 0.0; + float amb_da = 0.0; - dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - slit = getProjectedLightSpecularColor( pos, n ); + if (nl > 0.0) + { + amb_da += (nl*0.5 + 0.5) * proj_ambiance; + lit = nl * dist_atten; - colorDiffuse = shadow * dist_atten * nl * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); - colorSpec = shadow * dist_atten * nl * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - #if DEBUG_PBR_SPOT_DIFFUSE - colorDiffuse = dlit.rgb; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SPOT_SPECULAR - colorDiffuse = vec3(0); colorSpec = slit.rgb; + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); + slit = getProjectedLightSpecularColor( pos, n ); + + colorDiffuse = shadow * lit * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); + colorSpec = shadow * lit * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); + + #if DEBUG_PBR_SPOT_DIFFUSE + colorDiffuse = dlit.rgb; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SPOT_SPECULAR + colorDiffuse = vec3(0); colorSpec = slit.rgb; + #endif + #if DEBUG_PBR_SPOT + colorDiffuse = dlit; colorSpec = vec3(0); + colorDiffuse *= nl; + colorDiffuse *= shadow; + #endif + + #if DEBUG_SPOT_SPEC_POS + colorDiffuse = pos + ref * dot(pdelta, proj_n)/ds; colorSpec = vec3(0); + #endif + #if DEBUG_SPOT_REFLECTION + colorDiffuse = ref; colorSpec = vec3(0); + #endif + + } + + vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); + colorDiffuse += diffuse.rgb * amb_rgb; + + #if DEBUG_LIGHT_FRUSTUM + colorDiffuse = vec3(0,1,0); colorSpec = vec3(0); #endif #if DEBUG_PBR_SPOT colorDiffuse = dlit; colorSpec = vec3(0); @@ -217,7 +247,6 @@ void main() #if DEBUG_SPOT_REFLECTION colorDiffuse = ref; colorSpec = vec3(0); #endif - } #if DEBUG_SPOT_DIFFUSE -- cgit v1.2.3 From 9d20e66a0972d1405378a44b779483dad02bcff3 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 10 Aug 2022 14:52:13 -0700 Subject: SL-17763: Cleanup legacy multiSpotLight to use ambiance utility --- .../shaders/class3/deferred/multiSpotLightF.glsl | 27 +++------------------- 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index d061b3984e..86235f3b89 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -119,20 +119,6 @@ vec3 colorized_dot(float x) return vec3( 0, 0, 1 ); } -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - vec4 getPosition(vec2 pos_screen); void main() @@ -336,7 +322,7 @@ void main() proj_tc.x > 0.0 && proj_tc.y > 0.0) { - float amb_da = proj_ambiance; + float amb_da = 0; float lit = 0.0; if (nl > 0.0) @@ -351,15 +337,8 @@ void main() amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - // use unshadowed for consistency between forward and deferred? - amb_da += (nl*nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; - amb_da *= dist_atten * noise; - amb_da = min(amb_da, 1.0-lit); - - final_color += amb_da*color.rgb*diffuse.rgb*amb_plcol.rgb*amb_plcol.a; + amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); + final_color += diffuse.rgb * amb_rgb; } if (spec.a > 0.0) -- cgit v1.2.3 From 291350e00f40fab1072a78ea92d5ea5aafcf5d32 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 10 Aug 2022 16:46:40 -0700 Subject: SL-17763: Cleanup debug infor for lights --- .../shaders/class3/deferred/multiSpotLightF.glsl | 113 ++++++++++++--------- .../shaders/class3/deferred/spotLightF.glsl | 16 +-- 2 files changed, 75 insertions(+), 54 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 86235f3b89..f28619b11a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -29,29 +29,36 @@ /*[EXTRA_CODE_HERE]*/ #define DEBUG_PBR_LIGHT_TYPE 0 // Ouput gray if PBR multiSpot lights object +#define DEBUG_PBR_SPOT_ZERO 0 // Output zero for spotlight #define DEBUG_PBR_SPOT 0 #define DEBUG_PBR_SPOT_DIFFUSE 0 // PBR diffuse lit #define DEBUG_PBR_SPOT_SPECULAR 0 // PBR spec lit -#define DEBUG_SPOT_DIFFUSE 0 -#define DEBUG_SPOT_NL 0 // monochome area effected by light -#define DEBUG_SPOT_SPEC_POS 0 -#define DEBUG_SPOT_REFLECTION 0 +#define DEBUG_LIGHT_FRUSTUM 0 // If projected light effects a surface +#define DEBUG_AMBIANCE_COLOR 0 // calculated ambiance color +#define DEBUG_AMBIANCE_AOE 0 // area of effect using inverse ambiance color +#define DEBUG_AMBIANCE_FINAL 0 // light color * ambiance color +#define DEBUG_NOISE 0 // monochrome noise +#define DEBUG_SHADOW 0 // Show inverted shadow +#define DEBUG_SPOT_DIFFUSE 0 // dot(n,l) * dist_atten +#define DEBUG_SPOT_NL 0 // monochome area effected by light +#define DEBUG_SPOT_SPEC_POS 0 +#define DEBUG_SPOT_REFLECTION 0 // color: pos reflected along n #define DEBUG_PBR_LIGHT_H 0 // Half vector #define DEBUG_PBR_LIHGT_L 0 // Light vector -#define DEBUG_PBR_LIGHT_NH 0 // dot(n,h) -#define DEBUG_PBR_LIGHT_NL 0 // doh(n,l) -#define DEBUG_PBR_LIGHT_NV 0 // doh(n,v) -#define DEBUG_PBR_LIGHT_VH 0 // doh(v,h) +#define DEBUG_PBR_LIGHT_NH 0 // colorized dot(n,h) +#define DEBUG_PBR_LIGHT_NL 0 // colorized dot(n,l) +#define DEBUG_PBR_LIGHT_NV 0 // colorized dot(n,v) +#define DEBUG_PBR_LIGHT_VH 0 // colorized dot(v,h) #define DEBUG_PBR_LIGHT_DIFFUSE_COLOR 0 // non PBR spotlight #define DEBUG_PBR_LIGHT_SPECULAR_COLOR 0 // non PBR spotlight #define DEBUG_PBR_LIGHT_INTENSITY 0 // Light intensity #define DEBUG_PBR_LIGHT_INTENSITY_NL 0 // Light intensity * dot(n,l) -#define DEBUG_PBR_LIGHT_BRDF_DIFFUSE 0 +#define DEBUG_PBR_LIGHT_BRDF_DIFFUSE 0 // like "fullbright" if no "nl" factor #define DEBUG_PBR_LIGHT_BRDF_SPECULAR 0 #define DEBUG_PBR_LIGHT_BRDF_FINAL 0 // BRDF Diffuse + BRDF Specular -#define DEBUG_PBR_SHADOW 0 // Show inverted shadow + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -164,6 +171,8 @@ void main() vec3 dlit = vec3(0, 0, 0); vec3 slit = vec3(0, 0, 0); + vec3 amb_rgb = vec3(0); + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { vec3 colorDiffuse = vec3(0); @@ -205,42 +214,23 @@ void main() colorDiffuse *= nl; colorDiffuse *= shadow; #endif - - #if DEBUG_SPOT_SPEC_POS - colorDiffuse = pos + ref * dot(pdelta, proj_n)/ds; colorSpec = vec3(0); - #endif - #if DEBUG_SPOT_REFLECTION - colorDiffuse = ref; colorSpec = vec3(0); - #endif - } - vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); + amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); colorDiffuse += diffuse.rgb * amb_rgb; + #if DEBUG_AMBIANCE_FINAL + colorDiffuse = diffuse.rgb * amb_rgb; colorSpec = vec3(0); + #endif #if DEBUG_LIGHT_FRUSTUM colorDiffuse = vec3(0,1,0); colorSpec = vec3(0); #endif - #if DEBUG_PBR_SPOT - colorDiffuse = dlit; colorSpec = vec3(0); - colorDiffuse *= nl; - colorDiffuse *= shadow; - #endif - - #if DEBUG_SPOT_SPEC_POS - colorDiffuse = pos + ref * dot(pdelta, proj_n)/ds; colorSpec = vec3(0); - #endif - #if DEBUG_SPOT_REFLECTION - colorDiffuse = ref; colorSpec = vec3(0); + #if DEBUG_NOISE + float noise = texture2D(noiseMap, tc/128.0).b; + colorDiffuse = vec3(noise); colorSpec = vec3(0); #endif } - #if DEBUG_SPOT_DIFFUSE - colorDiffuse = vec3(nl * dist_atten); - #endif - #if DEBUG_SPOT_NL - colorDiffuse = vec3(nl); colorSpec = vec3(0); - #endif #if DEBUG_PBR_LIGHT_TYPE colorDiffuse = vec3(0.5); colorSpec = vec3(0); #endif @@ -299,10 +289,6 @@ void main() colorDiffuse = nl * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); colorSpec = nl * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); #endif - #if DEBUG_PBR_SHADOW - colorDiffuse = 1.0 - vec3(shadow); - colorSpec = vec3(0); - #endif final_color = colorDiffuse + colorSpec; } @@ -386,22 +372,55 @@ void main() } } } - #if DEBUG_SPOT_SPEC_POS - final_color = pos + ref * dot(pdelta, proj_n)/ds; - #endif #if DEBUG_SPOT_REFLECTION final_color = ref; #endif } +#if DEBUG_LIGHT_FRUSTUM + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) + { + final_color = vec3(0,0,1); + } +#endif + } + +#if DEBUG_AMBIANCE_AOE + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) + { + final_color = 1.0 - amb_rgb; + } +#endif +#if DEBUG_AMBIANCE_COLOR + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) + { + final_color = amb_rgb; + } +#endif +#if DEBUG_SHADOW + final_color = 1.0 - vec3(shadow); +#endif +#if DEBUG_SPOT_DIFFUSE + final_color = vec3(nl * dist_atten); +#endif #if DEBUG_SPOT_NL final_color =vec3(nl); #endif -#if DEBUG_SPOT_DIFFUSE - final_color = vec3(nl * dist_atten * noise); +#if DEBUG_SPOT_SPEC_POS + vec3 ref = reflect(normalize(pos), n); + vec3 pdelta = proj_p-pos; + float ds = dot(ref, proj_n); + final_color = pos + ref * dot(pdelta, proj_n)/ds; +#endif +#if DEBUG_SPOT_REFLECTION + final_color = reflect(normalize(pos), n); +#endif +#if DEBUG_SPOT_ZERO + final_color = vec3(0); #endif - - } //not sure why, but this line prevents MATBUG-194 final_color = max(final_color, vec3(0.0)); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 062062f976..25622d4f83 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -30,10 +30,11 @@ #define DEBUG_PBR_LIGHT_TYPE 0 #define DEBUG_PBR_SPOT 0 -#define DEBUG_PBR_NL 0 // monochome area effected by light #define DEBUG_PBR_SPOT_DIFFUSE 0 #define DEBUG_PBR_SPOT_SPECULAR 0 +#define DEBUG_SPOT_NL 0 // monochome area effected by light + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -185,12 +186,6 @@ void main() } - #if DEBUG_SPOT_DIFFUSE - colorDiffuse = vec3(nl * dist_atten); - #endif - #if DEBUG_PBR_NL - colorDiffuse = vec3(nl); colorSpec = vec3(0); - #endif #if DEBUG_PBR_LIGHT_TYPE colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0.0); #endif @@ -279,6 +274,13 @@ void main() } } +#if DEBUG_SPOT_DIFFUSE + final_color = vec3(nl * dist_atten); +#endif +#if DEBUG_SPOT_NL + final_color = vec3(nl); +#endif + //not sure why, but this line prevents MATBUG-194 final_color = max(final_color, vec3(0.0)); -- cgit v1.2.3 From 9e1692ace915b495047678bd5a8f3acdf22d291a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 11 Aug 2022 11:21:02 -0700 Subject: SL-17763: Make dist_atten consistent between PBR and Legacy --- .../shaders/class3/deferred/multiPointLightF.glsl | 2 ++ .../shaders/class3/deferred/multiSpotLightF.glsl | 13 ++++++------- .../app_settings/shaders/class3/deferred/pointLightF.glsl | 5 ++--- .../app_settings/shaders/class3/deferred/spotLightF.glsl | 14 ++++++-------- 4 files changed, 16 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index b27b171122..399948459b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -106,6 +106,8 @@ void main() { float dist = lightDist / lightSize; float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + dist_atten *= dist_atten; + dist_atten *= 2.0; vec3 intensity = dist_atten * getLightIntensityPoint(lightColor, lightSize, lightDist); colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index f28619b11a..fdbeb34116 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -160,6 +160,12 @@ void main() vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + dist_atten *= dist_atten; + dist_atten *= 2.0; + if (dist_atten <= 0.0) + { + discard; + } lv = proj_origin-pos.xyz; vec3 h, l, v = -normalize(pos); @@ -294,13 +300,6 @@ void main() } else { - dist_atten *= dist_atten; - dist_atten *= 2.0; - if (dist_atten <= 0.0) - { - discard; - } - float noise = texture2D(noiseMap, tc/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index b4640187c7..42d7407456 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -90,6 +90,8 @@ void main() float dist = lightDist / size; float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + dist_atten *= dist_atten; + dist_atten *= 2.0; if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { @@ -129,9 +131,6 @@ void main() discard; } - dist_atten *= dist_atten; - dist_atten *= 2.0; - float noise = texture2D(noiseMap, tc/128.0).b; float lit = nl * dist_atten * noise; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 25622d4f83..d82baf0804 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -127,6 +127,12 @@ void main() vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + dist_atten *= dist_atten; + dist_atten *= 2.0; + if (dist_atten <= 0.0) + { + discard; + } lv = proj_origin-pos.xyz; // NOTE: Re-using lv vec3 h, l, v = -normalize(pos); @@ -194,14 +200,6 @@ void main() } else { - dist_atten *= dist_atten; - dist_atten *= 2.0; - - if (dist_atten <= 0.0) - { - discard; - } - float noise = texture2D(noiseMap, tc/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && -- cgit v1.2.3 From 8abc2ad094c150479530d2c8d99ceb7c484497d7 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 11 Aug 2022 15:26:51 -0700 Subject: SL-17929: PBR: Add sun/moon reflection in surface --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index c2a3e472d0..e3608a1136 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -319,6 +319,16 @@ void main() #endif colorDiffuse *= packedORM.r; // Occlusion -- NOTE: pbropaque will need occlusion_strength pre-multiplied into spec.r + // Add in sun/moon reflection + if (metal > 0.0) + { + vec3 r = reflect(pos.xyz, norm.xyz); + float sa = dot(normalize(r), light_dir.xyz); + float sun = texture2D(lightFunc, vec2(sa, metal)).r; + vec3 sunSpec = sunlit * scol * sun; + colorSpec += sunSpec; + bloom = dot(sunSpec, sunSpec) / 6; + } color.rgb = colorDiffuse + colorEmissive + colorSpec; vec3 sun_contrib = min(da, scol) * sunlit; -- cgit v1.2.3 From bc31d4f204329d1356c9c505a856a26bc2db9aa4 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 11 Aug 2022 16:19:08 -0700 Subject: SL-17929: PBR: Fix sun reflection artifacts from lightFunc being noisy --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index e3608a1136..7602fa9712 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -326,7 +326,7 @@ void main() float sa = dot(normalize(r), light_dir.xyz); float sun = texture2D(lightFunc, vec2(sa, metal)).r; vec3 sunSpec = sunlit * scol * sun; - colorSpec += sunSpec; + colorSpec += sunSpec * metal; bloom = dot(sunSpec, sunSpec) / 6; } color.rgb = colorDiffuse + colorEmissive + colorSpec; -- cgit v1.2.3 From 9586465672dcedd16bbbaf4e104b76acaf05ebb8 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 11 Aug 2022 21:54:42 -0700 Subject: SL-17930: PBR: Add SSAO --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 7602fa9712..510f8c8b45 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -291,7 +291,7 @@ void main() #if DEBUG_PBR_IRRADIANCE_RAW vec3 debug_irradiance = irradiance; #endif - irradiance = max(amblit,irradiance); + irradiance = max(amblit,irradiance) * ambocc; #if PBR_USE_IRRADIANCE_HACK irradiance += amblit*0.5*vec3(dot(n, light_dir)); #endif -- cgit v1.2.3 From 4e3ca393c0d569bd3343861f878e1772c8e1b102 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 11 Aug 2022 22:02:54 -0700 Subject: SL-17736: Remove Irradiance hack. Use EEP Reflection Probe Ambiance to adjust irradiance. --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 ---- 1 file changed, 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 510f8c8b45..d1c8ce9606 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -25,7 +25,6 @@ #define PBR_USE_ATMOS 0 #define PBR_USE_GGX_EMS_HACK 0 -#define PBR_USE_IRRADIANCE_HACK 1 #define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 @@ -292,9 +291,6 @@ void main() vec3 debug_irradiance = irradiance; #endif irradiance = max(amblit,irradiance) * ambocc; -#if PBR_USE_IRRADIANCE_HACK - irradiance += amblit*0.5*vec3(dot(n, light_dir)); -#endif specLight = srgb_to_linear(specLight); #if DEBUG_PBR_SPECLIGHT051 specLight = vec3(0,0.5,1.0); -- cgit v1.2.3 From c707b4015f83ef4623fdb0454160f79ec235abcf Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 16 Aug 2022 09:37:41 -0700 Subject: SL-17975: PBR: Fix sun/moon color not being applied --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index d1c8ce9606..18a2aeaeaa 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -23,7 +23,7 @@ * $/LicenseInfo$ */ -#define PBR_USE_ATMOS 0 +#define PBR_USE_ATMOS 1 #define PBR_USE_GGX_EMS_HACK 0 #define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight -- cgit v1.2.3 From e6171a8d097b2ac0242a29dcd78e297da27d7c97 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Mon, 22 Aug 2022 15:52:43 -0700 Subject: SL-17975: PBR: Add light debugging --- .../shaders/class3/deferred/multiPointLightF.glsl | 17 +++++++++++++++-- .../shaders/class3/deferred/multiSpotLightF.glsl | 22 ++++++++++++---------- .../shaders/class3/deferred/pointLightF.glsl | 16 +++++++++++++++- .../shaders/class3/deferred/spotLightF.glsl | 14 +++++++++++++- 4 files changed, 55 insertions(+), 14 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 399948459b..d8e1bba5d8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -27,7 +27,10 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_PBR_LIGHT_TYPE 0 +#define DEBUG_ANY_LIGHT_TYPE 0 // Output red light cone +#define DEBUG_PBR_LIGHT_TYPE 0 // Output PBR objects in red +#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in red +#define DEBUG_POINT_ZERO 0 // Output zero for spotlight #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -115,7 +118,7 @@ void main() } #if DEBUG_PBR_LIGHT_TYPE - colorDiffuse = vec3(0,0.5,0); colorSpec = vec3(0); + colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0); #endif final_color = colorDiffuse + colorSpec; } @@ -175,8 +178,18 @@ void main() } } } + #if DEBUG_LEG_LIGHT_TYPE + final_color.rgb = vec3(0.5,0,0.0); + #endif } +#if DEBUG_POINT_ZERO + final_color = vec3(0); +#endif +#if DEBUG_ANY_LIGHT_TYPE + final_color = vec3(0.3333,0,0); +#endif + frag_color.rgb = final_color; frag_color.a = 0.0; #endif // LOCAL_LIGHT_KILL diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index fdbeb34116..a9a2b8dcb4 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -28,8 +28,9 @@ /*[EXTRA_CODE_HERE]*/ +#define DEBUG_ANY_LIGHT_TYPE 0 // Output blue light cone +#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in blue #define DEBUG_PBR_LIGHT_TYPE 0 // Ouput gray if PBR multiSpot lights object -#define DEBUG_PBR_SPOT_ZERO 0 // Output zero for spotlight #define DEBUG_PBR_SPOT 0 #define DEBUG_PBR_SPOT_DIFFUSE 0 // PBR diffuse lit #define DEBUG_PBR_SPOT_SPECULAR 0 // PBR spec lit @@ -44,6 +45,7 @@ #define DEBUG_SPOT_NL 0 // monochome area effected by light #define DEBUG_SPOT_SPEC_POS 0 #define DEBUG_SPOT_REFLECTION 0 // color: pos reflected along n +#define DEBUG_SPOT_ZERO 0 // Output zero for spotlight #define DEBUG_PBR_LIGHT_H 0 // Half vector #define DEBUG_PBR_LIHGT_L 0 // Light vector @@ -108,6 +110,7 @@ uniform mat4 inv_proj; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); +vec3 colorized_dot(float x); bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); @@ -119,13 +122,6 @@ void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 vec3 srgb_to_linear(vec3 cs); vec4 texture2DLodSpecular(vec2 tc, float lod); -vec3 colorized_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 ); -} - vec4 getPosition(vec2 pos_screen); void main() @@ -238,7 +234,7 @@ void main() } #if DEBUG_PBR_LIGHT_TYPE - colorDiffuse = vec3(0.5); colorSpec = vec3(0); + colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0); #endif #if DEBUG_PBR_LIGHT_H @@ -324,6 +320,9 @@ void main() amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); final_color += diffuse.rgb * amb_rgb; +#if DEBUG_LEG_LIGHT_TYPE + final_color = vec3(0,0,0.5); +#endif } if (spec.a > 0.0) @@ -418,7 +417,10 @@ void main() final_color = reflect(normalize(pos), n); #endif #if DEBUG_SPOT_ZERO - final_color = vec3(0); + final_color = vec3(0,0,0); +#endif +#if DEBUG_ANY_LIGHT_TYPE + final_color = vec3(0,0,0.3333); #endif //not sure why, but this line prevents MATBUG-194 diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 42d7407456..a1298a8409 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -27,7 +27,10 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_PBR_LIGHT_TYPE 0 +#define DEBUG_ANY_LIGHT_TYPE 0 // Output magenta light cone +#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in green +#define DEBUG_PBR_LIGHT_TYPE 0 // Show PBR objects in blue +#define DEBUG_POINT_ZERO 0 // Output zero for point light #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -156,8 +159,19 @@ void main() { discard; } + +#if DEBUG_LEG_LIGHT_TYPE + final_color.rgb = vec3(0,0.25,0); +#endif } +#if DEBUG_POINT_ZERO + final_color = vec3(0); +#endif +#if DEBUG_ANY_LIGHT_TYPE + final_color = vec3(0.25,0,0.25); +#endif + frag_color.rgb = final_color; frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index d82baf0804..41e40a07e7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -28,12 +28,15 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_PBR_LIGHT_TYPE 0 +#define DEBUG_ANY_LIGHT_TYPE 0 // Output green light cone +#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in green +#define DEBUG_PBR_LIGHT_TYPE 0 // Show PBR objects in green #define DEBUG_PBR_SPOT 0 #define DEBUG_PBR_SPOT_DIFFUSE 0 #define DEBUG_PBR_SPOT_SPECULAR 0 #define DEBUG_SPOT_NL 0 // monochome area effected by light +#define DEBUG_SPOT_ZERO 0 // Output zero for spotlight #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -223,6 +226,9 @@ void main() vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); final_color += diffuse.rgb*amb_rgb; + #if DEBUG_LEG_LIGHT_TYPE + final_color = vec3(0,0.5,0); + #endif } if (spec.a > 0.0) @@ -278,6 +284,12 @@ void main() #if DEBUG_SPOT_NL final_color = vec3(nl); #endif +#if DEBUG_SPOT_ZERO + final_color = vec3(0,0,0); +#endif +#if DEBUG_ANY_LIGHT_TYPE + final_color = vec3(0,0.3333,0); +#endif //not sure why, but this line prevents MATBUG-194 final_color = max(final_color, vec3(0.0)); -- cgit v1.2.3 From d79af5b6de84ab37be30b070a96e016b5fd9be34 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 23 Aug 2022 02:18:24 -0700 Subject: SL-17703: PBR: Add debug ability to turn off IBL --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 18a2aeaeaa..f284afbad0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -25,6 +25,7 @@ #define PBR_USE_ATMOS 1 #define PBR_USE_GGX_EMS_HACK 0 +#define PBR_USE_IBL 1 #define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 @@ -59,6 +60,8 @@ #define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel #define DEBUG_PBR_KSPEC 0 // Output: K spec #define DEBUG_PBR_REFLECTION_DIR 0 // Output: reflection dir +#define DEBUG_PBR_SPEC_IBL 0 // Output: IBL specularity +#define DEBUG_PBR_SPEC_LEGACY 0 // Output: legacyenv #define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection #define DEBUG_PBR_FSS_ESS_GGX 0 // Output: FssEssGGX #define DEBUG_PBR_SPEC 0 // Output: Final spec @@ -300,7 +303,12 @@ void main() kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); #endif vec3 FssEssGGX = kSpec*vScaleBias.x + vScaleBias.y; +#if DEBUG_PBR_SPEC_IBL + vec3 debug_color_spec = specWeight * specLight * FssEssGGX; +#endif +#if PBR_USE_IBL colorSpec += specWeight * specLight * FssEssGGX; +#endif // Reference: getIBLRadianceLambertian vec3 FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term -- cgit v1.2.3 From f8974f4d783521846a985dd3d08067bd8e7f66a2 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 23 Aug 2022 02:19:29 -0700 Subject: SL-17703: Add debug output for ambocc and ambenv --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index f284afbad0..ed478fad1c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -79,6 +79,7 @@ #define DEBUG_PBR_DIFFUSE 0 // Output: diffuse post AO // Atmospheric Lighting +#define DEBUG_PBR_AMBENV 0 // Output: ambient environment #define DEBUG_PBR_AMBOCC 0 // Output: ambient occlusion #define DEBUG_PBR_DA_RAW 0 // Output: da pre pow() #define DEBUG_PBR_DA_POW 0 // Output: da post pow() @@ -476,9 +477,6 @@ void main() color.rgb = v*0.5 + vec3(0.5); #endif - #if DEBUG_PBR_AMBOCC - color.rgb = vec3(ambocc); - #endif #if DEBUG_PBR_DA_RAW color.rgb = vec3(debug_da); #endif @@ -558,12 +556,20 @@ else color = fogged.rgb; bloom = fogged.a; #endif + #if DEBUG_PBR_LIGHT_TYPE + color.rgb = vec3(0); + #endif // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... - //color = vec3(ambocc); //color = ambenv; //color.b = diffuse.a; frag_color.rgb = srgb_to_linear(color.rgb); } +#if DEBUG_PBR_AMBOCC + frag_color.rgb = vec3(ambocc); +#endif +#if DEBUG_PBR_AMBENV + frag_color.rgb = ambenv; +#endif frag_color.a = bloom; } -- cgit v1.2.3 From 5e41024b9c02176ccfe292f067fb34f0607e59d5 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 23 Aug 2022 02:22:03 -0700 Subject: SL-17703: PBR: Move IOR calcF0() to deferred utils --- .../shaders/class3/deferred/softenLightF.glsl | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index ed478fad1c..9253b63ca1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -138,6 +138,9 @@ vec3 getNorm(vec2 pos_screen); vec4 getPositionWithDepth(vec2 pos_screen, float depth); void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +float calcF0(float ior); +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); + float getAmbientClamp(); vec2 getGGX( vec2 brdfPoint ); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); @@ -154,18 +157,18 @@ void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); +// Debug Utils +vec3 BRDFDiffuse(vec3 color); +vec3 fresnelSchlick( vec3 reflect0, vec3 reflect90, float vh); +float D_GGX( float nh, float alphaRough ); +float V_GGX( float nl, float nv, float alphaRough ); + #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); #endif uniform vec3 view_dir; // PBR -vec3 calcBaseReflect0(float ior) -{ - vec3 reflect0 = vec3(pow((ior - 1.0) / (ior + 1.0), 2.0)); - return reflect0; -} - void main() { vec2 tc = vary_fragcoord.xy; @@ -241,10 +244,10 @@ void main() float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics) vec3 reflect0 = vec3(0.04); // -> incidence reflectance 0.04 #if HAS_IOR - reflect0 = calcBaseReflect0(IOR); + reflect0 = vec3(calcF0(IOR)); #endif #if DEBUG_PBR_REFLECT0_BASE - vec3 debug_reflect0 = reflect0; + vec3 debug_reflect0 = vec3(calcF0(IOR)); #endif float metal = packedORM.b; -- cgit v1.2.3 From df81e15ab81dd5e41e0d522e54177bbb7153c2dd Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 23 Aug 2022 02:26:15 -0700 Subject: SL-17703: Cleanup --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 9253b63ca1..847da4295d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -24,7 +24,6 @@ */ #define PBR_USE_ATMOS 1 -#define PBR_USE_GGX_EMS_HACK 0 #define PBR_USE_IBL 1 #define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight @@ -544,7 +543,7 @@ else if (envIntensity > 0.0) { // add environmentmap //fudge darker - legacyenv *= 0.5*diffuse.a+0.5;; + legacyenv *= 0.5*diffuse.a+0.5; applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); } -- cgit v1.2.3 From 7951a1554324054cfb8947272a82e21913145865 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 23 Aug 2022 02:50:51 -0700 Subject: SL-17703: PBR: Don't add diffuse if IBL off --- .../shaders/class3/deferred/softenLightF.glsl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 847da4295d..cd12003f89 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -87,6 +87,25 @@ #define DEBUG_PBR_SKY_ADDITIVE 0 // Output: additive #define DEBUG_PBR_SKY_ATTEN 0 // Output: greyscale atten.r +// Sun +#define DEBUG_PBR_SUN_FULL_BRIGHT 0 // Sunlit color = <1,1,1> +#define DEBUG_PBR_SUN_H 0 // Half Vector +#define DEBUG_PBR_SUN_L 0 // Light Vector +#define DEBUG_PBR_SUN_V 0 // Surface to Light Vector +#define DEBUG_PBR_SUN_NH 0 // dot(n,h) +#define DEBUG_PBR_SUN_NL 0 // dot(n,l) +#define DEBUG_PBR_SUN_NV 0 // dot(n,v) +#define DEBUG_PBR_SUN_VH 0 // dot(v,h) +#define DEBUG_PBR_SUN_REFLECT0 0 // reflect0 only +#define DEBUG_PBR_SUN_SPEC_FRESNEL 0 // Fresnel +#define DEBUG_PBR_SUN_SPEC_D 0 // D(h) +#define DEBUG_PBR_SUN_SPEC_V 0 // V(l,v,h) +#define DEBUG_PBR_SUN_SPEC_DF 0 // D() * F() +#define DEBUG_PBR_SUN_SPEC_DV 0 // D() * V() +#define DEBUG_PBR_SUN_SPEC_FV 0 // F() * V() +#define DEBUG_PBR_SUN_SPECULAR 0 // D() * F() * V() +#define DEBUG_PBR_SUN_SPEC_FUNC 0 // D() * F() * V() + #define DEBUG_PBR_IOR 0 // Output: grayscale IOR #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior #define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior @@ -320,7 +339,9 @@ void main() vec3 AvgEms = avg * Ems; vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms); vec3 kDiffuse = c_diff * (1.0 - FssEssLambert + FmsEms); +#if PBR_USE_IBL colorDiffuse += (FmsEms + kDiffuse) * irradiance; +#endif #if DEBUG_PBR_DIFFUSE_PRE_AO vec3 debug_diffuse = colorDiffuse; #endif -- cgit v1.2.3 From 71b7648d13f1182865cf7d584670088da8939ee0 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 23 Aug 2022 02:55:30 -0700 Subject: SL-17975: PBR: Factor ambient occlusion into specular --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index cd12003f89..6a4060beaa 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -267,7 +267,7 @@ void main() #if DEBUG_PBR_REFLECT0_BASE vec3 debug_reflect0 = vec3(calcF0(IOR)); #endif - + float ao = packedORM.r; float metal = packedORM.b; vec3 c_diff = mix(diffuse.rgb,vec3(0),metal); vec3 reflect90 = vec3(0); @@ -345,7 +345,9 @@ void main() #if DEBUG_PBR_DIFFUSE_PRE_AO vec3 debug_diffuse = colorDiffuse; #endif - colorDiffuse *= packedORM.r; // Occlusion -- NOTE: pbropaque will need occlusion_strength pre-multiplied into spec.r + + colorDiffuse *= ao; // Occlusion -- NOTE: pbropaque will need occlusion_strength pre-multiplied into spec.r + colorSpec *= ao; // Add in sun/moon reflection if (metal > 0.0) @@ -382,7 +384,7 @@ void main() color.rgb = diffuse.rgb; #endif #if DEBUG_PBR_OCCLUSION - color.rgb = vec3(packedORM.r); + color.rgb = vec3(ao); #endif #if DEBUG_PBR_ORM color.rgb = packedORM; -- cgit v1.2.3 From 6bc22eb6f458c73dfeb25cb5c011f5500103ae2d Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 23 Aug 2022 03:55:33 -0700 Subject: SL-17703: PBR: Add BRDF prototypes --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 6a4060beaa..dcb03642cd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -155,12 +155,16 @@ uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); +vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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 calcF0(float ior); 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); float getAmbientClamp(); vec2 getGGX( vec2 brdfPoint ); +void initMaterial( vec3 diffuse, vec3 packedORM, + out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -- cgit v1.2.3 From 459faa8f7f93b4a0f83b8862eb6b4679ed3635e6 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 23 Aug 2022 04:15:36 -0700 Subject: SL-17703: PBR: Clamp roughness to minimum to match Blender, etc. --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index dcb03642cd..5323159058 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -264,7 +264,6 @@ void main() packedORM = vec3(1,1,1); #endif float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics) - vec3 reflect0 = vec3(0.04); // -> incidence reflectance 0.04 #if HAS_IOR reflect0 = vec3(calcF0(IOR)); #endif @@ -274,7 +273,6 @@ void main() float ao = packedORM.r; float metal = packedORM.b; vec3 c_diff = mix(diffuse.rgb,vec3(0),metal); - vec3 reflect90 = vec3(0); vec3 v = -normalize(pos.xyz); #if DEBUG_PBR_VERT2CAM1 v = vec3(0,0,1); @@ -292,11 +290,11 @@ void main() float dotBV = clamp(dot(b,v),0,1); // Reference: getMetallicRoughnessInfo - float perceptualRough = packedORM.g; + vec3 base = linear_to_srgb(diffuse.rgb); + float perceptualRough = max(packedORM.g, 0.1); float alphaRough = perceptualRough * perceptualRough; - vec3 colorDiff = mix( diffuse.rgb, vec3(0) , metal); - reflect0 = mix( reflect0 , diffuse.rgb, metal); // reflect at 0 degrees - reflect90 = vec3(1); // reflect at 90 degrees + vec3 reflect0 = mix(vec3(0.04), base, metal); // incidence reflectance 0.04 -> reflect at 0 degrees + vec3 reflect90 = vec3(1); // reflect at 90 degrees #if DEBUG_PBR_REFLECTANCE float reflectance = max( max( reflect0.r, reflect0.g ), reflect0.b ); #endif -- cgit v1.2.3 From 9a592264423824010058f8232cc2d986658438bd Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 23 Aug 2022 04:21:32 -0700 Subject: SL-17703: PBR: Use BRDF for sun/moon diffuse and specular --- .../shaders/class3/deferred/softenLightF.glsl | 95 ++++++++++++++++++++-- 1 file changed, 86 insertions(+), 9 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 5323159058..356aed9f24 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -352,21 +352,98 @@ void main() colorSpec *= ao; // Add in sun/moon reflection - if (metal > 0.0) + vec3 h, l; + float nh, nl, nv, vh, lightDist; + calcHalfVectors(light_dir, n, v, h, l, nh, nl, nv, vh, lightDist); + + if (nl > 0.0 || nv > 0.0) { - vec3 r = reflect(pos.xyz, norm.xyz); - float sa = dot(normalize(r), light_dir.xyz); - float sun = texture2D(lightFunc, vec2(sa, metal)).r; - vec3 sunSpec = sunlit * scol * sun; - colorSpec += sunSpec * metal; - bloom = dot(sunSpec, sunSpec) / 6; +#if DEBUG_PBR_SUN_FULL_BRIGHT + vec3 sunlit = vec3(1); +#endif + vec3 c_diff, reflect0, reflect90; + initMaterial( base, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + + // scol = sun shadow + vec3 intensity = ambocc * sunlit * nl * scol; + colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); + bloom = dot(colorSpec, colorSpec) / 8.0; + + #if DEBUG_PBR_SUN_SPEC_FRESNEL + colorDiffuse = vec3(0); + colorSpec = fresnelSchlick( reflect0, reflect90, vh ); + #endif + #if DEBUG_PBR_SUN_SPEC_D + colorDiffuse = vec3(0); + colorSpec = vec3(D_GGX( nh, alphaRough )); + #endif + #if DEBUG_PBR_SUN_SPEC_V + colorDiffuse = vec3(0); + colorSpec = vec3(V_GGX( nl, nv, alphaRough )); + #endif + #if DEBUG_PBR_SUN_SPEC_DF + colorDiffuse = vec3(0); + colorSpec = fresnelSchlick( reflect0, reflect90, vh ); + colorSpec *= D_GGX( nh, alphaRough ); + #endif + #if DEBUG_PBR_SUN_SPEC_DV + colorDiffuse = vec3(0); + colorSpec = vec3(D_GGX( nh, alphaRough )); + colorSpec *= vec3(V_GGX( nl, nv, alphaRough )); + #endif + #if DEBUG_PBR_SUN_SPEC_FV + colorDiffuse = vec3(0); + colorSpec = fresnelSchlick( reflect0, reflect90, vh ); + colorSpec *= V_GGX( nl, nv, alphaRough ); + #endif + #if DEBUG_PBR_SUN_SPECULAR + colorDiffuse = vec3(0); + colorSpec = fresnelSchlick( reflect0, reflect90, vh ); + colorSpec *= D_GGX( nh, alphaRough ); + colorSpec *= V_GGX( nl, nv, alphaRough ); + #endif + #if DEBUG_PBR_SUN_SPEC_FUNC + colorDiffuse = vec3(0); + colorSpec = nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); + #endif + + #if DEBUG_PBR_SUN_DIFFUSE + colorDiffuse = linear_to_srgb(diffuse.rgb); + colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SUN_REFLECT0 + colorDiffuse = reflect0; + colorSpec = vec3(0); + #endif } + + #if DEBUG_PBR_SUN_H + colorDiffuse = h*0.5 + 0.5; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SUN_L + colorDiffuse = l*0.5 + 0.5; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SUN_V + colorDiffuse = v*0.5 + 0.5; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SUN_NH + colorDiffuse = colorize_dot(nh); colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SUN_NL + colorDiffuse = colorize_dot(nl); colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SUN_NV + colorDiffuse = colorize_dot(nv); colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SUN_VH + colorDiffuse = colorize_dot(vh); colorSpec = vec3(0); + #endif + color.rgb = colorDiffuse + colorEmissive + colorSpec; - vec3 sun_contrib = min(da, scol) * sunlit; #if PBR_USE_ATMOS color = linear_to_srgb(color); - color += 2.0*sun_contrib; // 2x = Undo legacy hack of calcAtmosphericVars() returning sunlight.rgb * 0.5; color *= atten.r; color += 2.0*additive; color = scaleSoftClipFrag(color); -- cgit v1.2.3 From 7c72b4be8c40f4963d4b51385ff0bc13da9a7c9e Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 24 Aug 2022 14:29:45 -0700 Subject: SL-17766: PBR: Refactor to use initMaterial() instead of duplicating material setup for both IBL and Sunlight BRDF --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 356aed9f24..e072748e8a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -264,15 +264,11 @@ void main() packedORM = vec3(1,1,1); #endif float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics) -#if HAS_IOR - reflect0 = vec3(calcF0(IOR)); -#endif #if DEBUG_PBR_REFLECT0_BASE vec3 debug_reflect0 = vec3(calcF0(IOR)); #endif float ao = packedORM.r; float metal = packedORM.b; - vec3 c_diff = mix(diffuse.rgb,vec3(0),metal); vec3 v = -normalize(pos.xyz); #if DEBUG_PBR_VERT2CAM1 v = vec3(0,0,1); @@ -292,15 +288,14 @@ void main() // Reference: getMetallicRoughnessInfo vec3 base = linear_to_srgb(diffuse.rgb); float perceptualRough = max(packedORM.g, 0.1); - float alphaRough = perceptualRough * perceptualRough; - vec3 reflect0 = mix(vec3(0.04), base, metal); // incidence reflectance 0.04 -> reflect at 0 degrees - vec3 reflect90 = vec3(1); // reflect at 90 degrees + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( base, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); #if DEBUG_PBR_REFLECTANCE float reflectance = max( max( reflect0.r, reflect0.g ), reflect0.b ); #endif // Common to RadianceGGX and RadianceLambertian - float specWeight = 1.0; vec2 brdfPoint = clamp(vec2(dotNV, perceptualRough), vec2(0,0), vec2(1,1)); vec2 vScaleBias = getGGX( brdfPoint); // Environment BRDF: scale and bias applied to reflect0 vec3 fresnelR = max(vec3(1.0 - perceptualRough), reflect0) - reflect0; // roughness dependent fresnel @@ -361,9 +356,6 @@ void main() #if DEBUG_PBR_SUN_FULL_BRIGHT vec3 sunlit = vec3(1); #endif - vec3 c_diff, reflect0, reflect90; - initMaterial( base, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - // scol = sun shadow vec3 intensity = ambocc * sunlit * nl * scol; colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); -- cgit v1.2.3 From 5a346844df747ada7468c5814c2d1cd7c5d74f60 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 24 Aug 2022 16:07:18 -0700 Subject: SL-17703: PBR: Add debug ability to turn sun/off, view sun contrib --- .../shaders/class3/deferred/softenLightF.glsl | 62 +++++++++++++++++----- 1 file changed, 50 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index e072748e8a..8ee8210fb8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -25,6 +25,7 @@ #define PBR_USE_ATMOS 1 #define PBR_USE_IBL 1 +#define PBR_USE_SUN 1 #define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 @@ -68,7 +69,7 @@ // IBL Diffuse #define DEBUG_PBR_DIFFUSE_C 0 // Output: diffuse non metal mix #define DEBUG_PBR_IRRADIANCE_RAW 0 // Output: Diffuse Irradiance pre-mix -#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance +#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance, NOTE: SSAO is factored in #define DEBUG_PBR_FSS_ESS_LAMBERT 0 // Output: FssEssLambert #define DEBUG_PBR_EMS 0 // Output: Ems = (1 - BRDF Scale + BRDF Bias) #define DEBUG_PBR_AVG 0 // Output: Avg @@ -89,6 +90,10 @@ // Sun #define DEBUG_PBR_SUN_FULL_BRIGHT 0 // Sunlit color = <1,1,1> +#define DEBUG_PBR_SUN_OUT_DIFFUSE 0 // Final sun diffuse : intensity * nl * diffuse +#define DEBUG_PBR_SUN_OUT_SPECULAR 0 // Final sun specular: intensity * nl * specular +#define DEBUG_PBR_SUN_LAMBERT 0 // BRDF Diffuse: Lambertian Diffuse color +#define DEBUG_PBR_SUN_LAMBERT_NL 0 // BRDF Diffuse: nl * Lambertian Diffuse color #define DEBUG_PBR_SUN_H 0 // Half Vector #define DEBUG_PBR_SUN_L 0 // Light Vector #define DEBUG_PBR_SUN_V 0 // Surface to Light Vector @@ -103,8 +108,8 @@ #define DEBUG_PBR_SUN_SPEC_DF 0 // D() * F() #define DEBUG_PBR_SUN_SPEC_DV 0 // D() * V() #define DEBUG_PBR_SUN_SPEC_FV 0 // F() * V() -#define DEBUG_PBR_SUN_SPECULAR 0 // D() * F() * V() -#define DEBUG_PBR_SUN_SPEC_FUNC 0 // D() * F() * V() +#define DEBUG_PBR_SUN_SPEC_DFV 0 // D() * F() * V() +#define DEBUG_PBR_SUN_SPEC_NL_DFV 0 // nl * D() * F() * V() #define DEBUG_PBR_IOR 0 // Output: grayscale IOR #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior @@ -353,63 +358,96 @@ void main() if (nl > 0.0 || nv > 0.0) { + vec3 sunColor = sunlit * 2.0; // Midday should have strong sunlight #if DEBUG_PBR_SUN_FULL_BRIGHT - vec3 sunlit = vec3(1); + sunColor = vec3(1); #endif // scol = sun shadow - vec3 intensity = ambocc * sunlit * nl * scol; - colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); - bloom = dot(colorSpec, colorSpec) / 8.0; + vec3 intensity = ambocc * sunColor * nl * scol; + vec3 sunDiffuse = intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); + bloom = dot(sunSpec, sunSpec) / 8.0; #if DEBUG_PBR_SUN_SPEC_FRESNEL colorDiffuse = vec3(0); colorSpec = fresnelSchlick( reflect0, reflect90, vh ); + bloom = 0; #endif #if DEBUG_PBR_SUN_SPEC_D colorDiffuse = vec3(0); colorSpec = vec3(D_GGX( nh, alphaRough )); + bloom = 0; #endif #if DEBUG_PBR_SUN_SPEC_V colorDiffuse = vec3(0); colorSpec = vec3(V_GGX( nl, nv, alphaRough )); + bloom = 0; #endif #if DEBUG_PBR_SUN_SPEC_DF colorDiffuse = vec3(0); colorSpec = fresnelSchlick( reflect0, reflect90, vh ); colorSpec *= D_GGX( nh, alphaRough ); + bloom = 0; #endif #if DEBUG_PBR_SUN_SPEC_DV colorDiffuse = vec3(0); colorSpec = vec3(D_GGX( nh, alphaRough )); colorSpec *= vec3(V_GGX( nl, nv, alphaRough )); + bloom = 0; #endif #if DEBUG_PBR_SUN_SPEC_FV colorDiffuse = vec3(0); colorSpec = fresnelSchlick( reflect0, reflect90, vh ); colorSpec *= V_GGX( nl, nv, alphaRough ); + bloom = 0; #endif - #if DEBUG_PBR_SUN_SPECULAR + #if DEBUG_PBR_SUN_SPEC_DFV colorDiffuse = vec3(0); colorSpec = fresnelSchlick( reflect0, reflect90, vh ); colorSpec *= D_GGX( nh, alphaRough ); colorSpec *= V_GGX( nl, nv, alphaRough ); + bloom = 0; #endif - #if DEBUG_PBR_SUN_SPEC_FUNC + #if DEBUG_PBR_SUN_SPEC_NL_DFV colorDiffuse = vec3(0); colorSpec = nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); #endif + #if DEBUG_PBR_SUN_FINAL + colorDiffuse = nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + colorSpec = nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); + #endif - #if DEBUG_PBR_SUN_DIFFUSE - colorDiffuse = linear_to_srgb(diffuse.rgb); + #if DEBUG_PBR_SUN_OUT_DIFFUSE + colorDiffuse = linear_to_srgb(sunDiffuse); + colorSpec = vec3(0); + bloom = 0.0; + #endif + #if DEBUG_PBR_SUN_OUT_SPECULAR + colorDiffuse = linear_to_srgb(sunSpec); colorSpec = vec3(0); #endif #if DEBUG_PBR_SUN_REFLECT0 colorDiffuse = reflect0; colorSpec = vec3(0); #endif + +#if PBR_USE_SUN + colorDiffuse += sunDiffuse; + colorSpec += sunSpec; +#endif } +#if DEBUG_PBR_SUN_LAMBERT + colorDiffuse = BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + colorSpec = vec3(0); + bloom = 0; +#endif +#if DEBUG_PBR_SUN_LAMBERT_NL + colorDiffuse = nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + colorSpec = vec3(0); + bloom = 0; +#endif + #if DEBUG_PBR_SUN_H colorDiffuse = h*0.5 + 0.5; colorSpec = vec3(0); #endif -- cgit v1.2.3 From becdf08d0f79a1a676fdc51d5c889dbab5954832 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 24 Aug 2022 17:21:32 -0700 Subject: SL-17702: PBR: Use legacy attenuation for point lights --- .../shaders/class3/deferred/multiPointLightF.glsl | 20 ++++++----------- .../shaders/class3/deferred/pointLightF.glsl | 25 ++++++++++------------ 2 files changed, 18 insertions(+), 27 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index d8e1bba5d8..98a03c2aaa 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -60,6 +60,7 @@ VARYING vec4 vary_fragcoord; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); +float calcLegacyDistanceAttenuation(float distance, float falloff); vec3 getLightIntensityPoint(vec3 lightColor, float lightRange, float lightDistance); vec4 getPosition(vec2 pos_screen); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); @@ -108,12 +109,11 @@ void main() if (nl > 0.0) { float dist = lightDist / lightSize; - float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); - dist_atten *= dist_atten; - dist_atten *= 2.0; - vec3 intensity = dist_atten * getLightIntensityPoint(lightColor, lightSize, lightDist); - colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); + float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); + + vec3 intensity = dist_atten * nl * lightColor; + colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } } @@ -146,13 +146,7 @@ void main() calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); 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; - + float dist_atten = calcLegacyDistanceAttenuation(dist, fa); dist_atten *= noise; float lit = nl * dist_atten; diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index a1298a8409..d65a53b6d3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -65,6 +65,7 @@ uniform vec4 viewport; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); +float calcLegacyDistanceAttenuation(float distance, float falloff); vec3 getLightIntensityPoint(vec3 lightColor, float lightRange, float lightDistance); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec4 getPosition(vec2 pos_screen); @@ -91,10 +92,12 @@ void main() float nh, nl, nv, vh, lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + if (lightDist >= size) + { + discard; + } float dist = lightDist / size; - float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); - dist_atten *= dist_atten; - dist_atten *= 2.0; + float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { @@ -102,6 +105,8 @@ void main() vec3 colorSpec = vec3(0); vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl + float lightSize = size; + vec3 lightColor = color; vec3 c_diff, reflect0, reflect90; float alphaRough, specWeight; @@ -109,26 +114,18 @@ void main() if (nl > 0.0) { - vec3 intensity = dist_atten * getLightIntensityPoint(color, size, lightDist); - colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); + vec3 intensity = dist_atten * nl * lightColor; // Legacy attenuation + colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } #if DEBUG_PBR_LIGHT_TYPE colorDiffuse = vec3(0,0,0.5); colorSpec = vec3(0); #endif - final_color = colorDiffuse + colorSpec; } else { - float dist = lightDist; - if (dist >= size) - { - discard; - } - dist /= size; - if (nl < 0.0) { discard; -- cgit v1.2.3 From b7cb20bfcdd0a8dab7882ccaad0982d3cdd65d5f Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 24 Aug 2022 22:59:28 -0700 Subject: SL-17702: PBR: Document lights are in linear from C++ side --- .../newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 98a03c2aaa..1175f3e644 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -100,7 +100,7 @@ void main() for (int light_idx = 0; light_idx < LIGHT_COUNT; ++light_idx) { - vec3 lightColor = light_col[ light_idx ].rgb; + vec3 lightColor = light_col[ light_idx ].rgb; // Already in linear, see pipeline.cpp: volume->getLightLinearColor(); float falloff = light_col[ light_idx ].a; float lightSize = light [ light_idx ].w; vec3 lv =(light [ light_idx ].xyz - pos); diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index d65a53b6d3..6f39b0173b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -106,7 +106,7 @@ void main() vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl float lightSize = size; - vec3 lightColor = color; + vec3 lightColor = color; // Already in linear, see pipeline.cpp: volume->getLightLinearColor(); vec3 c_diff, reflect0, reflect90; float alphaRough, specWeight; -- cgit v1.2.3 From 23126b78255adcb02bafe39891d31da70a0884e8 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 24 Aug 2022 23:03:31 -0700 Subject: SL-17703: PBR: Convert sunlight color in sRGB to Linear due to EEP/Windlight. --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8ee8210fb8..d4140a0d92 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -358,7 +358,7 @@ void main() if (nl > 0.0 || nv > 0.0) { - vec3 sunColor = sunlit * 2.0; // Midday should have strong sunlight + vec3 sunColor = srgb_to_linear(sunlit * 2.0); // NOTE: *2.0 Midday should have strong sunlight #if DEBUG_PBR_SUN_FULL_BRIGHT sunColor = vec3(1); #endif -- cgit v1.2.3 From 7923f255b6815f2a687ef1fbaad5ef11465d6756 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 25 Aug 2022 10:45:12 -0700 Subject: SL-17702: PBR: Fix light bleed out of range --- .../app_settings/shaders/class3/deferred/multiPointLightF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 1175f3e644..91d041cafa 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -76,6 +76,10 @@ void main() vec3 final_color = vec3(0, 0, 0); vec2 tc = getScreenXY(vary_fragcoord); vec3 pos = getPosition(tc).xyz; + if (pos.z < far_z) + { + discard; + } float envIntensity; // not used for this shader vec3 n; @@ -124,10 +128,6 @@ void main() } else { - if (pos.z < far_z) - { - discard; - } float noise = texture2D(noiseMap, tc/128.0).b; -- cgit v1.2.3 From 7ceaa01878c13082a3a803e1d369eaddfea76050 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Thu, 25 Aug 2022 15:45:15 -0700 Subject: SL-17703: PBR: Tweak sunlight scaling to better match Substance 3D Stager, don't blow bloom out --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index d4140a0d92..3f21bd0219 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -358,7 +358,8 @@ void main() if (nl > 0.0 || nv > 0.0) { - vec3 sunColor = srgb_to_linear(sunlit * 2.0); // NOTE: *2.0 Midday should have strong sunlight + float scale = 4.9; + vec3 sunColor = srgb_to_linear(sunlit * scale); // NOTE: Midday should have strong sunlight #if DEBUG_PBR_SUN_FULL_BRIGHT sunColor = vec3(1); #endif @@ -366,7 +367,7 @@ void main() vec3 intensity = ambocc * sunColor * nl * scol; vec3 sunDiffuse = intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); - bloom = dot(sunSpec, sunSpec) / 8.0; + bloom = dot(sunSpec, sunSpec) / (scale * scale * scale); #if DEBUG_PBR_SUN_SPEC_FRESNEL colorDiffuse = vec3(0); -- cgit v1.2.3 From 140909c77553db6115e4eeaf14afece498f0a140 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 25 Aug 2022 18:14:22 -0700 Subject: SL-17967 - .glsl typos. No we get pink PBR! --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 13 ++++++++----- .../app_settings/shaders/class3/deferred/spotLightF.glsl | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index d4140a0d92..9286c43ace 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -28,8 +28,8 @@ #define PBR_USE_SUN 1 #define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight -#define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 -#define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 +#define DEBUG_PBR_PACK_ORM0 0 // Rough=0, Metal=0 +#define DEBUG_PBR_PACK_ORM1 0 // Rough=1, Metal=1 #define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 #define DEBUG_PBR_VERT2CAM1 0 // vertex2camera = 0,0,1 #define DEBUG_PBR_SPECLIGHT051 0 // Force specLigh to be 0,0.5,1 @@ -72,6 +72,7 @@ #define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance, NOTE: SSAO is factored in #define DEBUG_PBR_FSS_ESS_LAMBERT 0 // Output: FssEssLambert #define DEBUG_PBR_EMS 0 // Output: Ems = (1 - BRDF Scale + BRDF Bias) +#define DEBUG_PBR_EMS_AVG 0 // Output: Avg Ems #define DEBUG_PBR_AVG 0 // Output: Avg #define DEBUG_PBR_FMS_EMS 0 // Output: FmsEms #define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms @@ -110,6 +111,7 @@ #define DEBUG_PBR_SUN_SPEC_FV 0 // F() * V() #define DEBUG_PBR_SUN_SPEC_DFV 0 // D() * F() * V() #define DEBUG_PBR_SUN_SPEC_NL_DFV 0 // nl * D() * F() * V() +#define DEBUG_PBR_SUN_FINAL 0 // LAMBERT_NL + NL_DFV ? #define DEBUG_PBR_IOR 0 // Output: grayscale IOR #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior @@ -323,9 +325,10 @@ void main() specLight = vec3(0,0.5,1.0); irradiance = specLight; #endif -#if HAS_IBL - kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); -#endif +// TODO: +//#if PBR_USE_IBL +// kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); +//#endif vec3 FssEssGGX = kSpec*vScaleBias.x + vScaleBias.y; #if DEBUG_PBR_SPEC_IBL vec3 debug_color_spec = specWeight * specLight * FssEssGGX; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 41e40a07e7..769589eff1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -278,7 +278,7 @@ void main() } } -#if DEBUG_SPOT_DIFFUSE +#if DEBUG_PBR_SPOT_DIFFUSE final_color = vec3(nl * dist_atten); #endif #if DEBUG_SPOT_NL -- cgit v1.2.3 From a8d122365db280d04552dbc23db9c43dbf1cb400 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 26 Aug 2022 09:48:18 -0700 Subject: SL-17967 - review comments --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 9286c43ace..01ed71d45d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -111,7 +111,7 @@ #define DEBUG_PBR_SUN_SPEC_FV 0 // F() * V() #define DEBUG_PBR_SUN_SPEC_DFV 0 // D() * F() * V() #define DEBUG_PBR_SUN_SPEC_NL_DFV 0 // nl * D() * F() * V() -#define DEBUG_PBR_SUN_FINAL 0 // LAMBERT_NL + NL_DFV ? +#define DEBUG_PBR_SUN_FINAL 0 // LAMBERT_NL + BRDF() #define DEBUG_PBR_IOR 0 // Output: grayscale IOR #define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior @@ -325,10 +325,6 @@ void main() specLight = vec3(0,0.5,1.0); irradiance = specLight; #endif -// TODO: -//#if PBR_USE_IBL -// kSpec = mix( kSpec, iridescenceFresnel, iridescenceFactor); -//#endif vec3 FssEssGGX = kSpec*vScaleBias.x + vScaleBias.y; #if DEBUG_PBR_SPEC_IBL vec3 debug_color_spec = specWeight * specLight * FssEssGGX; -- cgit v1.2.3 From dc8773ffe91d51f1918a7f6756b2746440d6a1b9 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 26 Aug 2022 15:09:02 -0700 Subject: SL-17703: PBR: Fix albedo being washed out due to wrong color space. --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 3f21bd0219..36407065c0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -291,7 +291,7 @@ void main() float dotBV = clamp(dot(b,v),0,1); // Reference: getMetallicRoughnessInfo - vec3 base = linear_to_srgb(diffuse.rgb); + vec3 base = diffuse.rgb; float perceptualRough = max(packedORM.g, 0.1); vec3 c_diff, reflect0, reflect90; float alphaRough, specWeight; -- cgit v1.2.3 From 8b45dfd477f6aedbf2c835fa276733ce6eba8e9f Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 26 Aug 2022 15:19:03 -0700 Subject: DRTVWR-559: PBR: Cleanup debug --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 36407065c0..02e7c55718 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -186,6 +186,7 @@ vec3 srgb_to_linear(vec3 c); // Debug Utils vec3 BRDFDiffuse(vec3 color); +vec3 colorize_dot(float x); vec3 fresnelSchlick( vec3 reflect0, vec3 reflect90, float vh); float D_GGX( float nh, float alphaRough ); float V_GGX( float nl, float nv, float alphaRough ); -- cgit v1.2.3 From 08c23419befc99f4b2de16cce9f296234e8b8f5a Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 26 Aug 2022 15:31:30 -0700 Subject: DRTVWR-559: PBR: Cleanup --- .../newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 91d041cafa..71135786c3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -68,6 +68,9 @@ vec2 getScreenXY(vec4 clip); void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); +// Util +vec3 hue_to_rgb(float hue); + void main() { #if defined(LOCAL_LIGHT_KILL) -- cgit v1.2.3 From dd3c13a198fcc61f9056d42d136265fc38c45aba Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 26 Aug 2022 15:51:39 -0700 Subject: SL-17766: PBR: Remove redundant misc. dot() calculations --- .../shaders/class3/deferred/softenLightF.glsl | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 02e7c55718..e5e0a37d4f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -287,9 +287,12 @@ void main() vec3 b = cross( n,t); vec3 reflectVN = normalize(reflect(-v,n)); - float dotNV = clamp(dot(n,v),0,1); - float dotTV = clamp(dot(t,v),0,1); - float dotBV = clamp(dot(b,v),0,1); + vec3 h, l; + float nh, nl, nv, vh, lightDist; + calcHalfVectors(light_dir, n, v, h, l, nh, nl, nv, vh, lightDist); + + float tv = clamp(dot(t,v),0,1); + float bv = clamp(dot(b,v),0,1); // Reference: getMetallicRoughnessInfo vec3 base = diffuse.rgb; @@ -302,10 +305,10 @@ void main() #endif // Common to RadianceGGX and RadianceLambertian - vec2 brdfPoint = clamp(vec2(dotNV, perceptualRough), vec2(0,0), vec2(1,1)); + vec2 brdfPoint = clamp(vec2(nv, perceptualRough), vec2(0,0), vec2(1,1)); vec2 vScaleBias = getGGX( brdfPoint); // Environment BRDF: scale and bias applied to reflect0 vec3 fresnelR = max(vec3(1.0 - perceptualRough), reflect0) - reflect0; // roughness dependent fresnel - vec3 kSpec = reflect0 + fresnelR*pow(1.0 - dotNV, 5.0); + vec3 kSpec = reflect0 + fresnelR*pow(1.0 - nv, 5.0); // Reference: getIBLRadianceGGX // https://forum.substance3d.com/index.php?topic=3243.0 @@ -353,10 +356,6 @@ void main() colorSpec *= ao; // Add in sun/moon reflection - vec3 h, l; - float nh, nl, nv, vh, lightDist; - calcHalfVectors(light_dir, n, v, h, l, nh, nl, nv, vh, lightDist); - if (nl > 0.0 || nv > 0.0) { float scale = 4.9; @@ -518,13 +517,13 @@ void main() color.rgb = b; #endif #if DEBUG_PBR_DOT_NV - color.rgb = vec3(dotNV); + color.rgb = vec3(nv); #endif #if DEBUG_PBR_DOT_TV - color.rgb = vec3(dotTV); + color.rgb = vec3(tv); #endif #if DEBUG_PBR_DOT_BV - color.rgb = vec3(dotBV); + color.rgb = vec3(bv); #endif #if DEBUG_PBR_AVG -- cgit v1.2.3 From d6e8a6c98aa426e8f1ee92cd7bc65703cf0a22aa Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 26 Aug 2022 17:47:47 -0700 Subject: SL-17703: PBR: revert dc8773ff, tweak sunlight albedo to be darker --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index e5e0a37d4f..998ebf8836 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -295,7 +295,7 @@ void main() float bv = clamp(dot(b,v),0,1); // Reference: getMetallicRoughnessInfo - vec3 base = diffuse.rgb; + vec3 base = linear_to_srgb(diffuse.rgb); float perceptualRough = max(packedORM.g, 0.1); vec3 c_diff, reflect0, reflect90; float alphaRough, specWeight; @@ -365,8 +365,8 @@ void main() #endif // scol = sun shadow vec3 intensity = ambocc * sunColor * nl * scol; - vec3 sunDiffuse = intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); + vec3 sunDiffuse = base * intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); bloom = dot(sunSpec, sunSpec) / (scale * scale * scale); #if DEBUG_PBR_SUN_SPEC_FRESNEL -- cgit v1.2.3 From e928e3fec4cd2b370421e592a1f01bb3874de67b Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 30 Aug 2022 13:57:46 -0500 Subject: SL-17705 AMD compatibility -- use a specific LoD of irradiance map to avoid black outlines on AMD --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 83348077d7..1f5fdde9ca 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -364,7 +364,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, vec3 c, float r2, int i) v -= c; v = env_mat * v; { - return texture(irradianceProbes, vec4(v.xyz, refIndex[i].x)).rgb * refParams[i].x; + return textureLod(irradianceProbes, vec4(v.xyz, refIndex[i].x), 0).rgb * refParams[i].x; } } -- cgit v1.2.3 From 2158162b50673afd7b93822823ce1f2be78e2842 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 30 Aug 2022 15:46:38 -0500 Subject: SL-18055 Fix for soft cube maps on chrome (don't clamp roughness value) --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 998ebf8836..34ebb67c3c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -296,7 +296,7 @@ void main() // Reference: getMetallicRoughnessInfo vec3 base = linear_to_srgb(diffuse.rgb); - float perceptualRough = max(packedORM.g, 0.1); + float perceptualRough = packedORM.g; // NOTE: do NOT clamp here to be consistent with Blender, Blender is wrong and Substance is right vec3 c_diff, reflect0, reflect90; float alphaRough, specWeight; initMaterial( base, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); -- cgit v1.2.3 From 8eaee1f033d9dac892e749cc65416e149021d8f6 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Tue, 30 Aug 2022 20:35:15 -0700 Subject: SL-17703: PBR: Fix albedo being in wrong color space, add support for debug default_irradiance.png --- .../shaders/class3/deferred/softenLightF.glsl | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 998ebf8836..56aa8437de 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -27,6 +27,10 @@ #define PBR_USE_IBL 1 #define PBR_USE_SUN 1 +#define PBR_USE_LINEAR_ALBEDO 1 +#define PBR_USE_DEFAULT_IRRADIANCE 0 // PBR: irradiance, skins/default/textures/default_irradiance.png +#define PBR_USE_IRRADIANCE_HACK 1 + #define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight #define DEBUG_PBR_PACKORM0 0 // Rough=0, Metal=0 #define DEBUG_PBR_PACKORM1 0 // Rough=1, Metal=1 @@ -135,6 +139,9 @@ uniform sampler2DRect diffuseRect; uniform sampler2DRect specularRect; uniform sampler2DRect normalMap; uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl +uniform sampler2D altDiffuseMap; // PBR: irradiance, skins/default/textures/default_irradiance.png + +const float M_PI = 3.14159265; #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) uniform sampler2DRect lightMap; @@ -295,7 +302,11 @@ void main() float bv = clamp(dot(b,v),0,1); // Reference: getMetallicRoughnessInfo +#if PBR_USE_LINEAR_ALBEDO + vec3 base = diffuse.rgb; +#else vec3 base = linear_to_srgb(diffuse.rgb); +#endif float perceptualRough = max(packedORM.g, 0.1); vec3 c_diff, reflect0, reflect90; float alphaRough, specWeight; @@ -321,7 +332,14 @@ void main() #if DEBUG_PBR_IRRADIANCE_RAW vec3 debug_irradiance = irradiance; #endif + +#if PBR_USE_DEFAULT_IRRADIANCE + vec2 iruv = vec2(0.5f + 0.5f * atan(reflectVN.z, reflectVN.x) / M_PI, 1.f - acos(reflectVN.y) / M_PI); + irradiance = texture2D(altDiffuseMap, iruv).rgb * ambocc; +#endif +#if PBR_USE_IRRADIANCE_HACK irradiance = max(amblit,irradiance) * ambocc; +#endif specLight = srgb_to_linear(specLight); #if DEBUG_PBR_SPECLIGHT051 specLight = vec3(0,0.5,1.0); @@ -365,8 +383,13 @@ void main() #endif // scol = sun shadow vec3 intensity = ambocc * sunColor * nl * scol; +#if PBR_USE_LINEAR_ALBEDO + vec3 sunDiffuse = intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); + vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); +#else vec3 sunDiffuse = base * intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); +#endif bloom = dot(sunSpec, sunSpec) / (scale * scale * scale); #if DEBUG_PBR_SUN_SPEC_FRESNEL @@ -577,9 +600,11 @@ void main() #endif #if DEBUG_PBR_IRRADIANCE_RAW color.rgb = debug_irradiance; + bloom = 0; #endif #if DEBUG_PBR_IRRADIANCE color.rgb = irradiance; + bloom = 0; #endif #if DEBUG_PBR_KSPEC color.rgb = kSpec; @@ -633,6 +658,7 @@ void main() #if DEBUG_PBR_LIGHT_TYPE color.rgb = vec3(0); #endif + frag_color.rgb = color.rgb; // PBR is done in linear } else -- cgit v1.2.3 From eff9f08bd9128bfa64ce1b86ce0d74a76d8cc548 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 31 Aug 2022 13:19:56 -0700 Subject: DRTVWR-559: PBR: Disable PBR bloom --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index fe829edb88..507eb37627 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -390,7 +390,10 @@ void main() vec3 sunDiffuse = base * intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); #endif - bloom = dot(sunSpec, sunSpec) / (scale * scale * scale); + // Disabling PBR bloom due to two reasons: + // 1. The glTF 2.0 Specification does not specify bloom, + // 2. As the camera moves there are lots of bloom shimmering. + //bloom = dot(sunSpec, sunSpec) / (scale * scale * scale); #if DEBUG_PBR_SUN_SPEC_FRESNEL colorDiffuse = vec3(0); -- cgit v1.2.3 From f4d7b11e16edc7fb803496801873a03587270e54 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 31 Aug 2022 20:59:43 -0700 Subject: SL-17975: PBR: Fix point light popping --- .../newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 71135786c3..679d3dacca 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -148,7 +148,7 @@ void main() float lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); - float fa = light_col[i].a + 1.0; + float fa = light_col[i].a; float dist_atten = calcLegacyDistanceAttenuation(dist, fa); dist_atten *= noise; -- cgit v1.2.3 From 17a957fe44539a3d076e67ffc352036051814359 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 31 Aug 2022 21:00:58 -0700 Subject: DRTVWR-559: PBR: Cleanup: Don't do redundant dot(n,l) calc --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 507eb37627..85bb9fbbd1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -214,12 +214,7 @@ void main() norm.xyz = getNorm(tc); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); -#if DEBUG_PBR_DA_RAW - float debug_da = da; -#endif float light_gamma = 1.0 / 1.3; - da = pow(da, light_gamma); vec4 diffuse = texture2DRect(diffuseRect, tc); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR sRGB Emissive @@ -666,6 +661,12 @@ void main() } else { + float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); +#if DEBUG_PBR_DA_RAW + float debug_da = da; +#endif + da = pow(da, light_gamma); + diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); -- cgit v1.2.3 From 539fd5fcf9fa1872996fbb687b49307737f1c8b5 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 31 Aug 2022 21:04:45 -0700 Subject: SL-17975: PBR: Don't process point light if outside light radius --- .../app_settings/shaders/class3/deferred/multiPointLightF.glsl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 679d3dacca..c7c241b76e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -30,7 +30,7 @@ #define DEBUG_ANY_LIGHT_TYPE 0 // Output red light cone #define DEBUG_PBR_LIGHT_TYPE 0 // Output PBR objects in red #define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in red -#define DEBUG_POINT_ZERO 0 // Output zero for spotlight +#define DEBUG_POINT_ZERO 0 // Output zero for point lights #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -113,11 +113,10 @@ void main() vec3 lv =(light [ light_idx ].xyz - pos); calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); - if (nl > 0.0) + float dist = lightDist / lightSize; + if (dist <= 1.0 && nl > 0.0) { - float dist = lightDist / lightSize; float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); - vec3 intensity = dist_atten * nl * lightColor; colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); -- cgit v1.2.3 From ce685a12b9acc888a39c336c91ae6272db74ce91 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Wed, 31 Aug 2022 21:06:41 -0700 Subject: DRTVWR-559: PBR: Cleanup distance attenuation calcs --- .../app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 5 ++--- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index a9a2b8dcb4..3efc9c1689 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -110,6 +110,7 @@ uniform mat4 inv_proj; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); +float calcLegacyDistanceAttenuation(float distance, float falloff); vec3 colorized_dot(float x); bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); @@ -155,9 +156,7 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); - float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); - dist_atten *= dist_atten; - dist_atten *= 2.0; + float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); if (dist_atten <= 0.0) { discard; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 41e40a07e7..87b7977f64 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -85,6 +85,7 @@ uniform mat4 inv_proj; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); +float calcLegacyDistanceAttenuation(float distance, float falloff); bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); @@ -129,9 +130,7 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() - float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); - dist_atten *= dist_atten; - dist_atten *= 2.0; + float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); if (dist_atten <= 0.0) { discard; -- cgit v1.2.3 From ef98be881c3f13e7668f75cb0d302261053d9804 Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Thu, 1 Sep 2022 17:30:48 -0400 Subject: Use an SRGB buffer for initial reflection map capture for proper linear sampling Fix irradiance gen up vector to be properly normalized --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 85bb9fbbd1..e6017534ca 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -335,7 +335,6 @@ void main() #if PBR_USE_IRRADIANCE_HACK irradiance = max(amblit,irradiance) * ambocc; #endif - specLight = srgb_to_linear(specLight); #if DEBUG_PBR_SPECLIGHT051 specLight = vec3(0,0.5,1.0); irradiance = specLight; @@ -670,6 +669,9 @@ else diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + ambenv.rgb = linear_to_srgb(ambenv.rgb); + glossenv.rgb = linear_to_srgb(glossenv.rgb); + legacyenv.rgb = linear_to_srgb(legacyenv.rgb); amblit = max(ambenv, amblit); color.rgb = amblit*ambocc; -- cgit v1.2.3 From 88e1740d205bdfaa57d1d5dec4e6e9e755eae075 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 1 Sep 2022 16:18:14 -0700 Subject: SL-17967 - block layout binding acceptable to apple --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 1f5fdde9ca..3ff039261b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -33,7 +33,7 @@ uniform samplerCubeArray reflectionProbes; uniform samplerCubeArray irradianceProbes; -layout (std140, binding = 1) uniform ReflectionProbes +layout (std140) uniform ReflectionProbes { // list of OBBs for user override probes // box is a set of 3 planes outward facing planes and the depth of the box along that plane -- cgit v1.2.3 From d9d33c15973550efdb428a165aacd3ccdd7cc14f Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 2 Sep 2022 00:00:30 -0700 Subject: SL-18082: PBR: Fix spotlight color and seam --- .../app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 10 ++++++++-- .../app_settings/shaders/class3/deferred/spotLightF.glsl | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 3efc9c1689..7e81516f93 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -125,6 +125,8 @@ vec4 texture2DLodSpecular(vec2 tc, float lod); vec4 getPosition(vec2 pos_screen); +const float M_PI = 3.14159265; + void main() { #if defined(LOCAL_LIGHT_KILL) @@ -201,8 +203,12 @@ void main() dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); slit = getProjectedLightSpecularColor( pos, n ); - colorDiffuse = shadow * lit * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); - colorSpec = shadow * lit * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); + float exposure = M_PI; + dlit *= exposure; + slit *= exposure; + + colorDiffuse = shadow * lit * dlit * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); + colorSpec = shadow * lit * slit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); #if DEBUG_PBR_SPOT_DIFFUSE colorDiffuse = dlit.rgb; colorSpec = vec3(0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 87b7977f64..f186db5a50 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -99,6 +99,8 @@ vec4 texture2DLodSpecular(vec2 tc, float lod); vec4 getPosition(vec2 pos_screen); +const float M_PI = 3.14159265; + void main() { #if defined(LOCAL_LIGHT_KILL) @@ -173,8 +175,12 @@ void main() dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); slit = getProjectedLightSpecularColor( pos, n ); - colorDiffuse = shadow * dist_atten * nl * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); - colorSpec = shadow * dist_atten * nl * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); + float exposure = M_PI; + dlit *= exposure; + slit *= exposure; + + colorDiffuse = shadow * lit * dlit * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); + colorSpec = shadow * lit * slit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); #if DEBUG_PBR_SPOT_DIFFUSE colorDiffuse = dlit.rgb; colorSpec = vec3(0); -- cgit v1.2.3 From 7bb5315847f6ad68927efac9914bee3bb81bb894 Mon Sep 17 00:00:00 2001 From: Ptolemy Date: Fri, 2 Sep 2022 09:53:02 -0700 Subject: DRTVWR-559: PBR: Show sun in specular spotlight relfection --- indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 1 + indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 1 + 2 files changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 7e81516f93..bc4b4eb7e1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -209,6 +209,7 @@ void main() colorDiffuse = shadow * lit * dlit * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); colorSpec = shadow * lit * slit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + colorSpec += shadow * lit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); #if DEBUG_PBR_SPOT_DIFFUSE colorDiffuse = dlit.rgb; colorSpec = vec3(0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index f186db5a50..9153fe031e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -181,6 +181,7 @@ void main() colorDiffuse = shadow * lit * dlit * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); colorSpec = shadow * lit * slit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + colorSpec += shadow * lit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); #if DEBUG_PBR_SPOT_DIFFUSE colorDiffuse = dlit.rgb; colorSpec = vec3(0); -- cgit v1.2.3 From 402ab8c8f657f050a2ea30ebe562008130cb9bcd Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 13 Sep 2022 15:25:15 -0500 Subject: SL-17701 WIP -- Cleanup/refactor PBR lighting implementation and get parity between deferred and alpha passes for sunlight and IBL. --- .../shaders/class3/deferred/softenLightF.glsl | 637 +++------------------ 1 file changed, 89 insertions(+), 548 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index d78c47a36a..50aa93fea6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -23,106 +23,6 @@ * $/LicenseInfo$ */ -#define PBR_USE_ATMOS 1 -#define PBR_USE_IBL 1 -#define PBR_USE_SUN 1 - -#define PBR_USE_LINEAR_ALBEDO 1 -#define PBR_USE_DEFAULT_IRRADIANCE 0 // PBR: irradiance, skins/default/textures/default_irradiance.png -#define PBR_USE_IRRADIANCE_HACK 1 - -#define DEBUG_PBR_LIGHT_TYPE 0 // Output no global light to make it easier to see pointLight and spotLight -#define DEBUG_PBR_PACK_ORM0 0 // Rough=0, Metal=0 -#define DEBUG_PBR_PACK_ORM1 0 // Rough=1, Metal=1 -#define DEBUG_PBR_TANGENT1 1 // Tangent = 1,0,0 -#define DEBUG_PBR_VERT2CAM1 0 // vertex2camera = 0,0,1 -#define DEBUG_PBR_SPECLIGHT051 0 // Force specLigh to be 0,0.5,1 - -// Pass input through "as is" -#define DEBUG_PBR_DIFFUSE_MAP 0 // Output: use diffuse in G-Buffer -#define DEBUG_PBR_EMISSIVE 0 // Output: Emissive -#define DEBUG_PBR_METAL 0 // Output: grayscale Metal map -#define DEBUG_PBR_NORMAL_MAP 0 // Output: Normal -- also need to set DEBUG_NORMAL_MAP in pbropaqueF -#define DEBUG_PBR_OCCLUSION 0 // Output: grayscale Occlusion map -#define DEBUG_PBR_ORM 0 // Output: Packed Occlusion Roughness Metal -#define DEBUG_PBR_ROUGH_PERCEPTUAL 0 // Output: grayscale Perceptual Roughness map -#define DEBUG_PBR_ROUGH_ALPHA 0 // Output: grayscale Alpha Roughness - -#define DEBUG_PBR_TANGENT 0 // Output: Tangent -#define DEBUG_PBR_BITANGENT 0 // Output: Bitangent -#define DEBUG_PBR_DOT_BV 0 // Output: graysacle dot(Bitangent,Vertex2Camera) -#define DEBUG_PBR_DOT_TV 0 // Output: grayscale dot(Tangent ,Vertex2Camera) - -// IBL Spec -#define DEBUG_PBR_NORMAL 0 // Output: passed in normal -#define DEBUG_PBR_V2C_RAW 0 // Output: vertex2camera -#define DEBUG_PBR_DOT_NV 0 // Output: grayscale dot(Normal ,Vertex2Camera) -#define DEBUG_PBR_BRDF_UV 0 // Output: red green BRDF UV (GGX input) -#define DEBUG_PBR_BRDF_SCALE_BIAS 0 // Output: red green BRDF Scale Bias (GGX output) -#define DEBUG_PBR_BRDF_SCALE_ONLY 0 // Output: grayscale BRDF Scale -#define DEBUG_PBR_BRDF_BIAS_ONLY 0 // Output: grayscale BRDER Bias -#define DEBUG_PBR_FRESNEL 0 // Output: roughness dependent fresnel -#define DEBUG_PBR_KSPEC 0 // Output: K spec -#define DEBUG_PBR_REFLECTION_DIR 0 // Output: reflection dir -#define DEBUG_PBR_SPEC_IBL 0 // Output: IBL specularity -#define DEBUG_PBR_SPEC_LEGACY 0 // Output: legacyenv -#define DEBUG_PBR_SPEC_REFLECTION 0 // Output: environment reflection -#define DEBUG_PBR_FSS_ESS_GGX 0 // Output: FssEssGGX -#define DEBUG_PBR_SPEC 0 // Output: Final spec - -// IBL Diffuse -#define DEBUG_PBR_DIFFUSE_C 0 // Output: diffuse non metal mix -#define DEBUG_PBR_IRRADIANCE_RAW 0 // Output: Diffuse Irradiance pre-mix -#define DEBUG_PBR_IRRADIANCE 0 // Output: Diffuse Irradiance, NOTE: SSAO is factored in -#define DEBUG_PBR_FSS_ESS_LAMBERT 0 // Output: FssEssLambert -#define DEBUG_PBR_EMS 0 // Output: Ems = (1 - BRDF Scale + BRDF Bias) -#define DEBUG_PBR_EMS_AVG 0 // Output: Avg Ems -#define DEBUG_PBR_AVG 0 // Output: Avg -#define DEBUG_PBR_FMS_EMS 0 // Output: FmsEms -#define DEBUG_PBR_DIFFUSE_K 0 // Output: diffuse FssEssLambert + FmsEms -#define DEBUG_PBR_DIFFUSE_PRE_AO 0 // Output: diffuse pre AO -#define DEBUG_PBR_DIFFUSE 0 // Output: diffuse post AO - -// Atmospheric Lighting -#define DEBUG_PBR_AMBENV 0 // Output: ambient environment -#define DEBUG_PBR_AMBOCC 0 // Output: ambient occlusion -#define DEBUG_PBR_DA_RAW 0 // Output: da pre pow() -#define DEBUG_PBR_DA_POW 0 // Output: da post pow() -#define DEBUG_PBR_SUN_LIT 0 // Ouput: sunlit -#define DEBUG_PBR_SUN_CONTRIB 0 // Output: sun_contrib -#define DEBUG_PBR_SKY_ADDITIVE 0 // Output: additive -#define DEBUG_PBR_SKY_ATTEN 0 // Output: greyscale atten.r - -// Sun -#define DEBUG_PBR_SUN_FULL_BRIGHT 0 // Sunlit color = <1,1,1> -#define DEBUG_PBR_SUN_OUT_DIFFUSE 0 // Final sun diffuse : intensity * nl * diffuse -#define DEBUG_PBR_SUN_OUT_SPECULAR 0 // Final sun specular: intensity * nl * specular -#define DEBUG_PBR_SUN_LAMBERT 0 // BRDF Diffuse: Lambertian Diffuse color -#define DEBUG_PBR_SUN_LAMBERT_NL 0 // BRDF Diffuse: nl * Lambertian Diffuse color -#define DEBUG_PBR_SUN_H 0 // Half Vector -#define DEBUG_PBR_SUN_L 0 // Light Vector -#define DEBUG_PBR_SUN_V 0 // Surface to Light Vector -#define DEBUG_PBR_SUN_NH 0 // dot(n,h) -#define DEBUG_PBR_SUN_NL 0 // dot(n,l) -#define DEBUG_PBR_SUN_NV 0 // dot(n,v) -#define DEBUG_PBR_SUN_VH 0 // dot(v,h) -#define DEBUG_PBR_SUN_REFLECT0 0 // reflect0 only -#define DEBUG_PBR_SUN_SPEC_FRESNEL 0 // Fresnel -#define DEBUG_PBR_SUN_SPEC_D 0 // D(h) -#define DEBUG_PBR_SUN_SPEC_V 0 // V(l,v,h) -#define DEBUG_PBR_SUN_SPEC_DF 0 // D() * F() -#define DEBUG_PBR_SUN_SPEC_DV 0 // D() * V() -#define DEBUG_PBR_SUN_SPEC_FV 0 // F() * V() -#define DEBUG_PBR_SUN_SPEC_DFV 0 // D() * F() * V() -#define DEBUG_PBR_SUN_SPEC_NL_DFV 0 // nl * D() * F() * V() -#define DEBUG_PBR_SUN_FINAL 0 // LAMBERT_NL + BRDF() - -#define DEBUG_PBR_IOR 0 // Output: grayscale IOR -#define DEBUG_PBR_REFLECT0_BASE 0 // Output: black reflect0 default from ior -#define DEBUG_PBR_REFLECT0_MIX 0 // Output: diffuse reflect0 calculated from ior -#define DEBUG_PBR_REFLECTANCE 0 // Output: diffuse reflectance -- NOT USED -#define DEBUG_PBR_SPEC_WEIGHT 0 // Output: specWeight -#define DEBUG_PBR_V2C_REMAP 0 // Output: vertex2camera (remap [-1,1] -> [0,1]) #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable @@ -169,16 +69,7 @@ uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); vec4 getPositionWithDepth(vec2 pos_screen, float depth); -vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); -vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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 calcF0(float ior); -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); - -float getAmbientClamp(); -vec2 getGGX( vec2 brdfPoint ); -void initMaterial( vec3 diffuse, vec3 packedORM, - out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFrag(vec3 l); vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); @@ -193,18 +84,39 @@ void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); -// Debug Utils -vec3 BRDFDiffuse(vec3 color); -vec3 colorize_dot(float x); -vec3 fresnelSchlick( vec3 reflect0, vec3 reflect90, float vh); -float D_GGX( float nh, float alphaRough ); -float V_GGX( float nl, float nv, float alphaRough ); - #ifdef WATER_FOG vec4 applyWaterFogView(vec3 pos, vec4 color); #endif -uniform vec3 view_dir; // PBR +// PBR interface +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); +void initMaterial( vec3 diffuse, vec3 packedORM, + out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); +// perform PBR image based lighting according to GLTF spec +// all parameters are in linear space +void pbrIbl(out vec3 colorDiffuse, // diffuse color output + out vec3 colorSpec, // specular color output, + vec3 radiance, // radiance map sample + vec3 irradiance, // irradiance map sample + float ao, // ambient occlusion factor + float nv, + float perceptualRough, // roughness factor + float gloss, // 1.0 - roughness factor + vec3 reflect0, + vec3 c_diff); + +void pbrDirectionalLight(inout vec3 colorDiffuse, + inout vec3 colorSpec, + vec3 sunlit, + float scol, + vec3 reflect0, + vec3 reflect90, + vec3 c_diff, + float alphaRough, + float vh, + float nl, + float nv, + float nh); void main() { @@ -241,8 +153,6 @@ void main() calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); - //vec3 amb_vec = env_mat * norm.xyz; - vec3 ambenv; vec3 glossenv; vec3 legacyenv; @@ -262,480 +172,111 @@ void main() vec3 colorDiffuse = vec3(0); vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl vec3 colorSpec = vec3(0); -// vec3 colorClearCoat = vec3(0); -// vec3 colorSheen = vec3(0); -// vec3 colorTransmission = vec3(0); vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl -#if DEBUG_PBR_PACK_ORM0 - packedORM = vec3(0,0,0); -#endif -#if DEBUG_PBR_PACK_ORM1 - packedORM = vec3(1,1,1); -#endif float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics) -#if DEBUG_PBR_REFLECT0_BASE - vec3 debug_reflect0 = vec3(calcF0(IOR)); -#endif float ao = packedORM.r; float metal = packedORM.b; vec3 v = -normalize(pos.xyz); -#if DEBUG_PBR_VERT2CAM1 - v = vec3(0,0,1); -#endif vec3 n = norm.xyz; -// vec3 t = texture2DRect(tangentMap, tc).rgb; -#if DEBUG_PBR_TANGENT1 - vec3 t = vec3(1,0,0); -#endif - vec3 b = cross( n,t); - vec3 reflectVN = normalize(reflect(-v,n)); vec3 h, l; float nh, nl, nv, vh, lightDist; calcHalfVectors(light_dir, n, v, h, l, nh, nl, nv, vh, lightDist); - float tv = clamp(dot(t,v),0,1); - float bv = clamp(dot(b,v),0,1); - - // Reference: getMetallicRoughnessInfo -#if PBR_USE_LINEAR_ALBEDO - vec3 base = diffuse.rgb; -#else - vec3 base = linear_to_srgb(diffuse.rgb); -#endif float perceptualRough = packedORM.g; // NOTE: do NOT clamp here to be consistent with Blender, Blender is wrong and Substance is right + vec3 c_diff, reflect0, reflect90; float alphaRough, specWeight; - initMaterial( base, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); -#if DEBUG_PBR_REFLECTANCE - float reflectance = max( max( reflect0.r, reflect0.g ), reflect0.b ); -#endif - - // Common to RadianceGGX and RadianceLambertian - vec2 brdfPoint = clamp(vec2(nv, perceptualRough), vec2(0,0), vec2(1,1)); - vec2 vScaleBias = getGGX( brdfPoint); // Environment BRDF: scale and bias applied to reflect0 - vec3 fresnelR = max(vec3(1.0 - perceptualRough), reflect0) - reflect0; // roughness dependent fresnel - vec3 kSpec = reflect0 + fresnelR*pow(1.0 - nv, 5.0); + initMaterial( diffuse.rgb, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - // Reference: getIBLRadianceGGX - // https://forum.substance3d.com/index.php?topic=3243.0 - // Glossiness - // This map is the inverse of the roughness map. - vec3 irradiance = vec3(0); - vec3 specLight = vec3(0); float gloss = 1.0 - perceptualRough; - sampleReflectionProbes(irradiance, specLight, legacyenv, pos.xyz, norm.xyz, gloss, 0.0); -#if DEBUG_PBR_IRRADIANCE_RAW - vec3 debug_irradiance = irradiance; -#endif - -#if PBR_USE_DEFAULT_IRRADIANCE - vec2 iruv = vec2(0.5f + 0.5f * atan(reflectVN.z, reflectVN.x) / M_PI, 1.f - acos(reflectVN.y) / M_PI); - irradiance = texture2D(altDiffuseMap, iruv).rgb * ambocc; -#endif -#if PBR_USE_IRRADIANCE_HACK + vec3 irradiance = vec3(0); + vec3 radiance = vec3(0); + sampleReflectionProbes(irradiance, radiance, legacyenv, pos.xyz, norm.xyz, gloss, 0.0); irradiance = max(amblit,irradiance) * ambocc; -#endif -#if DEBUG_PBR_SPECLIGHT051 - specLight = vec3(0,0.5,1.0); - irradiance = specLight; -#endif - vec3 FssEssGGX = kSpec*vScaleBias.x + vScaleBias.y; -#if DEBUG_PBR_SPEC_IBL - vec3 debug_color_spec = specWeight * specLight * FssEssGGX; -#endif -#if PBR_USE_IBL - colorSpec += specWeight * specLight * FssEssGGX; -#endif - - // Reference: getIBLRadianceLambertian - vec3 FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term - float Ems = 1.0 - (vScaleBias.x + vScaleBias.y); - vec3 avg = specWeight * (reflect0 + (1.0 - reflect0) / 21.0); - vec3 AvgEms = avg * Ems; - vec3 FmsEms = AvgEms * FssEssLambert / (1.0 - AvgEms); - vec3 kDiffuse = c_diff * (1.0 - FssEssLambert + FmsEms); -#if PBR_USE_IBL - colorDiffuse += (FmsEms + kDiffuse) * irradiance; -#endif - #if DEBUG_PBR_DIFFUSE_PRE_AO - vec3 debug_diffuse = colorDiffuse; - #endif - - colorDiffuse *= ao; // Occlusion -- NOTE: pbropaque will need occlusion_strength pre-multiplied into spec.r - colorSpec *= ao; - // Add in sun/moon reflection + pbrIbl(colorDiffuse, colorSpec, radiance, irradiance, ao, nv, perceptualRough, gloss, reflect0, c_diff); + + // Add in sun/moon punctual light if (nl > 0.0 || nv > 0.0) { - float scale = 4.9; - vec3 sunColor = srgb_to_linear(sunlit * scale); // NOTE: Midday should have strong sunlight -#if DEBUG_PBR_SUN_FULL_BRIGHT - sunColor = vec3(1); -#endif - // scol = sun shadow - vec3 intensity = ambocc * sunColor * nl * scol; -#if PBR_USE_LINEAR_ALBEDO - vec3 sunDiffuse = intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); -#else - vec3 sunDiffuse = base * intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - vec3 sunSpec = intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); -#endif - // Disabling PBR bloom due to two reasons: - // 1. The glTF 2.0 Specification does not specify bloom, - // 2. As the camera moves there are lots of bloom shimmering. - //bloom = dot(sunSpec, sunSpec) / (scale * scale * scale); - - #if DEBUG_PBR_SUN_SPEC_FRESNEL - colorDiffuse = vec3(0); - colorSpec = fresnelSchlick( reflect0, reflect90, vh ); - bloom = 0; - #endif - #if DEBUG_PBR_SUN_SPEC_D - colorDiffuse = vec3(0); - colorSpec = vec3(D_GGX( nh, alphaRough )); - bloom = 0; - #endif - #if DEBUG_PBR_SUN_SPEC_V - colorDiffuse = vec3(0); - colorSpec = vec3(V_GGX( nl, nv, alphaRough )); - bloom = 0; - #endif - #if DEBUG_PBR_SUN_SPEC_DF - colorDiffuse = vec3(0); - colorSpec = fresnelSchlick( reflect0, reflect90, vh ); - colorSpec *= D_GGX( nh, alphaRough ); - bloom = 0; - #endif - #if DEBUG_PBR_SUN_SPEC_DV - colorDiffuse = vec3(0); - colorSpec = vec3(D_GGX( nh, alphaRough )); - colorSpec *= vec3(V_GGX( nl, nv, alphaRough )); - bloom = 0; - #endif - #if DEBUG_PBR_SUN_SPEC_FV - colorDiffuse = vec3(0); - colorSpec = fresnelSchlick( reflect0, reflect90, vh ); - colorSpec *= V_GGX( nl, nv, alphaRough ); - bloom = 0; - #endif - #if DEBUG_PBR_SUN_SPEC_DFV - colorDiffuse = vec3(0); - colorSpec = fresnelSchlick( reflect0, reflect90, vh ); - colorSpec *= D_GGX( nh, alphaRough ); - colorSpec *= V_GGX( nl, nv, alphaRough ); - bloom = 0; - #endif - #if DEBUG_PBR_SUN_SPEC_NL_DFV - colorDiffuse = vec3(0); - colorSpec = nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); - #endif - #if DEBUG_PBR_SUN_FINAL - colorDiffuse = nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - colorSpec = nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); - #endif - - #if DEBUG_PBR_SUN_OUT_DIFFUSE - colorDiffuse = linear_to_srgb(sunDiffuse); - colorSpec = vec3(0); - bloom = 0.0; - #endif - #if DEBUG_PBR_SUN_OUT_SPECULAR - colorDiffuse = linear_to_srgb(sunSpec); - colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SUN_REFLECT0 - colorDiffuse = reflect0; - colorSpec = vec3(0); - #endif - -#if PBR_USE_SUN - colorDiffuse += sunDiffuse; - colorSpec += sunSpec; -#endif + pbrDirectionalLight(colorDiffuse, colorSpec, srgb_to_linear(sunlit), scol, reflect0, reflect90, c_diff, alphaRough, vh, nl, nv, nh); } -#if DEBUG_PBR_SUN_LAMBERT - colorDiffuse = BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - colorSpec = vec3(0); - bloom = 0; -#endif -#if DEBUG_PBR_SUN_LAMBERT_NL - colorDiffuse = nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - colorSpec = vec3(0); - bloom = 0; -#endif - - #if DEBUG_PBR_SUN_H - colorDiffuse = h*0.5 + 0.5; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SUN_L - colorDiffuse = l*0.5 + 0.5; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SUN_V - colorDiffuse = v*0.5 + 0.5; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SUN_NH - colorDiffuse = colorize_dot(nh); colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SUN_NL - colorDiffuse = colorize_dot(nl); colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SUN_NV - colorDiffuse = colorize_dot(nv); colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SUN_VH - colorDiffuse = colorize_dot(vh); colorSpec = vec3(0); - #endif - color.rgb = colorDiffuse + colorEmissive + colorSpec; -#if PBR_USE_ATMOS color = linear_to_srgb(color); color *= atten.r; color += 2.0*additive; color = scaleSoftClipFrag(color); color = srgb_to_linear(color); -#endif // PBR_USE_ATMOS - - #if DEBUG_PBR_DIFFUSE - color.rgb = colorDiffuse; - #endif - #if DEBUG_PBR_EMISSIVE - color.rgb = colorEmissive; - #endif - #if DEBUG_PBR_METAL - color.rgb = vec3(metal); - #endif - #if DEBUG_PBR_NORMAL_MAP - color.rgb = diffuse.rgb; - #endif - #if DEBUG_PBR_OCCLUSION - color.rgb = vec3(ao); - #endif - #if DEBUG_PBR_ORM - color.rgb = packedORM; - #endif - #if DEBUG_PBR_ROUGH_PERCEPTUAL - color.rgb = vec3(perceptualRough); - #endif - #if DEBUG_PBR_ROUGH_ALPHA - color.rgb = vec3(alphaRough); - #endif - #if DEBUG_PBR_NORMAL - color.rgb = norm.xyz*0.5 + vec3(0.5); - color.rgb = srgb_to_linear(color.rgb); - #endif - #if DEBUG_PBR_TANGENT - color.rgb = t; - #endif - #if DEBUG_PBR_BITANGENT - color.rgb = b; - #endif - #if DEBUG_PBR_DOT_NV - color.rgb = vec3(nv); - #endif - #if DEBUG_PBR_DOT_TV - color.rgb = vec3(tv); - #endif - #if DEBUG_PBR_DOT_BV - color.rgb = vec3(bv); - #endif - - #if DEBUG_PBR_AVG - color.rgb = avg; - #endif - #if DEBUG_PBR_BRDF_UV - color.rgb = vec3(brdfPoint,0.0); - color.rgb = linear_to_srgb(color.rgb); - #endif - #if DEBUG_PBR_BRDF_SCALE_BIAS - color.rgb = vec3(vScaleBias,0.0); - #endif - #if DEBUG_PBR_DIFFUSE_C - color.rgb = c_diff; - #endif - #if DEBUG_PBR_BRDF_SCALE_ONLY - color.rgb = vec3(vScaleBias.x); - #endif - #if DEBUG_PBR_BRDF_BIAS_ONLY - color.rgb = vec3(vScaleBias.y); - #endif - #if DEBUG_PBR_DIFFUSE_K - color.rgb = kDiffuse; - #endif - #if DEBUG_PBR_DIFFUSE_MAP - color.rgb = diffuse.rgb; - #endif - #if DEBUG_PBR_DIFFUSE_PRE_AO - color.rgb = debug_diffuse; - #endif - #if DEBUG_PBR_EMS - color.rgb = vec3(Ems); - #endif - #if DEBUG_PBR_EMS_AVG - color.rgb = AvgEms; - #endif - #if DEBUG_PBR_FMS_EMS - color.rgb = FmsEms; - #endif - #if DEBUG_PBR_FSS_ESS_GGX - color.rgb = FssEssGGX; // spec - #endif - #if DEBUG_PBR_FSS_ESS_LAMBERT - color.rgb = FssEssLambert; // diffuse - #endif - #if DEBUG_PBR_FRESNEL - color.rgb = fresnelR; - #endif - #if DEBUG_PBR_IOR - color.rgb = vec3(IOR); - #endif - #if DEBUG_PBR_IRRADIANCE_RAW - color.rgb = debug_irradiance; - bloom = 0; - #endif - #if DEBUG_PBR_IRRADIANCE - color.rgb = irradiance; - bloom = 0; - #endif - #if DEBUG_PBR_KSPEC - color.rgb = kSpec; - #endif - #if DEBUG_PBR_REFLECT0_BASE - color.rgb = vec3(debug_reflect0); - #endif - #if DEBUG_PBR_REFLECT0_MIX - color.rgb = vec3(reflect0); - #endif - #if DEBUG_PBR_REFLECTANCE - color.rgb = vec3(reflectance); - #endif - #if DEBUG_PBR_REFLECTION_DIR - color.rgb = reflect(-v, n); // NOTE: equivalent to normalize(reflect(pos.xyz, norm.xyz)); - #endif - #if DEBUG_PBR_SPEC - color.rgb = colorSpec; - #endif - #if DEBUG_PBR_SPEC_REFLECTION - color.rgb = specLight; - #endif - #if DEBUG_PBR_SPEC_WEIGHT - color.rgb = vec3(specWeight); - #endif - #if DEBUG_PBR_V2C_RAW - color.rgb = v; - #endif - #if DEBUG_PBR_V2C_REMAP - color.rgb = v*0.5 + vec3(0.5); - #endif - - #if DEBUG_PBR_DA_RAW - color.rgb = vec3(debug_da); - #endif - #if DEBUG_PBR_DA_POW - color.rgb = vec3(da); - #endif - #if DEBUG_PBR_SKY_ADDITIVE - color.rgb = additive; - #endif - #if DEBUG_PBR_SKY_ATTEN - color.rgb = vec3(atten.r); - #endif - #if DEBUG_PBR_SUN_LIT - color.rgb = sunlit; - #endif - #if DEBUG_PBR_SUN_CONTRIB - color.rgb = sun_contrib; - #endif - #if DEBUG_PBR_LIGHT_TYPE - color.rgb = vec3(0); - #endif - - frag_color.rgb = color.rgb; // PBR is done in linear + frag_color.rgb = color.rgb; //output linear since local lights will be added to this shader's results } -else -{ - float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); -#if DEBUG_PBR_DA_RAW - float debug_da = da; -#endif - da = pow(da, light_gamma); + else + { + float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); + da = pow(da, light_gamma); - diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 + diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 - sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); - ambenv.rgb = linear_to_srgb(ambenv.rgb); - glossenv.rgb = linear_to_srgb(glossenv.rgb); - legacyenv.rgb = linear_to_srgb(legacyenv.rgb); + sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + ambenv.rgb = linear_to_srgb(ambenv.rgb); + glossenv.rgb = linear_to_srgb(glossenv.rgb); + legacyenv.rgb = linear_to_srgb(legacyenv.rgb); - amblit = max(ambenv, amblit); - color.rgb = amblit*ambocc; + amblit = max(ambenv, amblit); + color.rgb = amblit*ambocc; - //float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); - //ambient *= 0.5; - //ambient *= ambient; - //ambient = (1.0 - ambient); - //color.rgb *= ambient; + vec3 sun_contrib = min(da, scol) * sunlit; + color.rgb += sun_contrib; + color.rgb = min(color.rgb, vec3(1,1,1)); + color.rgb *= diffuse.rgb; - vec3 sun_contrib = min(da, scol) * sunlit; - color.rgb += sun_contrib; - color.rgb = min(color.rgb, vec3(1,1,1)); - color.rgb *= diffuse.rgb; + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - vec3 refnormpersp = reflect(pos.xyz, norm.xyz); + if (spec.a > 0.0) // specular reflection + { + float sa = dot(normalize(refnormpersp), light_dir.xyz); + vec3 dumbshiny = sunlit * scol * (texture2D(lightFunc, vec2(sa, spec.a)).r); - if (spec.a > 0.0) // specular reflection - { - float sa = dot(normalize(refnormpersp), light_dir.xyz); - vec3 dumbshiny = sunlit * scol * (texture2D(lightFunc, vec2(sa, spec.a)).r); + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + color.rgb += spec_contrib; - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; - color.rgb += spec_contrib; + // add reflection map - EXPERIMENTAL WORK IN PROGRESS + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + } - // add reflection map - EXPERIMENTAL WORK IN PROGRESS - applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); - } + color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); - color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); + if (envIntensity > 0.0) + { // add environmentmap + //fudge darker + legacyenv *= 0.5*diffuse.a+0.5; + applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + } - if (envIntensity > 0.0) - { // add environmentmap - //fudge darker - legacyenv *= 0.5*diffuse.a+0.5; - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); - } + 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); + } - 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); + #ifdef WATER_FOG + vec4 fogged = applyWaterFogView(pos.xyz, vec4(color, bloom)); + color = fogged.rgb; + bloom = fogged.a; + #endif + + // convert to linear as fullscreen lights need to sum in linear colorspace + // and will be gamma (re)corrected downstream... + //color = ambenv; + //color.b = diffuse.a; + frag_color.rgb = srgb_to_linear(color.rgb); } -#ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz, vec4(color, bloom)); - color = fogged.rgb; - bloom = fogged.a; -#endif - #if DEBUG_PBR_LIGHT_TYPE - color.rgb = vec3(0); - #endif - // convert to linear as fullscreen lights need to sum in linear colorspace - // and will be gamma (re)corrected downstream... - //color = ambenv; - //color.b = diffuse.a; - frag_color.rgb = srgb_to_linear(color.rgb); -} -#if DEBUG_PBR_AMBOCC - frag_color.rgb = vec3(ambocc); -#endif -#if DEBUG_PBR_AMBENV - frag_color.rgb = ambenv; -#endif frag_color.a = bloom; } -- cgit v1.2.3 From ff3a28422dc65afe4cf3131daf953d0567711b8a Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 13 Sep 2022 17:07:30 -0500 Subject: SL-17701 WIP -- Parity for point lights between opaque and transparent PBR materials --- .../shaders/class3/deferred/multiPointLightF.glsl | 18 ------------------ .../shaders/class3/deferred/pointLightF.glsl | 19 ------------------- 2 files changed, 37 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index c7c241b76e..d8175aa260 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -27,11 +27,6 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_ANY_LIGHT_TYPE 0 // Output red light cone -#define DEBUG_PBR_LIGHT_TYPE 0 // Output PBR objects in red -#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in red -#define DEBUG_POINT_ZERO 0 // Output zero for point lights - #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -123,9 +118,6 @@ void main() } } - #if DEBUG_PBR_LIGHT_TYPE - colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0); - #endif final_color = colorDiffuse + colorSpec; } else @@ -174,18 +166,8 @@ void main() } } } - #if DEBUG_LEG_LIGHT_TYPE - final_color.rgb = vec3(0.5,0,0.0); - #endif } -#if DEBUG_POINT_ZERO - final_color = vec3(0); -#endif -#if DEBUG_ANY_LIGHT_TYPE - final_color = vec3(0.3333,0,0); -#endif - frag_color.rgb = final_color; frag_color.a = 0.0; #endif // LOCAL_LIGHT_KILL diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 6f39b0173b..509f9f6dd0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -27,11 +27,6 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_ANY_LIGHT_TYPE 0 // Output magenta light cone -#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in green -#define DEBUG_PBR_LIGHT_TYPE 0 // Show PBR objects in blue -#define DEBUG_POINT_ZERO 0 // Output zero for point light - #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -119,9 +114,6 @@ void main() colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } -#if DEBUG_PBR_LIGHT_TYPE - colorDiffuse = vec3(0,0,0.5); colorSpec = vec3(0); -#endif final_color = colorDiffuse + colorSpec; } else @@ -156,19 +148,8 @@ void main() { discard; } - -#if DEBUG_LEG_LIGHT_TYPE - final_color.rgb = vec3(0,0.25,0); -#endif } -#if DEBUG_POINT_ZERO - final_color = vec3(0); -#endif -#if DEBUG_ANY_LIGHT_TYPE - final_color = vec3(0.25,0,0.25); -#endif - frag_color.rgb = final_color; frag_color.a = 0.0; } -- cgit v1.2.3 From 2a5219b23f5f91a2415a51324bb5c160a0139663 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 13 Sep 2022 18:41:24 -0500 Subject: SL-17701 WIP -- Correct color space management for base color and emissive color factors and textures. Support for double sided alpha blended PBR materials. --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 50aa93fea6..1a7e11a1cd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -131,7 +131,7 @@ void main() float light_gamma = 1.0 / 1.3; vec4 diffuse = texture2DRect(diffuseRect, tc); - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR sRGB Emissive + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR linear Emissive #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; -- cgit v1.2.3 From b2cf07f53ca9f0ab82d466063af8307631c50f31 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 17 Sep 2022 01:12:52 -0500 Subject: WIP - switch PBR implementations --- .../shaders/class3/deferred/multiPointLightF.glsl | 2 +- .../shaders/class3/deferred/multiSpotLightF.glsl | 167 --------------------- .../shaders/class3/deferred/pointLightF.glsl | 2 +- .../shaders/class3/deferred/reflectionProbeF.glsl | 4 +- .../shaders/class3/deferred/softenLightF.glsl | 97 +++++------- 5 files changed, 38 insertions(+), 234 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index d8175aa260..3b57821758 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -112,7 +112,7 @@ void main() if (dist <= 1.0 && nl > 0.0) { float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); - vec3 intensity = dist_atten * nl * lightColor; + vec3 intensity = dist_atten * nl * lightColor * 2.0; colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index bc4b4eb7e1..cabc175da9 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -28,40 +28,6 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_ANY_LIGHT_TYPE 0 // Output blue light cone -#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in blue -#define DEBUG_PBR_LIGHT_TYPE 0 // Ouput gray if PBR multiSpot lights object -#define DEBUG_PBR_SPOT 0 -#define DEBUG_PBR_SPOT_DIFFUSE 0 // PBR diffuse lit -#define DEBUG_PBR_SPOT_SPECULAR 0 // PBR spec lit - -#define DEBUG_LIGHT_FRUSTUM 0 // If projected light effects a surface -#define DEBUG_AMBIANCE_COLOR 0 // calculated ambiance color -#define DEBUG_AMBIANCE_AOE 0 // area of effect using inverse ambiance color -#define DEBUG_AMBIANCE_FINAL 0 // light color * ambiance color -#define DEBUG_NOISE 0 // monochrome noise -#define DEBUG_SHADOW 0 // Show inverted shadow -#define DEBUG_SPOT_DIFFUSE 0 // dot(n,l) * dist_atten -#define DEBUG_SPOT_NL 0 // monochome area effected by light -#define DEBUG_SPOT_SPEC_POS 0 -#define DEBUG_SPOT_REFLECTION 0 // color: pos reflected along n -#define DEBUG_SPOT_ZERO 0 // Output zero for spotlight - -#define DEBUG_PBR_LIGHT_H 0 // Half vector -#define DEBUG_PBR_LIHGT_L 0 // Light vector -#define DEBUG_PBR_LIGHT_NH 0 // colorized dot(n,h) -#define DEBUG_PBR_LIGHT_NL 0 // colorized dot(n,l) -#define DEBUG_PBR_LIGHT_NV 0 // colorized dot(n,v) -#define DEBUG_PBR_LIGHT_VH 0 // colorized dot(v,h) -#define DEBUG_PBR_LIGHT_DIFFUSE_COLOR 0 // non PBR spotlight -#define DEBUG_PBR_LIGHT_SPECULAR_COLOR 0 // non PBR spotlight -#define DEBUG_PBR_LIGHT_INTENSITY 0 // Light intensity -#define DEBUG_PBR_LIGHT_INTENSITY_NL 0 // Light intensity * dot(n,l) -#define DEBUG_PBR_LIGHT_BRDF_DIFFUSE 0 // like "fullbright" if no "nl" factor -#define DEBUG_PBR_LIGHT_BRDF_SPECULAR 0 -#define DEBUG_PBR_LIGHT_BRDF_FINAL 0 // BRDF Diffuse + BRDF Specular - - #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -211,93 +177,13 @@ void main() colorSpec = shadow * lit * slit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); colorSpec += shadow * lit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); - #if DEBUG_PBR_SPOT_DIFFUSE - colorDiffuse = dlit.rgb; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SPOT_SPECULAR - colorDiffuse = vec3(0); colorSpec = slit.rgb; - #endif - #if DEBUG_PBR_SPOT - colorDiffuse = dlit; colorSpec = vec3(0); - colorDiffuse *= nl; - colorDiffuse *= shadow; - #endif } amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); colorDiffuse += diffuse.rgb * amb_rgb; - #if DEBUG_AMBIANCE_FINAL - colorDiffuse = diffuse.rgb * amb_rgb; colorSpec = vec3(0); - #endif - #if DEBUG_LIGHT_FRUSTUM - colorDiffuse = vec3(0,1,0); colorSpec = vec3(0); - #endif - #if DEBUG_NOISE - float noise = texture2D(noiseMap, tc/128.0).b; - colorDiffuse = vec3(noise); colorSpec = vec3(0); - #endif } - #if DEBUG_PBR_LIGHT_TYPE - colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0); - #endif - - #if DEBUG_PBR_LIGHT_H - colorDiffuse = h*0.5 + 0.5; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_LIHGT_L - colorDiffuse = l*0.5 + 0.5; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_LIGHT_NH - colorDiffuse = colorized_dot(nh); colorSpec = vec3(0); - #endif - #if DEBUG_PBR_LIGHT_NL - colorDiffuse = colorized_dot(nl); colorSpec = vec3(0); - #endif - #if DEBUG_PBR_LIGHT_NV - colorDiffuse = colorized_dot(nv); colorSpec = vec3(0); - #endif - #if DEBUG_PBR_LIGHT_VH - colorDiffuse = colorized_dot(vh); colorSpec = vec3(0); - #endif - #if DEBUG_PBR_LIGHT_DIFFUSE_COLOR - colorDiffuse = dlit; - #endif - #if DEBUG_PBR_LIGHT_SPECULAR_COLOR - colorDiffuse = slit; - #endif - #if DEBUG_PBR_LIGHT_INTENSITY - colorDiffuse = getLightIntensitySpot( color, size, lightDist, v ); colorSpec = vec3(0); -// colorDiffuse = nl * dist_atten; - #endif - #if DEBUG_PBR_LIGHT_INTENSITY_NL - colorDiffuse = getLightIntensitySpot( color, size, lightDist, v ) * nl; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_LIGHT_BRDF_DIFFUSE - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - - colorDiffuse = BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); - colorSpec = vec3(0); - #endif - #if DEBUG_PBR_LIGHT_BRDF_SPECULAR - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - - colorDiffuse = vec3(0); - colorSpec = BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); - #endif - #if DEBUG_PBR_LIGHT_BRDF_FINAL - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - colorDiffuse = nl * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); - colorSpec = nl * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); - #endif - final_color = colorDiffuse + colorSpec; } else @@ -326,9 +212,6 @@ void main() amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); final_color += diffuse.rgb * amb_rgb; -#if DEBUG_LEG_LIGHT_TYPE - final_color = vec3(0,0,0.5); -#endif } if (spec.a > 0.0) @@ -376,58 +259,8 @@ void main() } } } - #if DEBUG_SPOT_REFLECTION - final_color = ref; - #endif - } - -#if DEBUG_LIGHT_FRUSTUM - if (proj_tc.x > 0.0 && proj_tc.x < 1.0 - && proj_tc.y > 0.0 && proj_tc.y < 1.0) - { - final_color = vec3(0,0,1); } -#endif - } - -#if DEBUG_AMBIANCE_AOE - if (proj_tc.x > 0.0 && proj_tc.x < 1.0 - && proj_tc.y > 0.0 && proj_tc.y < 1.0) - { - final_color = 1.0 - amb_rgb; - } -#endif -#if DEBUG_AMBIANCE_COLOR - if (proj_tc.x > 0.0 && proj_tc.x < 1.0 - && proj_tc.y > 0.0 && proj_tc.y < 1.0) - { - final_color = amb_rgb; } -#endif -#if DEBUG_SHADOW - final_color = 1.0 - vec3(shadow); -#endif -#if DEBUG_SPOT_DIFFUSE - final_color = vec3(nl * dist_atten); -#endif -#if DEBUG_SPOT_NL - final_color =vec3(nl); -#endif -#if DEBUG_SPOT_SPEC_POS - vec3 ref = reflect(normalize(pos), n); - vec3 pdelta = proj_p-pos; - float ds = dot(ref, proj_n); - final_color = pos + ref * dot(pdelta, proj_n)/ds; -#endif -#if DEBUG_SPOT_REFLECTION - final_color = reflect(normalize(pos), n); -#endif -#if DEBUG_SPOT_ZERO - final_color = vec3(0,0,0); -#endif -#if DEBUG_ANY_LIGHT_TYPE - final_color = vec3(0,0,0.3333); -#endif //not sure why, but this line prevents MATBUG-194 final_color = max(final_color, vec3(0.0)); diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 509f9f6dd0..0472f08852 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -109,7 +109,7 @@ void main() if (nl > 0.0) { - vec3 intensity = dist_atten * nl * lightColor; // Legacy attenuation + vec3 intensity = dist_atten * nl * lightColor * 2.0; // Legacy attenuation colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 3ff039261b..37fe5f53a2 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -524,14 +524,14 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 l vec3 pos, vec3 norm, float glossiness, float envIntensity) { // TODO - don't hard code lods - float reflection_lods = 8; + float reflection_lods = 7; preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); ambenv = sampleProbeAmbient(pos, norm); - if (glossiness > 0.0) + //if (glossiness > 0.0) { float lod = (1.0-glossiness)*reflection_lods; glossenv = sampleProbes(pos, normalize(refnormpersp), lod, 1.f); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 1a7e11a1cd..6dd140bff3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -89,34 +89,21 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); #endif // PBR interface -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); -void initMaterial( vec3 diffuse, vec3 packedORM, - out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); -// perform PBR image based lighting according to GLTF spec -// all parameters are in linear space -void pbrIbl(out vec3 colorDiffuse, // diffuse color output - out vec3 colorSpec, // specular color output, +vec3 pbrIbl(vec3 diffuseColor, + vec3 specularColor, vec3 radiance, // radiance map sample vec3 irradiance, // irradiance map sample float ao, // ambient occlusion factor - float nv, - float perceptualRough, // roughness factor - float gloss, // 1.0 - roughness factor - vec3 reflect0, - vec3 c_diff); - -void pbrDirectionalLight(inout vec3 colorDiffuse, - inout vec3 colorSpec, - vec3 sunlit, - float scol, - vec3 reflect0, - vec3 reflect90, - vec3 c_diff, - float alphaRough, - float vh, - float nl, - float nv, - float nh); + float nv, // normal dot view vector + float perceptualRoughness); + +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 + void main() { @@ -160,51 +147,34 @@ void main() bool hasPBR = GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR); if (hasPBR) { - // 5.22.2. material.pbrMetallicRoughness.baseColorTexture - // The first three components (RGB) MUST be encoded with the sRGB transfer function. - // - // 5.19.7. material.emissiveTexture - // This texture contains RGB components encoded with the sRGB transfer function. - // - // 5.22.5. material.pbrMetallicRoughness.metallicRoughnessTexture - // These values MUST be encoded with a linear transfer function. - - vec3 colorDiffuse = vec3(0); - vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl - vec3 colorSpec = vec3(0); - - vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl - float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics) - float ao = packedORM.r; - float metal = packedORM.b; - vec3 v = -normalize(pos.xyz); - vec3 n = norm.xyz; - - vec3 h, l; - float nh, nl, nv, vh, lightDist; - calcHalfVectors(light_dir, n, v, h, l, nh, nl, nv, vh, lightDist); - - float perceptualRough = packedORM.g; // NOTE: do NOT clamp here to be consistent with Blender, Blender is wrong and Substance is right - - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse.rgb, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + float perceptualRoughness = orm.g; + float metallic = orm.b; + float ao = orm.r * ambocc; - float gloss = 1.0 - perceptualRough; + vec3 colorEmissive = texture2DRect(specularRect, tc).rgb; //specularRect is sRGB sampler, result is in linear space + + // PBR IBL + float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, legacyenv, pos.xyz, norm.xyz, gloss, 0.0); - irradiance = max(amblit,irradiance) * ambocc; + irradiance = max(srgb_to_linear(amblit),irradiance) * ambocc*4.0; - pbrIbl(colorDiffuse, colorSpec, radiance, irradiance, ao, nv, perceptualRough, gloss, reflect0, c_diff); + vec3 f0 = vec3(0.04); + vec3 baseColor = diffuse.rgb; - // Add in sun/moon punctual light - if (nl > 0.0 || nv > 0.0) - { - pbrDirectionalLight(colorDiffuse, colorSpec, srgb_to_linear(sunlit), scol, reflect0, reflect90, c_diff, alphaRough, vh, nl, nv, nh); - } + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); + diffuseColor *= 1.0 - metallic; + + vec3 specularColor = mix(f0, baseColor.rgb, metallic); - color.rgb = colorDiffuse + colorEmissive + colorSpec; + vec3 v = -normalize(pos.xyz); + float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); + + color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); + color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*8.0 * scol; + color.rgb += colorEmissive; color = linear_to_srgb(color); color *= atten.r; @@ -212,6 +182,7 @@ void main() color = scaleSoftClipFrag(color); color = srgb_to_linear(color); + frag_color.rgb = color.rgb; //output linear since local lights will be added to this shader's results } else -- cgit v1.2.3 From a32125bc0edcc583b185c08af0df1988855c0bac Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 17 Sep 2022 01:52:01 -0500 Subject: WIP - replace PBR implementation - point lights --- .../shaders/class3/deferred/multiPointLightF.glsl | 45 ++++++++++++++-------- .../shaders/class3/deferred/pointLightF.glsl | 40 ++++++++++--------- 2 files changed, 51 insertions(+), 34 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 3b57821758..4fbfaf9898 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -66,6 +66,14 @@ vec3 srgb_to_linear(vec3 c); // Util vec3 hue_to_rgb(float hue); +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 + + void main() { #if defined(LOCAL_LIGHT_KILL) @@ -87,38 +95,43 @@ void main() vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; vec3 h, l, v = -normalize(pos); - float nh, nl, nv, vh, lightDist; + float nh, nv, vh, lightDist; if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorDiffuse = vec3(0); - vec3 colorSpec = vec3(0); vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl - vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl + vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + float perceptualRoughness = orm.g; + float metallic = orm.b; + vec3 f0 = vec3(0.04); + vec3 baseColor = diffuse.rgb; + + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); + diffuseColor *= 1.0 - metallic; - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + vec3 specularColor = mix(f0, baseColor.rgb, metallic); for (int light_idx = 0; light_idx < LIGHT_COUNT; ++light_idx) { vec3 lightColor = light_col[ light_idx ].rgb; // Already in linear, see pipeline.cpp: volume->getLightLinearColor(); float falloff = light_col[ light_idx ].a; - float lightSize = light [ light_idx ].w; - vec3 lv =(light [ light_idx ].xyz - pos); - calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + float lightSize = light[ light_idx ].w; + vec3 lv = light[ light_idx ].xyz - pos; + + lightDist = length(lv); float dist = lightDist / lightSize; - if (dist <= 1.0 && nl > 0.0) + if (dist <= 1.0) { + lv /= lightDist; + float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); - vec3 intensity = dist_atten * nl * lightColor * 2.0; - colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); + + vec3 intensity = dist_atten * lightColor * 3.0; + + final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); } } - - final_color = colorDiffuse + colorSpec; } else { diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 0472f08852..88f165f315 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -68,6 +68,13 @@ vec2 getScreenXY(vec4 clip); void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); +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 + void main() { vec3 final_color = vec3(0); @@ -96,25 +103,22 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorDiffuse = vec3(0); - vec3 colorSpec = vec3(0); vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl - vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl - float lightSize = size; - vec3 lightColor = color; // Already in linear, see pipeline.cpp: volume->getLightLinearColor(); - - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - - if (nl > 0.0) - { - vec3 intensity = dist_atten * nl * lightColor * 2.0; // Legacy attenuation - colorDiffuse += intensity * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); - colorSpec += intensity * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); - } - - final_color = colorDiffuse + colorSpec; + vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + float perceptualRoughness = orm.g; + float metallic = orm.b; + vec3 f0 = vec3(0.04); + vec3 baseColor = diffuse.rgb; + + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); + diffuseColor *= 1.0 - metallic; + + vec3 specularColor = mix(f0, baseColor.rgb, metallic); + + vec3 v = -normalize(pos.xyz); + + vec3 intensity = dist_atten * color * 3.0; // Legacy attenuation + final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); } else { -- cgit v1.2.3 From 69ee8337026e4fc77205d501635822fc44989f62 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 17 Sep 2022 11:04:50 -0500 Subject: WIP - multiSpotLightF uses proper PBR shading, alpha is broken but pushing now in case my hard drive melts --- .../shaders/class3/deferred/multiSpotLightF.glsl | 44 +++++++++++----------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index cabc175da9..2294418e8a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -93,6 +93,13 @@ vec4 getPosition(vec2 pos_screen); const float M_PI = 3.14159265; +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 + void main() { #if defined(LOCAL_LIGHT_KILL) @@ -144,11 +151,17 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorDiffuse = vec3(0); - vec3 colorSpec = vec3(0); vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl - vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl - float metal = packedORM.b; + vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + float perceptualRoughness = orm.g; + float metallic = orm.b; + vec3 f0 = vec3(0.04); + vec3 baseColor = diffuse.rgb; + + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); + diffuseColor *= 1.0 - metallic; + + vec3 specularColor = mix(f0, baseColor.rgb, metallic); // We need this additional test inside a light's frustum since a spotlight's ambiance can be applied if (proj_tc.x > 0.0 && proj_tc.x < 1.0 @@ -160,31 +173,16 @@ void main() if (nl > 0.0) { amb_da += (nl*0.5 + 0.5) * proj_ambiance; - lit = nl * dist_atten; - - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - slit = getProjectedLightSpecularColor( pos, n ); - - float exposure = M_PI; - dlit *= exposure; - slit *= exposure; - - colorDiffuse = shadow * lit * dlit * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); - colorSpec = shadow * lit * slit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); - colorSpec += shadow * lit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); + vec3 intensity = dist_atten * dlit * 3.0 * shadow; // Legacy attenuation + final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); } amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); - colorDiffuse += diffuse.rgb * amb_rgb; - + final_color += diffuse.rgb * amb_rgb; } - - final_color = colorDiffuse + colorSpec; } else { -- cgit v1.2.3 From 679060557555742b0631aec14b59ebcab64c081f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 17 Sep 2022 13:04:23 -0500 Subject: WIP - Fix for alpha PBR lighting for point lights (spot lights treated as point lights for now) --- indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 88f165f315..1fc80016cb 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -115,8 +115,6 @@ void main() vec3 specularColor = mix(f0, baseColor.rgb, metallic); - vec3 v = -normalize(pos.xyz); - vec3 intensity = dist_atten * color * 3.0; // Legacy attenuation final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); } -- cgit v1.2.3 From 13ac0f77ffe488ccdebfd28cabe8ed95d61aa684 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 17 Sep 2022 14:38:07 -0500 Subject: Make sure specular highlights from punctual lights don't fall off of polished surfaces --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 6dd140bff3..a8a3b5d33f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -111,9 +111,6 @@ void main() float depth = texture2DRect(depthMap, tc.xy).r; vec4 pos = getPositionWithDepth(tc, depth); vec4 norm = texture2DRect(normalMap, tc); - float envIntensity = norm.z; - norm.xyz = getNorm(tc); - vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; float light_gamma = 1.0 / 1.3; @@ -147,6 +144,7 @@ void main() bool hasPBR = GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR); if (hasPBR) { + norm.xyz = getNorm(tc); vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space float perceptualRoughness = orm.g; float metallic = orm.b; @@ -164,6 +162,10 @@ void main() vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; + //baseColor.rgb = vec3(0,0,0); + //colorEmissive = srgb_to_linear(norm.xyz*0.5+0.5); + + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); diffuseColor *= 1.0 - metallic; @@ -187,6 +189,9 @@ void main() } else { + float envIntensity = norm.z; + norm.xyz = getNorm(tc); + float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); da = pow(da, light_gamma); @@ -249,5 +254,6 @@ void main() frag_color.rgb = srgb_to_linear(color.rgb); } + frag_color.a = bloom; } -- cgit v1.2.3 From b2553fc8b46e44dd74b2840e041b3cf46d2b39fc Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 17 Sep 2022 15:48:55 -0500 Subject: Fix for spotlights in background not matching foreground. Remove some unused functions. --- .../shaders/class3/deferred/multiSpotLightF.glsl | 1 - .../shaders/class3/deferred/spotLightF.glsl | 55 ++++++---------------- 2 files changed, 15 insertions(+), 41 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 2294418e8a..bcacc44d0b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -74,7 +74,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); -vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); float calcLegacyDistanceAttenuation(float distance, float falloff); vec3 colorized_dot(float x); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index f23e9db040..787da799a5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -83,7 +83,6 @@ uniform vec2 screen_res; uniform mat4 inv_proj; vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); -vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); float calcLegacyDistanceAttenuation(float distance, float falloff); bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); @@ -150,11 +149,17 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorDiffuse = vec3(0); - vec3 colorSpec = vec3(0); vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl - vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl - float metal = packedORM.b; + vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + float perceptualRoughness = orm.g; + float metallic = orm.b; + vec3 f0 = vec3(0.04); + vec3 baseColor = diffuse.rgb; + + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); + diffuseColor *= 1.0 - metallic; + + vec3 specularColor = mix(f0, baseColor.rgb, metallic); // We need this additional test inside a light's frustum since a spotlight's ambiance can be applied if (proj_tc.x > 0.0 && proj_tc.x < 1.0 @@ -166,46 +171,16 @@ void main() if (nl > 0.0) { amb_da += (nl*0.5 + 0.5) * proj_ambiance; - lit = nl * dist_atten; - - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - slit = getProjectedLightSpecularColor( pos, n ); - float exposure = M_PI; - dlit *= exposure; - slit *= exposure; - - colorDiffuse = shadow * lit * dlit * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); - colorSpec = shadow * lit * slit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); - colorSpec += shadow * lit * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); - - #if DEBUG_PBR_SPOT_DIFFUSE - colorDiffuse = dlit.rgb; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SPOT_SPECULAR - colorDiffuse = vec3(0); colorSpec = slit.rgb; - #endif - #if DEBUG_PBR_SPOT - colorDiffuse = dlit; colorSpec = vec3(0); - colorDiffuse *= nl; - colorDiffuse *= shadow; - #endif + vec3 intensity = dist_atten * dlit * 3.0 * shadow; // Legacy attenuation + final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); } - vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); - colorDiffuse += diffuse.rgb * amb_rgb; - + amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); + final_color += diffuse.rgb * amb_rgb; } - - #if DEBUG_PBR_LIGHT_TYPE - colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0.0); - #endif - - final_color = colorDiffuse + colorSpec; } else { -- cgit v1.2.3 From 29f92451f6dfb95b6d2e7e56d65a07df59ea9afd Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Sat, 17 Sep 2022 16:09:11 -0500 Subject: Cleanup more unused functions and fix spotLightF (whoops) --- .../shaders/class3/deferred/multiPointLightF.glsl | 4 ---- .../app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 3 --- .../app_settings/shaders/class3/deferred/pointLightF.glsl | 4 ---- .../app_settings/shaders/class3/deferred/spotLightF.glsl | 11 ++++++++--- 4 files changed, 8 insertions(+), 14 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 4fbfaf9898..2ee439f61a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -52,15 +52,11 @@ uniform mat4 inv_proj; VARYING vec4 vary_fragcoord; -vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); -vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); float calcLegacyDistanceAttenuation(float distance, float falloff); -vec3 getLightIntensityPoint(vec3 lightColor, float lightRange, float lightDistance); vec4 getPosition(vec2 pos_screen); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec2 getScreenXY(vec4 clip); -void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); // Util diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index bcacc44d0b..6424e18079 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -73,18 +73,15 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); 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); float calcLegacyDistanceAttenuation(float distance, float falloff); vec3 colorized_dot(float x); bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); -vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv); vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip); -void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 cs); vec4 texture2DLodSpecular(vec2 tc, float lod); diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 1fc80016cb..27fca64ab3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -57,15 +57,11 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); -vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh ); 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); float calcLegacyDistanceAttenuation(float distance, float falloff); -vec3 getLightIntensityPoint(vec3 lightColor, float lightRange, float lightDistance); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec4 getPosition(vec2 pos_screen); vec2 getScreenXY(vec4 clip); -void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 787da799a5..c8d45eb429 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -82,17 +82,14 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh ); 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); float calcLegacyDistanceAttenuation(float distance, float falloff); bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); -vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv); vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip_point); -void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight ); vec3 srgb_to_linear(vec3 c); vec4 texture2DLodSpecular(vec2 tc, float lod); @@ -100,6 +97,13 @@ vec4 getPosition(vec2 pos_screen); const float M_PI = 3.14159265; +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 + void main() { #if defined(LOCAL_LIGHT_KILL) @@ -147,6 +151,7 @@ void main() vec3 dlit = vec3(0, 0, 0); vec3 slit = vec3(0, 0, 0); + vec3 amb_rgb = vec3(0); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl -- cgit v1.2.3 From 1eeee12ecb4753cc4b651e18474bb80de45fcede Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 20 Sep 2022 12:28:45 -0500 Subject: SL-18190 Don't allocate mips for irradiance maps because they're never generated. Disable OpenGL core profile on Intel by default. --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 37fe5f53a2..463709de9e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -364,7 +364,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, vec3 c, float r2, int i) v -= c; v = env_mat * v; { - return textureLod(irradianceProbes, vec4(v.xyz, refIndex[i].x), 0).rgb * refParams[i].x; + return texture(irradianceProbes, vec4(v.xyz, refIndex[i].x)).rgb * refParams[i].x; } } -- cgit v1.2.3 From c466e44334fd60c8270b68c70b8ae999b8dbd395 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 20 Sep 2022 19:09:26 -0500 Subject: SL-18190 Reduce banding (stay in linear space as much as possible, increase precision of reflection probes). Faster radiance and irradiance map generation. --- .../app_settings/shaders/class3/deferred/fullbrightShinyF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 3 --- .../app_settings/shaders/class3/deferred/multiPointLightF.glsl | 7 +++++-- .../app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 8 ++++++-- .../newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 7 +++++-- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 7 +++---- .../newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 7 +++++-- 7 files changed, 25 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index a04f611440..67f1fc4c18 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -115,8 +115,8 @@ void main() */ color.a = 1.0; - //color.rgb = linear_to_srgb(color.rgb); + color.rgb = srgb_to_linear(color.rgb); frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 7f8536cdab..fcda50c4de 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -433,9 +433,6 @@ void main() 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; diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 2ee439f61a..6dd446d9f7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -95,8 +95,8 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl - vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; vec3 f0 = vec3(0.04); @@ -134,6 +134,9 @@ void main() float noise = texture2D(noiseMap, tc/128.0).b; + diffuse = srgb_to_linear(diffuse); + spec.rgb = srgb_to_linear(spec.rgb); + // As of OSX 10.6.7 ATI Apple's crash when using a variable size loop for (int i = 0; i < LIGHT_COUNT; ++i) { diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 6424e18079..cb8877ebe5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -147,8 +147,8 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl - vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; vec3 f0 = vec3(0.04); @@ -182,6 +182,10 @@ void main() } else { + + diffuse = srgb_to_linear(diffuse); + spec.rgb = srgb_to_linear(spec.rgb); + float noise = texture2D(noiseMap, tc/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 27fca64ab3..cdffcf103d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -99,8 +99,8 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl - vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; vec3 f0 = vec3(0.04); @@ -121,6 +121,9 @@ void main() discard; } + diffuse = srgb_to_linear(diffuse); + spec.rgb = srgb_to_linear(spec.rgb); + float noise = texture2D(noiseMap, tc/128.0).b; float lit = nl * dist_atten * noise; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index a8a3b5d33f..5c049b6bd6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -145,12 +145,12 @@ void main() if (hasPBR) { norm.xyz = getNorm(tc); - vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + vec3 orm = texture2DRect(specularRect, tc).rgb; float perceptualRoughness = orm.g; float metallic = orm.b; float ao = orm.r * ambocc; - vec3 colorEmissive = texture2DRect(specularRect, tc).rgb; //specularRect is sRGB sampler, result is in linear space + vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; // PBR IBL float gloss = 1.0 - perceptualRoughness; @@ -165,7 +165,6 @@ void main() //baseColor.rgb = vec3(0,0,0); //colorEmissive = srgb_to_linear(norm.xyz*0.5+0.5); - vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); diffuseColor *= 1.0 - metallic; @@ -195,7 +194,7 @@ void main() float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); da = pow(da, light_gamma); - diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 + //diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); ambenv.rgb = linear_to_srgb(ambenv.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index c8d45eb429..3274153a46 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -154,8 +154,8 @@ void main() vec3 amb_rgb = vec3(0); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl - vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; vec3 f0 = vec3(0.04); @@ -189,6 +189,9 @@ void main() } else { + diffuse = srgb_to_linear(diffuse); + spec.rgb = srgb_to_linear(spec.rgb); + float noise = texture2D(noiseMap, tc/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && -- cgit v1.2.3 From d72c0f1d6aff3fc3ea011e38f58b209ffa0bb639 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 21 Sep 2022 12:48:10 -0500 Subject: SL-18190 Fix for fullbright alpha blended legacy materials appearing in wrong color space --- .../app_settings/shaders/class3/deferred/materialF.glsl | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index fcda50c4de..07f50af7e3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -244,11 +244,6 @@ void main() } #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; @@ -293,7 +288,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - //forward rendering, output just lit sRGBA + //forward rendering, output lit linear color vec3 pos = vary_position; float shadow = 1.0f; @@ -355,7 +350,7 @@ void main() color += sun_contrib; - color *= gamma_diff.rgb; + color *= diffcol.rgb; float glare = 0.0; @@ -378,9 +373,6 @@ void main() #endif } - - color = mix(color.rgb, diffcol.rgb, diffuse.a); - #ifdef HAS_REFLECTION_PROBES if (envIntensity > 0.0) { // add environmentmap @@ -439,12 +431,13 @@ void main() al = temp.a; #endif + color = mix(color.rgb, srgb_to_linear(diffcol.rgb), diffuse.a); frag_color = vec4(color, al); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl - frag_data[0] = final_color; // gbuffer is sRGB + frag_data[0] = final_color; // gbuffer is sRGB for legacy materials frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) #endif -- cgit v1.2.3 From e5d463ca200bdfa93b8c65e588d490c2f23e3918 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 22 Sep 2022 17:27:18 -0500 Subject: SL-17705 Backwards compatibility pass. Support OpenGL pre-4.0 by disabling reflection probes and anti-aliasing. Get render parity with current release viewer when reflection probes are disabled. --- .../shaders/class3/deferred/fullbrightShinyF.glsl | 26 +++--------- .../shaders/class3/deferred/materialF.glsl | 49 +++------------------- .../shaders/class3/deferred/reflectionProbeF.glsl | 31 +++++++++++--- .../shaders/class3/deferred/softenLightF.glsl | 25 +++++------ 4 files changed, 46 insertions(+), 85 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index 67f1fc4c18..c0a1491446 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -55,13 +55,11 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); -#ifdef HAS_REFLECTION_PROBES // reflection probe interface -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, vec3 pos, vec3 norm, float glossiness, float envIntensity); 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); -#endif // See: // class1\deferred\fullbrightShinyF.glsl @@ -87,35 +85,21 @@ void main() calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); float env_intensity = vertex_color.a; -#ifndef HAS_REFLECTION_PROBES - vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; - color.rgb = mix(color.rgb, envColor.rgb, env_intensity); -#else + vec3 ambenv; vec3 glossenv; vec3 legacyenv; vec3 norm = normalize(vary_texcoord1.xyz); vec4 spec = vec4(0,0,0,0); - sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, env_intensity); - legacyenv *= 1.5; // fudge brighter + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, env_intensity); applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); -#endif + color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); color.rgb = fullbrightScaleSoftClip(color.rgb); } -/* - // NOTE: HUD objects will be full bright. Uncomment if you want "some" environment lighting effecting these HUD objects. - else - { - vec3 envColor = textureCube(environmentMap, vary_texcoord1.xyz).rgb; - float env_intensity = vertex_color.a; - color.rgb = mix(color.rgb, envColor.rgb, env_intensity); - } -*/ - color.a = 1.0; - + color.rgb = srgb_to_linear(color.rgb); frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 07f50af7e3..27eb0b9888 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -64,12 +64,10 @@ out vec4 frag_color; float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif -#ifdef HAS_REFLECTION_PROBES -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, vec3 pos, vec3 norm, float glossiness, float envIntensity); 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); -#endif uniform samplerCube environmentMap; uniform sampler2D lightFunc; @@ -326,27 +324,12 @@ void main() da = pow(da, 1.0 / 1.3); vec3 sun_contrib = min(da, shadow) * sunlit; -#ifdef HAS_REFLECTION_PROBES vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); amblit = max(ambenv, amblit); color.rgb = amblit; -#else - - 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); - - color *= ambient; -#endif color += sun_contrib; @@ -368,37 +351,14 @@ void main() color += spec_contrib; -#ifdef HAS_REFLECTION_PROBES applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); -#endif } -#ifdef HAS_REFLECTION_PROBES + color = atmosFragLighting(color, additive, atten); if (envIntensity > 0.0) { // add environmentmap - //fudge darker - legacyenv *= 0.5*diffuse.a+0.5; - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); } -#else - 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; - } -#endif - - color = atmosFragLighting(color, additive, atten); color = scaleSoftClipFrag(color); //convert to linear before adding local lights @@ -410,6 +370,8 @@ void main() final_specular.rgb = srgb_to_linear(final_specular.rgb); // SL-14035 + color = mix(color.rgb, srgb_to_linear(diffcol.rgb), diffuse.a); + #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) @@ -431,7 +393,6 @@ void main() al = temp.a; #endif - color = mix(color.rgb, srgb_to_linear(diffcol.rgb), diffuse.a); frag_color = vec4(color, al); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 463709de9e..beb0f6f2a6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -23,8 +23,6 @@ * $/LicenseInfo$ */ -#extension GL_ARB_shader_texture_lod : enable - #define FLT_MAX 3.402823466e+38 #define REFMAP_COUNT 256 @@ -33,6 +31,8 @@ uniform samplerCubeArray reflectionProbes; uniform samplerCubeArray irradianceProbes; +vec3 linear_to_srgb(vec3 col); + layout (std140) uniform ReflectionProbes { // list of OBBs for user override probes @@ -520,7 +520,22 @@ vec3 brighten(vec3 c) } -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec3 pos, vec3 norm, float glossiness) +{ + // TODO - don't hard code lods + float reflection_lods = 7; + preProbeSample(pos); + + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); + + ambenv = sampleProbeAmbient(pos, norm); + + float lod = (1.0-glossiness)*reflection_lods; + glossenv = sampleProbes(pos, normalize(refnormpersp), lod, 1.f); +} + +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, vec3 pos, vec3 norm, float glossiness, float envIntensity) { // TODO - don't hard code lods @@ -531,16 +546,22 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 l ambenv = sampleProbeAmbient(pos, norm); - //if (glossiness > 0.0) + if (glossiness > 0.0) { float lod = (1.0-glossiness)*reflection_lods; glossenv = sampleProbes(pos, normalize(refnormpersp), lod, 1.f); + glossenv = linear_to_srgb(glossenv); } if (envIntensity > 0.0) { legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, 1.f); + legacyenv = linear_to_srgb(legacyenv); } + + // legacy expects values in sRGB space for now + ambenv = linear_to_srgb(ambenv); + } void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) @@ -555,7 +576,7 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) { - vec3 reflected_color = legacyenv; //*0.5; //fudge darker + vec3 reflected_color = legacyenv; vec3 lookAt = normalize(pos); float fresnel = 1.0+dot(lookAt, norm.xyz); fresnel *= fresnel; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 5c049b6bd6..cfdbbdfe2c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -76,7 +76,9 @@ vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClip(vec3 light); // reflection probe interface -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec3 pos, vec3 norm, float glossiness); +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, vec3 pos, vec3 norm, float glossiness, float envIntensity); 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); @@ -156,7 +158,7 @@ void main() float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, legacyenv, pos.xyz, norm.xyz, gloss, 0.0); + sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); irradiance = max(srgb_to_linear(amblit),irradiance) * ambocc*4.0; vec3 f0 = vec3(0.04); @@ -196,10 +198,8 @@ void main() //diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 - sampleReflectionProbes(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); - ambenv.rgb = linear_to_srgb(ambenv.rgb); - glossenv.rgb = linear_to_srgb(glossenv.rgb); - legacyenv.rgb = linear_to_srgb(legacyenv.rgb); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + vec3 debug = legacyenv; amblit = max(ambenv, amblit); color.rgb = amblit*ambocc; @@ -227,16 +227,13 @@ void main() color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); - if (envIntensity > 0.0) - { // add environmentmap - //fudge darker - legacyenv *= 0.5*diffuse.a+0.5; - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); - } - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); + if (envIntensity > 0.0) + { // add environmentmap + applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + } color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); } @@ -248,8 +245,6 @@ void main() // convert to linear as fullscreen lights need to sum in linear colorspace // and will be gamma (re)corrected downstream... - //color = ambenv; - //color.b = diffuse.a; frag_color.rgb = srgb_to_linear(color.rgb); } -- cgit v1.2.3 From 01d667109159666150816ff728fa941d2fb54299 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 23 Sep 2022 10:42:09 -0500 Subject: SL-18120 Fix for specular color of legacy materials tinting environment reflections from "environment" intensity. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index beb0f6f2a6..73b852e008 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -506,20 +506,6 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) return col; } -// brighten a color so that at least one component is 1 -vec3 brighten(vec3 c) -{ - float m = max(max(c.r, c.g), c.b); - - if (m == 0) - { - return vec3(1,1,1); - } - - return c * 1.0/m; -} - - void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec3 pos, vec3 norm, float glossiness) { @@ -581,7 +567,7 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no float fresnel = 1.0+dot(lookAt, norm.xyz); fresnel *= fresnel; fresnel = min(fresnel+envIntensity, 1.0); - reflected_color *= (envIntensity*fresnel)*brighten(spec.rgb); + reflected_color *= (envIntensity*fresnel); color = mix(color.rgb, reflected_color, envIntensity); } -- cgit v1.2.3 From 725d042640f5b0474b58e6a1af0a4063c7e5cfc2 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 26 Sep 2022 17:17:34 -0500 Subject: SL-18190 WIP - Windlight to linear space proof of concept, better parity between release viewer and materials viewer when reflections disabled. Avoid run-away probe ambiance. --- .../shaders/class3/avatar/avatarV.glsl | 134 --------------------- .../shaders/class3/deferred/materialF.glsl | 32 ++--- .../shaders/class3/deferred/reflectionProbeF.glsl | 20 ++- .../shaders/class3/deferred/softenLightF.glsl | 48 ++++---- .../shaders/class3/windlight/advancedAtmoF.glsl | 73 ----------- .../shaders/class3/windlight/advancedAtmoV.glsl | 43 ------- .../shaders/class3/windlight/atmosphericsF.glsl | 46 ------- .../shaders/class3/windlight/atmosphericsV.glsl | 51 -------- .../shaders/class3/windlight/transportF.glsl | 68 ----------- 9 files changed, 45 insertions(+), 470 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl delete mode 100644 indra/newview/app_settings/shaders/class3/windlight/transportF.glsl (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl b/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl deleted file mode 100644 index df9704ec25..0000000000 --- a/indra/newview/app_settings/shaders/class3/avatar/avatarV.glsl +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @file avatarV.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; -ATTRIBUTE vec4 clothing; - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -vec4 calcLighting(vec3 pos, vec3 norm, vec4 color); -mat4 getSkinnedTransform(); -void calcAtmospherics(vec3 inPositionEye); - -uniform vec4 color; - -uniform vec4 gWindDir; -uniform vec4 gSinWaveParams; -uniform vec4 gGravity; - -const vec4 gMinMaxConstants = vec4(1.0, 0.166666, 0.0083143, .00018542); // #minimax-generated coefficients -const vec4 gPiConstants = vec4(0.159154943, 6.28318530, 3.141592653, 1.5707963); // # {1/2PI, 2PI, PI, PI/2} - -void main() -{ - vary_texcoord0 = texcoord0; - - vec4 pos; - mat4 trans = getSkinnedTransform(); - - vec3 norm; - norm.x = dot(trans[0].xyz, normal); - norm.y = dot(trans[1].xyz, normal); - norm.z = dot(trans[2].xyz, normal); - norm = normalize(norm); - - //wind - vec4 windEffect; - windEffect = vec4(dot(norm, gWindDir.xyz)); - pos.x = dot(trans[2].xyz, position.xyz); - windEffect.xyz = pos.x * vec3(0.015, 0.015, 0.015) - + windEffect.xyz; - windEffect.w = windEffect.w * 2.0 + 1.0; // move wind offset value to [-1, 3] - windEffect.w = windEffect.w*gWindDir.w; // modulate wind strength - - windEffect.xyz = windEffect.xyz*gSinWaveParams.xyz - +vec3(gSinWaveParams.w); // use sin wave params to scale and offset input - - - //reduce to period of 2 PI - vec4 temp1, temp0, temp2, offsetPos; - temp1.xyz = windEffect.xyz * gPiConstants.x; // change input as multiple of [0-2PI] to [0-1] - temp0.y = mod(temp1.x,1.0); - windEffect.x = temp0.y * gPiConstants.y; // scale from [0,1] to [0, 2PI] - temp1.z = temp1.z - gPiConstants.w; // shift normal oscillation by PI/2 - temp0.y = mod(temp1.z,1.0); - - windEffect.z = temp0.y * gPiConstants.y; // scale from [0,1] to [0, 2PI] - windEffect.xyz = windEffect.xyz + vec3(-3.141592); // offset to [-PI, PI] - - - //calculate sinusoid - vec4 sinWave; - temp1 = windEffect*windEffect; - sinWave = -temp1 * gMinMaxConstants.w - + vec4(gMinMaxConstants.z); // y = -(x^2)/7! + 1/5! - sinWave = sinWave * -temp1 + vec4(gMinMaxConstants.y); // y = -(x^2) * (-(x^2)/7! + 1/5!) + 1/3! - sinWave = sinWave * -temp1 + vec4(gMinMaxConstants.x); // y = -(x^2) * (-(x^2) * (-(x^2)/7! + 1/5!) + 1/3!) + 1 - sinWave = sinWave * windEffect; // y = x * (-(x^2) * (-(x^2) * (-(x^2)/7! + 1/5!) + 1/3!) + 1) - - // sinWave.x holds sin(norm . wind_direction) with primary frequency - // sinWave.y holds sin(norm . wind_direction) with secondary frequency - // sinWave.z hold cos(norm . wind_direction) with primary frequency - sinWave.xyz = sinWave.xyz * gWindDir.w - + vec3(windEffect.w); // multiply by wind strength in gWindDir.w [-wind, wind] - - // add normal facing bias offset [-wind,wind] -> [-wind - .25, wind + 1] - temp1 = vec4(dot(norm, gGravity.xyz)); // how much is this normal facing in direction of gGravity? - temp1 = min(temp1, vec4(0.2,0.0,0.0,0.0)); // clamp [-1, 1] to [-1, 0.2] - temp1 = temp1*vec4(1.5,0.0,0.0,0.0); // scale from [-1,0.2] to [-1.5, 0.3] - sinWave.x = sinWave.x + temp1.x; // add gGravity effect to sinwave (only primary frequency) - sinWave.xyz = sinWave.xyz * clothing.w; // modulate by clothing coverage - - sinWave.xyz = max(sinWave.xyz, vec3(-1.0, -1.0, -1.0)); // clamp to underlying body shape - offsetPos = clothing * sinWave.x; // multiply wind effect times clothing displacement - temp2 = gWindDir*sinWave.z + vec4(norm,0); // calculate normal offset due to wind oscillation - offsetPos = vec4(1.0,1.0,1.0,0.0)*offsetPos+vec4(position.xyz, 1.0); // add to offset vertex position, and zero out effect from w - norm += temp2.xyz*2.0; // add sin wave effect on normals (exaggerated) - - //add "backlighting" effect - float colorAcc; - colorAcc = 1.0 - clothing.w; - norm.z -= colorAcc * 0.2; - - //renormalize normal (again) - norm = normalize(norm); - - pos.x = dot(trans[0], offsetPos); - pos.y = dot(trans[1], offsetPos); - pos.z = dot(trans[2], offsetPos); - pos.w = 1.0; - - calcAtmospherics(pos.xyz); - - vec4 col = calcLighting(pos.xyz, norm, color); - vertex_color = col; - - gl_Position = projection_matrix * pos; -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 27eb0b9888..7c0a11d442 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -287,6 +287,9 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output lit linear color + diffcol.rgb = srgb_to_linear(diffcol.rgb); + spec.rgb = srgb_to_linear(spec.rgb); + vec3 pos = vary_position; float shadow = 1.0f; @@ -318,20 +321,23 @@ void main() 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); - vec3 sun_contrib = min(da, shadow) * sunlit; - vec3 ambenv; vec3 glossenv; vec3 legacyenv; sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); - amblit = max(ambenv, amblit); - color.rgb = amblit; + // use sky settings ambient or irradiance map sample, whichever is brighter + color = max(amblit, ambenv); - color += sun_contrib; + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + color.rgb *= ambient; + + float da = clamp(dot(norm.xyz, sun_dir.xyz), 0.0, 1.0); + vec3 sun_contrib = min(da, shadow) * sunlit; + color.rgb += sun_contrib; + color.rgb *= diffuse.rgb; color *= diffcol.rgb; @@ -359,18 +365,14 @@ void main() { // add environmentmap applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); } - 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 + final_specular.rgb = final_specular.rgb; // SL-14035 - color = mix(color.rgb, srgb_to_linear(diffcol.rgb), diffuse.a); + color = mix(color.rgb, diffcol.rgb, diffuse.a); #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 ); diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 73b852e008..de18251dc4 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -31,8 +31,6 @@ uniform samplerCubeArray reflectionProbes; uniform samplerCubeArray irradianceProbes; -vec3 linear_to_srgb(vec3 col); - layout (std140) uniform ReflectionProbes { // list of OBBs for user override probes @@ -531,32 +529,28 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 refnormpersp = reflect(pos.xyz, norm.xyz); ambenv = sampleProbeAmbient(pos, norm); + ambenv /= 1.725; if (glossiness > 0.0) { float lod = (1.0-glossiness)*reflection_lods; glossenv = sampleProbes(pos, normalize(refnormpersp), lod, 1.f); - glossenv = linear_to_srgb(glossenv); } if (envIntensity > 0.0) { legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, 1.f); - legacyenv = linear_to_srgb(legacyenv); } - - // legacy expects values in sRGB space for now - ambenv = linear_to_srgb(ambenv); - } void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) { - glossenv *= 0.35; // fudge darker - float fresnel = 1.0+dot(normalize(pos.xyz), norm.xyz); - float minf = spec.a * 0.1; - fresnel = fresnel * (1.0-minf) + minf; - glossenv *= spec.rgb*min(fresnel, 1.0); + glossenv *= 0.5; // fudge darker + float fresnel = clamp(1.0+dot(normalize(pos.xyz), norm.xyz), 0.3, 1.0); + fresnel *= fresnel; + fresnel *= spec.a; + glossenv *= spec.rgb*fresnel; + glossenv *= vec3(1.0) - color; // fake energy conservation color.rgb += glossenv; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index cfdbbdfe2c..9374922494 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -114,14 +114,12 @@ void main() vec4 pos = getPositionWithDepth(tc, depth); vec4 norm = texture2DRect(normalMap, tc); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - float light_gamma = 1.0 / 1.3; vec4 diffuse = texture2DRect(diffuseRect, tc); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR linear Emissive #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; - scol_ambocc = pow(scol_ambocc, vec2(light_gamma)); float scol = max(scol_ambocc.r, diffuse.a); float ambocc = scol_ambocc.g; #else @@ -159,13 +157,10 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(srgb_to_linear(amblit),irradiance) * ambocc*4.0; + irradiance = max(amblit*1.725,irradiance*ambocc); vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; - - //baseColor.rgb = vec3(0,0,0); - //colorEmissive = srgb_to_linear(norm.xyz*0.5+0.5); vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); diffuseColor *= 1.0 - metallic; @@ -179,34 +174,37 @@ void main() color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*8.0 * scol; color.rgb += colorEmissive; - color = linear_to_srgb(color); + //color = atmosFragLighting(color, additive, atten); color *= atten.r; - color += 2.0*additive; - color = scaleSoftClipFrag(color); - color = srgb_to_linear(color); - - - frag_color.rgb = color.rgb; //output linear since local lights will be added to this shader's results + color += additive; + } else { + + // legacy shaders are still writng sRGB to gbuffer + diffuse.rgb = srgb_to_linear(diffuse.rgb); + spec.rgb = srgb_to_linear(spec.rgb); + float envIntensity = norm.z; norm.xyz = getNorm(tc); float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); - da = pow(da, light_gamma); - - //diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); - vec3 debug = legacyenv; - amblit = max(ambenv, amblit); - color.rgb = amblit*ambocc; + // use sky settings ambient or irradiance map sample, whichever is brighter + color = max(amblit, ambenv*ambocc); + color = ambenv; + + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0 - ambient); + color.rgb *= ambient; vec3 sun_contrib = min(da, scol) * sunlit; color.rgb += sun_contrib; - color.rgb = min(color.rgb, vec3(1,1,1)); color.rgb *= diffuse.rgb; vec3 refnormpersp = reflect(pos.xyz, norm.xyz); @@ -234,8 +232,9 @@ void main() { // add environmentmap applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); } - color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); + color = mix(color, fullbrightScaleSoftClip(color), diffuse.a); } + } #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos.xyz, vec4(color, bloom)); @@ -243,11 +242,6 @@ void main() bloom = fogged.a; #endif - // convert to linear as fullscreen lights need to sum in linear colorspace - // and will be gamma (re)corrected downstream... - frag_color.rgb = srgb_to_linear(color.rgb); - } - - + frag_color.rgb = color.rgb; //output linear since local lights will be added to this shader's results frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl deleted file mode 100644 index c6ea3ec9d4..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoF.glsl +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @file class3\wl\advancedAtmoF.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 - -in vec3 view_dir; - -uniform vec3 cameraPosLocal; -uniform vec3 sun_dir; -uniform float sun_size; - -uniform sampler2D transmittance_texture; -uniform sampler3D scattering_texture; -uniform sampler3D mie_scattering_texture; -uniform sampler2D irradiance_texture; - -vec3 GetSolarLuminance(); -vec3 GetSkyLuminance(vec3 camPos, vec3 view_dir, float shadow_length, vec3 sun_dir, out vec3 transmittance); -vec3 GetSkyLuminanceToPoint(vec3 camPos, vec3 pos, float shadow_length, vec3 sun_dir, out vec3 transmittance); -vec3 GetSunAndSkyIlluminance(vec3 pos, vec3 norm, vec3 sun_dir, out vec3 sky_irradiance); - -void main() -{ - vec3 view_direction = normalize(view_dir); - - vec3 camPos = cameraPosLocal; - vec3 transmittance; - vec3 sky_illum; - vec3 radiance = GetSkyLuminance(camPos, view_direction, 0.0f, sun_dir, transmittance); - vec3 radiance2 = GetSunAndSkyIlluminance(camPos, view_direction, sun_dir, sky_illum); - - //radiance *= transmittance; - - // If the view ray intersects the Sun, add the Sun radiance. - if (dot(view_direction, sun_dir) >= sun_size) - { - radiance = radiance + transmittance * GetSolarLuminance(); - } - - //vec3 color = vec3(1.0) - exp(-radiance); - //color = pow(color, vec3(1.0 / 2.2)); - - frag_color.rgb = radiance; - - frag_color.a = 1.0; -} - diff --git a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl b/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl deleted file mode 100644 index 65bb00b1f6..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/advancedAtmoV.glsl +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file class3\wl\advancedAtmoV.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$ - */ - -uniform mat4 modelview_projection_matrix; - -ATTRIBUTE vec3 position; - -// Inputs -uniform vec3 camPosLocal; - -out vec3 view_dir; - -void main() -{ - // World / view / projection - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - - // this will be normalized in the frag shader... - view_dir = position.xyz - camPosLocal.xyz; -} - diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl deleted file mode 100644 index 2b70ba76dc..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsF.glsl +++ /dev/null @@ -1,46 +0,0 @@ -/** - * @file class3\wl\atmosphericsF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); -vec3 scaleSoftClipFrag(vec3 light); - -uniform int no_atmo; - -vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten) -{ - if (no_atmo == 1) - { - return light; - } - light *= atten.r; - light += additive; - return light * 2.0; -} - -vec3 atmosLighting(vec3 light) -{ - return atmosFragLighting(light, getAdditiveColor(), getAtmosAttenuation()); -} diff --git a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl deleted file mode 100644 index b76192d73f..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/atmosphericsV.glsl +++ /dev/null @@ -1,51 +0,0 @@ -/** - * @file class3\wl\atmosphericsV.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$ - */ - -// VARYING param funcs -void setSunlitColor(vec3 v); -void setAmblitColor(vec3 v); -void setAdditiveColor(vec3 v); -void setAtmosAttenuation(vec3 v); -void setPositionEye(vec3 v); - -vec3 getAdditiveColor(); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); - -void calcAtmospherics(vec3 inPositionEye) { - - vec3 P = inPositionEye; - setPositionEye(P); - vec3 tmpsunlit = vec3(1); - vec3 tmpamblit = vec3(1); - vec3 tmpaddlit = vec3(1); - vec3 tmpattenlit = vec3(1); - calcAtmosphericVars(inPositionEye, vec3(0), 1, tmpsunlit, tmpamblit, tmpaddlit, tmpattenlit, true); - setSunlitColor(tmpsunlit); - setAmblitColor(tmpamblit); - setAdditiveColor(tmpaddlit); - setAtmosAttenuation(tmpattenlit); -} - diff --git a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl b/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl deleted file mode 100644 index 545a32a227..0000000000 --- a/indra/newview/app_settings/shaders/class3/windlight/transportF.glsl +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @file class3\wl\transportF.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$ - */ - -////////////////////////////////////////////////////////// -// The fragment shader for the terrain atmospherics -////////////////////////////////////////////////////////// - -vec3 getAdditiveColor(); -vec3 getAtmosAttenuation(); - -uniform int no_atmo; - -vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - if (no_atmo == 1) - { - return light; - } - // fullbright responds minimally to atmos scatter effects - light *= min(15.0 * atten.r, 1.0); - light += (0.1 * additive); - return light * 2.0; -} - -vec3 atmosTransport(vec3 light) -{ - return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); -} - -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten) -{ - float brightness = dot(light.rgb, vec3(0.33333)); - return vec3(1,0,1); - //return atmosTransportFrag(light * 0.5, additive * (brightness * 0.5 + 0.5), atten); -} - -vec3 fullbrightAtmosTransport(vec3 light) -{ - return atmosTransportFrag(light, getAdditiveColor(), getAtmosAttenuation()); -} - -vec3 fullbrightShinyAtmosTransport(vec3 light) -{ - float brightness = dot(light.rgb, vec3(0.33333)); - return atmosTransportFrag(light * 0.5, getAdditiveColor() * (brightness * brightness), getAtmosAttenuation()); -} -- cgit v1.2.3 From 23ad6e930b6b4a163c2bb83905ca38ceb04e780e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 26 Sep 2022 17:41:22 -0500 Subject: SL-18190 WIP - Whoopsie from last commit --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 9374922494..29aea62f7b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -176,7 +176,7 @@ void main() //color = atmosFragLighting(color, additive, atten); color *= atten.r; - color += additive; + color += additive*2.0; } else @@ -195,7 +195,6 @@ void main() // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv*ambocc); - color = ambenv; float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; -- cgit v1.2.3 From 44f2286e42a10270c23ea11e308143948d1e3288 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 26 Sep 2022 18:08:42 -0500 Subject: SL-18190 Use bindDeferredShader in alpha pool. Don't redundantly apply ao to irradiance. --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 29aea62f7b..d525b673bf 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -157,7 +157,8 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit*1.725,irradiance*ambocc); + + irradiance = max(amblit*1.725,irradiance); vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; -- cgit v1.2.3 From aaf7b17db047f0cb2630b479d5468062e6ca815e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 27 Sep 2022 23:32:02 -0500 Subject: SL-18190 WIP -- Take 2 on linear space windlight (more methodical approach -- make desired interface but brute force color conversions). Placeholder PBR water and move to deprecate forward rendering shaders. --- .../shaders/class3/deferred/materialF.glsl | 88 ++++++++-------------- .../shaders/class3/deferred/softenLightF.glsl | 44 +++++------ 2 files changed, 50 insertions(+), 82 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 7c0a11d442..c1f60da7ee 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -41,13 +41,10 @@ uniform int sun_up_factor; 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 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFragLinear(vec3 l); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -94,7 +91,7 @@ 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) +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, 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 @@ -172,11 +169,6 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe 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); } } } @@ -288,7 +280,7 @@ void main() //forward rendering, output lit linear color diffcol.rgb = srgb_to_linear(diffcol.rgb); - spec.rgb = srgb_to_linear(spec.rgb); + final_specular.rgb = srgb_to_linear(final_specular.rgb); vec3 pos = vary_position; @@ -298,9 +290,7 @@ void main() 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); @@ -311,70 +301,62 @@ void main() vec3 amblit; vec3 additive; vec3 atten; - - calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVarsLinear(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)); - vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, final_specular.a, env_intensity); + // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv); - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + float ambient = min(abs(dot(norm.xyz, light_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); color.rgb *= ambient; - float da = clamp(dot(norm.xyz, sun_dir.xyz), 0.0, 1.0); + float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); vec3 sun_contrib = min(da, shadow) * sunlit; color.rgb += sun_contrib; - color.rgb *= diffuse.rgb; - color *= diffcol.rgb; - float glare = 0.0; + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - if (spec.a > 0.0) // specular reflection + if (final_specular.a > 0.0) // specular reflection { - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, spec.a)).r); + float sa = dot(normalize(refnormpersp), light_dir.xyz); + vec3 dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, final_specular.a)).r); // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; + vec3 spec_contrib = dumbshiny * final_specular.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; - applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + applyGlossEnv(color, glossenv, final_specular, pos.xyz, norm.xyz); } - color = atmosFragLighting(color, additive, atten); - if (envIntensity > 0.0) + color = mix(color.rgb, diffcol.rgb, diffuse.a); + + if (env_intensity > 0.0) { // add environmentmap - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + applyLegacyEnv(color, legacyenv, final_specular, pos.xyz, norm.xyz, env_intensity); } - vec3 npos = normalize(-pos.xyz); + color.rgb = mix(atmosFragLightingLinear(color.rgb, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a); + color.rgb = scaleSoftClipFragLinear(color.rgb); - vec3 light = vec3(0, 0, 0); - - final_specular.rgb = final_specular.rgb; // SL-14035 +#ifdef WATER_FOG + vec4 temp = applyWaterFogView(pos, vec4(color, 0.0)); + color = temp.rgb; +#endif - color = mix(color.rgb, diffcol.rgb, diffuse.a); + vec3 npos = normalize(-pos.xyz); + vec3 light = vec3(0, 0, 0); -#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 ); +#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, light_attenuation[i].w ); LIGHT_LOOP(1) LIGHT_LOOP(2) @@ -386,17 +368,9 @@ void main() color += light; - glare = min(glare, 1.0); - float al = max(diffcol.a, glare)*vertex_color.a; - -#ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color, al)); - color = temp.rgb; - al = temp.a; -#endif + float al = diffcol.a*vertex_color.a; frag_color = vec4(color, al); - #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index d525b673bf..c7ec1ddde9 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -69,11 +69,10 @@ uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); vec4 getPositionWithDepth(vec2 pos_screen, float depth); -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); -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 calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); +vec3 scaleSoftClipFragLinear(vec3 l); +vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); // reflection probe interface void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, @@ -135,7 +134,7 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, light_dir, ambocc, sunlit, amblit, additive, atten, true); + calcAtmosphericVarsLinear(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); vec3 ambenv; vec3 glossenv; @@ -158,7 +157,7 @@ void main() vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit*1.725,irradiance); + irradiance = max(amblit*ao,irradiance); vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; @@ -172,17 +171,14 @@ void main() float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); - color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*8.0 * scol; + color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*2.75 * scol; color.rgb += colorEmissive; - //color = atmosFragLighting(color, additive, atten); - color *= atten.r; - color += additive*2.0; - + color = atmosFragLightingLinear(color, additive, atten); + color = scaleSoftClipFragLinear(color); } else { - // legacy shaders are still writng sRGB to gbuffer diffuse.rgb = srgb_to_linear(diffuse.rgb); spec.rgb = srgb_to_linear(spec.rgb); @@ -197,7 +193,7 @@ void main() // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv*ambocc); - float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + float ambient = min(abs(dot(norm.xyz, light_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0 - ambient); @@ -216,32 +212,30 @@ void main() // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 6; color.rgb += spec_contrib; - // add reflection map - EXPERIMENTAL WORK IN PROGRESS + // add radiance map applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); - + + if (envIntensity > 0.0) + { // add environment map + applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); + } if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { - color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a); - if (envIntensity > 0.0) - { // add environmentmap - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); - } - color = mix(color, fullbrightScaleSoftClip(color), diffuse.a); + color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a); + color = scaleSoftClipFragLinear(color); } } #ifdef WATER_FOG vec4 fogged = applyWaterFogView(pos.xyz, vec4(color, bloom)); color = fogged.rgb; - bloom = fogged.a; #endif frag_color.rgb = color.rgb; //output linear since local lights will be added to this shader's results - frag_color.a = bloom; + frag_color.a = 0.0; } -- cgit v1.2.3 From f887f65830c05d15517cbd8f15ca0e59210dfbee Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 28 Sep 2022 16:49:11 -0500 Subject: SL-18190 WIP - Linear space atmospherics take 2 --- .../shaders/class3/deferred/reflectionProbeF.glsl | 4 ++-- .../shaders/class3/deferred/softenLightF.glsl | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index de18251dc4..a1125cc1dd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -551,7 +551,7 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no fresnel *= spec.a; glossenv *= spec.rgb*fresnel; glossenv *= vec3(1.0) - color; // fake energy conservation - color.rgb += glossenv; + color.rgb += glossenv*0.5; } void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) @@ -562,6 +562,6 @@ void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 no fresnel *= fresnel; fresnel = min(fresnel+envIntensity, 1.0); reflected_color *= (envIntensity*fresnel); - color = mix(color.rgb, reflected_color, envIntensity); + color = mix(color.rgb, reflected_color*0.5, envIntensity); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index c7ec1ddde9..1795f3fd1a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -140,8 +140,7 @@ void main() vec3 glossenv; vec3 legacyenv; - bool hasPBR = GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR); - if (hasPBR) + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { norm.xyz = getNorm(tc); vec3 orm = texture2DRect(specularRect, tc).rgb; @@ -157,7 +156,7 @@ void main() vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit*ao,irradiance); + irradiance = max(amblit*2.0*ao,irradiance); vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; @@ -170,13 +169,19 @@ void main() vec3 v = -normalize(pos.xyz); float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); - color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*2.75 * scol; color.rgb += colorEmissive; + + color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); color = atmosFragLightingLinear(color, additive, atten); color = scaleSoftClipFragLinear(color); } + else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) + { + //should only be true of WL sky, just port over diffuse value + color = srgb_to_linear(diffuse.rgb); + } else { // legacy shaders are still writng sRGB to gbuffer @@ -223,12 +228,10 @@ void main() if (envIntensity > 0.0) { // add environment map applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); - } - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) - { - color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a); - color = scaleSoftClipFragLinear(color); } + + color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a); + color = scaleSoftClipFragLinear(color); } #ifdef WATER_FOG -- cgit v1.2.3 From 411aa9f727efba971c8577cef4d6a31f096a6fea Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 29 Sep 2022 00:19:52 -0500 Subject: SL-18190 Fix for haze color being completely wrong (now it's just half wrong). --- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 1795f3fd1a..7635897db1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -156,7 +156,7 @@ void main() vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit*2.0*ao,irradiance); + irradiance = max(amblit*0.75,irradiance); vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; @@ -169,8 +169,8 @@ void main() vec3 v = -normalize(pos.xyz); float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); - color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*2.75 * scol; - color.rgb += colorEmissive; + color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit * 2.75 * scol; + color.rgb += colorEmissive*0.5; color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); -- cgit v1.2.3 From d001c52c346d957375afc36bd83550a5702d4727 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 29 Sep 2022 19:24:08 -0500 Subject: SL-18132 Fix for errant shadow when sun shadows are disabled. --- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 7635897db1..3e44e87f1e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -119,10 +119,16 @@ void main() #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; +#endif + +#if defined(HAS_SUN_SHADOW) float scol = max(scol_ambocc.r, diffuse.a); - float ambocc = scol_ambocc.g; #else float scol = 1.0; +#endif +#if defined(HAS_SSAO) + float ambocc = scol_ambocc.g; +#else float ambocc = 1.0; #endif -- cgit v1.2.3 From 7d426815019ac5394e5821f1c6ba374e12606aaa Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 30 Sep 2022 10:57:01 -0500 Subject: SL-18239 Unify PBR and non-PBR treatment of ambient/SSAO/irradiance. Restore SSAO to release version. --- .../shaders/class3/deferred/materialF.glsl | 10 +--- .../shaders/class3/deferred/reflectionProbeF.glsl | 1 - .../shaders/class3/deferred/softenLightF.glsl | 53 ++++++++++------------ 3 files changed, 26 insertions(+), 38 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index c1f60da7ee..1150d40007 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -43,7 +43,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFragLinear(vec3 l); -void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); vec3 srgb_to_linear(vec3 cs); @@ -301,7 +301,7 @@ void main() vec3 amblit; vec3 additive; vec3 atten; - calcAtmosphericVarsLinear(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); vec3 ambenv; vec3 glossenv; @@ -311,12 +311,6 @@ void main() // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv); - float ambient = min(abs(dot(norm.xyz, light_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - color.rgb *= ambient; - float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); vec3 sun_contrib = min(da, shadow) * sunlit; color.rgb += sun_contrib; diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index a1125cc1dd..80f9e29123 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -529,7 +529,6 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 refnormpersp = reflect(pos.xyz, norm.xyz); ambenv = sampleProbeAmbient(pos, norm); - ambenv /= 1.725; if (glossiness > 0.0) { diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 3e44e87f1e..e5ffe55163 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -69,7 +69,7 @@ uniform vec2 screen_res; vec3 getNorm(vec2 pos_screen); vec4 getPositionWithDepth(vec2 pos_screen, float depth); -void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFragLinear(vec3 l); vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); @@ -112,9 +112,11 @@ void main() float depth = texture2DRect(depthMap, tc.xy).r; vec4 pos = getPositionWithDepth(tc, depth); vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = getNorm(tc); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - vec4 diffuse = texture2DRect(diffuseRect, tc); + vec4 baseColor = texture2DRect(diffuseRect, tc); vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR linear Emissive #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) @@ -122,7 +124,7 @@ void main() #endif #if defined(HAS_SUN_SHADOW) - float scol = max(scol_ambocc.r, diffuse.a); + float scol = max(scol_ambocc.r, baseColor.a); #else float scol = 1.0; #endif @@ -140,15 +142,10 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVarsLinear(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - - vec3 ambenv; - vec3 glossenv; - vec3 legacyenv; + calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - norm.xyz = getNorm(tc); vec3 orm = texture2DRect(specularRect, tc).rgb; float perceptualRoughness = orm.g; float metallic = orm.b; @@ -162,11 +159,11 @@ void main() vec3 radiance = vec3(0); sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); - irradiance = max(amblit*0.75,irradiance); + // Take maximium of legacy ambient vs irradiance sample as irradiance + // NOTE: ao is applied in pbrIbl, do not apply here + irradiance = max(amblit,irradiance); vec3 f0 = vec3(0.04); - vec3 baseColor = diffuse.rgb; - vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); diffuseColor *= 1.0 - metallic; @@ -185,35 +182,33 @@ void main() } else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { - //should only be true of WL sky, just port over diffuse value - color = srgb_to_linear(diffuse.rgb); + //should only be true of WL sky, just port over base color value + color = srgb_to_linear(baseColor.rgb); } else { // legacy shaders are still writng sRGB to gbuffer - diffuse.rgb = srgb_to_linear(diffuse.rgb); + baseColor.rgb = srgb_to_linear(baseColor.rgb); spec.rgb = srgb_to_linear(spec.rgb); - float envIntensity = norm.z; - norm.xyz = getNorm(tc); - float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + vec3 irradiance = vec3(0); + vec3 glossenv = vec3(0); + vec3 legacyenv = vec3(0); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + // use sky settings ambient or irradiance map sample, whichever is brighter - color = max(amblit, ambenv*ambocc); + irradiance = max(amblit, irradiance); - float ambient = min(abs(dot(norm.xyz, light_dir.xyz)), 1.0); - ambient *= 0.5; - ambient *= ambient; - ambient = (1.0 - ambient); - color.rgb *= ambient; + // apply lambertian IBL only (see pbrIbl) + color.rgb = irradiance * ambocc; vec3 sun_contrib = min(da, scol) * sunlit; color.rgb += sun_contrib; - color.rgb *= diffuse.rgb; - + color.rgb *= baseColor.rgb; + vec3 refnormpersp = reflect(pos.xyz, norm.xyz); if (spec.a > 0.0) // specular reflection @@ -229,14 +224,14 @@ void main() applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } - color.rgb = mix(color.rgb, diffuse.rgb, diffuse.a); + color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a); if (envIntensity > 0.0) { // add environment map applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); } - color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a); + color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), baseColor.a); color = scaleSoftClipFragLinear(color); } -- cgit v1.2.3 From 9448db5d4af7bba094e5bc51f85e5c2491d3f5a1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 6 Oct 2022 18:40:01 -0500 Subject: SL-18190 Water shader WIP. Better parallax correction for sphere probes. Reduce probe memory footprint. Remove framebuffer copies and move to deprecate stencil buffer usage. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 66 ++++++++++++++++------ 1 file changed, 49 insertions(+), 17 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 80f9e29123..ec9218f00e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -239,7 +239,7 @@ bool intersect(const Ray &ray) const return true; } */ -// adapted -- assume that origin is inside sphere, return distance from origin to edge of sphere +// adapted -- assume that origin is inside sphere, return intersection of ray with edge of sphere vec3 sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) { float t0, t1; // solutions for t if the ray intersects @@ -310,17 +310,19 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i) // Tap a reflection probe // pos - position of pixel // dir - pixel normal +// vi - return value of intersection point with influence volume +// wi - return value of approximate world space position of sampled pixel // lod - which mip to bias towards (lower is higher res, sharper reflections) // c - center of probe // r2 - radius of probe squared // i - index of probe -// vi - point at which reflection vector struck the influence volume, in clip space -vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) +vec3 tapRefMap(vec3 pos, vec3 dir, out vec3 vi, out vec3 wi, float lod, vec3 c, float r2, int i) { //lod = max(lod, 1); // parallax adjustment vec3 v; + if (refIndex[i].w < 0) { v = boxIntersect(pos, dir, i); @@ -330,11 +332,18 @@ vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) v = sphereIntersect(pos, dir, c, r2); } + vi = v; + v -= c; + vec3 d = normalize(v); + v = env_mat * v; - { - return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod).rgb; - } + + vec4 ret = textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod); + + wi = d * ret.a * 256.0+c; + + return ret.rgb; } // Tap an irradiance map @@ -343,7 +352,6 @@ vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) // c - center of probe // r2 - radius of probe squared // i - index of probe -// vi - point at which reflection vector struck the influence volume, in clip space vec3 tapIrradianceMap(vec3 pos, vec3 dir, vec3 c, float r2, int i) { //lod = max(lod, 1); @@ -383,26 +391,48 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) float p = float(abs(refIndex[i].w)); // priority float rr = r*r; // radius squred - float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) + float r1 = r * 0.1; // 90% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz-refSphere[i].xyz; float d2 = dot(delta,delta); float r2 = r1*r1; { - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, rr, i); - - float w = 1.0/d2; + vec3 vi, wi; + + vec3 refcol = tapRefMap(pos, dir, vi, wi, lod, refSphere[i].xyz, rr, i); float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); + + if (refIndex[i].w >= 0) + { + //adjust lookup by distance result + float d = length(vi - wi); + vi += dir * d; + + vi -= refSphere[i].xyz; + + vi = env_mat * vi; + + refcol = textureLod(reflectionProbes, vec4(vi, refIndex[i].x), lod).rgb; + } + + //float w = 1.0 / max(d3, 1.0); + vec3 pi = normalize(wi - pos); + float w = max(dot(pi, dir), 0.1); + w = pow(w, 32.0); + w *= atten; + + //w *= p; // boost weight based on priority - col += refcol*w; - + col += refcol.rgb*w; + wsum += w; } } - if (probeInfluences <= 1) +#if 1 + if (probeInfluences < 1) { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera for (int idx = 0; idx < 8; ++idx) { @@ -415,15 +445,17 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) float d2 = dot(delta,delta); { - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, d2, i); - + vec3 vi, wi; + vec3 refcol = tapRefMap(pos, dir, vi, wi, lod, refSphere[i].xyz, d2, i); + float w = 1.0/d2; w *= w; - col += refcol*w; + col += refcol.rgb*w; wsum += w; } } } +#endif if (wsum > 0.0) { -- cgit v1.2.3 From 25bff0c21dafcfca4d098f2d51a46a09c543a12c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 7 Oct 2022 19:27:19 -0500 Subject: SL-18190 Move water shaders to class 3, add debug stub for underWaterF.glsl, make underWaterF and softenLightF apply water fog in linear space. --- .../shaders/class3/deferred/softenLightF.glsl | 4 +- .../shaders/class3/environment/underWaterF.glsl | 74 ++++++ .../shaders/class3/environment/waterF.glsl | 258 +++++++++++++++++++++ 3 files changed, 334 insertions(+), 2 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/environment/waterF.glsl (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index e5ffe55163..eea497bce5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -86,7 +86,7 @@ vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); #ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); #endif // PBR interface @@ -236,7 +236,7 @@ void main() } #ifdef WATER_FOG - vec4 fogged = applyWaterFogView(pos.xyz, vec4(color, bloom)); + vec4 fogged = applyWaterFogViewLinear(pos.xyz, vec4(color, bloom)); color = fogged.rgb; #endif diff --git a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl new file mode 100644 index 0000000000..819e6dcf15 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl @@ -0,0 +1,74 @@ +/** + * @file class3\environment\underWaterF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +out vec4 frag_color; + +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; +in vec3 vary_position; + +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); + +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 = applyWaterFogViewLinear(vary_position, fb); +} diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl new file mode 100644 index 0000000000..4c361884a5 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -0,0 +1,258 @@ +/** + * @file waterF.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$ + */ + +// class3/environment/waterF.glsl + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +vec3 scaleSoftClipFragLinear(vec3 l); +vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); + +// PBR interface +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 perceptualRoughness); + +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 + +uniform sampler2D bumpMap; +uniform sampler2D bumpMap2; +uniform float blend_factor; +uniform sampler2D screenTex; +uniform sampler2D screenDepth; + +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 vec4 waterFogColor; + + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; +in vec3 vary_position; +in vec3 vary_normal; +in vec3 vary_tangent; +in vec3 vary_light_dir; + +vec3 BlendNormal(vec3 bump1, vec3 bump2) +{ + vec3 n = mix(bump1, bump2, blend_factor); + return n; +} + +vec3 srgb_to_linear(vec3 col); + +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec3 pos, vec3 norm, float glossiness, float envIntensity); + +vec3 vN, vT, vB; + +vec3 transform_normal(vec3 vNt) +{ + return normalize(vNt.x * vT + vNt.y * vB + vNt.z * vN); +} + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec3 pos, vec3 norm, float glossiness); + +vec3 getPositionWithNDC(vec3 ndc); + +void main() +{ + vec4 color; + + vN = vary_normal; + vT = vary_tangent; + vB = cross(vN, vT); + + vec3 pos = vary_position.xyz; + + float dist = length(pos.xyz); + + //normalize view vector + vec3 viewVec = normalize(pos.xyz); + + //get wave normals + vec2 bigwave = vec2(refCoord.w, view.w); + vec3 wave1_a = texture(bumpMap, bigwave, -2 ).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 = texture(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); + + wave1 = transform_normal(wave1); + wave2 = transform_normal(wave2); + wave3 = transform_normal(wave3); + + vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + + //wavef.z *= max(-viewVec.z, 0.1); + + wavef = normalize(wavef); + + //get base fresnel components + + vec3 df = vec3( + dot(viewVec, wave1), + dot(viewVec, (wave2 + wave3) * 0.5), + dot(viewVec, wave3) + ) * fresnelScale + fresnelOffset; + + 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); + + float df1 = df.x + df.y + df.z; + + //wavef = normalize(wavef - vary_normal); + //wavef = vary_normal; + + vec3 waver = reflect(viewVec, -wavef)*3; + + //figure out distortion vector (ripply) + vec2 distort2 = distort + waver.xy * refScale / max(dmod * df1, 1.0); + distort2 = clamp(distort2, vec2(0), vec2(0.99)); + + vec4 fb = texture2D(screenTex, distort2); + float depth = texture2D(screenDepth, distort2).r; + vec3 refPos = getPositionWithNDC(vec3(distort2*2.0-vec2(1.0), depth*2.0-1.0)); + + if (refPos.z > pos.z-0.05) + { + //we sampled an above water sample, don't distort + distort2 = distort; + fb = texture2D(screenTex, distort2); + depth = texture2D(screenDepth, distort2).r; + refPos = getPositionWithNDC(vec3(distort2 * 2.0 - vec2(1.0), depth * 2.0 - 1.0)); + } + + fb = applyWaterFogViewLinear(refPos, fb); + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); + sunlit = vec3(1); // TODO -- figure out why sunlit is breaking at some view angles + vec3 v = -viewVec; + float NdotV = clamp(abs(dot(wavef.xyz, v)), 0.001, 1.0); + + float metallic = fresnelOffset * 0.1; // fudge -- use fresnelOffset as metalness + float roughness = 0.1; + float gloss = 1.0 - roughness; + + vec3 baseColor = vec3(0.25); + vec3 f0 = vec3(0.04); + vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0); + diffuseColor *= gloss; + + vec3 specularColor = mix(f0, baseColor.rgb, metallic); + + vec3 refnorm = normalize(wavef + vary_normal); + //vec3 refnorm = wavef; + + vec3 irradiance = vec3(0); + vec3 radiance = vec3(0); + sampleReflectionProbes(irradiance, radiance, pos, refnorm, gloss); + radiance *= 0.5; + irradiance = fb.rgb; + + color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0); + + // fudge -- for punctual lighting, pretend water is metallic + diffuseColor = vec3(0); + specularColor = vec3(1); + roughness = 0.1; + float scol = 1.0; // TODO -- incorporate shadow map + + //color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir) * sunlit * 2.75 * scol; + + //get specular component + float spec = clamp(dot(vary_light_dir, (reflect(viewVec, wavef))), 0.0, 1.0); + + //harden specular + spec = pow(spec, 128.0); + + color.rgb += spec * specular; + + color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); + color.rgb = scaleSoftClipFragLinear(color.rgb); + + color.a = 0.f; + //color.rgb = fb.rgb; + //color.rgb = vec3(depth*depth*depth*depth); + //color.rgb = srgb_to_linear(normalize(refPos) * 0.5 + 0.5); + //color.rgb = srgb_to_linear(normalize(pos) * 0.5 + 0.5); + //color.rgb = srgb_to_linear(wavef * 0.5 + 0.5); + + //color.rgb = radiance; + frag_color = color; + +#if defined(WATER_EDGE) + gl_FragDepth = 0.9999847f; +#endif + +} + -- cgit v1.2.3 From 0fed3884c21453eac23a4de714bc87cac9e5377e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 10 Oct 2022 10:19:36 -0500 Subject: SL-18190 Use funky distance based error correction only on water surface (revisit for general use later). --- .../shaders/class3/deferred/reflectionProbeF.glsl | 46 ++++++++++++++-------- .../shaders/class3/environment/waterF.glsl | 4 +- 2 files changed, 31 insertions(+), 19 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index ec9218f00e..925398671c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -374,7 +374,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, vec3 c, float r2, int i) } } -vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) +vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) { float wsum = 0.0; vec3 col = vec3(0,0,0); @@ -399,12 +399,15 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) { vec3 vi, wi; - vec3 refcol = tapRefMap(pos, dir, vi, wi, lod, refSphere[i].xyz, rr, i); + float atten = 1.0 - max(d2 - r2, 0.0) / (rr - r2); + float w; + vec3 refcol; - float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); + if (errorCorrect && refIndex[i].w >= 0) + { // error correction is on and this probe is a sphere + //take a sample to get depth value, then error correct + refcol = tapRefMap(pos, dir, vi, wi, abs(lod + 2), refSphere[i].xyz, rr, i); - if (refIndex[i].w >= 0) - { //adjust lookup by distance result float d = length(vi - wi); vi += dir * d; @@ -414,16 +417,20 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) vi = env_mat * vi; refcol = textureLod(reflectionProbes, vec4(vi, refIndex[i].x), lod).rgb; + + // weight by vector correctness + vec3 pi = normalize(wi - pos); + w = max(dot(pi, dir), 0.1); + w = pow(w, 32.0); + } + else + { + w = 1.0 / d2; + refcol = tapRefMap(pos, dir, vi, wi, lod, refSphere[i].xyz, rr, i); } - //float w = 1.0 / max(d3, 1.0); - vec3 pi = normalize(wi - pos); - float w = max(dot(pi, dir), 0.1); - w = pow(w, 32.0); - w *= atten; - //w *= p; // boost weight based on priority col += refcol.rgb*w; @@ -431,7 +438,6 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) } } -#if 1 if (probeInfluences < 1) { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera for (int idx = 0; idx < 8; ++idx) @@ -455,7 +461,6 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) } } } -#endif if (wsum > 0.0) { @@ -537,7 +542,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness) + vec3 pos, vec3 norm, float glossiness, bool errorCorrect) { // TODO - don't hard code lods float reflection_lods = 7; @@ -548,7 +553,14 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, ambenv = sampleProbeAmbient(pos, norm); float lod = (1.0-glossiness)*reflection_lods; - glossenv = sampleProbes(pos, normalize(refnormpersp), lod, 1.f); + glossenv = sampleProbes(pos, normalize(refnormpersp), lod, errorCorrect); +} + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec3 pos, vec3 norm, float glossiness) +{ + sampleReflectionProbes(ambenv, glossenv, + pos, norm, glossiness, false); } void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, @@ -565,12 +577,12 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout if (glossiness > 0.0) { float lod = (1.0-glossiness)*reflection_lods; - glossenv = sampleProbes(pos, normalize(refnormpersp), lod, 1.f); + glossenv = sampleProbes(pos, normalize(refnormpersp), lod, false); } if (envIntensity > 0.0) { - legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, 1.f); + legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, false); } } diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 4c361884a5..9793a0e786 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -103,7 +103,7 @@ vec3 transform_normal(vec3 vNt) } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness); + vec3 pos, vec3 norm, float glossiness, bool errorCorrect); vec3 getPositionWithNDC(vec3 ndc); @@ -215,7 +215,7 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, pos, refnorm, gloss); + sampleReflectionProbes(irradiance, radiance, pos, refnorm, gloss, true); radiance *= 0.5; irradiance = fb.rgb; -- cgit v1.2.3 From 07bca31e06e4219401f82ae04539418c65e22ea8 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 10 Oct 2022 18:53:43 -0500 Subject: SL-18190 Fix alpha not playing nice with water surface by split LLDrawPoolAlpha into two passes, one above water, one below water, and clip against water plane. Currently brute forces two complete alpha passes, still need to cull against water plane and add support for fullbright shaders. --- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 1150d40007..8016022d78 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -90,6 +90,7 @@ uniform vec4 light_attenuation[8]; uniform vec3 light_diffuse[8]; float getAmbientClamp(); +void waterClip(vec3 pos); 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, float ambiance) { @@ -219,6 +220,10 @@ vec2 encode_normal(vec3 n); void main() { +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + waterClip(vary_position.xyz); +#endif + vec2 pos_screen = vary_texcoord0.xy; vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); @@ -277,7 +282,6 @@ void main() #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - //forward rendering, output lit linear color diffcol.rgb = srgb_to_linear(diffcol.rgb); final_specular.rgb = srgb_to_linear(final_specular.rgb); -- cgit v1.2.3 From dafa93304335c3c48042e4b5a014dea2480f253f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 11 Oct 2022 16:33:51 -0500 Subject: SL-18190 Fix for mystery circle showing up on east side of reflection probes. Add one probe to rule them all as a fallback for pixels that aren't inside any influence volume. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 140 ++++++++------------- 1 file changed, 51 insertions(+), 89 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 925398671c..6d3bff0562 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -114,8 +114,7 @@ bool shouldSampleProbe(int i, vec3 pos) void preProbeSample(vec3 pos) { // TODO: make some sort of structure that reduces the number of distance checks - - for (int i = 0; i < refmapCount; ++i) + for (int i = 1; i < refmapCount; ++i) { // found an influencing probe if (shouldSampleProbe(i, pos)) @@ -200,6 +199,12 @@ void preProbeSample(vec3 pos) } } } + + if (probeInfluences == 0) + { // probe at index 0 is a special fallback probe + probeIndex[0] = 0; + probeInfluences = 1; + } } // from https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection @@ -316,7 +321,7 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i) // c - center of probe // r2 - radius of probe squared // i - index of probe -vec3 tapRefMap(vec3 pos, vec3 dir, out vec3 vi, out vec3 wi, float lod, vec3 c, float r2, int i) +vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out vec3 vi, out vec3 wi, float lod, vec3 c, int i) { //lod = max(lod, 1); // parallax adjustment @@ -326,10 +331,26 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out vec3 vi, out vec3 wi, float lod, vec3 c, if (refIndex[i].w < 0) { v = boxIntersect(pos, dir, i); + w = 1.0; } else { - v = sphereIntersect(pos, dir, c, r2); + float r = refSphere[i].w; // radius of sphere volume + float rr = r * r; // radius squared + + v = sphereIntersect(pos, dir, c, rr); + + float p = float(abs(refIndex[i].w)); // priority + + float r1 = r * 0.1; // 90% of radius (outer sphere to start interpolating down) + vec3 delta = pos.xyz - refSphere[i].xyz; + float d2 = max(dot(delta, delta), 0.001); + float r2 = r1 * r1; + + float atten = 1.0 - max(d2 - r2, 0.0) / max((rr - r2), 0.001); + + w = 1.0 / d2; + w *= atten; } vi = v; @@ -352,19 +373,32 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out vec3 vi, out vec3 wi, float lod, vec3 c, // c - center of probe // r2 - radius of probe squared // i - index of probe -vec3 tapIrradianceMap(vec3 pos, vec3 dir, vec3 c, float r2, int i) +vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) { - //lod = max(lod, 1); // parallax adjustment - vec3 v; if (refIndex[i].w < 0) { v = boxIntersect(pos, dir, i); + w = 1.0; } else { - v = sphereIntersect(pos, dir, c, r2); + float r = refSphere[i].w; // radius of sphere volume + float p = float(abs(refIndex[i].w)); // priority + float rr = r * r; // radius squred + + v = sphereIntersect(pos, dir, c, rr); + + float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) + vec3 delta = pos.xyz - refSphere[i].xyz; + float d2 = dot(delta, delta); + float r2 = r1 * r1; + + w = 1.0 / d2; + + float atten = 1.0 - max(d2 - r2, 0.0) / (rr - r2); + w *= atten; } v -= c; @@ -387,26 +421,17 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) { continue; } - float r = refSphere[i].w; // radius of sphere volume - float p = float(abs(refIndex[i].w)); // priority - - float rr = r*r; // radius squred - float r1 = r * 0.1; // 90% of radius (outer sphere to start interpolating down) - vec3 delta = pos.xyz-refSphere[i].xyz; - float d2 = dot(delta,delta); - float r2 = r1*r1; - - { - vec3 vi, wi; - float atten = 1.0 - max(d2 - r2, 0.0) / (rr - r2); - float w; - vec3 refcol; + float w; + vec3 vi, wi; + vec3 refcol; + + { if (errorCorrect && refIndex[i].w >= 0) { // error correction is on and this probe is a sphere //take a sample to get depth value, then error correct - refcol = tapRefMap(pos, dir, vi, wi, abs(lod + 2), refSphere[i].xyz, rr, i); + refcol = tapRefMap(pos, dir, w, vi, wi, abs(lod + 2), refSphere[i].xyz, i); //adjust lookup by distance result float d = length(vi - wi); @@ -425,43 +450,15 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) } else { - w = 1.0 / d2; - refcol = tapRefMap(pos, dir, vi, wi, lod, refSphere[i].xyz, rr, i); + refcol = tapRefMap(pos, dir, w, vi, wi, lod, refSphere[i].xyz, i); } - w *= atten; - - //w *= p; // boost weight based on priority col += refcol.rgb*w; wsum += w; } } - if (probeInfluences < 1) - { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera - for (int idx = 0; idx < 8; ++idx) - { - if (refIndex[idx].w < 0) - { // don't fallback to box probes, they are *very* specific - continue; - } - int i = idx; - vec3 delta = pos.xyz-refSphere[i].xyz; - float d2 = dot(delta,delta); - - { - vec3 vi, wi; - vec3 refcol = tapRefMap(pos, dir, vi, wi, lod, refSphere[i].xyz, d2, i); - - float w = 1.0/d2; - w *= w; - col += refcol.rgb*w; - wsum += w; - } - } - } - if (wsum > 0.0) { col *= 1.0/wsum; @@ -487,52 +484,17 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) { continue; } - float r = refSphere[i].w; // radius of sphere volume - float p = float(abs(refIndex[i].w)); // priority - - float rr = r*r; // radius squred - float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) - vec3 delta = pos.xyz-refSphere[i].xyz; - float d2 = dot(delta,delta); - float r2 = r1*r1; { - vec3 refcol = tapIrradianceMap(pos, dir, refSphere[i].xyz, rr, i); - - float w = 1.0/d2; + float w; + vec3 refcol = tapIrradianceMap(pos, dir, w, refSphere[i].xyz, i); - float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); - w *= atten; - //w *= p; // boost weight based on priority col += refcol*w; wsum += w; } } - if (probeInfluences <= 1) - { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera - for (int idx = 0; idx < 8; ++idx) - { - if (refIndex[idx].w < 0) - { // don't fallback to box probes, they are *very* specific - continue; - } - int i = idx; - vec3 delta = pos.xyz-refSphere[i].xyz; - float d2 = dot(delta,delta); - - { - vec3 refcol = tapIrradianceMap(pos, dir, refSphere[i].xyz, d2, i); - - float w = 1.0/d2; - w *= w; - col += refcol*w; - wsum += w; - } - } - } - if (wsum > 0.0) { col *= 1.0/wsum; -- cgit v1.2.3 From 42ec639c860e172803753b9cb41ae9483305f2f8 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 12 Oct 2022 14:46:51 -0500 Subject: SL-18190 Remove water reflection detail combo box and reimplement "Transparent Water" checkbox. --- .../shaders/class3/environment/underWaterF.glsl | 19 +++++++++++++------ .../shaders/class3/environment/waterF.glsl | 7 +++++++ 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl index 819e6dcf15..a5e0adf8fa 100644 --- a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl @@ -26,10 +26,12 @@ out vec4 frag_color; uniform sampler2D diffuseMap; -uniform sampler2D bumpMap; +uniform sampler2D bumpMap; + +#ifdef TRANSPARENT_WATER uniform sampler2D screenTex; -uniform sampler2D refTex; uniform sampler2D screenDepth; +#endif uniform vec4 fogCol; uniform vec3 lightDir; @@ -43,6 +45,7 @@ uniform float kd; uniform vec4 waterPlane; uniform vec3 eyeVec; uniform vec4 waterFogColor; +uniform vec3 waterFogColorLinear; uniform float waterFogKS; uniform vec2 screenRes; @@ -57,8 +60,8 @@ vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); void main() { vec4 color; - - //get detail normals + + //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; @@ -67,8 +70,12 @@ void main() //figure out distortion vector (ripply) vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; distort = distort+wavef.xy*refScale; - + +#ifdef TRANSPARENT_WATER vec4 fb = texture2D(screenTex, distort); - +#else + vec4 fb = vec4(waterFogColorLinear, 0.0); +#endif + frag_color = applyWaterFogViewLinear(vary_position, fb); } diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 9793a0e786..a6517be433 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -55,8 +55,10 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, uniform sampler2D bumpMap; uniform sampler2D bumpMap2; uniform float blend_factor; +#ifdef TRANSPARENT_WATER uniform sampler2D screenTex; uniform sampler2D screenDepth; +#endif uniform sampler2D refTex; @@ -73,6 +75,7 @@ uniform float fresnelScale; uniform float fresnelOffset; uniform float blurMultiplier; uniform vec4 waterFogColor; +uniform vec3 waterFogColorLinear; //bigWave is (refCoord.w, view.w); @@ -174,6 +177,7 @@ void main() vec2 distort2 = distort + waver.xy * refScale / max(dmod * df1, 1.0); distort2 = clamp(distort2, vec2(0), vec2(0.99)); +#ifdef TRANSPARENT_WATER vec4 fb = texture2D(screenTex, distort2); float depth = texture2D(screenDepth, distort2).r; vec3 refPos = getPositionWithNDC(vec3(distort2*2.0-vec2(1.0), depth*2.0-1.0)); @@ -188,6 +192,9 @@ void main() } fb = applyWaterFogViewLinear(refPos, fb); +#else + vec4 fb = vec4(waterFogColorLinear.rgb, 0.0); +#endif vec3 sunlit; vec3 amblit; -- cgit v1.2.3 From bb70a2bc773c34e50020abf3679cbbd566cb7dfa Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 13 Oct 2022 12:55:47 -0500 Subject: SL-18190 Tweak reflection probe mixing on water. --- .../app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 6d3bff0562..211e1f5d8d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -445,8 +445,8 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) // weight by vector correctness vec3 pi = normalize(wi - pos); - w = max(dot(pi, dir), 0.1); - w = pow(w, 32.0); + w *= max(dot(pi, dir), 0.1); + //w = pow(w, 32.0); } else { -- cgit v1.2.3 From 982e2bcbeaa3a56a884ecb168dc655dc6413465c Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Thu, 13 Oct 2022 16:59:34 -0700 Subject: SL-18340: Consolidate shared pbr shading into calcDiffuseSpecular, pbrBaseLight --- .../shaders/class3/deferred/softenLightF.glsl | 45 +++++++++++----------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index eea497bce5..879f4ef510 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -89,14 +89,23 @@ vec3 srgb_to_linear(vec3 c); vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); #endif -// PBR interface -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 perceptualRoughness); +void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); + +vec3 pbrBaseLight(vec3 diffuseColor, + vec3 specularColor, + float metallic, + vec3 pos, + vec3 norm, + float perceptualRoughness, + vec3 light_dir, + vec3 sunlit, + float scol, + vec3 radiance, + vec3 irradiance, + vec3 colorEmissive, + float ao, + vec3 additive, + vec3 atten); vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, @@ -160,25 +169,15 @@ void main() sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); // Take maximium of legacy ambient vs irradiance sample as irradiance - // NOTE: ao is applied in pbrIbl, do not apply here + // NOTE: ao is applied in pbrIbl (see pbrBaseLight), do not apply here irradiance = max(amblit,irradiance); - vec3 f0 = vec3(0.04); - vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); - diffuseColor *= 1.0 - metallic; - - vec3 specularColor = mix(f0, baseColor.rgb, metallic); + vec3 diffuseColor; + vec3 specularColor; + calcDiffuseSpecular(baseColor.rgb, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); - float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); - - color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit * 2.75 * scol; - color.rgb += colorEmissive*0.5; - - color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); - - color = atmosFragLightingLinear(color, additive, atten); - color = scaleSoftClipFragLinear(color); + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten); } else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { -- cgit v1.2.3 From de4c018499ddaebbe466fb5a8938554a2d4a3b19 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 19 Oct 2022 14:41:17 -0500 Subject: SL-18105 Hook up render pipe directly to LLTextureEntry::mGLTFMaterial and add LLViewerFetchedTextures to LLFetchedGLTFMaterial. Lower reflection probe resolution to 128x128 per side. --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 211e1f5d8d..ca436033f1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -507,7 +507,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) { // TODO - don't hard code lods - float reflection_lods = 7; + float reflection_lods = 6; preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); -- cgit v1.2.3 From 97277e74a9d966ed441e51f844f9012f55cca3dc Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Mon, 14 Nov 2022 18:12:22 +0000 Subject: Merged in SL-18332 (pull request #1194) First pass of Screen Space Reflections Approved-by: Dave Parks --- .../shaders/class3/deferred/multiPointLightF.glsl | 17 +-- .../shaders/class3/deferred/multiPointLightV.glsl | 4 +- .../shaders/class3/deferred/multiSpotLightF.glsl | 23 ++-- .../shaders/class3/deferred/pointLightF.glsl | 20 +-- .../class3/deferred/screenSpaceReflPostF.glsl | 98 +++++++++++++++ .../class3/deferred/screenSpaceReflPostV.glsl | 48 +++++++ .../class3/deferred/screenSpaceReflUtil.glsl | 138 +++++++++++++++++++++ .../shaders/class3/deferred/softenLightF.glsl | 27 ++-- .../shaders/class3/deferred/spotLightF.glsl | 23 ++-- 9 files changed, 343 insertions(+), 55 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostV.glsl create mode 100644 indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 6dd446d9f7..43327be49f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -33,10 +33,10 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect depthMap; -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl +uniform sampler2D depthMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D noiseMap; uniform sampler2D lightFunc; @@ -57,6 +57,7 @@ float calcLegacyDistanceAttenuation(float distance, float falloff); vec4 getPosition(vec2 pos_screen); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec2 getScreenXY(vec4 clip); +vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); // Util @@ -76,7 +77,7 @@ void main() discard; // Bail immediately #else vec3 final_color = vec3(0, 0, 0); - vec2 tc = getScreenXY(vary_fragcoord); + vec2 tc = getScreenCoord(vary_fragcoord); vec3 pos = getPosition(tc).xyz; if (pos.z < far_z) { @@ -87,15 +88,15 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() - vec4 spec = texture2DRect(specularRect, tc); - vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; + vec4 spec = texture2D(specularRect, tc); + vec3 diffuse = texture2D(diffuseRect, tc).rgb; vec3 h, l, v = -normalize(pos); float nh, nv, vh, lightDist; if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl index ad6a0fa752..831b3b2684 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl +++ b/indra/newview/app_settings/shaders/class3/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/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index cb8877ebe5..4a172f7a10 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -34,13 +34,13 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform samplerCube environmentMap; -uniform sampler2DRect lightMap; +uniform sampler2D lightMap; uniform sampler2D noiseMap; uniform sampler2D projectionMap; // rgba uniform sampler2D lightFunc; @@ -82,6 +82,7 @@ vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip); +vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 cs); vec4 texture2DLodSpecular(vec2 tc, float lod); @@ -102,7 +103,7 @@ void main() discard; #else vec3 final_color = vec3(0,0,0); - vec2 tc = getScreenXY(vary_fragcoord); + vec2 tc = getScreenCoord(vary_fragcoord); vec3 pos = getPosition(tc).xyz; vec3 lv; @@ -117,7 +118,7 @@ void main() if (proj_shadow_idx >= 0) { - vec4 shd = texture2DRect(lightMap, tc); + vec4 shd = texture2D(lightMap, tc); shadow = (proj_shadow_idx==0)?shd.b:shd.a; shadow += shadow_fade; shadow = clamp(shadow, 0.0, 1.0); @@ -138,8 +139,8 @@ void main() float nh, nl, nv, vh, lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); - vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; - vec4 spec = texture2DRect(specularRect, tc); + vec3 diffuse = texture2D(diffuseRect, tc).rgb; + vec4 spec = texture2D(specularRect, tc); vec3 dlit = vec3(0, 0, 0); vec3 slit = vec3(0, 0, 0); @@ -147,7 +148,7 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index cdffcf103d..0c8baab14f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -33,13 +33,13 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; -uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D normalMap; +uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D noiseMap; uniform sampler2D lightFunc; -uniform sampler2DRect depthMap; +uniform sampler2D depthMap; uniform vec3 env_mat[3]; uniform float sun_wash; @@ -62,7 +62,9 @@ float calcLegacyDistanceAttenuation(float distance, float falloff); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec4 getPosition(vec2 pos_screen); vec2 getScreenXY(vec4 clip); +vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); +float getDepth(vec2 tc); vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, float perceptualRoughness, @@ -74,15 +76,15 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, void main() { vec3 final_color = vec3(0); - vec2 tc = getScreenXY(vary_fragcoord); + vec2 tc = getScreenCoord(vary_fragcoord); vec3 pos = getPosition(tc).xyz; float envIntensity; vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() - vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; - vec4 spec = texture2DRect(specularRect, tc); + vec3 diffuse = texture2D(diffuseRect, tc).rgb; + vec4 spec = texture2D(specularRect, tc); // Common half vectors calcs vec3 lv = trans_center.xyz-pos; @@ -99,7 +101,7 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl new file mode 100644 index 0000000000..9172789b38 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -0,0 +1,98 @@ +/** + * @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$ + */ + +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +uniform vec2 screen_res; +uniform mat4 projection_matrix; +uniform mat4 inv_proj; +uniform float zNear; +uniform float zFar; + +VARYING vec2 vary_fragcoord; +VARYING vec3 camera_ray; + +uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D sceneMap; +uniform sampler2D diffuseRect; + +vec3 getNorm(vec2 screenpos); +float getDepth(vec2 pos_screen); +float linearDepth(float d, float znear, float zfar); +float linearDepth01(float d, float znear, float zfar); + +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition(vec2 pos_screen); + +bool traceScreenRay(vec3 position, vec3 reflection, out vec3 hitColor, out float hitDepth, float depth, sampler2D textureFrame); +float random (vec2 uv); +void main() { + vec2 tc = vary_fragcoord.xy; + float depth = linearDepth01(getDepth(tc), zNear, zFar); + vec3 pos = getPositionWithDepth(tc, getDepth(tc)).xyz; + vec3 viewPos = camera_ray * depth; + vec3 rayDirection = normalize(reflect(normalize(viewPos), getNorm(tc))) * -viewPos.z; + vec2 hitpixel; + vec3 hitpoint; + + vec2 uv2 = tc * screen_res; + float c = (uv2.x + uv2.y) * 0.125; + float jitter = mod( c, 1.0); + + vec3 firstBasis = normalize(cross(vec3(0.f, 0.f, 1.f), rayDirection)); + vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); + + frag_color.rgb = texture(diffuseRect, tc).rgb; + vec4 collectedColor; + for (int i = 0; i < 1; i++) { + vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))) * 0.25; + vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y; + + bool hit = traceScreenRay(pos, reflectionDirectionRandomized, hitpoint, depth, depth, diffuseRect); + if (hit) { + vec2 screenpos = tc * 2 - 1; + float vignette = 1;// clamp((1 - dot(screenpos, screenpos)) * 4,0, 1); + vignette *= dot(normalize(viewPos), getNorm(tc)) * 0.5 + 0.5; + vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / (zFar * 0.0125), 1); + collectedColor.rgb = hitpoint * vignette * 0.25; + frag_color.rgb = hitpoint; + } + } + + //frag_color.rgb = collectedColor.rgb; + + + + frag_color.a = 1.0; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostV.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostV.glsl new file mode 100644 index 0000000000..b084094d4d --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostV.glsl @@ -0,0 +1,48 @@ +/** + * @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 inv_proj; + +ATTRIBUTE vec3 position; + +uniform vec2 screen_res; + +VARYING vec2 vary_fragcoord; +VARYING vec3 camera_ray; + + +void main() +{ + //transform vertex + vec4 pos = vec4(position.xyz, 1.0); + gl_Position = pos; + + vary_fragcoord = pos.xy * 0.5 + 0.5; + + vec4 rayOrig = inv_proj * vec4(pos.xy, 1, 1); + camera_ray = rayOrig.xyz / rayOrig.w; + +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl new file mode 100644 index 0000000000..5eefd99d00 --- /dev/null +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -0,0 +1,138 @@ +/** + * @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$ + */ + +uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D sceneMap; +uniform vec2 screen_res; +uniform mat4 projection_matrix; +uniform float zNear; +uniform float zFar; +uniform mat4 inv_proj; + +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +float linearDepth(float depth, float near, float far); +float getDepth(vec2 pos_screen); +float linearDepth01(float d, float znear, float zfar); + +float random (vec2 uv) { + return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123); //simple random function +} + +// Based off of https://github.com/RoundedGlint585/ScreenSpaceReflection/ +// A few tweaks here and there to suit our needs. + +vec2 generateProjectedPosition(vec3 pos){ + vec4 samplePosition = projection_matrix * vec4(pos, 1.f); + samplePosition.xy = (samplePosition.xy / samplePosition.w) * 0.5 + 0.5; + return samplePosition.xy; +} + +bool isBinarySearchEnabled = true; +bool isAdaptiveStepEnabled = true; +bool isExponentialStepEnabled = false; +bool debugDraw = false; +int iterationCount = 100; +float rayStep = 0.2; +float distanceBias = 0.05; +float depthRejectBias = 0.001; +float epsilon = 0.1; + +bool traceScreenRay(vec3 position, vec3 reflection, out vec3 hitColor, out float hitDepth, float depth, sampler2D textureFrame) { + vec3 step = rayStep * reflection; + vec3 marchingPosition = position + step; + float delta; + float depthFromScreen; + vec2 screenPosition; + bool hit = false; + hitColor = vec3(0); + + int i = 0; + if (depth > depthRejectBias) { + for (; i < iterationCount && !hit; i++) { + screenPosition = generateProjectedPosition(marchingPosition); + depthFromScreen = abs(getPositionWithDepth(screenPosition, linearDepth(getDepth(screenPosition), zNear, zFar)).z); + delta = abs(marchingPosition.z) - depthFromScreen; + + if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { + break; + } + + if (abs(delta) < distanceBias) { + vec3 color = vec3(1); + if(debugDraw) + color = vec3( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2); + hitColor = texture(textureFrame, screenPosition).xyz * color; + hitDepth = depthFromScreen; + hit = true; + break; + } + if (isBinarySearchEnabled && delta > 0) { + break; + } + if (isAdaptiveStepEnabled){ + float directionSign = sign(abs(marchingPosition.z) - depthFromScreen); + //this is sort of adapting step, should prevent lining reflection by doing sort of iterative converging + //some implementation doing it by binary search, but I found this idea more cheaty and way easier to implement + step = step * (1.0 - rayStep * max(directionSign, 0.0)); + marchingPosition += step * (-directionSign); + } + else { + marchingPosition += step; + } + + if (isExponentialStepEnabled){ + step *= 1.05; + } + } + if(isBinarySearchEnabled){ + for(; i < iterationCount && !hit; i++){ + + step *= 0.5; + marchingPosition = marchingPosition - step * sign(delta); + + screenPosition = generateProjectedPosition(marchingPosition); + depthFromScreen = abs(getPositionWithDepth(screenPosition, getDepth(screenPosition)).z); + delta = abs(marchingPosition.z) - depthFromScreen; + + if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { + break; + } + + if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias)) { + vec3 color = vec3(1); + if(debugDraw) + color = vec3( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2); + hitColor = texture(textureFrame, screenPosition).xyz * color; + hitDepth = depthFromScreen; + hit = true; + break; + } + } + } + } + + return hit; +} diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 879f4ef510..5f6982746b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -37,19 +37,19 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; -uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D normalMap; +uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform sampler2D altDiffuseMap; // PBR: irradiance, skins/default/textures/default_irradiance.png const float M_PI = 3.14159265; #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) -uniform sampler2DRect lightMap; +uniform sampler2D lightMap; #endif -uniform sampler2DRect depthMap; +uniform sampler2D depthMap; uniform sampler2D lightFunc; uniform float blur_size; @@ -81,6 +81,7 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 pos, vec3 norm, float glossiness, float envIntensity); 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); +float getDepth(vec2 pos_screen); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); @@ -118,18 +119,18 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, void main() { vec2 tc = vary_fragcoord.xy; - float depth = texture2DRect(depthMap, tc.xy).r; + float depth = getDepth(tc.xy); vec4 pos = getPositionWithDepth(tc, depth); - vec4 norm = texture2DRect(normalMap, tc); + vec4 norm = texture2D(normalMap, tc); float envIntensity = norm.z; norm.xyz = getNorm(tc); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - vec4 baseColor = texture2DRect(diffuseRect, tc); - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR linear Emissive + vec4 baseColor = texture2D(diffuseRect, tc); + vec4 spec = texture2D(specularRect, vary_fragcoord.xy); // NOTE: PBR linear Emissive #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) - vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; + vec2 scol_ambocc = texture2D(lightMap, vary_fragcoord.xy).rg; #endif #if defined(HAS_SUN_SHADOW) @@ -155,12 +156,12 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 orm = texture2DRect(specularRect, tc).rgb; + vec3 orm = texture2D(specularRect, tc).rgb; float perceptualRoughness = orm.g; float metallic = orm.b; float ao = orm.r * ambocc; - vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; // PBR IBL float gloss = 1.0 - perceptualRoughness; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 3274153a46..8618159313 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -44,13 +44,13 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform samplerCube environmentMap; -uniform sampler2DRect lightMap; +uniform sampler2D lightMap; uniform sampler2D noiseMap; uniform sampler2D projectionMap; // rgba uniform sampler2D lightFunc; @@ -90,6 +90,7 @@ vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip_point); +vec2 getScreenCoord(vec4 clip_point); vec3 srgb_to_linear(vec3 c); vec4 texture2DLodSpecular(vec2 tc, float lod); @@ -110,7 +111,7 @@ void main() discard; #else vec3 final_color = vec3(0,0,0); - vec2 tc = getScreenXY(vary_fragcoord); + vec2 tc = getScreenCoord(vary_fragcoord); vec3 pos = getPosition(tc).xyz; vec3 lv; @@ -125,7 +126,7 @@ void main() if (proj_shadow_idx >= 0) { - vec4 shd = texture2DRect(lightMap, tc); + vec4 shd = texture2D(lightMap, tc); shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; shadow += shadow_fade; shadow = clamp(shadow, 0.0, 1.0); @@ -146,15 +147,15 @@ void main() float nh, nl, nv, vh, lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); - vec3 diffuse = texture2DRect(diffuseRect, tc).rgb; - vec4 spec = texture2DRect(specularRect, tc); + vec3 diffuse = texture2D(diffuseRect, tc).rgb; + vec4 spec = texture2D(specularRect, tc); vec3 dlit = vec3(0, 0, 0); vec3 slit = vec3(0, 0, 0); vec3 amb_rgb = vec3(0); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture2DRect(emissiveRect, tc).rgb; + vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; -- cgit v1.2.3 From 07ada65df1c72adff6e356011840ca262beb4be0 Mon Sep 17 00:00:00 2001 From: Geenz Date: Wed, 16 Nov 2022 07:11:13 -0800 Subject: A few tweaks to SSR while I'm in the neighborhood. Mostly just making it actually kind of work. Still needs a lot more tweaking - but can revisit later. SL-18332 --- .../class3/deferred/screenSpaceReflPostF.glsl | 58 +++++++++++++++------- .../class3/deferred/screenSpaceReflUtil.glsl | 28 +++++------ 2 files changed, 53 insertions(+), 33 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl index 9172789b38..d48aeb98b6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -44,8 +44,10 @@ VARYING vec3 camera_ray; uniform sampler2D depthMap; uniform sampler2D normalMap; +uniform sampler2D specularRect; uniform sampler2D sceneMap; uniform sampler2D diffuseRect; +uniform sampler2D diffuseMap; vec3 getNorm(vec2 screenpos); float getDepth(vec2 pos_screen); @@ -54,45 +56,63 @@ float linearDepth01(float d, float znear, float zfar); vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition(vec2 pos_screen); - -bool traceScreenRay(vec3 position, vec3 reflection, out vec3 hitColor, out float hitDepth, float depth, sampler2D textureFrame); +vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame); float random (vec2 uv); void main() { vec2 tc = vary_fragcoord.xy; float depth = linearDepth01(getDepth(tc), zNear, zFar); + vec3 n = vec3(0, 0, 1); + float envIntensity; + vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() vec3 pos = getPositionWithDepth(tc, getDepth(tc)).xyz; + vec4 spec = texture2D(specularRect, tc); vec3 viewPos = camera_ray * depth; - vec3 rayDirection = normalize(reflect(normalize(viewPos), getNorm(tc))) * -viewPos.z; + vec3 rayDirection = normalize(reflect(normalize(viewPos), n)) * -viewPos.z; vec2 hitpixel; - vec3 hitpoint; + vec4 hitpoint; + vec4 diffuse = texture2D(diffuseRect, tc); + vec3 specCol = spec.rgb; + + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { + vec3 orm = specCol.rgb; + float perceptualRoughness = orm.g; + float metallic = orm.b; + vec3 f0 = vec3(0.04); + vec3 baseColor = diffuse.rgb; + + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); + + specCol = mix(f0, baseColor.rgb, metallic); + } vec2 uv2 = tc * screen_res; float c = (uv2.x + uv2.y) * 0.125; float jitter = mod( c, 1.0); - vec3 firstBasis = normalize(cross(vec3(0.f, 0.f, 1.f), rayDirection)); + vec3 firstBasis = normalize(cross(vec3(1.f, 1.f, 1.f), rayDirection)); vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); - frag_color.rgb = texture(diffuseRect, tc).rgb; + frag_color = texture(diffuseMap, tc); vec4 collectedColor; - for (int i = 0; i < 1; i++) { - vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))) * 0.25; + + vec2 screenpos = 1 - abs(tc * 2 - 1); + float vignette = clamp((screenpos.x * screenpos.y) * 16,0, 1); + vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5 - 0.2) * 8, 0, 1); + vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / zFar, 1); + int totalSamples = 4; + for (int i = 0; i < totalSamples; i++) { + vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y; - bool hit = traceScreenRay(pos, reflectionDirectionRandomized, hitpoint, depth, depth, diffuseRect); + bool hit = traceScreenRay(pos, reflectionDirectionRandomized, hitpoint, depth, depth, diffuseMap); if (hit) { - vec2 screenpos = tc * 2 - 1; - float vignette = 1;// clamp((1 - dot(screenpos, screenpos)) * 4,0, 1); - vignette *= dot(normalize(viewPos), getNorm(tc)) * 0.5 + 0.5; - vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / (zFar * 0.0125), 1); - collectedColor.rgb = hitpoint * vignette * 0.25; - frag_color.rgb = hitpoint; + collectedColor += hitpoint; + collectedColor.rgb *= specCol.rgb; } } - //frag_color.rgb = collectedColor.rgb; - - + collectedColor *= vignette; - frag_color.a = 1.0; + frag_color += collectedColor; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index 5eefd99d00..f8c6e5701a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -52,28 +52,28 @@ vec2 generateProjectedPosition(vec3 pos){ bool isBinarySearchEnabled = true; bool isAdaptiveStepEnabled = true; -bool isExponentialStepEnabled = false; +bool isExponentialStepEnabled = true; bool debugDraw = false; -int iterationCount = 100; -float rayStep = 0.2; -float distanceBias = 0.05; +int iterationCount = 40; +float rayStep = 0.1; +float distanceBias = 0.02; float depthRejectBias = 0.001; float epsilon = 0.1; -bool traceScreenRay(vec3 position, vec3 reflection, out vec3 hitColor, out float hitDepth, float depth, sampler2D textureFrame) { +bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) { vec3 step = rayStep * reflection; vec3 marchingPosition = position + step; float delta; float depthFromScreen; vec2 screenPosition; bool hit = false; - hitColor = vec3(0); + hitColor = vec4(0); int i = 0; if (depth > depthRejectBias) { for (; i < iterationCount && !hit; i++) { screenPosition = generateProjectedPosition(marchingPosition); - depthFromScreen = abs(getPositionWithDepth(screenPosition, linearDepth(getDepth(screenPosition), zNear, zFar)).z); + depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); delta = abs(marchingPosition.z) - depthFromScreen; if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { @@ -81,10 +81,10 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec3 hitColor, out float } if (abs(delta) < distanceBias) { - vec3 color = vec3(1); + vec4 color = vec4(1); if(debugDraw) - color = vec3( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2); - hitColor = texture(textureFrame, screenPosition).xyz * color; + color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); + hitColor = texture(textureFrame, screenPosition) * color; hitDepth = depthFromScreen; hit = true; break; @@ -114,7 +114,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec3 hitColor, out float marchingPosition = marchingPosition - step * sign(delta); screenPosition = generateProjectedPosition(marchingPosition); - depthFromScreen = abs(getPositionWithDepth(screenPosition, getDepth(screenPosition)).z); + depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); delta = abs(marchingPosition.z) - depthFromScreen; if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { @@ -122,10 +122,10 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec3 hitColor, out float } if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias)) { - vec3 color = vec3(1); + vec4 color = vec4(1); if(debugDraw) - color = vec3( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2); - hitColor = texture(textureFrame, screenPosition).xyz * color; + color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); + hitColor = texture(textureFrame, screenPosition) * color; hitDepth = depthFromScreen; hit = true; break; -- cgit v1.2.3 From 34d3f94db6d2ab243f8ee63522e60cb1e22dedff Mon Sep 17 00:00:00 2001 From: Geenz Linden Date: Sun, 20 Nov 2022 11:09:05 +0100 Subject: Fix for SSAO not behaving properly. SL-18662 --- .../newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 43327be49f..7d8f9c218d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -133,7 +133,7 @@ void main() else { - float noise = texture2D(noiseMap, tc/128.0).b; + float noise = texture2D(noiseMap, tc).b; diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 4a172f7a10..5ed8a75e0e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -187,7 +187,7 @@ void main() diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); - float noise = texture2D(noiseMap, tc/128.0).b; + float noise = texture2D(noiseMap, tc).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 0c8baab14f..d9cbae45a6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -126,7 +126,7 @@ void main() diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); - float noise = texture2D(noiseMap, tc/128.0).b; + float noise = texture2D(noiseMap, tc).b; float lit = nl * dist_atten * noise; final_color = color.rgb*lit*diffuse; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 8618159313..3d8b95b882 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -193,7 +193,7 @@ void main() diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); - float noise = texture2D(noiseMap, tc/128.0).b; + float noise = texture2D(noiseMap, tc).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && -- cgit v1.2.3 From e6b5481cad3f81f18ff04ff6af86bd7ad5b9c5da Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 14 Dec 2022 11:00:31 -0600 Subject: SL-18782 WIP -- stub for reflection probe display. --- .../app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index ca436033f1..977b2e6b24 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -518,6 +518,13 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, glossenv = sampleProbes(pos, normalize(refnormpersp), lod, errorCorrect); } +vec4 sampleReflectionProbesDebug(vec3 pos) +{ + preProbeSample(pos); + + return vec4(probeInfluences*0.25, 0, 0, probeInfluences*0.25); +} + void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec3 pos, vec3 norm, float glossiness) { @@ -525,6 +532,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, pos, norm, glossiness, false); } + void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, vec3 pos, vec3 norm, float glossiness, float envIntensity) { -- cgit v1.2.3 From 4d0bd020a0e3ce87731478bbb74e93b96a64b74e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 14 Dec 2022 16:17:48 -0600 Subject: SL-18782 WIP -- Functional Build->Options->Show Reflection Probe Volumes --- .../shaders/class3/deferred/reflectionProbeF.glsl | 145 ++++++++++++++++++++- 1 file changed, 143 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 977b2e6b24..865b7e7a47 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -262,6 +262,40 @@ vec3 sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) return v; } +void swap(inout float a, inout float b) +{ + float t = a; + a = b; + b = a; +} + +// debug implementation, make no assumptions about origin +bool sphereIntersectDebug(vec3 origin, vec3 dir, vec3 center, float radius2, out float t) +{ + float t0, t1; // solutions for t if the ray intersects + + // geometric solution + vec3 L = center - origin; + float tca = dot(L, dir); + // if (tca < 0) return false; + float d2 = dot(L, L) - tca * tca; + if (d2 > radius2) return false; + float thc = sqrt(radius2 - d2); + t0 = tca - thc; + t1 = tca + thc; + + if (t0 > t1) swap(t0, t1); + + if (t0 < 0) { + t0 = t1; // if t0 is negative, let's use t1 instead + if (t0 < 0) return false; // both t0 and t1 are negative + } + + t = t0; + + return true; +} + // from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ /* vec3 DirectionWS = normalize(PositionWS - CameraWS); @@ -310,6 +344,48 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i) return IntersectPositionCS; } +// cribbed from https://iquilezles.org/articles/intersectors/ +// axis aligned box centered at the origin, with size boxSize +bool boxIntersectionDebug( in vec3 ro, in vec3 p, vec3 boxSize, out bool behind) +{ + vec3 rd = normalize(p-ro); + + vec3 m = 1.0/rd; // can precompute if traversing a set of aligned boxes + vec3 n = m*ro; // can precompute if traversing a set of aligned boxes + vec3 k = abs(m)*boxSize; + vec3 t1 = -n - k; + vec3 t2 = -n + k; + float tN = max( max( t1.x, t1.y ), t1.z ); + float tF = min( min( t2.x, t2.y ), t2.z ); + if( tN>tF || tF<0.0) return false; // no intersection + + float t = tN < 0 ? tF : tN; + + vec3 v = ro + rd * t; + + v -= ro; + vec3 pos = p - ro; + + behind = dot(v,v) > dot(pos,pos); + + return true; +} + +bool boxIntersectDebug(vec3 origin, vec3 pos, int i, out bool behind) +{ + mat4 clipToLocal = refBox[i]; + + // transform into unit cube space + origin = (clipToLocal * vec4(origin, 1.0)).xyz; + pos = (clipToLocal * vec4(pos, 1.0)).xyz; + + if (boxIntersectionDebug(origin, pos, vec3(1), behind)) + { + return true; + } + + return false; +} // Tap a reflection probe @@ -518,11 +594,76 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, glossenv = sampleProbes(pos, normalize(refnormpersp), lod, errorCorrect); } +void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) +{ + vec3 origin = vec3(0,0,0); + + bool manual_probe = abs(refIndex[i].w) > 2; + + if (refIndex[i].w < 0) + { + vec3 v; + bool behind; + + if (boxIntersectDebug(origin, pos, i, behind)) + { + float w = 0.5; + if (behind) + { + w *= 0.5; + col += vec4(0,0,w,w); + } + else + { + col += vec4(w,w,0,w); + } + } + } + else + { + float r = refSphere[i].w; // radius of sphere volume + float rr = r * r; // radius squared + + float t = 0.0; + + if (sphereIntersectDebug(origin, dir, refSphere[i].xyz, rr, t)) + { + if (t > depth) + { + float w = 0.25/((t-depth)*0.125 + 1.0); + + if (manual_probe) + { + col += vec4(0, 0, w, w); + } + } + else + { + if (manual_probe) + { + float w = 0.5; + + col += vec4(w,w,0,w); + } + } + } + } +} + vec4 sampleReflectionProbesDebug(vec3 pos) { - preProbeSample(pos); + vec4 col = vec4(0,0,0,0); + + vec3 dir = normalize(pos); + + float d = length(pos); - return vec4(probeInfluences*0.25, 0, 0, probeInfluences*0.25); + for (int i = 1; i < refmapCount; ++i) + { + debugTapRefMap(pos, dir, d, i, col); + } + + return col; } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, -- cgit v1.2.3 From aa76fbb0b2ea93d1b7908faa66a40a1a8fc29113 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 15 Dec 2022 13:43:16 -0600 Subject: SL-18782 Finishing touches on Reflection Probe Volumes display (for now). --- .../shaders/class3/deferred/reflectionProbeF.glsl | 151 ++++++++++----------- 1 file changed, 72 insertions(+), 79 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 865b7e7a47..ea41ac5f2d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -270,30 +270,37 @@ void swap(inout float a, inout float b) } // debug implementation, make no assumptions about origin -bool sphereIntersectDebug(vec3 origin, vec3 dir, vec3 center, float radius2, out float t) +void sphereIntersectDebug(vec3 origin, vec3 dir, vec3 center, float radius2, float depth, inout vec4 col) { - float t0, t1; // solutions for t if the ray intersects - - // geometric solution - vec3 L = center - origin; - float tca = dot(L, dir); - // if (tca < 0) return false; - float d2 = dot(L, L) - tca * tca; - if (d2 > radius2) return false; - float thc = sqrt(radius2 - d2); - t0 = tca - thc; - t1 = tca + thc; + float t[2]; // solutions for t if the ray intersects + + // geometric solution + vec3 L = center - origin; + float tca = dot(L, dir); + // if (tca < 0) return false; + float d2 = dot(L, L) - tca * tca; + if (d2 > radius2) return; + float thc = sqrt(radius2 - d2); + t[0] = tca - thc; + t[1] = tca + thc; + + for (int i = 0; i < 2; ++i) + { + if (t[i] > 0) + { + if (t[i] > depth) + { + float w = 0.125/((t[i]-depth)*0.125 + 1.0); + col += vec4(0, 0, w, w)*(1.0-min(col.a, 1.0)); + } + else + { + float w = 0.25; + col += vec4(w,w,0,w)*(1.0-min(col.a, 1.0)); + } + } + } - if (t0 > t1) swap(t0, t1); - - if (t0 < 0) { - t0 = t1; // if t0 is negative, let's use t1 instead - if (t0 < 0) return false; // both t0 and t1 are negative - } - - t = t0; - - return true; } // from https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ @@ -344,9 +351,33 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i) return IntersectPositionCS; } +void debugBoxCol(vec3 ro, vec3 rd, float t, vec3 p, inout vec4 col) +{ + vec3 v = ro + rd * t; + + v -= ro; + vec3 pos = p - ro; + + + bool behind = dot(v,v) > dot(pos,pos); + + float w = 0.25; + + if (behind) + { + w *= 0.5; + w /= (length(v)-length(pos))*0.5+1.0; + col += vec4(0,0,w,w)*(1.0-min(col.a, 1.0)); + } + else + { + col += vec4(w,w,0,w)*(1.0-min(col.a, 1.0)); + } +} + // cribbed from https://iquilezles.org/articles/intersectors/ // axis aligned box centered at the origin, with size boxSize -bool boxIntersectionDebug( in vec3 ro, in vec3 p, vec3 boxSize, out bool behind) +void boxIntersectionDebug( in vec3 ro, in vec3 p, vec3 boxSize, inout vec4 col) { vec3 rd = normalize(p-ro); @@ -357,21 +388,20 @@ bool boxIntersectionDebug( in vec3 ro, in vec3 p, vec3 boxSize, out bool behind) vec3 t2 = -n + k; float tN = max( max( t1.x, t1.y ), t1.z ); float tF = min( min( t2.x, t2.y ), t2.z ); - if( tN>tF || tF<0.0) return false; // no intersection - - float t = tN < 0 ? tF : tN; - - vec3 v = ro + rd * t; + if( tN>tF || tF<0.0) return ; // no intersection - v -= ro; - vec3 pos = p - ro; + float t = tN < 0 ? tF : tN; - behind = dot(v,v) > dot(pos,pos); + debugBoxCol(ro, rd, t, p, col); - return true; + if (tN > 0) // eye is outside box, check backside, too + { + debugBoxCol(ro, rd, tF, p, col); + } } -bool boxIntersectDebug(vec3 origin, vec3 pos, int i, out bool behind) + +void boxIntersectDebug(vec3 origin, vec3 pos, int i, inout vec4 col) { mat4 clipToLocal = refBox[i]; @@ -379,12 +409,7 @@ bool boxIntersectDebug(vec3 origin, vec3 pos, int i, out bool behind) origin = (clipToLocal * vec4(origin, 1.0)).xyz; pos = (clipToLocal * vec4(pos, 1.0)).xyz; - if (boxIntersectionDebug(origin, pos, vec3(1), behind)) - { - return true; - } - - return false; + boxIntersectionDebug(origin, pos, vec3(1), col); } @@ -600,52 +625,20 @@ void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) bool manual_probe = abs(refIndex[i].w) > 2; - if (refIndex[i].w < 0) + if (manual_probe) { - vec3 v; - bool behind; - - if (boxIntersectDebug(origin, pos, i, behind)) + if (refIndex[i].w < 0) { - float w = 0.5; - if (behind) - { - w *= 0.5; - col += vec4(0,0,w,w); - } - else - { - col += vec4(w,w,0,w); - } + boxIntersectDebug(origin, pos, i, col); } - } - else - { - float r = refSphere[i].w; // radius of sphere volume - float rr = r * r; // radius squared - - float t = 0.0; - - if (sphereIntersectDebug(origin, dir, refSphere[i].xyz, rr, t)) + else { - if (t > depth) - { - float w = 0.25/((t-depth)*0.125 + 1.0); + float r = refSphere[i].w; // radius of sphere volume + float rr = r * r; // radius squared - if (manual_probe) - { - col += vec4(0, 0, w, w); - } - } - else - { - if (manual_probe) - { - float w = 0.5; + float t = 0.0; - col += vec4(w,w,0,w); - } - } + sphereIntersectDebug(origin, dir, refSphere[i].xyz, rr, depth, col); } } } -- cgit v1.2.3 From 2de9e631d91cab993257eea82cb5356ca9f73fd0 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 19 Dec 2022 11:48:56 -0600 Subject: SL-18730 Dumb down water distortions to reduce appearance of brokenness. --- .../shaders/class3/environment/waterF.glsl | 39 ++++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index a6517be433..dbe0929657 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -120,12 +120,12 @@ void main() vec3 pos = vary_position.xyz; - float dist = length(pos.xyz); - - //normalize view vector - vec3 viewVec = normalize(pos.xyz); - - //get wave normals + float dist = length(pos.xyz); + + //normalize view vector + vec3 viewVec = normalize(pos.xyz); + + //get wave normals vec2 bigwave = vec2(refCoord.w, view.w); vec3 wave1_a = texture(bumpMap, bigwave, -2 ).xyz*2.0-1.0; vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; @@ -135,16 +135,24 @@ void main() vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + //wave1_a = wave2_a = wave3_a = wave1_b = wave2_b = wave3_b = vec3(0,0,1); + vec3 wave1 = BlendNormal(wave1_a, wave1_b); vec3 wave2 = BlendNormal(wave2_a, wave2_b); vec3 wave3 = BlendNormal(wave3_a, wave3_b); - wave1 = transform_normal(wave1); - wave2 = transform_normal(wave2); - wave3 = transform_normal(wave3); + vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; + + //wave1 = transform_normal(wave1); + //wave2 = transform_normal(wave2); + //wave3 = transform_normal(wave3); vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + vec3 waver = wavef*3; + + wavef = transform_normal(wavef); + //wavef.z *= max(-viewVec.z, 0.1); wavef = normalize(wavef); @@ -157,25 +165,20 @@ void main() dot(viewVec, wave3) ) * fresnelScale + fresnelOffset; - 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); - float df1 = df.x + df.y + df.z; - //wavef = normalize(wavef - vary_normal); - //wavef = vary_normal; - vec3 waver = reflect(viewVec, -wavef)*3; + //figure out distortion vector (ripply) - vec2 distort2 = distort + waver.xy * refScale / max(dmod * df1, 1.0); - distort2 = clamp(distort2, vec2(0), vec2(0.99)); + vec2 distort2 = distort + waver.xy * refScale / max(dmod, 1.0); + + distort2 = clamp(distort2, vec2(0), vec2(0.999)); #ifdef TRANSPARENT_WATER vec4 fb = texture2D(screenTex, distort2); -- cgit v1.2.3 From 40799b97c188bb3c0a4b2d00a35bcc41be461f08 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 19 Dec 2022 15:27:43 -0600 Subject: SL-18779 Fix for water fog staying bright when sun is dark. --- .../shaders/class3/environment/waterF.glsl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index dbe0929657..85c3f42801 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -34,7 +34,7 @@ out vec4 frag_color; vec3 scaleSoftClipFragLinear(vec3 l); vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); -vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit); // PBR interface vec3 pbrIbl(vec3 diffuseColor, @@ -179,7 +179,14 @@ void main() vec2 distort2 = distort + waver.xy * refScale / max(dmod, 1.0); distort2 = clamp(distort2, vec2(0), vec2(0.999)); - + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + + calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); + #ifdef TRANSPARENT_WATER vec4 fb = texture2D(screenTex, distort2); float depth = texture2D(screenDepth, distort2).r; @@ -194,18 +201,11 @@ void main() refPos = getPositionWithNDC(vec3(distort2 * 2.0 - vec2(1.0), depth * 2.0 - 1.0)); } - fb = applyWaterFogViewLinear(refPos, fb); + fb = applyWaterFogViewLinear(refPos, fb, sunlit); #else vec4 fb = vec4(waterFogColorLinear.rgb, 0.0); #endif - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - - calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); - sunlit = vec3(1); // TODO -- figure out why sunlit is breaking at some view angles vec3 v = -viewVec; float NdotV = clamp(abs(dot(wavef.xyz, v)), 0.001, 1.0); -- cgit v1.2.3 From 7bd9d21e19b923096ba2b5ea3cbc8be3e13d7aa0 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 19 Jan 2023 09:13:45 -0600 Subject: Optimizations, decruft, and intel compatibility pass (#53) SL-18869, SL-18772 Overhaul VBO management, restore occlusion culling, intel compatibility pass, etc --- .../app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index ea41ac5f2d..0cb966296a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -505,7 +505,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) v -= c; v = env_mat * v; { - return texture(irradianceProbes, vec4(v.xyz, refIndex[i].x)).rgb * refParams[i].x; + return textureLod(irradianceProbes, vec4(v.xyz, refIndex[i].x), 0).rgb * refParams[i].x; } } @@ -676,14 +676,15 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 refnormpersp = reflect(pos.xyz, norm.xyz); + ambenv = sampleProbeAmbient(pos, norm); - + if (glossiness > 0.0) { float lod = (1.0-glossiness)*reflection_lods; glossenv = sampleProbes(pos, normalize(refnormpersp), lod, false); } - + if (envIntensity > 0.0) { legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, false); -- cgit v1.2.3 From c83e66414848e468cce01d36c1054b2e9314baf9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 20 Jan 2023 13:00:40 -0600 Subject: SL-18869 GL 3 compatibility pass and minor decruft. --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 5f6982746b..8e4197ae77 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -41,7 +41,6 @@ uniform sampler2D diffuseRect; uniform sampler2D specularRect; uniform sampler2D normalMap; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl -uniform sampler2D altDiffuseMap; // PBR: irradiance, skins/default/textures/default_irradiance.png const float M_PI = 3.14159265; -- cgit v1.2.3 From fea731ecb3fbe0472777bfafa98156ebe75a5049 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 24 Jan 2023 14:02:53 -0600 Subject: SL-19023 Reformat SSR shaders to match style standard. --- .../class3/deferred/screenSpaceReflPostF.glsl | 32 ++-- .../class3/deferred/screenSpaceReflUtil.glsl | 162 +++++++++++---------- 2 files changed, 109 insertions(+), 85 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl index d48aeb98b6..4813e6c2d9 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -58,8 +58,12 @@ vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition(vec2 pos_screen); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame); + float random (vec2 uv); -void main() { + + +void main() +{ vec2 tc = vary_fragcoord.xy; float depth = linearDepth01(getDepth(tc), zNear, zFar); vec3 n = vec3(0, 0, 1); @@ -74,7 +78,8 @@ void main() { vec4 diffuse = texture2D(diffuseRect, tc); vec3 specCol = spec.rgb; - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) + { vec3 orm = specCol.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; @@ -86,12 +91,12 @@ void main() { specCol = mix(f0, baseColor.rgb, metallic); } - vec2 uv2 = tc * screen_res; - float c = (uv2.x + uv2.y) * 0.125; - float jitter = mod( c, 1.0); + vec2 uv2 = tc * screen_res; + float c = (uv2.x + uv2.y) * 0.125; + float jitter = mod( c, 1.0); vec3 firstBasis = normalize(cross(vec3(1.f, 1.f, 1.f), rayDirection)); - vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); + vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); frag_color = texture(diffuseMap, tc); vec4 collectedColor; @@ -100,17 +105,22 @@ void main() { float vignette = clamp((screenpos.x * screenpos.y) * 16,0, 1); vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5 - 0.2) * 8, 0, 1); vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / zFar, 1); + int totalSamples = 4; - for (int i = 0; i < totalSamples; i++) { - vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); - vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y; + + for (int i = 0; i < totalSamples; i++) + { + vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); + vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y; bool hit = traceScreenRay(pos, reflectionDirectionRandomized, hitpoint, depth, depth, diffuseMap); - if (hit) { + + if (hit) + { collectedColor += hitpoint; collectedColor.rgb *= specCol.rgb; } - } + } collectedColor *= vignette; diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index f8c6e5701a..b6c789ad40 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -37,17 +37,19 @@ float linearDepth(float depth, float near, float far); float getDepth(vec2 pos_screen); float linearDepth01(float d, float znear, float zfar); -float random (vec2 uv) { - return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123); //simple random function +float random (vec2 uv) +{ + return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123); //simple random function } // Based off of https://github.com/RoundedGlint585/ScreenSpaceReflection/ // A few tweaks here and there to suit our needs. -vec2 generateProjectedPosition(vec3 pos){ - vec4 samplePosition = projection_matrix * vec4(pos, 1.f); - samplePosition.xy = (samplePosition.xy / samplePosition.w) * 0.5 + 0.5; - return samplePosition.xy; +vec2 generateProjectedPosition(vec3 pos) +{ + vec4 samplePosition = projection_matrix * vec4(pos, 1.f); + samplePosition.xy = (samplePosition.xy / samplePosition.w) * 0.5 + 0.5; + return samplePosition.xy; } bool isBinarySearchEnabled = true; @@ -60,79 +62,91 @@ float distanceBias = 0.02; float depthRejectBias = 0.001; float epsilon = 0.1; -bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) { - vec3 step = rayStep * reflection; - vec3 marchingPosition = position + step; - float delta; - float depthFromScreen; - vec2 screenPosition; +bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) +{ + vec3 step = rayStep * reflection; + vec3 marchingPosition = position + step; + float delta; + float depthFromScreen; + vec2 screenPosition; bool hit = false; hitColor = vec4(0); - - int i = 0; - if (depth > depthRejectBias) { - for (; i < iterationCount && !hit; i++) { - screenPosition = generateProjectedPosition(marchingPosition); - depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); - delta = abs(marchingPosition.z) - depthFromScreen; - - if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { - break; - } + + int i = 0; + if (depth > depthRejectBias) + { + for (; i < iterationCount && !hit; i++) + { + screenPosition = generateProjectedPosition(marchingPosition); + depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); + delta = abs(marchingPosition.z) - depthFromScreen; + + if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) + { + break; + } - if (abs(delta) < distanceBias) { - vec4 color = vec4(1); - if(debugDraw) - color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); - hitColor = texture(textureFrame, screenPosition) * color; - hitDepth = depthFromScreen; - hit = true; - break; - } - if (isBinarySearchEnabled && delta > 0) { - break; - } - if (isAdaptiveStepEnabled){ - float directionSign = sign(abs(marchingPosition.z) - depthFromScreen); - //this is sort of adapting step, should prevent lining reflection by doing sort of iterative converging - //some implementation doing it by binary search, but I found this idea more cheaty and way easier to implement - step = step * (1.0 - rayStep * max(directionSign, 0.0)); - marchingPosition += step * (-directionSign); - } - else { - marchingPosition += step; - } + if (abs(delta) < distanceBias) + { + vec4 color = vec4(1); + if(debugDraw) + color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); + hitColor = texture(textureFrame, screenPosition) * color; + hitDepth = depthFromScreen; + hit = true; + break; + } + if (isBinarySearchEnabled && delta > 0) + { + break; + } + if (isAdaptiveStepEnabled) + { + float directionSign = sign(abs(marchingPosition.z) - depthFromScreen); + //this is sort of adapting step, should prevent lining reflection by doing sort of iterative converging + //some implementation doing it by binary search, but I found this idea more cheaty and way easier to implement + step = step * (1.0 - rayStep * max(directionSign, 0.0)); + marchingPosition += step * (-directionSign); + } + else + { + marchingPosition += step; + } - if (isExponentialStepEnabled){ - step *= 1.05; - } - } - if(isBinarySearchEnabled){ - for(; i < iterationCount && !hit; i++){ - - step *= 0.5; - marchingPosition = marchingPosition - step * sign(delta); - - screenPosition = generateProjectedPosition(marchingPosition); - depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); - delta = abs(marchingPosition.z) - depthFromScreen; + if (isExponentialStepEnabled) + { + step *= 1.05; + } + } + if(isBinarySearchEnabled) + { + for(; i < iterationCount && !hit; i++) + { + step *= 0.5; + marchingPosition = marchingPosition - step * sign(delta); + + screenPosition = generateProjectedPosition(marchingPosition); + depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); + delta = abs(marchingPosition.z) - depthFromScreen; - if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { - break; - } + if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) + { + break; + } - if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias)) { - vec4 color = vec4(1); - if(debugDraw) - color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); - hitColor = texture(textureFrame, screenPosition) * color; - hitDepth = depthFromScreen; - hit = true; - break; - } - } - } - } - + if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias)) + { + vec4 color = vec4(1); + if(debugDraw) + color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); + hitColor = texture(textureFrame, screenPosition) * color; + hitDepth = depthFromScreen; + hit = true; + break; + } + } + } + } + return hit; } -- cgit v1.2.3 From 3ef31cb9b28f7b026e109eab69d383dddc922850 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 27 Jan 2023 17:24:22 -0600 Subject: SL-19203 et al -- Integrate SSR with reflection probes, tweak probe blending. (#63) * SL-19203 WIP -- Integrate SSR with reflection probes. Decruft LLRenderTarget. * SL-19203 WIP -- Re-integrate SSR. Incidental decruft. * SL-19203 WIP -- SSR frame delta correction (still broken for Z) * SL-19203 WIP -- SSR frame delta Z fix * SL-19203 WIP -- Make SSR toggleable again and disable SSR in cube snapshots. * SL-19203 WIP -- Soften sphere probe transitions and fix reflections on void water (make fallback probe a simple terrain+water+sky probe). Remove parallax correction for automatic probes to reduce artifacts. * SL-19203 Tune probe blending. * SL-19203 Cleanup. --- .../shaders/class3/deferred/fullbrightShinyF.glsl | 7 +- .../shaders/class3/deferred/materialF.glsl | 6 +- .../shaders/class3/deferred/reflectionProbeF.glsl | 150 +++++++++++++-------- .../class3/deferred/screenSpaceReflPostF.glsl | 50 ++----- .../class3/deferred/screenSpaceReflUtil.glsl | 104 ++++++++++++-- .../shaders/class3/deferred/softenLightF.glsl | 10 +- .../shaders/class3/environment/waterF.glsl | 10 +- 7 files changed, 217 insertions(+), 120 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index c0a1491446..160d360256 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -56,8 +56,9 @@ vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); // reflection probe interface -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, - vec3 pos, vec3 norm, float glossiness, float envIntensity); +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); + 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); @@ -91,7 +92,7 @@ void main() vec3 legacyenv; vec3 norm = normalize(vary_texcoord1.xyz); vec4 spec = vec4(0,0,0,0); - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, env_intensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity); applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 8016022d78..8d2a65d4a9 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -61,8 +61,8 @@ out vec4 frag_color; float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec3 pos, vec3 norm, float glossiness, float envIntensity); +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); 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); @@ -310,7 +310,7 @@ void main() vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xyz, norm.xyz, final_specular.a, env_intensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos_screen, pos.xyz, norm.xyz, final_specular.a, env_intensity); // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv); diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 0cb966296a..9793ab13de 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -25,11 +25,17 @@ #define FLT_MAX 3.402823466e+38 +#if defined(SSR) +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source); +#endif + #define REFMAP_COUNT 256 #define REF_SAMPLE_COUNT 64 //maximum number of samples to consider uniform samplerCubeArray reflectionProbes; uniform samplerCubeArray irradianceProbes; +uniform sampler2D sceneMap; +uniform int cube_snapshot; layout (std140) uniform ReflectionProbes { @@ -92,14 +98,17 @@ bool shouldSampleProbe(int i, vec3 pos) } else { - vec3 delta = pos.xyz - refSphere[i].xyz; - float d = dot(delta, delta); - float r2 = refSphere[i].w; - r2 *= r2; - - if (d > r2) - { //outside bounding sphere - return false; + if (refSphere[i].w > 0.0) // zero is special indicator to always sample this probe + { + vec3 delta = pos.xyz - refSphere[i].xyz; + float d = dot(delta, delta); + float r2 = refSphere[i].w; + r2 *= r2; + + if (d > r2) + { //outside bounding sphere + return false; + } } max_priority = max(max_priority, refIndex[i].w); @@ -138,13 +147,13 @@ void preProbeSample(vec3 pos) probeIndex[probeInfluences++] = idx; if (probeInfluences == REF_SAMPLE_COUNT) { - return; + break; } } count++; if (count == neighborCount) { - return; + break; } idx = refNeighbor[neighborIdx].y; @@ -153,13 +162,13 @@ void preProbeSample(vec3 pos) probeIndex[probeInfluences++] = idx; if (probeInfluences == REF_SAMPLE_COUNT) { - return; + break; } } count++; if (count == neighborCount) { - return; + break; } idx = refNeighbor[neighborIdx].z; @@ -168,13 +177,13 @@ void preProbeSample(vec3 pos) probeIndex[probeInfluences++] = idx; if (probeInfluences == REF_SAMPLE_COUNT) { - return; + break; } } count++; if (count == neighborCount) { - return; + break; } idx = refNeighbor[neighborIdx].w; @@ -183,27 +192,26 @@ void preProbeSample(vec3 pos) probeIndex[probeInfluences++] = idx; if (probeInfluences == REF_SAMPLE_COUNT) { - return; + break; } } count++; if (count == neighborCount) { - return; + break; } ++neighborIdx; } - return; + break; } } } - if (probeInfluences == 0) - { // probe at index 0 is a special fallback probe - probeIndex[0] = 0; - probeInfluences = 1; + if (max_priority <= 1) + { // probe at index 0 is a special probe for smoothing out automatic probes + probeIndex[probeInfluences++] = 0; } } @@ -330,7 +338,8 @@ return texCUBE(envMap, ReflDirectionWS); // origin - ray origin in clip space // dir - ray direction in clip space // i - probe index in refBox/refSphere -vec3 boxIntersect(vec3 origin, vec3 dir, int i) +// d - distance to nearest wall in clip space +vec3 boxIntersect(vec3 origin, vec3 dir, int i, out float d) { // Intersection with OBB convertto unit box space // Transform in local unit parallax cube space (scaled and rotated) @@ -339,6 +348,8 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i) vec3 RayLS = mat3(clipToLocal) * dir; vec3 PositionLS = (clipToLocal * vec4(origin, 1.0)).xyz; + d = 1.0-max(max(abs(PositionLS.x), abs(PositionLS.y)), abs(PositionLS.z)); + vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; @@ -413,6 +424,29 @@ void boxIntersectDebug(vec3 origin, vec3 pos, int i, inout vec4 col) } +// get the weight of a sphere probe +// pos - position to be weighted +// dir - normal to be weighted +// origin - center of sphere probe +// r - radius of probe influence volume +// min_da - minimum angular attenuation coefficient +float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da) +{ + float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) + vec3 delta = pos.xyz - origin; + float d2 = max(length(delta), 0.001); + float r2 = r1; //r1 * r1; + + //float atten = 1.0 - max(d2 - r2, 0.0) / max((rr - r2), 0.001); + float atten = 1.0 - max(d2 - r2, 0.0) / max((r - r2), 0.001); + + atten *= max(dot(normalize(-delta), dir), min_da); + float w = 1.0 / d2; + w *= atten; + + return w; +} + // Tap a reflection probe // pos - position of pixel // dir - pixel normal @@ -431,27 +465,21 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out vec3 vi, out vec3 wi, float if (refIndex[i].w < 0) { - v = boxIntersect(pos, dir, i); - w = 1.0; + float d = 0; + v = boxIntersect(pos, dir, i, d); + + w = max(d, 0.001); } else { float r = refSphere[i].w; // radius of sphere volume float rr = r * r; // radius squared - v = sphereIntersect(pos, dir, c, rr); - - float p = float(abs(refIndex[i].w)); // priority - - float r1 = r * 0.1; // 90% of radius (outer sphere to start interpolating down) - vec3 delta = pos.xyz - refSphere[i].xyz; - float d2 = max(dot(delta, delta), 0.001); - float r2 = r1 * r1; + v = sphereIntersect(pos, dir, c, + refIndex[i].w <= 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres + rr); - float atten = 1.0 - max(d2 - r2, 0.0) / max((rr - r2), 0.001); - - w = 1.0 / d2; - w *= atten; + w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.25); } vi = v; @@ -480,8 +508,9 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) vec3 v; if (refIndex[i].w < 0) { - v = boxIntersect(pos, dir, i); - w = 1.0; + float d = 0.0; + v = boxIntersect(pos, dir, i, d); + w = max(d, 0.001); } else { @@ -489,17 +518,11 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) float p = float(abs(refIndex[i].w)); // priority float rr = r * r; // radius squred - v = sphereIntersect(pos, dir, c, rr); - - float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) - vec3 delta = pos.xyz - refSphere[i].xyz; - float d2 = dot(delta, delta); - float r2 = r1 * r1; + v = sphereIntersect(pos, dir, c, + refIndex[i].w <= 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres + rr); - w = 1.0 / d2; - - float atten = 1.0 - max(d2 - r2, 0.0) / (rr - r2); - w *= atten; + w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.001); } v -= c; @@ -605,7 +628,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness, bool errorCorrect) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) { // TODO - don't hard code lods float reflection_lods = 6; @@ -617,6 +640,17 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, float lod = (1.0-glossiness)*reflection_lods; glossenv = sampleProbes(pos, normalize(refnormpersp), lod, errorCorrect); + +#if defined(SSR) + if (cube_snapshot != 1) + { + vec4 ssr = vec4(0); + //float w = tapScreenSpaceReflection(errorCorrect ? 1 : 4, tc, pos, norm, ssr, sceneMap); + float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap); + + glossenv = mix(glossenv, ssr.rgb, w); + } +#endif } void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) @@ -660,15 +694,15 @@ vec4 sampleReflectionProbesDebug(vec3 pos) } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness) + vec2 tc, vec3 pos, vec3 norm, float glossiness) { sampleReflectionProbes(ambenv, glossenv, - pos, norm, glossiness, false); + tc, pos, norm, glossiness, false); } void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec3 pos, vec3 norm, float glossiness, float envIntensity) + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity) { // TODO - don't hard code lods float reflection_lods = 7; @@ -676,7 +710,6 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - ambenv = sampleProbeAmbient(pos, norm); if (glossiness > 0.0) @@ -689,6 +722,17 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout { legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, false); } + +#if defined(SSR) + if (cube_snapshot != 1) + { + vec4 ssr = vec4(0); + float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap); + + glossenv = mix(glossenv, ssr.rgb, w); + legacyenv = mix(legacyenv, ssr.rgb, w); + } +#endif } void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl index 4813e6c2d9..742f528cb1 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -42,10 +42,7 @@ uniform float zFar; VARYING vec2 vary_fragcoord; VARYING vec3 camera_ray; -uniform sampler2D depthMap; -uniform sampler2D normalMap; uniform sampler2D specularRect; -uniform sampler2D sceneMap; uniform sampler2D diffuseRect; uniform sampler2D diffuseMap; @@ -57,27 +54,27 @@ float linearDepth01(float d, float znear, float zfar); vec4 getPositionWithDepth(vec2 pos_screen, float depth); vec4 getPosition(vec2 pos_screen); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); -bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame); float random (vec2 uv); +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source); void main() { vec2 tc = vary_fragcoord.xy; float depth = linearDepth01(getDepth(tc), zNear, zFar); - vec3 n = vec3(0, 0, 1); float envIntensity; + vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() vec3 pos = getPositionWithDepth(tc, getDepth(tc)).xyz; vec4 spec = texture2D(specularRect, tc); - vec3 viewPos = camera_ray * depth; - vec3 rayDirection = normalize(reflect(normalize(viewPos), n)) * -viewPos.z; vec2 hitpixel; - vec4 hitpoint; + vec4 diffuse = texture2D(diffuseRect, tc); vec3 specCol = spec.rgb; + frag_color = texture(diffuseMap, tc); + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { vec3 orm = specCol.rgb; @@ -85,44 +82,17 @@ void main() float metallic = orm.b; vec3 f0 = vec3(0.04); vec3 baseColor = diffuse.rgb; - + vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); specCol = mix(f0, baseColor.rgb, metallic); } - vec2 uv2 = tc * screen_res; - float c = (uv2.x + uv2.y) * 0.125; - float jitter = mod( c, 1.0); + vec4 collectedColor = vec4(0); - vec3 firstBasis = normalize(cross(vec3(1.f, 1.f, 1.f), rayDirection)); - vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); - - frag_color = texture(diffuseMap, tc); - vec4 collectedColor; - - vec2 screenpos = 1 - abs(tc * 2 - 1); - float vignette = clamp((screenpos.x * screenpos.y) * 16,0, 1); - vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5 - 0.2) * 8, 0, 1); - vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / zFar, 1); - - int totalSamples = 4; - - for (int i = 0; i < totalSamples; i++) - { - vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); - vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y; - - bool hit = traceScreenRay(pos, reflectionDirectionRandomized, hitpoint, depth, depth, diffuseMap); - - if (hit) - { - collectedColor += hitpoint; - collectedColor.rgb *= specCol.rgb; - } - } + float w = tapScreenSpaceReflection(4, tc, pos, n, collectedColor, diffuseMap); - collectedColor *= vignette; + collectedColor.rgb *= specCol.rgb; - frag_color += collectedColor; + frag_color += collectedColor * w; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index b6c789ad40..570235a816 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -23,19 +23,18 @@ * $/LicenseInfo$ */ -uniform sampler2D depthMap; -uniform sampler2D normalMap; uniform sampler2D sceneMap; +uniform sampler2D sceneDepth; + uniform vec2 screen_res; uniform mat4 projection_matrix; -uniform float zNear; -uniform float zFar; +//uniform float zNear; +//uniform float zFar; uniform mat4 inv_proj; +uniform mat4 modelview_delta; // should be transform from last camera space to current camera space +uniform mat4 inv_modelview_delta; vec4 getPositionWithDepth(vec2 pos_screen, float depth); -float linearDepth(float depth, float near, float far); -float getDepth(vec2 pos_screen); -float linearDepth01(float d, float znear, float zfar); float random (vec2 uv) { @@ -62,8 +61,25 @@ float distanceBias = 0.02; float depthRejectBias = 0.001; float epsilon = 0.1; +float getLinearDepth(vec2 tc) +{ + float depth = texture(sceneDepth, tc).r; + + vec4 pos = getPositionWithDepth(tc, depth); + + return -pos.z; +} + bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) { + // transform position and reflection into same coordinate frame as the sceneMap and sceneDepth + reflection += position; + position = (inv_modelview_delta * vec4(position, 1)).xyz; + reflection = (inv_modelview_delta * vec4(reflection, 1)).xyz; + reflection -= position; + + depth = -position.z; + vec3 step = rayStep * reflection; vec3 marchingPosition = position + step; float delta; @@ -72,13 +88,14 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float bool hit = false; hitColor = vec4(0); + int i = 0; if (depth > depthRejectBias) { for (; i < iterationCount && !hit; i++) { screenPosition = generateProjectedPosition(marchingPosition); - depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); + depthFromScreen = getLinearDepth(screenPosition); delta = abs(marchingPosition.z) - depthFromScreen; if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) @@ -91,7 +108,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float vec4 color = vec4(1); if(debugDraw) color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); - hitColor = texture(textureFrame, screenPosition) * color; + hitColor = texture(sceneMap, screenPosition) * color; hitDepth = depthFromScreen; hit = true; break; @@ -126,7 +143,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float marchingPosition = marchingPosition - step * sign(delta); screenPosition = generateProjectedPosition(marchingPosition); - depthFromScreen = linearDepth(getDepth(screenPosition), zNear, zFar); + depthFromScreen = getLinearDepth(screenPosition); delta = abs(marchingPosition.z) - depthFromScreen; if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) @@ -139,7 +156,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float vec4 color = vec4(1); if(debugDraw) color = vec4( 0.5+ sign(delta)/2,0.3,0.5- sign(delta)/2, 0); - hitColor = texture(textureFrame, screenPosition) * color; + hitColor = texture(sceneMap, screenPosition) * color; hitDepth = depthFromScreen; hit = true; break; @@ -150,3 +167,68 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float return hit; } + +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source) +{ + collectedColor = vec4(0); + int hits = 0; + + float depth = -viewPos.z; + + vec3 rayDirection = normalize(reflect(viewPos, normalize(n))); + + vec2 uv2 = tc * screen_res; + float c = (uv2.x + uv2.y) * 0.125; + float jitter = mod( c, 1.0); + + vec3 firstBasis = normalize(cross(vec3(1,1,1), rayDirection)); + vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); + + vec2 screenpos = 1 - abs(tc * 2 - 1); + float vignette = clamp((screenpos.x * screenpos.y) * 16,0, 1); + vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5 - 0.2) * 8, 0, 1); + float zFar = 64.0; + vignette *= clamp(1.0+(viewPos.z/zFar), 0.0, 1.0); + //vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / zFar, 1); + + vec4 hitpoint; + + if (totalSamples > 1) + { + for (int i = 0; i < totalSamples; i++) + { + vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); + vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y; + + //float hitDepth; + + bool hit = traceScreenRay(viewPos, normalize(reflectionDirectionRandomized), hitpoint, depth, depth, source); + + if (hit) + { + ++hits; + collectedColor += hitpoint; + } + } + } + else + { + bool hit = traceScreenRay(viewPos, normalize(rayDirection), hitpoint, depth, depth, source); + if (hit) + { + ++hits; + collectedColor += hitpoint; + } + } + + if (hits > 0) + { + collectedColor /= hits; + } + else + { + collectedColor = vec4(0); + } + + return min(float(hits), 1.0) * vignette; +} \ No newline at end of file diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8e4197ae77..8d48e6f596 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -75,9 +75,9 @@ vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); // reflection probe interface void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness); -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyEnv, - vec3 pos, vec3 norm, float glossiness, float envIntensity); + vec2 tc, vec3 pos, vec3 norm, float glossiness); +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); 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); float getDepth(vec2 pos_screen); @@ -166,7 +166,7 @@ void main() float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, pos.xyz, norm.xyz, gloss); + sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss); // Take maximium of legacy ambient vs irradiance sample as irradiance // NOTE: ao is applied in pbrIbl (see pbrBaseLight), do not apply here @@ -196,7 +196,7 @@ void main() vec3 glossenv = vec3(0); vec3 legacyenv = vec3(0); - sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, pos.xyz, norm.xyz, spec.a, envIntensity); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity); // use sky settings ambient or irradiance map sample, whichever is brighter irradiance = max(amblit, irradiance); diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 85c3f42801..b792feee2a 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -95,9 +95,6 @@ vec3 BlendNormal(vec3 bump1, vec3 bump2) vec3 srgb_to_linear(vec3 col); -void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec3 pos, vec3 norm, float glossiness, float envIntensity); - vec3 vN, vT, vB; vec3 transform_normal(vec3 vNt) @@ -106,7 +103,10 @@ vec3 transform_normal(vec3 vNt) } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec3 pos, vec3 norm, float glossiness, bool errorCorrect); + vec2 tc, vec3 pos, vec3 norm, float glossiness); + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect); vec3 getPositionWithNDC(vec3 ndc); @@ -225,7 +225,7 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, pos, refnorm, gloss, true); + sampleReflectionProbes(irradiance, radiance, distort, pos, refnorm, gloss, true); radiance *= 0.5; irradiance = fb.rgb; -- cgit v1.2.3 From 12afbacd83f07f5df11e15996b8f6357fb49b9b2 Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Mon, 30 Jan 2023 10:09:04 -0800 Subject: Fix DRTVWR-559 EOL at EOF to pass coding policy checks --- .../app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index 570235a816..c355b671c0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -231,4 +231,4 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, } return min(float(hits), 1.0) * vignette; -} \ No newline at end of file +} -- cgit v1.2.3 From 10b8dcc497599042655dcc4037c9ae98d494bd6f Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 30 Jan 2023 18:56:19 -0600 Subject: SL-19015 Bump probe resolution back to 256 by default (drop to 128 if vram < 2GB), remove irradiance map feedback loop (one bounce, but but more stable and allows for much brighter first bounce), make sky contribution to irradiance not tint the world blue. Make irradiance that appears in radiance maps match world irradiance. --- .../app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 9793ab13de..bb3be7260b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -36,6 +36,7 @@ uniform samplerCubeArray reflectionProbes; uniform samplerCubeArray irradianceProbes; uniform sampler2D sceneMap; uniform int cube_snapshot; +uniform float max_probe_lod; layout (std140) uniform ReflectionProbes { @@ -623,7 +624,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) { col *= 1.0/wsum; } - + return col; } @@ -631,7 +632,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) { // TODO - don't hard code lods - float reflection_lods = 6; + float reflection_lods = max_probe_lod; preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); @@ -705,7 +706,7 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity) { // TODO - don't hard code lods - float reflection_lods = 7; + float reflection_lods = max_probe_lod; preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); -- cgit v1.2.3 From 830cb6b66551025285120fb628f0b5ebf3841756 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 3 Feb 2023 17:18:39 -0600 Subject: SL-19148 Decruft some forward shaders and drawpools. Fix HUDs being in wrong color space. --- .../shaders/class3/deferred/fullbrightShinyF.glsl | 55 ++++++++++------------ 1 file changed, 24 insertions(+), 31 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index 160d360256..b90de7609b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -43,9 +43,6 @@ VARYING vec3 vary_position; uniform samplerCube environmentMap; -// render_hud_attachments() -> HUD objects set LLShaderMgr::NO_ATMO; used in LLDrawPoolAlpha::beginRenderPass() -uniform int no_atmo; - vec3 fullbrightShinyAtmosTransport(vec3 light); vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); vec3 fullbrightScaleSoftClip(vec3 light); @@ -59,12 +56,8 @@ vec3 srgb_to_linear(vec3 c); void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); -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); -// See: -// class1\deferred\fullbrightShinyF.glsl -// class1\lighting\lightFullbrightShinyF.glsl void main() { #ifdef HAS_DIFFUSE_LOOKUP @@ -76,32 +69,32 @@ void main() color.rgb *= vertex_color.rgb; // SL-9632 HUDs are affected by Atmosphere - if (no_atmo == 0) - { - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; - vec3 pos = vary_position; - calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); - - float env_intensity = vertex_color.a; - - vec3 ambenv; - vec3 glossenv; - vec3 legacyenv; - vec3 norm = normalize(vary_texcoord1.xyz); - vec4 spec = vec4(0,0,0,0); - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity); - applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); - - color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); - color.rgb = fullbrightScaleSoftClip(color.rgb); - } +#ifndef IS_HUD + + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; + vec3 pos = vary_position; + calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); + + float env_intensity = vertex_color.a; + + vec3 ambenv; + vec3 glossenv; + vec3 legacyenv; + vec3 norm = normalize(vary_texcoord1.xyz); + vec4 spec = vec4(0,0,0,0); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity); + applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); + + color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); + color.rgb = fullbrightScaleSoftClip(color.rgb); + color.rgb = srgb_to_linear(color.rgb); +#endif color.a = 1.0; - - color.rgb = srgb_to_linear(color.rgb); + frag_color = color; } -- cgit v1.2.3 From b52699091da791a1349daf66d405f27ca2568ea9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 7 Feb 2023 11:40:56 -0600 Subject: SL-19147 Water quality pass. Remove gl_FragDepth writes from sky rendering (optimization). Incidental decruft. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 2 +- .../shaders/class3/environment/underWaterF.glsl | 4 +- .../shaders/class3/environment/waterF.glsl | 134 +++++++++++---------- 3 files changed, 74 insertions(+), 66 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index bb3be7260b..8b1d41776f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -643,7 +643,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, glossenv = sampleProbes(pos, normalize(refnormpersp), lod, errorCorrect); #if defined(SSR) - if (cube_snapshot != 1) + if (cube_snapshot != 1 && glossiness >= 0.9) { vec4 ssr = vec4(0); //float w = tapScreenSpaceReflection(errorCorrect ? 1 : 4, tc, pos, norm, ssr, sceneMap); diff --git a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl index a5e0adf8fa..83454631d4 100644 --- a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl @@ -55,7 +55,7 @@ VARYING vec4 littleWave; VARYING vec4 view; in vec3 vary_position; -vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); +vec4 applyWaterFogViewLinearNoClip(vec3 pos, vec4 color, vec3 sunlit); void main() { @@ -77,5 +77,5 @@ void main() vec4 fb = vec4(waterFogColorLinear, 0.0); #endif - frag_color = applyWaterFogViewLinear(vary_position, fb); + frag_color = applyWaterFogViewLinearNoClip(vary_position, fb, vec3(1)); } diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index b792feee2a..98e8d189c5 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -37,6 +37,10 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit); // PBR interface +vec2 BRDF(float NoV, float roughness); + +void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); + vec3 pbrIbl(vec3 diffuseColor, vec3 specularColor, vec3 radiance, // radiance map sample @@ -52,6 +56,22 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 v, // surface point to camera vec3 l); //surface point to light +vec3 pbrBaseLight(vec3 diffuseColor, + vec3 specularColor, + float metallic, + vec3 pos, + vec3 norm, + float perceptualRoughness, + vec3 light_dir, + vec3 sunlit, + float scol, + vec3 radiance, + vec3 irradiance, + vec3 colorEmissive, + float ao, + vec3 additive, + vec3 atten); + uniform sampler2D bumpMap; uniform sampler2D bumpMap2; uniform float blend_factor; @@ -112,8 +132,6 @@ vec3 getPositionWithNDC(vec3 ndc); void main() { - vec4 color; - vN = vary_normal; vT = vary_tangent; vB = cross(vN, vT); @@ -151,30 +169,28 @@ void main() vec3 waver = wavef*3; - wavef = transform_normal(wavef); + vec3 up = transform_normal(vec3(0,0,1)); + float vdu = -dot(viewVec, up)*2; + + vec3 wave_ibl = wavef; + wave_ibl.z *= 2.0; + wave_ibl = transform_normal(normalize(wave_ibl)); - //wavef.z *= max(-viewVec.z, 0.1); + vec3 norm = transform_normal(normalize(wavef)); + + vdu = clamp(vdu, 0, 1); + wavef.z *= max(vdu*vdu*vdu, 0.1); wavef = normalize(wavef); - //get base fresnel components - - vec3 df = vec3( - dot(viewVec, wave1), - dot(viewVec, (wave2 + wave3) * 0.5), - dot(viewVec, wave3) - ) * fresnelScale + fresnelOffset; - + //wavef = vec3(0, 0, 1); + wavef = transform_normal(wavef); + float dist2 = dist; dist = max(dist, 5.0); float dmod = sqrt(dist); - float df1 = df.x + df.y + df.z; - - - - //figure out distortion vector (ripply) vec2 distort2 = distort + waver.xy * refScale / max(dmod, 1.0); @@ -203,66 +219,58 @@ void main() fb = applyWaterFogViewLinear(refPos, fb, sunlit); #else - vec4 fb = vec4(waterFogColorLinear.rgb, 0.0); + vec4 fb = applyWaterFogViewLinear(viewVec*1024.0, vec4(0.5), sunlit); #endif - vec3 v = -viewVec; - float NdotV = clamp(abs(dot(wavef.xyz, v)), 0.001, 1.0); - - float metallic = fresnelOffset * 0.1; // fudge -- use fresnelOffset as metalness - float roughness = 0.1; - float gloss = 1.0 - roughness; + float metallic = 0.0; + float perceptualRoughness = 0.1; + float gloss = 1.0 - perceptualRoughness; + + vec3 irradiance = vec3(0); + vec3 radiance = vec3(0); + sampleReflectionProbes(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss); - vec3 baseColor = vec3(0.25); - vec3 f0 = vec3(0.04); - vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0); - diffuseColor *= gloss; + irradiance = vec3(0); - vec3 specularColor = mix(f0, baseColor.rgb, metallic); + vec3 diffuseColor; + vec3 specularColor; + calcDiffuseSpecular(vec3(1), metallic, diffuseColor, specularColor); - vec3 refnorm = normalize(wavef + vary_normal); - //vec3 refnorm = wavef; - - vec3 irradiance = vec3(0); - vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, distort, pos, refnorm, gloss, true); - radiance *= 0.5; - irradiance = fb.rgb; + vec3 v = -normalize(pos.xyz); - color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0); + float scol = 1.0; + vec3 colorEmissive = vec3(0); + float ao = 1.0; + vec3 light_dir = transform_normal(lightDir); - // fudge -- for punctual lighting, pretend water is metallic - diffuseColor = vec3(0); - specularColor = vec3(1); - roughness = 0.1; - float scol = 1.0; // TODO -- incorporate shadow map + perceptualRoughness = 0.0; + metallic = 1.0; - //color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir) * sunlit * 2.75 * scol; + float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); - //get specular component - float spec = clamp(dot(vary_light_dir, (reflect(viewVec, wavef))), 0.0, 1.0); + vec3 punctual = pbrPunctual(vec3(0), specularColor, 0.1, metallic, normalize(wavef+up*max(dist, 32.0)/32.0*(1.0-vdu)), v, normalize(light_dir)); - //harden specular - spec = pow(spec, 128.0); + vec3 color = punctual * sunlit * 2.75 * scol; - color.rgb += spec * specular; + color = atmosFragLightingLinear(color, additive, atten); + color = scaleSoftClipFragLinear(color); - color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); - color.rgb = scaleSoftClipFragLinear(color.rgb); + vec3 ibl = pbrIbl(vec3(0), vec3(1), radiance, vec3(0), ao, NdotV, 0.0); - color.a = 0.f; - //color.rgb = fb.rgb; - //color.rgb = vec3(depth*depth*depth*depth); - //color.rgb = srgb_to_linear(normalize(refPos) * 0.5 + 0.5); - //color.rgb = srgb_to_linear(normalize(pos) * 0.5 + 0.5); - //color.rgb = srgb_to_linear(wavef * 0.5 + 0.5); + color += ibl; - //color.rgb = radiance; - frag_color = color; + float nv = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0); + vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0); + float f = 1.0-brdf.y; //1.0 - (brdf.x+brdf.y); + f *= 0.9; + f *= f; -#if defined(WATER_EDGE) - gl_FragDepth = 0.9999847f; -#endif - + f = clamp(f, 0, 1); + //fb.rgb *= 1.; + + color = mix(color, fb.rgb, f); + float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05); + + frag_color = vec4(color, spec); //*sunAngle2); } -- cgit v1.2.3 From 9036d801065dcd4bc0ff03c4f7c641c434a8fbea Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 13 Feb 2023 10:12:48 -0600 Subject: SL-18664 Fix for "transparent water" off causing broken horizon line. --- indra/newview/app_settings/shaders/class3/environment/waterF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 98e8d189c5..3d721cd048 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -219,7 +219,7 @@ void main() fb = applyWaterFogViewLinear(refPos, fb, sunlit); #else - vec4 fb = applyWaterFogViewLinear(viewVec*1024.0, vec4(0.5), sunlit); + vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(0.5), sunlit); #endif float metallic = 0.0; -- cgit v1.2.3 From 50c57b6be72541b92340c6230d417c508a4fa6f9 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 17 Feb 2023 10:34:27 -0600 Subject: SL-19128 Soften the transition between manual and automatic sphere probes. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 174 ++++++++++++++------- .../shaders/class3/environment/waterF.glsl | 4 +- 2 files changed, 116 insertions(+), 62 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 8b1d41776f..24539c3c3a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -80,7 +80,7 @@ bool isAbove(vec3 pos, vec4 plane) return (dot(plane.xyz, pos) + plane.w) > 0; } -int max_priority = 0; +bool sample_automatic = true; // return true if probe at index i influences position pos bool shouldSampleProbe(int i, vec3 pos) @@ -95,24 +95,24 @@ bool shouldSampleProbe(int i, vec3 pos) return false; } - max_priority = max(max_priority, -refIndex[i].w); + sample_automatic = false; } else { - if (refSphere[i].w > 0.0) // zero is special indicator to always sample this probe + if (refIndex[i].w == 0 && !sample_automatic) { - vec3 delta = pos.xyz - refSphere[i].xyz; - float d = dot(delta, delta); - float r2 = refSphere[i].w; - r2 *= r2; - - if (d > r2) - { //outside bounding sphere - return false; - } + return false; } - max_priority = max(max_priority, refIndex[i].w); + vec3 delta = pos.xyz - refSphere[i].xyz; + float d = dot(delta, delta); + float r2 = refSphere[i].w; + r2 *= r2; + + if (d > r2) + { // outside bounding sphere + return false; + } } return true; @@ -120,7 +120,6 @@ bool shouldSampleProbe(int i, vec3 pos) // call before sampleRef // populate "probeIndex" with N probe indices that influence pos where N is REF_SAMPLE_COUNT -// overall algorithm -- void preProbeSample(vec3 pos) { // TODO: make some sort of structure that reduces the number of distance checks @@ -210,7 +209,7 @@ void preProbeSample(vec3 pos) } } - if (max_priority <= 1) + if (sample_automatic) { // probe at index 0 is a special probe for smoothing out automatic probes probeIndex[probeInfluences++] = 0; } @@ -342,7 +341,7 @@ return texCUBE(envMap, ReflDirectionWS); // d - distance to nearest wall in clip space vec3 boxIntersect(vec3 origin, vec3 dir, int i, out float d) { - // Intersection with OBB convertto unit box space + // Intersection with OBB convert to unit box space // Transform in local unit parallax cube space (scaled and rotated) mat4 clipToLocal = refBox[i]; @@ -431,18 +430,24 @@ void boxIntersectDebug(vec3 origin, vec3 pos, int i, inout vec4 col) // origin - center of sphere probe // r - radius of probe influence volume // min_da - minimum angular attenuation coefficient -float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da) +// i - index of probe in refSphere +// dw - distance weight +float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da, int i, out float dw) { float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz - origin; float d2 = max(length(delta), 0.001); + float r2 = r1; //r1 * r1; //float atten = 1.0 - max(d2 - r2, 0.0) / max((rr - r2), 0.001); float atten = 1.0 - max(d2 - r2, 0.0) / max((r - r2), 0.001); + float w = 1.0 / d2; + + dw = w * atten * max(r, 1.0)*4; atten *= max(dot(normalize(-delta), dir), min_da); - float w = 1.0 / d2; + w *= atten; return w; @@ -451,13 +456,15 @@ float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da) // Tap a reflection probe // pos - position of pixel // dir - pixel normal +// w - weight of sample (distance and angular attenuation) +// dw - weight of sample (distance only) // vi - return value of intersection point with influence volume // wi - return value of approximate world space position of sampled pixel // lod - which mip to bias towards (lower is higher res, sharper reflections) // c - center of probe // r2 - radius of probe squared // i - index of probe -vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out vec3 vi, out vec3 wi, float lod, vec3 c, int i) +vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, out vec3 vi, out vec3 wi, float lod, vec3 c, int i) { //lod = max(lod, 1); // parallax adjustment @@ -473,14 +480,15 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out vec3 vi, out vec3 wi, float } else { - float r = refSphere[i].w; // radius of sphere volume - float rr = r * r; // radius squared + float r = refSphere[i].w; + + float rr = r * r; v = sphereIntersect(pos, dir, c, - refIndex[i].w <= 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres + refIndex[i].w < 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres rr); - w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.25); + w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.25, i, dw); } vi = v; @@ -500,10 +508,10 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out vec3 vi, out vec3 wi, float // Tap an irradiance map // pos - position of pixel // dir - pixel normal -// c - center of probe -// r2 - radius of probe squared +// w - weight of sample (distance and angular attenuation) +// dw - weight of sample (distance only) // i - index of probe -vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) +vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int i) { // parallax adjustment vec3 v; @@ -516,14 +524,15 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) else { float r = refSphere[i].w; // radius of sphere volume - float p = float(abs(refIndex[i].w)); // priority - float rr = r * r; // radius squred + + // pad sphere for manual probe extending into automatic probe space + float rr = r * r; v = sphereIntersect(pos, dir, c, - refIndex[i].w <= 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres + refIndex[i].w < 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres rr); - w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.001); + w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.001, i, dw); } v -= c; @@ -535,19 +544,30 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, vec3 c, int i) vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) { - float wsum = 0.0; - vec3 col = vec3(0,0,0); - float vd2 = dot(pos,pos); // view distance squared + float wsum[2]; + wsum[0] = 0; + wsum[1] = 0; + + float dwsum[2]; + dwsum[0] = 0; + dwsum[1] = 0; + + vec3 col[2]; + col[0] = vec3(0); + col[1] = vec3(0); for (int idx = 0; idx < probeInfluences; ++idx) { int i = probeIndex[idx]; - if (abs(refIndex[i].w) < max_priority) + int p = clamp(abs(refIndex[i].w), 0, 1); + + if (p == 0 && !sample_automatic) { continue; } - float w; + float w = 0; + float dw = 0; vec3 vi, wi; vec3 refcol; @@ -556,7 +576,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) if (errorCorrect && refIndex[i].w >= 0) { // error correction is on and this probe is a sphere //take a sample to get depth value, then error correct - refcol = tapRefMap(pos, dir, w, vi, wi, abs(lod + 2), refSphere[i].xyz, i); + refcol = tapRefMap(pos, dir, w, dw, vi, wi, abs(lod + 2), refSphere[i].xyz, i); //adjust lookup by distance result float d = length(vi - wi); @@ -571,61 +591,96 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) // weight by vector correctness vec3 pi = normalize(wi - pos); w *= max(dot(pi, dir), 0.1); - //w = pow(w, 32.0); } else { - refcol = tapRefMap(pos, dir, w, vi, wi, lod, refSphere[i].xyz, i); + refcol = tapRefMap(pos, dir, w, dw, vi, wi, lod, refSphere[i].xyz, i); } - col += refcol.rgb*w; - - wsum += w; + col[p] += refcol.rgb*w; + wsum[p] += w; + dwsum[p] += dw; } } - if (wsum > 0.0) + // mix automatic and manual probes + if (sample_automatic && wsum[0] > 0.0) + { // some automatic probes were sampled + col[0] *= 1.0/wsum[0]; + if (wsum[1] > 0.0) + { //some manual probes were sampled, mix between the two + col[1] *= 1.0/wsum[1]; + col[1] = mix(col[0], col[1], min(dwsum[1], 1.0)); + col[0] = vec3(0); + } + } + else if (wsum[1] > 0.0) { - col *= 1.0/wsum; + // manual probes were sampled but no automatic probes were + col[1] *= 1.0/wsum[1]; + col[0] = vec3(0); } - return col; + return col[1]+col[0]; } vec3 sampleProbeAmbient(vec3 pos, vec3 dir) { // modified copy/paste of sampleProbes follows, will likely diverge from sampleProbes further // as irradiance map mixing is tuned independently of radiance map mixing - float wsum = 0.0; - vec3 col = vec3(0,0,0); - float vd2 = dot(pos,pos); // view distance squared + float wsum[2]; + wsum[0] = 0; + wsum[1] = 0; - float minweight = 1.0; + float dwsum[2]; + dwsum[0] = 0; + dwsum[1] = 0; + + vec3 col[2]; + col[0] = vec3(0); + col[1] = vec3(0); for (int idx = 0; idx < probeInfluences; ++idx) { int i = probeIndex[idx]; - if (abs(refIndex[i].w) < max_priority) + int p = clamp(abs(refIndex[i].w), 0, 1); + + if (p == 0 && !sample_automatic) { continue; } { - float w; - vec3 refcol = tapIrradianceMap(pos, dir, w, refSphere[i].xyz, i); + float w = 0; + float dw = 0; - col += refcol*w; - - wsum += w; + vec3 refcol = tapIrradianceMap(pos, dir, w, dw, refSphere[i].xyz, i); + + col[p] += refcol*w; + wsum[p] += w; + dwsum[p] += dw; } } - if (wsum > 0.0) + // mix automatic and manual probes + if (sample_automatic && wsum[0] > 0.0) + { // some automatic probes were sampled + col[0] *= 1.0/wsum[0]; + if (wsum[1] > 0.0) + { //some manual probes were sampled, mix between the two + col[1] *= 1.0/wsum[1]; + col[1] = mix(col[0], col[1], min(dwsum[1], 1.0)); + col[0] = vec3(0); + } + } + else if (wsum[1] > 0.0) { - col *= 1.0/wsum; + // manual probes were sampled but no automatic probes were + col[1] *= 1.0/wsum[1]; + col[0] = vec3(0); } - - return col; + + return col[1]+col[0]; } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, @@ -658,7 +713,7 @@ void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) { vec3 origin = vec3(0,0,0); - bool manual_probe = abs(refIndex[i].w) > 2; + bool manual_probe = abs(refIndex[i].w) > 0; if (manual_probe) { @@ -705,7 +760,6 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity) { - // TODO - don't hard code lods float reflection_lods = max_probe_lod; preProbeSample(pos); diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 3d721cd048..631d2c04d0 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -232,8 +232,8 @@ void main() irradiance = vec3(0); - vec3 diffuseColor; - vec3 specularColor; + vec3 diffuseColor = vec3(0); + vec3 specularColor = vec3(0); calcDiffuseSpecular(vec3(1), metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); -- cgit v1.2.3 From 86427ec145c7b956ec9ff5d9aa7ddde630cf45e1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 24 Feb 2023 14:54:25 -0600 Subject: SL-19212 Resurrect glare and apply to PBR materials as well (and fix color mismatch in legacy alpha vs opaque). --- .../shaders/class3/deferred/materialF.glsl | 162 +++++++++++++-------- .../shaders/class3/deferred/pointLightF.glsl | 4 +- 2 files changed, 100 insertions(+), 66 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 8d2a65d4a9..48dd8e942e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -92,7 +92,7 @@ uniform vec3 light_diffuse[8]; float getAmbientClamp(); void waterClip(vec3 pos); -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, float ambiance) +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 @@ -170,6 +170,11 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe 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); } } } @@ -218,83 +223,104 @@ VARYING vec2 vary_texcoord0; vec2 encode_normal(vec3 n); -void main() +// get the transformed normal and apply glossiness component from normal map +vec3 getNormal(inout float glossiness) { -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - waterClip(vary_position.xyz); -#endif +#ifdef HAS_NORMAL_MAP + vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); + glossiness *= norm.a; - vec2 pos_screen = vary_texcoord0.xy; + norm.xyz = norm.xyz * 2 - 1; - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); - diffcol.rgb *= vertex_color.rgb; + return normalize(vec3(dot(norm.xyz,vary_mat0), + dot(norm.xyz,vary_mat1), + dot(norm.xyz,vary_mat2))); +#else + return normalize(vary_normal); +#endif +} -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) +vec4 getSpecular() +{ +#ifdef HAS_SPECULAR_MAP + vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + spec.rgb *= specular_color.rgb; +#else + vec4 spec = vec4(specular_color.rgb, 1.0); +#endif + return spec; +} +void alphaMask(float alpha) +{ +#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 - if (diffcol.a < minimum_alpha-bias) + if (alpha < minimum_alpha-bias) { discard; } #endif +} -#ifdef HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); - spec.rgb *= specular_color.rgb; -#else - vec4 spec = vec4(specular_color.rgb, 1.0); +void waterClip() +{ +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + waterClip(vary_position.xyz); #endif +} -#ifdef HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); - - norm.xyz = norm.xyz * 2 - 1; +float getEmissive(vec4 diffcol) +{ +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) + return emissive_brightness; +#else + return max(diffcol.a, emissive_brightness); +#endif +} - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); +float getShadow(vec3 pos, vec3 norm) +{ +#ifdef HAS_SUN_SHADOW + #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + return sampleDirectionalShadow(pos, norm, vary_texcoord0.xy); + #else + return 1; + #endif #else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; + return 1; #endif +} - norm.xyz = normalize(tnorm.xyz); +void main() +{ + waterClip(); - vec2 abnormal = encode_normal(norm.xyz); + // diffcol == diffuse map combined with vertex color + vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + diffcol.rgb *= vertex_color.rgb; - vec4 final_color = diffcol; + alphaMask(diffcol.a); -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = emissive_brightness; -#else - final_color.a = max(final_color.a, emissive_brightness); -#endif + // spec == specular map combined with specular color + vec4 spec = getSpecular(); + float glossiness = specular_color.a; + vec3 norm = getNormal(glossiness); - vec4 final_specular = spec; - -#ifdef HAS_SPECULAR_MAP - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, GBUFFER_FLAG_HAS_ATMOS); - final_specular.a = specular_color.a * norm.a; -#else - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, GBUFFER_FLAG_HAS_ATMOS); - final_specular.a = specular_color.a; -#endif + vec2 abnormal = encode_normal(norm.xyz); + + float emissive = getEmissive(diffcol); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output lit linear color diffcol.rgb = srgb_to_linear(diffcol.rgb); - final_specular.rgb = srgb_to_linear(final_specular.rgb); + spec.rgb = srgb_to_linear(spec.rgb); vec3 pos = vary_position; - float shadow = 1.0f; - -#ifdef HAS_SUN_SHADOW - shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); -#endif + float shadow = getShadow(pos, norm); - vec4 diffuse = final_color; + vec4 diffuse = diffcol; vec3 color = vec3(0,0,0); @@ -310,7 +336,7 @@ void main() vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos_screen, pos.xyz, norm.xyz, final_specular.a, env_intensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env_intensity); // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv); @@ -322,28 +348,37 @@ void main() vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - if (final_specular.a > 0.0) // specular reflection + float glare = 0.0; + + if (glossiness > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); - vec3 dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, final_specular.a)).r); + vec3 dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, glossiness)).r); // add the two types of shiny together - vec3 spec_contrib = dumbshiny * final_specular.rgb; + 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; - applyGlossEnv(color, glossenv, final_specular, pos.xyz, norm.xyz); + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } - color = mix(color.rgb, diffcol.rgb, diffuse.a); + color = mix(color.rgb, diffcol.rgb, emissive); if (env_intensity > 0.0) { // add environmentmap - applyLegacyEnv(color, legacyenv, final_specular, pos.xyz, norm.xyz, env_intensity); + applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, env_intensity); + + float cur_glare = max(max(legacyenv.r, legacyenv.g), legacyenv.b); + cur_glare *= env_intensity*4.0; + glare += cur_glare; } - color.rgb = mix(atmosFragLightingLinear(color.rgb, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), diffuse.a); + color.rgb = mix(atmosFragLightingLinear(color.rgb, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), emissive); color.rgb = scaleSoftClipFragLinear(color.rgb); #ifdef WATER_FOG @@ -354,7 +389,7 @@ void main() vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0, 0, 0); -#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, light_attenuation[i].w ); +#define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, spec, 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) @@ -366,15 +401,16 @@ void main() color += light; - float al = diffcol.a*vertex_color.a; - + glare = min(glare, 1.0); + float al = max(diffcol.a, glare) * vertex_color.a; + frag_color = vec4(color, al); -#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer +#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl - frag_data[0] = final_color; // gbuffer is sRGB for legacy materials - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) + frag_data[0] = vec4(diffcol.rgb, emissive); // gbuffer is sRGB for legacy materials + frag_data[1] = vec4(spec.rgb, glossiness); // XYZ = Specular color. W = Specular exponent. + frag_data[2] = vec4(encode_normal(norm), env_intensity, GBUFFER_FLAG_HAS_ATMOS);; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) #endif } diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index d9cbae45a6..8229ecbbb7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -37,7 +37,6 @@ uniform sampler2D diffuseRect; uniform sampler2D specularRect; uniform sampler2D normalMap; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl -uniform sampler2D noiseMap; uniform sampler2D lightFunc; uniform sampler2D depthMap; @@ -126,8 +125,7 @@ void main() diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); - float noise = texture2D(noiseMap, tc).b; - float lit = nl * dist_atten * noise; + float lit = nl * dist_atten; final_color = color.rgb*lit*diffuse; -- cgit v1.2.3 From b0fb4e3b7c6762d2f63ae349490c264e42809f60 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 24 Feb 2023 19:36:45 -0600 Subject: DRTVWR-559 Fix for ignoring specular channel alpha for attenuation environment intensity. --- .../app_settings/shaders/class3/deferred/materialF.glsl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 48dd8e942e..b00a6ed757 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -304,6 +304,7 @@ void main() // spec == specular map combined with specular color vec4 spec = getSpecular(); + float env = env_intensity * spec.a; float glossiness = specular_color.a; vec3 norm = getNormal(glossiness); @@ -336,7 +337,7 @@ void main() vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env_intensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env); // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit, ambenv); @@ -369,12 +370,12 @@ void main() color = mix(color.rgb, diffcol.rgb, emissive); - if (env_intensity > 0.0) + if (env > 0.0) { // add environmentmap - applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, env_intensity); + applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, env); float cur_glare = max(max(legacyenv.r, legacyenv.g), legacyenv.b); - cur_glare *= env_intensity*4.0; + cur_glare *= env*4.0; glare += cur_glare; } @@ -410,7 +411,7 @@ void main() // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl frag_data[0] = vec4(diffcol.rgb, emissive); // gbuffer is sRGB for legacy materials frag_data[1] = vec4(spec.rgb, glossiness); // XYZ = Specular color. W = Specular exponent. - frag_data[2] = vec4(encode_normal(norm), env_intensity, GBUFFER_FLAG_HAS_ATMOS);; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) + frag_data[2] = vec4(encode_normal(norm), env, GBUFFER_FLAG_HAS_ATMOS);; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) #endif } -- cgit v1.2.3 From 41e694c33efa17122c82950a0dc366d72019a5b2 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 27 Feb 2023 13:26:33 -0600 Subject: DRTVWR-559 Fix for local lights being applied to fullbright objects. --- .../app_settings/shaders/class3/deferred/materialF.glsl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index b00a6ed757..49529860be 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -382,11 +382,6 @@ void main() color.rgb = mix(atmosFragLightingLinear(color.rgb, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), emissive); color.rgb = scaleSoftClipFragLinear(color.rgb); -#ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color, 0.0)); - color = temp.rgb; -#endif - vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0, 0, 0); @@ -400,11 +395,18 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) + light *= 1.0-emissive; color += light; + glare *= 1.0-emissive; glare = min(glare, 1.0); float al = max(diffcol.a, glare) * vertex_color.a; +#ifdef WATER_FOG + vec4 temp = applyWaterFogView(pos, vec4(color, 0.0)); + color = temp.rgb; +#endif + frag_color = vec4(color, al); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer -- cgit v1.2.3 From e5a2f85005bbf94f39ef048dbfe43276990f1154 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 27 Feb 2023 16:53:56 -0600 Subject: SL-19226 Reimplement water fresnel offset/scale, exposure balance for midday, adjust reflections off, and decruft depth buffer error correction shenanigans that are no longer used. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 49 ++++++---------------- .../shaders/class3/environment/waterF.glsl | 25 ++++++----- 2 files changed, 27 insertions(+), 47 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 24539c3c3a..23c6f4d5ae 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -542,7 +542,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int } } -vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) +vec3 sampleProbes(vec3 pos, vec3 dir, float lod) { float wsum[2]; wsum[0] = 0; @@ -573,29 +573,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, bool errorCorrect) { - if (errorCorrect && refIndex[i].w >= 0) - { // error correction is on and this probe is a sphere - //take a sample to get depth value, then error correct - refcol = tapRefMap(pos, dir, w, dw, vi, wi, abs(lod + 2), refSphere[i].xyz, i); - - //adjust lookup by distance result - float d = length(vi - wi); - vi += dir * d; - - vi -= refSphere[i].xyz; - - vi = env_mat * vi; - - refcol = textureLod(reflectionProbes, vec4(vi, refIndex[i].x), lod).rgb; - - // weight by vector correctness - vec3 pi = normalize(wi - pos); - w *= max(dot(pi, dir), 0.1); - } - else - { - refcol = tapRefMap(pos, dir, w, dw, vi, wi, lod, refSphere[i].xyz, i); - } + refcol = tapRefMap(pos, dir, w, dw, vi, wi, lod, refSphere[i].xyz, i); col[p] += refcol.rgb*w; wsum[p] += w; @@ -684,7 +662,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect) + vec2 tc, vec3 pos, vec3 norm, float glossiness) { // TODO - don't hard code lods float reflection_lods = max_probe_lod; @@ -695,13 +673,12 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, ambenv = sampleProbeAmbient(pos, norm); float lod = (1.0-glossiness)*reflection_lods; - glossenv = sampleProbes(pos, normalize(refnormpersp), lod, errorCorrect); + glossenv = sampleProbes(pos, normalize(refnormpersp), lod); #if defined(SSR) if (cube_snapshot != 1 && glossiness >= 0.9) { vec4 ssr = vec4(0); - //float w = tapScreenSpaceReflection(errorCorrect ? 1 : 4, tc, pos, norm, ssr, sceneMap); float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap); glossenv = mix(glossenv, ssr.rgb, w); @@ -709,6 +686,12 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, #endif } +void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness) +{ + sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); +} + void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) { vec3 origin = vec3(0,0,0); @@ -749,14 +732,6 @@ vec4 sampleReflectionProbesDebug(vec3 pos) return col; } -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness) -{ - sampleReflectionProbes(ambenv, glossenv, - tc, pos, norm, glossiness, false); -} - - void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity) { @@ -770,12 +745,12 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout if (glossiness > 0.0) { float lod = (1.0-glossiness)*reflection_lods; - glossenv = sampleProbes(pos, normalize(refnormpersp), lod, false); + glossenv = sampleProbes(pos, normalize(refnormpersp), lod); } if (envIntensity > 0.0) { - legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0, false); + legacyenv = sampleProbes(pos, normalize(refnormpersp), 0.0); } #if defined(SSR) diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 631d2c04d0..a87682affb 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -122,11 +122,8 @@ vec3 transform_normal(vec3 vNt) return normalize(vNt.x * vT + vNt.y * vB + vNt.z * vN); } -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness); - -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, bool errorCorrect); +void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness); vec3 getPositionWithNDC(vec3 ndc); @@ -219,16 +216,16 @@ void main() fb = applyWaterFogViewLinear(refPos, fb, sunlit); #else - vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(0.5), sunlit); + vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(1.0), sunlit); #endif float metallic = 0.0; - float perceptualRoughness = 0.1; + float perceptualRoughness = 0.05; float gloss = 1.0 - perceptualRoughness; vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbes(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss); + sampleReflectionProbesWater(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss); irradiance = vec3(0); @@ -265,10 +262,18 @@ void main() f *= 0.9; f *= f; + // incoming scale is [0, 1] with 0.5 being default + // shift to 0.5 to 1.5 + f *= (fresnelScale - 0.5)+1.0; + + // incoming offset is [0, 1] with 0.5 being default + // shift from -1 to 1 + f += (fresnelOffset - 0.5) * 2.0; + f = clamp(f, 0, 1); - //fb.rgb *= 1.; - + color = mix(color, fb.rgb, f); + float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05); frag_color = vec4(color, spec); //*sunAngle2); -- cgit v1.2.3 From bc7856098f70371dd392c74689df267cce819aa7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 2 Mar 2023 16:36:03 -0600 Subject: SL-19281 Unify handling of haze and gamma between fullbright and not and move haze back to sRGB color space to stay consistent with sky colors. Also fix broken "roughness" stuck at 0.2. --- .../shaders/class3/deferred/materialF.glsl | 13 +++-- .../shaders/class3/deferred/reflectionProbeF.glsl | 24 ++++------ .../shaders/class3/deferred/softenLightF.glsl | 56 ++++++++++++++++++---- .../shaders/class3/environment/waterF.glsl | 17 +++++-- 4 files changed, 75 insertions(+), 35 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 49529860be..add1cb2a37 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -334,16 +334,19 @@ void main() vec3 atten; calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); + vec3 sunlit_linear = srgb_to_linear(sunlit); + vec3 amblit_linear = amblit; + vec3 ambenv; vec3 glossenv; vec3 legacyenv; sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env); // use sky settings ambient or irradiance map sample, whichever is brighter - color = max(amblit, ambenv); + color = max(amblit_linear, ambenv); float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); - vec3 sun_contrib = min(da, shadow) * sunlit; + vec3 sun_contrib = min(da, shadow) * sunlit_linear; color.rgb += sun_contrib; color *= diffcol.rgb; @@ -354,7 +357,7 @@ void main() if (glossiness > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); - vec3 dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, glossiness)).r); + vec3 dumbshiny = sunlit_linear * shadow * (texture2D(lightFunc, vec2(sa, glossiness)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -379,8 +382,10 @@ void main() glare += cur_glare; } - color.rgb = mix(atmosFragLightingLinear(color.rgb, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), emissive); + color.rgb = linear_to_srgb(color.rgb); + color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); color.rgb = scaleSoftClipFragLinear(color.rgb); + color.rgb = srgb_to_linear(color.rgb); vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0, 0, 0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 23c6f4d5ae..c6d649086a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -458,28 +458,24 @@ float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da, int i // dir - pixel normal // w - weight of sample (distance and angular attenuation) // dw - weight of sample (distance only) -// vi - return value of intersection point with influence volume -// wi - return value of approximate world space position of sampled pixel -// lod - which mip to bias towards (lower is higher res, sharper reflections) +// lod - which mip to sample (lower is higher res, sharper reflections) // c - center of probe // r2 - radius of probe squared // i - index of probe -vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, out vec3 vi, out vec3 wi, float lod, vec3 c, int i) +vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, float lod, vec3 c, int i) { - //lod = max(lod, 1); // parallax adjustment - vec3 v; if (refIndex[i].w < 0) - { + { // box probe float d = 0; v = boxIntersect(pos, dir, i, d); w = max(d, 0.001); } else - { + { // sphere probe float r = refSphere[i].w; float rr = r * r; @@ -491,16 +487,12 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, out vec3 vi, out v w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.25, i, dw); } - vi = v; - v -= c; vec3 d = normalize(v); v = env_mat * v; - vec4 ret = textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod); - - wi = d * ret.a * 256.0+c; + vec4 ret = textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod) * refParams[i].y; return ret.rgb; } @@ -568,12 +560,11 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod) float w = 0; float dw = 0; - vec3 vi, wi; vec3 refcol; { - refcol = tapRefMap(pos, dir, w, dw, vi, wi, lod, refSphere[i].xyz, i); + refcol = tapRefMap(pos, dir, w, dw, lod, refSphere[i].xyz, i); col[p] += refcol.rgb*w; wsum[p] += w; @@ -665,7 +656,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness) { // TODO - don't hard code lods - float reflection_lods = max_probe_lod; + float reflection_lods = max_probe_lod-1; preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); @@ -690,6 +681,7 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness) { sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); + glossenv *= 0.25; } void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8d48e6f596..dfd1d47b3e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -85,6 +85,8 @@ float getDepth(vec2 pos_screen); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); +uniform vec4 waterPlane; + #ifdef WATER_FOG vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); #endif @@ -153,6 +155,24 @@ void main() calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten); + vec3 sunlit_linear = srgb_to_linear(sunlit); + vec3 amblit_linear = amblit; + + bool do_atmospherics = false; + +#ifndef WATER_FOG + // when above water, mask off atmospherics below water + if (dot(pos.xyz, waterPlane.xyz) + waterPlane.w > 0.0) + { + do_atmospherics = true; + } +#else + do_atmospherics = true; +#endif + + vec3 irradiance = vec3(0); + vec3 radiance = vec3(0); + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { vec3 orm = texture2D(specularRect, tc).rgb; @@ -161,23 +181,32 @@ void main() float ao = orm.r * ambocc; vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; - // PBR IBL float gloss = 1.0 - perceptualRoughness; - vec3 irradiance = vec3(0); - vec3 radiance = vec3(0); + sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss); // Take maximium of legacy ambient vs irradiance sample as irradiance // NOTE: ao is applied in pbrIbl (see pbrBaseLight), do not apply here - irradiance = max(amblit,irradiance); + irradiance = max(amblit_linear,irradiance); vec3 diffuseColor; vec3 specularColor; calcDiffuseSpecular(baseColor.rgb, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); - color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten); + color = vec3(1,0,1); + color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten); + + + if (do_atmospherics) + { + color = linear_to_srgb(color); + color = atmosFragLightingLinear(color, additive, atten); + color = srgb_to_linear(color); + } + + } else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { @@ -199,12 +228,12 @@ void main() sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity); // use sky settings ambient or irradiance map sample, whichever is brighter - irradiance = max(amblit, irradiance); + irradiance = max(amblit_linear, irradiance); // apply lambertian IBL only (see pbrIbl) color.rgb = irradiance * ambocc; - vec3 sun_contrib = min(da, scol) * sunlit; + vec3 sun_contrib = min(da, scol) * sunlit_linear; color.rgb += sun_contrib; color.rgb *= baseColor.rgb; @@ -230,9 +259,16 @@ void main() applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, envIntensity); } - color = mix(atmosFragLightingLinear(color, additive, atten), fullbrightAtmosTransportFragLinear(color, additive, atten), baseColor.a); - color = scaleSoftClipFragLinear(color); - } + + if (do_atmospherics) + { + color = linear_to_srgb(color); + color = atmosFragLightingLinear(color, additive, atten); + color = srgb_to_linear(color); + } + } + + #ifdef WATER_FOG vec4 fogged = applyWaterFogViewLinear(pos.xyz, vec4(color, bloom)); diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index a87682affb..991079e77a 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -114,6 +114,7 @@ vec3 BlendNormal(vec3 bump1, vec3 bump2) } vec3 srgb_to_linear(vec3 col); +vec3 linear_to_srgb(vec3 col); vec3 vN, vT, vB; @@ -200,6 +201,8 @@ void main() calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); + vec3 sunlit_linear = srgb_to_linear(sunlit); + #ifdef TRANSPARENT_WATER vec4 fb = texture2D(screenTex, distort2); float depth = texture2D(screenDepth, distort2).r; @@ -216,9 +219,10 @@ void main() fb = applyWaterFogViewLinear(refPos, fb, sunlit); #else - vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(1.0), sunlit); + vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(1.0), sunlit_linear); #endif + fb.rgb *= 0.75; float metallic = 0.0; float perceptualRoughness = 0.05; float gloss = 1.0 - perceptualRoughness; @@ -247,10 +251,7 @@ void main() vec3 punctual = pbrPunctual(vec3(0), specularColor, 0.1, metallic, normalize(wavef+up*max(dist, 32.0)/32.0*(1.0-vdu)), v, normalize(light_dir)); - vec3 color = punctual * sunlit * 2.75 * scol; - - color = atmosFragLightingLinear(color, additive, atten); - color = scaleSoftClipFragLinear(color); + vec3 color = punctual * sunlit_linear * 2.75 * scol; vec3 ibl = pbrIbl(vec3(0), vec3(1), radiance, vec3(0), ao, NdotV, 0.0); @@ -274,6 +275,12 @@ void main() color = mix(color, fb.rgb, f); + color.rgb = linear_to_srgb(color.rgb); + color = atmosFragLightingLinear(color, additive, atten); + color = scaleSoftClipFragLinear(color); + color.rgb = srgb_to_linear(color.rgb); + + float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05); frag_color = vec4(color, spec); //*sunAngle2); -- cgit v1.2.3 From 7139444461aae953a263a60f1a093070cc870225 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 2 Mar 2023 18:36:57 -0600 Subject: SL-19281 Post review cleanup. --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 ++ indra/newview/app_settings/shaders/class3/environment/waterF.glsl | 2 ++ 2 files changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index c6d649086a..a6a2543915 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -681,6 +681,8 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness) { sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); + + // fudge factor to get PBR water at a similar luminance ot legacy water glossenv *= 0.25; } diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 991079e77a..7524567f6b 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -222,7 +222,9 @@ void main() vec4 fb = applyWaterFogViewLinear(viewVec*2048.0, vec4(1.0), sunlit_linear); #endif + // fudge sample on other side of water to be a tad darker fb.rgb *= 0.75; + float metallic = 0.0; float perceptualRoughness = 0.05; float gloss = 1.0 - perceptualRoughness; -- cgit v1.2.3 From b9df40c5a3bfa9d5ea4df9e77d9e7422c2c18eb3 Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Fri, 10 Mar 2023 09:23:24 -0500 Subject: Fix alpha blended blinn-phong glossiness in punctual lights and glossy env application (#117) --- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index add1cb2a37..d0c4b68013 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -316,6 +316,7 @@ void main() //forward rendering, output lit linear color diffcol.rgb = srgb_to_linear(diffcol.rgb); spec.rgb = srgb_to_linear(spec.rgb); + spec.a = glossiness; // pack glossiness into spec alpha for lighting functions vec3 pos = vary_position; -- cgit v1.2.3 From 97b5f07edd077e9b451e874275e9ce49c134f841 Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Fri, 10 Mar 2023 09:28:35 -0500 Subject: This corrects tangents on blinn-phong surfaces to use proper mikkt calculation (#118) --- .../shaders/class3/deferred/materialF.glsl | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index d0c4b68013..6e41df34a4 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -210,9 +210,9 @@ uniform float minimum_alpha; #endif #ifdef HAS_NORMAL_MAP -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; +in vec3 vary_normal; +in vec3 vary_tangent; +flat in float vary_sign; VARYING vec2 vary_texcoord1; #else VARYING vec3 vary_normal; @@ -227,14 +227,17 @@ vec2 encode_normal(vec3 n); vec3 getNormal(inout float glossiness) { #ifdef HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); - glossiness *= norm.a; - - norm.xyz = norm.xyz * 2 - 1; + vec4 vNt = texture2D(bumpMap, vary_texcoord1.xy); + glossiness *= vNt.a; + vNt.xyz = vNt.xyz * 2 - 1; + 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 ); - return normalize(vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2))); + return tnorm; #else return normalize(vary_normal); #endif -- cgit v1.2.3 From 8c7c4c424d07e39191e827f441af406724829b50 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 22 Mar 2023 10:38:24 -0500 Subject: DRTVWR-559 Quality pass -- Fix sky banding, fix off-by-one-mip in reflection probes (thanks Rye), remove noiseMap from light shaders (removes speckles), make irradiance maps RGB16F instead of RGBA16. Use actual luminance for sky instead of max color component during irradiance map pass. --- .../app_settings/shaders/class3/deferred/multiPointLightF.glsl | 5 ----- .../app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 6 ++---- .../app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- .../newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 6 ++---- 5 files changed, 6 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 7d8f9c218d..0fb30559d4 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -37,7 +37,6 @@ uniform sampler2D depthMap; uniform sampler2D diffuseRect; uniform sampler2D specularRect; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl -uniform sampler2D noiseMap; uniform sampler2D lightFunc; uniform vec3 env_mat[3]; @@ -132,9 +131,6 @@ void main() } else { - - float noise = texture2D(noiseMap, tc).b; - diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); @@ -154,7 +150,6 @@ void main() float fa = light_col[i].a; float dist_atten = calcLegacyDistanceAttenuation(dist, fa); - dist_atten *= noise; float lit = nl * dist_atten; diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 5ed8a75e0e..30b7895157 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -41,7 +41,6 @@ uniform sampler2D normalMap; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform samplerCube environmentMap; uniform sampler2D lightMap; -uniform sampler2D noiseMap; uniform sampler2D projectionMap; // rgba uniform sampler2D lightFunc; @@ -187,7 +186,6 @@ void main() diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); - float noise = texture2D(noiseMap, tc).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && @@ -199,7 +197,7 @@ void main() if (nl > 0.0) { - lit = nl * dist_atten * noise; + lit = nl * dist_atten; dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); @@ -209,7 +207,7 @@ void main() amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } - amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); + amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); final_color += diffuse.rgb * amb_rgb; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index a6a2543915..bd06a680f5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -656,7 +656,7 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness) { // TODO - don't hard code lods - float reflection_lods = max_probe_lod-1; + float reflection_lods = max_probe_lod; preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index dfd1d47b3e..0e3ebd1534 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -211,7 +211,7 @@ void main() else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { //should only be true of WL sky, just port over base color value - color = srgb_to_linear(baseColor.rgb); + color = srgb_to_linear(texture2D(emissiveRect, tc).rgb); } else { diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 3d8b95b882..33ea2129cf 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -51,7 +51,6 @@ uniform sampler2D normalMap; uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl uniform samplerCube environmentMap; uniform sampler2D lightMap; -uniform sampler2D noiseMap; uniform sampler2D projectionMap; // rgba uniform sampler2D lightFunc; @@ -193,7 +192,6 @@ void main() diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); - float noise = texture2D(noiseMap, tc).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && @@ -205,7 +203,7 @@ void main() if (nl > 0.0) { - lit = nl * dist_atten * noise; + lit = nl * dist_atten; dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); @@ -214,7 +212,7 @@ void main() amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } - vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); + vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); final_color += diffuse.rgb*amb_rgb; #if DEBUG_LEG_LIGHT_TYPE final_color = vec3(0,0.5,0); -- cgit v1.2.3 From 960715efc1cda86f924acc50f2a322e9403abd14 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 27 Mar 2023 13:07:31 -0500 Subject: SL-19477 Remove angular attenuation from sphere probe weight to fix harsh indirect lighting. Minor incidental decruft. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index bd06a680f5..1f4833ea21 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -95,6 +95,7 @@ bool shouldSampleProbe(int i, vec3 pos) return false; } + // never allow automatic probes to encroach on box probes sample_automatic = false; } else @@ -429,25 +430,19 @@ void boxIntersectDebug(vec3 origin, vec3 pos, int i, inout vec4 col) // dir - normal to be weighted // origin - center of sphere probe // r - radius of probe influence volume -// min_da - minimum angular attenuation coefficient // i - index of probe in refSphere // dw - distance weight -float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, float min_da, int i, out float dw) +float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, int i, out float dw) { float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz - origin; float d2 = max(length(delta), 0.001); - float r2 = r1; //r1 * r1; - - //float atten = 1.0 - max(d2 - r2, 0.0) / max((rr - r2), 0.001); - float atten = 1.0 - max(d2 - r2, 0.0) / max((r - r2), 0.001); + float atten = 1.0 - max(d2 - r1, 0.0) / max((r - r1), 0.001); float w = 1.0 / d2; dw = w * atten * max(r, 1.0)*4; - atten *= max(dot(normalize(-delta), dir), min_da); - w *= atten; return w; @@ -484,7 +479,7 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, float lod, vec3 c, refIndex[i].w < 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres rr); - w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.25, i, dw); + w = sphereWeight(pos, dir, refSphere[i].xyz, r, i, dw); } v -= c; @@ -524,7 +519,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int refIndex[i].w < 1 ? 4096.0*4096.0 : // <== effectively disable parallax correction for automatically placed probes to keep from bombing the world with obvious spheres rr); - w = sphereWeight(pos, dir, refSphere[i].xyz, r, 0.001, i, dw); + w = sphereWeight(pos, dir, refSphere[i].xyz, r, i, dw); } v -= c; @@ -562,7 +557,6 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod) float dw = 0; vec3 refcol; - { refcol = tapRefMap(pos, dir, w, dw, lod, refSphere[i].xyz, i); @@ -735,7 +729,7 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 refnormpersp = reflect(pos.xyz, norm.xyz); ambenv = sampleProbeAmbient(pos, norm); - + if (glossiness > 0.0) { float lod = (1.0-glossiness)*reflection_lods; -- cgit v1.2.3 From 6c554c9c92a0150fdf5a177bf33269eac8341d02 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Mon, 27 Mar 2023 15:06:25 -0700 Subject: Fix up the graphics setting detection SL-18563 --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 3 --- 1 file changed, 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index a6a2543915..9b5cb39883 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -29,9 +29,6 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source); #endif -#define REFMAP_COUNT 256 -#define REF_SAMPLE_COUNT 64 //maximum number of samples to consider - uniform samplerCubeArray reflectionProbes; uniform samplerCubeArray irradianceProbes; uniform sampler2D sceneMap; -- cgit v1.2.3 From e8114dbe14cc71664f6a27bbe727ff8c25fbc643 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 30 Mar 2023 14:53:01 -0500 Subject: SL-19517 Fix for RenderReflectionProbeCount other than 256 causing black reflections. --- .../app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 7a5676e0ab..ec7a2f4768 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -35,6 +35,8 @@ uniform sampler2D sceneMap; uniform int cube_snapshot; uniform float max_probe_lod; +#define MAX_REFMAP_COUNT 256 // must match LL_MAX_REFLECTION_PROBE_COUNT + layout (std140) uniform ReflectionProbes { // list of OBBs for user override probes @@ -42,18 +44,18 @@ layout (std140) uniform ReflectionProbes // for each box refBox[i]... /// box[0..2] - plane 0 .. 2 in [A,B,C,D] notation // box[3][0..2] - plane thickness - mat4 refBox[REFMAP_COUNT]; + mat4 refBox[MAX_REFMAP_COUNT]; // list of bounding spheres for reflection probes sorted by distance to camera (closest first) - vec4 refSphere[REFMAP_COUNT]; + vec4 refSphere[MAX_REFMAP_COUNT]; // extra parameters (currently only .x used for probe ambiance) - vec4 refParams[REFMAP_COUNT]; + vec4 refParams[MAX_REFMAP_COUNT]; // index of cube map in reflectionProbes for a corresponding reflection probe // e.g. cube map channel of refSphere[2] is stored in refIndex[2] // refIndex.x - cubemap channel in reflectionProbes // refIndex.y - index in refNeighbor of neighbor list (index is ivec4 index, not int index) // refIndex.z - number of neighbors // refIndex.w - priority, if negative, this probe has a box influence - ivec4 refIndex[REFMAP_COUNT]; + ivec4 refIndex[MAX_REFMAP_COUNT]; // neighbor list data (refSphere indices, not cubemap array layer) ivec4 refNeighbor[1024]; -- cgit v1.2.3 From 70bdf55439a57116cbd2c9bb32e78a8ada251d78 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 30 Mar 2023 16:24:04 -0500 Subject: SL-19517 Followup -- fix broken fallback probe. Adjust water brightness. --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index ec7a2f4768..94c40b1fa0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -676,7 +676,7 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); // fudge factor to get PBR water at a similar luminance ot legacy water - glossenv *= 0.25; + glossenv *= 0.5; } void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) -- cgit v1.2.3 From 46702c4e80e96cd8dbe7f37d5c14fbb1830e798d Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 30 Mar 2023 18:19:32 -0500 Subject: DRTVWR-559 Auto exposure tuning. --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 94c40b1fa0..677d83a1fe 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -676,7 +676,7 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); // fudge factor to get PBR water at a similar luminance ot legacy water - glossenv *= 0.5; + glossenv *= 0.4; } void debugTapRefMap(vec3 pos, vec3 dir, float depth, int i, inout vec4 col) diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 0e3ebd1534..b23741e574 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -212,6 +212,7 @@ void main() { //should only be true of WL sky, just port over base color value color = srgb_to_linear(texture2D(emissiveRect, tc).rgb); + color *= sun_up_factor + 1.0; } else { -- cgit v1.2.3 From c0958922c3b3015fd7f17781a79032050b2ed387 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 30 Mar 2023 18:41:34 -0500 Subject: DRTVWR-559 Auto exposure tuning (fix horizon). --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index b23741e574..0e3ebd1534 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -212,7 +212,6 @@ void main() { //should only be true of WL sky, just port over base color value color = srgb_to_linear(texture2D(emissiveRect, tc).rgb); - color *= sun_up_factor + 1.0; } else { -- cgit v1.2.3 From 0fe09bd968b987605123e99efb2fa040a988a942 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 31 Mar 2023 11:57:21 -0500 Subject: SL-19485 Fix for sun shadows having no effect on water. Make sphere probes fade in. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 6 ++++-- .../app_settings/shaders/class3/environment/waterF.glsl | 15 ++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 677d83a1fe..e73e396b8e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -433,13 +433,15 @@ void boxIntersectDebug(vec3 origin, vec3 pos, int i, inout vec4 col) // dw - distance weight float sphereWeight(vec3 pos, vec3 dir, vec3 origin, float r, int i, out float dw) { - float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) + float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz - origin; float d2 = max(length(delta), 0.001); float atten = 1.0 - max(d2 - r1, 0.0) / max((r - r1), 0.001); float w = 1.0 / d2; - + + w *= refParams[i].z; + dw = w * atten * max(r, 1.0)*4; w *= atten; diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 7524567f6b..9da86759c9 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -25,10 +25,10 @@ // class3/environment/waterF.glsl -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor + +#ifdef HAS_SUN_SHADOW +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif vec3 scaleSoftClipFragLinear(vec3 l); @@ -199,6 +199,12 @@ void main() vec3 additive; vec3 atten; + float shadow = 1.0f; + +#ifdef HAS_SUN_SHADOW + shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, distort); +#endif + calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); vec3 sunlit_linear = srgb_to_linear(sunlit); @@ -241,7 +247,6 @@ void main() vec3 v = -normalize(pos.xyz); - float scol = 1.0; vec3 colorEmissive = vec3(0); float ao = 1.0; vec3 light_dir = transform_normal(lightDir); @@ -253,7 +258,7 @@ void main() vec3 punctual = pbrPunctual(vec3(0), specularColor, 0.1, metallic, normalize(wavef+up*max(dist, 32.0)/32.0*(1.0-vdu)), v, normalize(light_dir)); - vec3 color = punctual * sunlit_linear * 2.75 * scol; + vec3 color = punctual * sunlit_linear * 2.75 * shadow; vec3 ibl = pbrIbl(vec3(0), vec3(1), radiance, vec3(0), ao, NdotV, 0.0); -- cgit v1.2.3 From 698966f8e7ddcc0b123a83d7c4e381778f8cd8ab Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 4 Apr 2023 12:29:12 -0500 Subject: =?UTF-8?q?SL-19538=20Remove=20hacky=20ambiance=20scale=20and=20ta?= =?UTF-8?q?ke=20the=20mittens=20off=20probe=20a=E2=80=A6=20(#151)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SL-19538 Remove hacky ambiance scale and take the mittens off probe ambiance values. Fix for sky brightening being done in sRGB space. --- .../app_settings/shaders/class3/deferred/fullbrightShinyF.glsl | 5 +---- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 4 ---- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 4 +--- indra/newview/app_settings/shaders/class3/environment/waterF.glsl | 4 ---- 4 files changed, 2 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index b90de7609b..f6bed16c84 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -43,9 +43,7 @@ VARYING vec3 vary_position; uniform samplerCube environmentMap; -vec3 fullbrightShinyAtmosTransport(vec3 light); vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClip(vec3 light); void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); @@ -88,9 +86,8 @@ void main() sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity); applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); - color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); - color.rgb = fullbrightScaleSoftClip(color.rgb); color.rgb = srgb_to_linear(color.rgb); + color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); #endif color.a = 1.0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 6e41df34a4..02ab4494f6 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -44,7 +44,6 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFragLinear(vec3 l); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); -vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -386,10 +385,7 @@ void main() glare += cur_glare; } - color.rgb = linear_to_srgb(color.rgb); color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); - color.rgb = scaleSoftClipFragLinear(color.rgb); - color.rgb = srgb_to_linear(color.rgb); vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0, 0, 0); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 0e3ebd1534..7953360054 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -71,7 +71,6 @@ vec4 getPositionWithDepth(vec2 pos_screen, float depth); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFragLinear(vec3 l); -vec3 fullbrightAtmosTransportFragLinear(vec3 light, vec3 additive, vec3 atten); // reflection probe interface void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, @@ -212,6 +211,7 @@ void main() { //should only be true of WL sky, just port over base color value color = srgb_to_linear(texture2D(emissiveRect, tc).rgb); + color *= sun_up_factor + 1.0; } else { @@ -262,9 +262,7 @@ void main() if (do_atmospherics) { - color = linear_to_srgb(color); color = atmosFragLightingLinear(color, additive, atten); - color = srgb_to_linear(color); } } diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 9da86759c9..ec0439fa97 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -282,11 +282,7 @@ void main() color = mix(color, fb.rgb, f); - color.rgb = linear_to_srgb(color.rgb); color = atmosFragLightingLinear(color, additive, atten); - color = scaleSoftClipFragLinear(color); - color.rgb = srgb_to_linear(color.rgb); - float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05); -- cgit v1.2.3 From 1f79379bf215c5368337c64b4f72c7c9ef3e09c2 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 5 Apr 2023 11:55:51 -0500 Subject: SL-19538 Followup -- tune exposure parameters and clamp local light ambiance. Make render targets 16F and scrube NaNs (thanks Rye). Update midday. (#154) --- .../app_settings/shaders/class3/deferred/multiPointLightF.glsl | 2 +- .../app_settings/shaders/class3/deferred/pointLightF.glsl | 2 +- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 9 +++------ 3 files changed, 5 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 0fb30559d4..23ba95949a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -176,7 +176,7 @@ void main() } } - frag_color.rgb = final_color; + frag_color.rgb = max(final_color, vec3(0)); frag_color.a = 0.0; #endif // LOCAL_LIGHT_KILL diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 8229ecbbb7..30b96ce8dc 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -151,6 +151,6 @@ void main() } } - frag_color.rgb = final_color; + frag_color.rgb = max(final_color, vec3(0)); frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 7953360054..99beb0d890 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -90,6 +90,8 @@ uniform vec4 waterPlane; vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); #endif +uniform float sky_hdr_scale; + void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); vec3 pbrBaseLight(vec3 diffuseColor, @@ -196,22 +198,17 @@ void main() vec3 v = -normalize(pos.xyz); color = vec3(1,0,1); color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten); - if (do_atmospherics) { - color = linear_to_srgb(color); color = atmosFragLightingLinear(color, additive, atten); - color = srgb_to_linear(color); } - - } else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { //should only be true of WL sky, just port over base color value color = srgb_to_linear(texture2D(emissiveRect, tc).rgb); - color *= sun_up_factor + 1.0; + color *= sun_up_factor * sky_hdr_scale + 1.0; } else { -- cgit v1.2.3 From bb79718c8f0050569c80a1bfe4dd428321706d1a Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 6 Apr 2023 13:21:25 -0500 Subject: SL-19538 Followup -- scrub all possible sources of NaNs, make dynamic exposure controls not persist, limit exposure range, and do a debug gl pass. --- .../app_settings/shaders/class3/deferred/fullbrightShinyF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 5 +++-- .../app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl | 5 +++-- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 2 +- .../newview/app_settings/shaders/class3/environment/underWaterF.glsl | 2 +- indra/newview/app_settings/shaders/class3/environment/waterF.glsl | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index f6bed16c84..6b7dc7ac1d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -92,6 +92,6 @@ void main() color.a = 1.0; - frag_color = color; + frag_color = max(color, vec4(0)); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 02ab4494f6..1aef971d3a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -183,7 +183,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe #else #ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; +out vec4 frag_data[4]; #else #define frag_data gl_FragData #endif @@ -412,13 +412,14 @@ void main() color = temp.rgb; #endif - frag_color = vec4(color, al); + frag_color = max(vec4(color, al), vec4(0)); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer // deferred path // See: C++: addDeferredAttachment(), shader: softenLightF.glsl frag_data[0] = vec4(diffcol.rgb, emissive); // gbuffer is sRGB for legacy materials frag_data[1] = vec4(spec.rgb, glossiness); // XYZ = Specular color. W = Specular exponent. frag_data[2] = vec4(encode_normal(norm), env, GBUFFER_FLAG_HAS_ATMOS);; // XY = Normal. Z = Env. intensity. W = 1 skip atmos (mask off fog) + frag_data[3] = vec4(0); #endif } diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl index 742f528cb1..f1865a77e2 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -73,7 +73,7 @@ void main() vec4 diffuse = texture2D(diffuseRect, tc); vec3 specCol = spec.rgb; - frag_color = texture(diffuseMap, tc); + vec4 fcol = texture(diffuseMap, tc); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { @@ -94,5 +94,6 @@ void main() collectedColor.rgb *= specCol.rgb; - frag_color += collectedColor * w; + fcol += collectedColor * w; + frag_color = max(fcol, vec4(0)); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 99beb0d890..e1206cc844 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -270,6 +270,6 @@ void main() color = fogged.rgb; #endif - frag_color.rgb = color.rgb; //output linear since local lights will be added to this shader's results + frag_color.rgb = max(color.rgb, vec3(0)); //output linear since local lights will be added to this shader's results frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl index 83454631d4..21c30012ab 100644 --- a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl @@ -77,5 +77,5 @@ void main() vec4 fb = vec4(waterFogColorLinear, 0.0); #endif - frag_color = applyWaterFogViewLinearNoClip(vary_position, fb, vec3(1)); + frag_color = max(applyWaterFogViewLinearNoClip(vary_position, fb, vec3(1)), vec4(0)); } diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index ec0439fa97..3d4f4fc17b 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -286,6 +286,6 @@ void main() float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05); - frag_color = vec4(color, spec); //*sunAngle2); + frag_color = max(vec4(color, spec), vec4(0)); } -- cgit v1.2.3 From de73cf7599e934441fe760f53163b0504c03adc7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 7 Apr 2023 11:06:09 -0500 Subject: SL-19538 Remove clouds from irradiance maps and don't conflate max probe samples with max probe neighbors, and don't move manual probes after they are complete (removes flickering around Sponza). --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index e73e396b8e..e1b18935e8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -134,7 +134,7 @@ void preProbeSample(vec3 pos) int neighborIdx = refIndex[i].y; if (neighborIdx != -1) { - int neighborCount = min(refIndex[i].z, REF_SAMPLE_COUNT-1); + int neighborCount = refIndex[i].z; int count = 0; while (count < neighborCount) -- cgit v1.2.3 From 2b2154f0217758b27b544d066024d922ba234d51 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 11 Apr 2023 15:09:58 -0500 Subject: SL-19564 Rebalance exposure and sky. Hack legacy diffuse map saturation and brightness to allow ACES Hill all the time. --- .../shaders/class3/deferred/multiPointLightF.glsl | 2 ++ .../shaders/class3/deferred/multiSpotLightF.glsl | 3 ++- .../app_settings/shaders/class3/deferred/pointLightF.glsl | 3 ++- .../app_settings/shaders/class3/deferred/softenLightF.glsl | 13 +++++++++++-- .../app_settings/shaders/class3/deferred/spotLightF.glsl | 2 ++ 5 files changed, 19 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 23ba95949a..5a2924afe5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -58,6 +58,7 @@ vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensi vec2 getScreenXY(vec4 clip); vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); +vec3 legacy_adjust(vec3 c); // Util vec3 hue_to_rgb(float hue); @@ -131,6 +132,7 @@ void main() } else { + diffuse.rgb = legacy_adjust(diffuse.rgb); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 30b7895157..33e5b2346c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -83,6 +83,7 @@ vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip); vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 cs); +vec3 legacy_adjust(vec3 c); vec4 texture2DLodSpecular(vec2 tc, float lod); vec4 getPosition(vec2 pos_screen); @@ -182,7 +183,7 @@ void main() } else { - + diffuse = legacy_adjust(diffuse); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 30b96ce8dc..471e5e7fd3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -63,6 +63,7 @@ vec4 getPosition(vec2 pos_screen); vec2 getScreenXY(vec4 clip); vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); +vec3 legacy_adjust(vec3 c); float getDepth(vec2 tc); vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, @@ -121,7 +122,7 @@ void main() { discard; } - + diffuse = legacy_adjust(diffuse); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index e1206cc844..8f5bd6141a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -83,9 +83,12 @@ float getDepth(vec2 pos_screen); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); +vec3 legacy_adjust(vec3 c); uniform vec4 waterPlane; +uniform int cube_snapshot; + #ifdef WATER_FOG vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); #endif @@ -207,12 +210,18 @@ void main() else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { //should only be true of WL sky, just port over base color value - color = srgb_to_linear(texture2D(emissiveRect, tc).rgb); - color *= sun_up_factor * sky_hdr_scale + 1.0; + color = texture2D(emissiveRect, tc).rgb; + color = srgb_to_linear(color); + if (sun_up_factor > 0) + { + color *= sky_hdr_scale + 1.0; + } } else { // legacy shaders are still writng sRGB to gbuffer + baseColor.rgb = legacy_adjust(baseColor.rgb); + baseColor.rgb = srgb_to_linear(baseColor.rgb); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 33ea2129cf..3d06bb27a5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -91,6 +91,7 @@ vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip_point); vec2 getScreenCoord(vec4 clip_point); vec3 srgb_to_linear(vec3 c); +vec3 legacy_adjust(vec3 c); vec4 texture2DLodSpecular(vec2 tc, float lod); vec4 getPosition(vec2 pos_screen); @@ -189,6 +190,7 @@ void main() } else { + diffuse = legacy_adjust(diffuse); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); -- cgit v1.2.3 From 6efe63f8c5497db4d53738a682f3e97ccd535431 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 11 Apr 2023 16:13:18 -0500 Subject: SL-19564 Add missing legacy_adjust --- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 1aef971d3a..d9e15738ad 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -47,6 +47,7 @@ void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, ou vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); +vec3 legacy_adjust(vec3 c); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -316,6 +317,7 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output lit linear color + diffcol.rgb = legacy_adjust(diffcol.rgb); diffcol.rgb = srgb_to_linear(diffcol.rgb); spec.rgb = srgb_to_linear(spec.rgb); spec.a = glossiness; // pack glossiness into spec alpha for lighting functions -- cgit v1.2.3 From ab28599ce54b68cdfb4dec6abd38649b4a83e4e7 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 11 Apr 2023 17:17:29 -0500 Subject: DRTVWR-559 Make sunlight specular consistent with pointlight specular. --- .../shaders/class3/deferred/materialF.glsl | 28 ++++++++++++++++++++++ .../shaders/class3/deferred/softenLightF.glsl | 28 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index d9e15738ad..62bb09e94b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -44,6 +44,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFragLinear(vec3 l); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +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); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -359,6 +360,7 @@ void main() float glare = 0.0; +#if 0 //wrong implementation if (glossiness > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); @@ -375,6 +377,32 @@ void main() applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } +#else //right implementation ported from pointLightF.glsl + if (glossiness > 0.0) + { + vec3 lv = light_dir.xyz; + vec3 h, l, v = -normalize(pos.xyz); + float nh, nl, nv, vh, lightDist; + vec3 n = norm.xyz; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + + if (nl > 0.0 && nh > 0.0) + { + float lit = min(nl*6.0, 1.0); + + float sa = nh; + float fres = pow(1 - vh, 5) * 0.4+0.5; + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); + + float scol = shadow*fres*texture2D(lightFunc, vec2(nh, glossiness)).r*gt/(nh*nl); + color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb; + } + + // add radiance map + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + } +#endif color = mix(color.rgb, diffcol.rgb, emissive); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8f5bd6141a..ab83708c7b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -95,6 +95,7 @@ vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); uniform float sky_hdr_scale; +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); void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); vec3 pbrBaseLight(vec3 diffuseColor, @@ -245,6 +246,7 @@ void main() vec3 refnormpersp = reflect(pos.xyz, norm.xyz); +#if 0 // wrong implementation if (spec.a > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); @@ -257,6 +259,32 @@ void main() // add radiance map applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } +#else //right implementation (ported from pointLightF.glsl) + if (spec.a > 0.0) + { + vec3 lv = light_dir.xyz; + vec3 h, l, v = -normalize(pos.xyz); + float nh, nl, nv, vh, lightDist; + vec3 n = norm.xyz; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + + if (nl > 0.0 && nh > 0.0) + { + float lit = min(nl*6.0, 1.0); + + float sa = nh; + float fres = pow(1 - vh, 5) * 0.4+0.5; + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); + + scol *= fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); + color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb; + } + + // add radiance map + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + } +#endif color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a); -- cgit v1.2.3 From 17615dd6b67f1ca019a44664318550240d289372 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 12 Apr 2023 08:58:20 -0500 Subject: DRTVWR-559 Fix for burn-in on legacy gloss materials. --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index e1b18935e8..55a43f76d0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -752,6 +752,8 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout legacyenv = mix(legacyenv, ssr.rgb, w); } #endif + + glossenv = clamp(glossenv, vec3(0), vec3(10)); } void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) -- cgit v1.2.3 From 63c571191489539faafd4c97b3c870fb5e630e97 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 12 Apr 2023 13:44:41 -0500 Subject: SL-19569 Don't reset probes when crossing parcel borders (whoops) and tone down glare on legacy materials. --- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 62bb09e94b..e5341386bd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -411,7 +411,8 @@ void main() applyLegacyEnv(color, legacyenv, spec, pos.xyz, norm.xyz, env); float cur_glare = max(max(legacyenv.r, legacyenv.g), legacyenv.b); - cur_glare *= env*4.0; + cur_glare = clamp(cur_glare, 0, 1); + cur_glare *= env; glare += cur_glare; } -- cgit v1.2.3 From 03bd681564f0b0a630f6330ab9c61daa4856e5fe Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 14 Apr 2023 19:24:21 -0500 Subject: DRTVWR-559 Balance night scenes against release, nudge glow down a smidge, remove exposure correction from legacy fullbright balance PBR materials against legacy. --- .../newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 5a2924afe5..2da177ea7e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -124,7 +124,7 @@ void main() float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); - vec3 intensity = dist_atten * lightColor * 3.0; + vec3 intensity = dist_atten * lightColor * 3.9; final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 33e5b2346c..33715d4d87 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -173,7 +173,7 @@ void main() dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - vec3 intensity = dist_atten * dlit * 3.0 * shadow; // Legacy attenuation + vec3 intensity = dist_atten * dlit * 3.9 * shadow; // Legacy attenuation, magic number to balance with legacy materials final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 471e5e7fd3..7724a6cac9 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -113,7 +113,7 @@ void main() vec3 specularColor = mix(f0, baseColor.rgb, metallic); - vec3 intensity = dist_atten * color * 3.0; // Legacy attenuation + vec3 intensity = dist_atten * color * 3.9; // Legacy attenuation, magic number to balance with legacy materials final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); } else diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 3d06bb27a5..f2ab585716 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -180,7 +180,7 @@ void main() dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - vec3 intensity = dist_atten * dlit * 3.0 * shadow; // Legacy attenuation + vec3 intensity = dist_atten * dlit * 3.9 * shadow; // Legacy attenuation final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); } -- cgit v1.2.3 From 37eee397b70e2a13a1309025207d1c301f7070c5 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 18 Apr 2023 19:11:38 -0500 Subject: DRTVWR-559 Add control for automatic reflection probes to advanced preferences and featuretable. Remove Reflections checkbox. Don't persist reflection probe volume display between sessions. Incidental decruft. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 4 ++++ .../shaders/class3/deferred/softenLightF.glsl | 15 --------------- 2 files changed, 4 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 55a43f76d0..36b5262104 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -122,6 +122,7 @@ bool shouldSampleProbe(int i, vec3 pos) // populate "probeIndex" with N probe indices that influence pos where N is REF_SAMPLE_COUNT void preProbeSample(vec3 pos) { +#if REFMAP_LEVEL > 0 // TODO: make some sort of structure that reduces the number of distance checks for (int i = 1; i < refmapCount; ++i) { @@ -213,6 +214,9 @@ void preProbeSample(vec3 pos) { // probe at index 0 is a special probe for smoothing out automatic probes probeIndex[probeInfluences++] = 0; } +#else + probeIndex[probeInfluences++] = 0; +#endif } // from https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index ab83708c7b..a8d61afeca 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -246,20 +246,6 @@ void main() vec3 refnormpersp = reflect(pos.xyz, norm.xyz); -#if 0 // wrong implementation - if (spec.a > 0.0) // specular reflection - { - float sa = dot(normalize(refnormpersp), light_dir.xyz); - vec3 dumbshiny = sunlit * scol * (texture2D(lightFunc, vec2(sa, spec.a)).r); - - // add the two types of shiny together - vec3 spec_contrib = dumbshiny * spec.rgb; - color.rgb += spec_contrib; - - // add radiance map - applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); - } -#else //right implementation (ported from pointLightF.glsl) if (spec.a > 0.0) { vec3 lv = light_dir.xyz; @@ -284,7 +270,6 @@ void main() // add radiance map applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } -#endif color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a); -- cgit v1.2.3 From 5c903d9c953e422a95ccd88b345d803b60ce65ff Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 21 Apr 2023 11:19:14 -0500 Subject: DRTVWR-559 Don't use automatic probes on water (fixes lots of visual artifacts) --- .../shaders/class3/deferred/reflectionProbeF.glsl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 36b5262104..9b42f0df5c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -651,12 +651,11 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) return col[1]+col[0]; } -void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, +void doProbeSample(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness) { // TODO - don't hard code lods float reflection_lods = max_probe_lod; - preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); @@ -676,10 +675,24 @@ void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, #endif } +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, + vec2 tc, vec3 pos, vec3 norm, float glossiness) +{ + preProbeSample(pos); + doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness); +} + void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, vec2 tc, vec3 pos, vec3 norm, float glossiness) { - sampleReflectionProbes(ambenv, glossenv, tc, pos, norm, glossiness); + // don't sample automatic probes for water + sample_automatic = false; + preProbeSample(pos); + sample_automatic = true; + // always include void probe on water + probeIndex[probeInfluences++] = 0; + + doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness); // fudge factor to get PBR water at a similar luminance ot legacy water glossenv *= 0.4; -- cgit v1.2.3 From 5d862c994c18b155bc761fa16dd4070281a1345e Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 25 Apr 2023 14:48:16 -0500 Subject: DRTVWR-559 Optimization pass on probe allocation and search. Incidental decruft. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 41 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 9b42f0df5c..bc631afd1d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -47,7 +47,11 @@ layout (std140) uniform ReflectionProbes mat4 refBox[MAX_REFMAP_COUNT]; // list of bounding spheres for reflection probes sorted by distance to camera (closest first) vec4 refSphere[MAX_REFMAP_COUNT]; - // extra parameters (currently only .x used for probe ambiance) + // extra parameters + // x - irradiance scale + // y - radiance scale + // z - fade in + // w - znear vec4 refParams[MAX_REFMAP_COUNT]; // index of cube map in reflectionProbes for a corresponding reflection probe // e.g. cube map channel of refSphere[2] is stored in refIndex[2] @@ -60,6 +64,8 @@ layout (std140) uniform ReflectionProbes // neighbor list data (refSphere indices, not cubemap array layer) ivec4 refNeighbor[1024]; + ivec4 refBucket[256]; + // number of reflection probes present in refSphere int refmapCount; }; @@ -118,13 +124,26 @@ bool shouldSampleProbe(int i, vec3 pos) return true; } +int getStartIndex(vec3 pos) +{ +#if 1 + int idx = clamp(int(floor(-pos.z)), 0, 255); + return clamp(refBucket[idx].x, 1, refmapCount+1); +#else + return 1; +#endif +} + // call before sampleRef // populate "probeIndex" with N probe indices that influence pos where N is REF_SAMPLE_COUNT void preProbeSample(vec3 pos) { #if REFMAP_LEVEL > 0 + + int start = getStartIndex(pos); + // TODO: make some sort of structure that reduces the number of distance checks - for (int i = 1; i < refmapCount; ++i) + for (int i = start; i < refmapCount; ++i) { // found an influencing probe if (shouldSampleProbe(i, pos)) @@ -142,6 +161,7 @@ void preProbeSample(vec3 pos) { // check up to REF_SAMPLE_COUNT-1 neighbors (neighborIdx is ivec4 index) + // sample refNeighbor[neighborIdx].x int idx = refNeighbor[neighborIdx].x; if (shouldSampleProbe(idx, pos)) { @@ -157,6 +177,7 @@ void preProbeSample(vec3 pos) break; } + // sample refNeighbor[neighborIdx].y idx = refNeighbor[neighborIdx].y; if (shouldSampleProbe(idx, pos)) { @@ -172,6 +193,7 @@ void preProbeSample(vec3 pos) break; } + // sample refNeighbor[neighborIdx].z idx = refNeighbor[neighborIdx].z; if (shouldSampleProbe(idx, pos)) { @@ -187,6 +209,7 @@ void preProbeSample(vec3 pos) break; } + // sample refNeighbor[neighborIdx].w idx = refNeighbor[neighborIdx].w; if (shouldSampleProbe(idx, pos)) { @@ -197,11 +220,7 @@ void preProbeSample(vec3 pos) } } count++; - if (count == neighborCount) - { - break; - } - + ++neighborIdx; } @@ -735,6 +754,14 @@ vec4 sampleReflectionProbesDebug(vec3 pos) debugTapRefMap(pos, dir, d, i, col); } +#if 0 //debug getStartIndex + col.g = float(getStartIndex(pos)); + + col.g /= 255.0; + col.rb = vec2(0); + col.a = 1.0; +#endif + return col; } -- cgit v1.2.3 From 339e02ef3311ad5c1197dfca2955a0c202b7c408 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Thu, 11 May 2023 21:19:58 -0700 Subject: Finally get glossy SSR up. DRTVWR-583 --- .../shaders/class3/deferred/reflectionProbeF.glsl | 12 +- .../class3/deferred/screenSpaceReflPostF.glsl | 4 +- .../class3/deferred/screenSpaceReflUtil.glsl | 217 +++++++++++++++++---- 3 files changed, 184 insertions(+), 49 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 9b42f0df5c..35563713f5 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -26,7 +26,7 @@ #define FLT_MAX 3.402823466e+38 #if defined(SSR) -float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source); +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness); #endif uniform samplerCubeArray reflectionProbes; @@ -668,9 +668,9 @@ void doProbeSample(inout vec3 ambenv, inout vec3 glossenv, if (cube_snapshot != 1 && glossiness >= 0.9) { vec4 ssr = vec4(0); - float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap); + float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap, glossiness); - glossenv = mix(glossenv, ssr.rgb, w); + glossenv = mix(glossenv, ssr.rgb, ssr.a); } #endif } @@ -763,10 +763,10 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout if (cube_snapshot != 1) { vec4 ssr = vec4(0); - float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap); + float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap, glossiness); - glossenv = mix(glossenv, ssr.rgb, w); - legacyenv = mix(legacyenv, ssr.rgb, w); + glossenv = mix(glossenv, ssr.rgb, ssr.a); + legacyenv = mix(legacyenv, ssr.rgb, ssr.a); } #endif diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl index f1865a77e2..8043a78a82 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -57,7 +57,7 @@ vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensi float random (vec2 uv); -float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source); +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness); void main() { @@ -90,7 +90,7 @@ void main() vec4 collectedColor = vec4(0); - float w = tapScreenSpaceReflection(4, tc, pos, n, collectedColor, diffuseMap); + float w = tapScreenSpaceReflection(4, tc, pos, n, collectedColor, diffuseMap, 0); collectedColor.rgb *= specCol.rgb; diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index c355b671c0..0f1b33f711 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -55,10 +55,14 @@ bool isBinarySearchEnabled = true; bool isAdaptiveStepEnabled = true; bool isExponentialStepEnabled = true; bool debugDraw = false; -int iterationCount = 40; -float rayStep = 0.1; -float distanceBias = 0.02; -float depthRejectBias = 0.001; + +uniform float iterationCount; +uniform float rayStep; +uniform float distanceBias; +uniform float depthRejectBias; +uniform float glossySampleCount; +uniform float noiseSine; + float epsilon = 0.1; float getLinearDepth(vec2 tc) @@ -168,7 +172,138 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float return hit; } -float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source) +uniform vec3 POISSON3D_SAMPLES[128] = vec3[128]( + vec3(0.5433144, 0.1122154, 0.2501391), + vec3(0.6575254, 0.721409, 0.16286), + vec3(0.02888453, 0.05170321, 0.7573566), + vec3(0.06635678, 0.8286457, 0.07157445), + vec3(0.8957489, 0.4005505, 0.7916042), + vec3(0.3423355, 0.5053263, 0.9193521), + vec3(0.9694794, 0.9461077, 0.5406441), + vec3(0.9975473, 0.02789414, 0.7320132), + vec3(0.07781899, 0.3862341, 0.918594), + vec3(0.4439073, 0.9686955, 0.4055861), + vec3(0.9657035, 0.6624081, 0.7082613), + vec3(0.7712346, 0.07273269, 0.3292839), + vec3(0.2489169, 0.2550394, 0.1950516), + vec3(0.7249326, 0.9328285, 0.3352458), + vec3(0.6028461, 0.4424961, 0.5393377), + vec3(0.2879795, 0.7427881, 0.6619173), + vec3(0.3193627, 0.0486145, 0.08109283), + vec3(0.1233155, 0.602641, 0.4378719), + vec3(0.9800708, 0.211729, 0.6771586), + vec3(0.4894537, 0.3319927, 0.8087631), + vec3(0.4802743, 0.6358885, 0.814935), + vec3(0.2692913, 0.9911493, 0.9934899), + vec3(0.5648789, 0.8553897, 0.7784553), + vec3(0.8497344, 0.7870212, 0.02065313), + vec3(0.7503014, 0.2826185, 0.05412734), + vec3(0.8045461, 0.6167251, 0.9532926), + vec3(0.04225039, 0.2141281, 0.8678675), + vec3(0.07116079, 0.9971236, 0.3396397), + vec3(0.464099, 0.480959, 0.2775862), + vec3(0.6346927, 0.31871, 0.6588384), + vec3(0.449012, 0.8189669, 0.2736875), + vec3(0.452929, 0.2119148, 0.672004), + vec3(0.01506042, 0.7102436, 0.9800494), + vec3(0.1970513, 0.4713539, 0.4644522), + vec3(0.13715, 0.7253224, 0.5056525), + vec3(0.9006432, 0.5335414, 0.02206874), + vec3(0.9960898, 0.7961011, 0.01468861), + vec3(0.3386469, 0.6337739, 0.9310676), + vec3(0.1745718, 0.9114985, 0.1728188), + vec3(0.6342545, 0.5721557, 0.4553517), + vec3(0.1347412, 0.1137158, 0.7793725), + vec3(0.3574478, 0.3448052, 0.08741581), + vec3(0.7283059, 0.4753885, 0.2240275), + vec3(0.8293507, 0.9971212, 0.2747005), + vec3(0.6501846, 0.000688076, 0.7795712), + vec3(0.01149416, 0.4930083, 0.792608), + vec3(0.666189, 0.1875442, 0.7256873), + vec3(0.8538797, 0.2107637, 0.1547532), + vec3(0.5826825, 0.9750752, 0.9105834), + vec3(0.8914346, 0.08266425, 0.5484225), + vec3(0.4374518, 0.02987111, 0.7810078), + vec3(0.2287418, 0.1443802, 0.1176908), + vec3(0.2671157, 0.8929081, 0.8989366), + vec3(0.5425819, 0.5524959, 0.6963879), + vec3(0.3515188, 0.8304397, 0.0502702), + vec3(0.3354864, 0.2130747, 0.141169), + vec3(0.9729427, 0.3509927, 0.6098799), + vec3(0.7585629, 0.7115368, 0.9099342), + vec3(0.0140543, 0.6072157, 0.9436461), + vec3(0.9190664, 0.8497264, 0.1643751), + vec3(0.1538157, 0.3219983, 0.2984214), + vec3(0.8854713, 0.2968667, 0.8511457), + vec3(0.1910622, 0.03047311, 0.3571215), + vec3(0.2456353, 0.5568692, 0.3530164), + vec3(0.6927255, 0.8073994, 0.5808484), + vec3(0.8089353, 0.8969175, 0.3427134), + vec3(0.194477, 0.7985603, 0.8712182), + vec3(0.7256182, 0.5653068, 0.3985921), + vec3(0.9889427, 0.4584851, 0.8363391), + vec3(0.5718582, 0.2127113, 0.2950557), + vec3(0.5480209, 0.0193435, 0.2992659), + vec3(0.6598953, 0.09478426, 0.92187), + vec3(0.1385615, 0.2193868, 0.205245), + vec3(0.7623423, 0.1790726, 0.1508465), + vec3(0.7569032, 0.3773386, 0.4393887), + vec3(0.5842971, 0.6538072, 0.5224424), + vec3(0.9954313, 0.5763943, 0.9169143), + vec3(0.001311183, 0.340363, 0.1488652), + vec3(0.8167927, 0.4947158, 0.4454727), + vec3(0.3978434, 0.7106082, 0.002727509), + vec3(0.5459411, 0.7473233, 0.7062873), + vec3(0.4151598, 0.5614617, 0.4748358), + vec3(0.4440694, 0.1195122, 0.9624678), + vec3(0.1081301, 0.4813806, 0.07047641), + vec3(0.2402785, 0.3633997, 0.3898734), + vec3(0.2317942, 0.6488295, 0.4221864), + vec3(0.01145542, 0.9304277, 0.4105759), + vec3(0.3563728, 0.9228861, 0.3282344), + vec3(0.855314, 0.6949819, 0.3175117), + vec3(0.730832, 0.01478493, 0.5728671), + vec3(0.9304829, 0.02653277, 0.712552), + vec3(0.4132186, 0.4127623, 0.6084146), + vec3(0.7517329, 0.9978395, 0.1330464), + vec3(0.5210338, 0.4318751, 0.9721575), + vec3(0.02953994, 0.1375937, 0.9458942), + vec3(0.1835506, 0.9896691, 0.7919457), + vec3(0.3857062, 0.2682322, 0.1264563), + vec3(0.6319699, 0.8735335, 0.04390657), + vec3(0.5630485, 0.3339024, 0.993995), + vec3(0.90701, 0.1512893, 0.8970422), + vec3(0.3027443, 0.1144253, 0.1488708), + vec3(0.9149003, 0.7382028, 0.7914025), + vec3(0.07979286, 0.6892691, 0.2866171), + vec3(0.7743186, 0.8046008, 0.4399814), + vec3(0.3128662, 0.4362317, 0.6030678), + vec3(0.1133721, 0.01605821, 0.391872), + vec3(0.5185481, 0.9210006, 0.7889017), + vec3(0.8217013, 0.325305, 0.1668191), + vec3(0.8358996, 0.1449739, 0.3668382), + vec3(0.1778213, 0.5599256, 0.1327691), + vec3(0.06690693, 0.5508637, 0.07212365), + vec3(0.9750564, 0.284066, 0.5727578), + vec3(0.4350255, 0.8949825, 0.03574753), + vec3(0.8931149, 0.9177974, 0.8123496), + vec3(0.9055127, 0.989903, 0.813235), + vec3(0.2897243, 0.3123978, 0.5083504), + vec3(0.1519223, 0.3958645, 0.2640327), + vec3(0.6840154, 0.6463035, 0.2346607), + vec3(0.986473, 0.8714055, 0.3960275), + vec3(0.6819352, 0.4169535, 0.8379834), + vec3(0.9147297, 0.6144146, 0.7313942), + vec3(0.6554981, 0.5014008, 0.9748477), + vec3(0.9805915, 0.1318207, 0.2371372), + vec3(0.5980836, 0.06796348, 0.9941338), + vec3(0.6836596, 0.9917196, 0.2319056), + vec3(0.5276511, 0.2745509, 0.5422578), + vec3(0.829482, 0.03758276, 0.1240466), + vec3(0.2698198, 0.0002266169, 0.3449324) +); + +float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness) { collectedColor = vec4(0); int hits = 0; @@ -180,55 +315,55 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, vec2 uv2 = tc * screen_res; float c = (uv2.x + uv2.y) * 0.125; float jitter = mod( c, 1.0); - - vec3 firstBasis = normalize(cross(vec3(1,1,1), rayDirection)); - vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); vec2 screenpos = 1 - abs(tc * 2 - 1); - float vignette = clamp((screenpos.x * screenpos.y) * 16,0, 1); - vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5 - 0.2) * 8, 0, 1); - float zFar = 64.0; - vignette *= clamp(1.0+(viewPos.z/zFar), 0.0, 1.0); - //vignette *= min(linearDepth(getDepth(tc), zNear, zFar) / zFar, 1); + float vignette = clamp((abs(screenpos.x) * abs(screenpos.y)) * 64,0, 1); + vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5) * 16, 0, 1); vec4 hitpoint; + + glossiness = 1 - glossiness; + + totalSamples = int(max(glossySampleCount, glossySampleCount * glossiness * vignette)); + + totalSamples = max(totalSamples, 4); - if (totalSamples > 1) { - for (int i = 0; i < totalSamples; i++) { - vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); - vec3 reflectionDirectionRandomized = rayDirection + firstBasis * coeffs.x + secondBasis * coeffs.y; + for (int i = 0; i < totalSamples; i++) + { + vec3 firstBasis = normalize(cross(POISSON3D_SAMPLES[i] * 2 - 1, rayDirection)); + vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); + vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); + vec3 reflectionDirectionRandomized = rayDirection + ((firstBasis * coeffs.x + secondBasis * coeffs.y) * 0.125 * max(glossiness, 0.025)); + //vec3 reflectionDirectionRandomized = rayDirection + (POISSON3D_SAMPLES[i] * 2 - 1) * 0.125 * max(glossiness, 0.025); - //float hitDepth; + //float hitDepth; - bool hit = traceScreenRay(viewPos, normalize(reflectionDirectionRandomized), hitpoint, depth, depth, source); + bool hit = traceScreenRay(viewPos, normalize(reflectionDirectionRandomized), hitpoint, depth, depth, source); - if (hit) - { - ++hits; - collectedColor += hitpoint; + hitpoint.a = 0; + + if (hit) + { + ++hits; + collectedColor += hitpoint; + collectedColor.a += 1; + } } } - } - else - { - bool hit = traceScreenRay(viewPos, normalize(rayDirection), hitpoint, depth, depth, source); - if (hit) + + if (hits > 0) { - ++hits; - collectedColor += hitpoint; + collectedColor /= hits; + } + else + { + collectedColor = vec4(0); } } - - if (hits > 0) - { - collectedColor /= hits; - } - else - { - collectedColor = vec4(0); - } - - return min(float(hits), 1.0) * vignette; + float hitAlpha = hits; + hitAlpha /= totalSamples; + collectedColor.a = hitAlpha * vignette; + return hits; } -- cgit v1.2.3 From cdc9852f052d804f8b25564ab7d90eb2b79cddd4 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 15 May 2023 11:01:24 -0500 Subject: SL-19709 Fix for fullbright shiny not factoring out exposure and flickering fullbright alpha. Incidental decruft. --- .../shaders/class3/deferred/fullbrightShinyF.glsl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index 6b7dc7ac1d..f1b1997c43 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -43,8 +43,9 @@ VARYING vec3 vary_position; uniform samplerCube environmentMap; -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); - +vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); +vec3 legacy_adjust_fullbright(vec3 c); +vec3 legacy_adjust(vec3 c); void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); vec3 linear_to_srgb(vec3 c); @@ -84,10 +85,13 @@ void main() vec3 norm = normalize(vary_texcoord1.xyz); vec4 spec = vec4(0,0,0,0); sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity); - applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); + color.rgb = legacy_adjust(color.rgb); color.rgb = srgb_to_linear(color.rgb); - color.rgb = fullbrightAtmosTransportFrag(color.rgb, additive, atten); + color.rgb = legacy_adjust_fullbright(color.rgb); + + applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); + color.rgb = atmosFragLighting(color.rgb, additive, atten); #endif color.a = 1.0; -- cgit v1.2.3 From c827d32ebedeaa46ed75a91ae779f6547fc0d090 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 17 May 2023 18:09:36 -0500 Subject: SL-19655 Decruft legacy GLSL shaders and now unused build queues. --- .../shaders/class3/deferred/fullbrightShinyF.glsl | 14 ++++----- .../shaders/class3/deferred/materialF.glsl | 34 +++++++++------------- .../shaders/class3/deferred/multiPointLightF.glsl | 16 ++++------ .../shaders/class3/deferred/multiPointLightV.glsl | 4 +-- .../shaders/class3/deferred/multiSpotLightF.glsl | 19 ++++-------- .../shaders/class3/deferred/pointLightF.glsl | 18 ++++-------- .../shaders/class3/deferred/pointLightV.glsl | 6 ++-- .../class3/deferred/screenSpaceReflPostF.glsl | 14 +++------ .../class3/deferred/screenSpaceReflPostV.glsl | 6 ++-- .../shaders/class3/deferred/softenLightF.glsl | 25 ++++++---------- .../shaders/class3/deferred/spotLightF.glsl | 21 +++++-------- .../shaders/class3/environment/underWaterF.glsl | 14 ++++----- .../shaders/class3/environment/waterF.glsl | 22 +++++++------- 13 files changed, 81 insertions(+), 132 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index f1b1997c43..1c79748b49 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -25,21 +25,17 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif #ifndef HAS_DIFFUSE_LOOKUP uniform sampler2D diffuseMap; #endif -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; -VARYING vec3 vary_texcoord1; -VARYING vec3 vary_position; +in vec4 vertex_color; +in vec2 vary_texcoord0; +in vec3 vary_texcoord1; +in vec3 vary_position; uniform samplerCube environmentMap; @@ -62,7 +58,7 @@ void main() #ifdef HAS_DIFFUSE_LOOKUP vec4 color = diffuseLookup(vary_texcoord0.xy); #else - vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 color = texture(diffuseMap, vary_texcoord0.xy); #endif color.rgb *= vertex_color.rgb; diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index e5341386bd..77e3b92385 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -52,11 +52,7 @@ vec3 legacy_adjust(vec3 c); #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); @@ -77,9 +73,9 @@ uniform mat3 env_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; -VARYING vec3 vary_position; +in vec3 vary_position; uniform mat4 proj_mat; uniform mat4 inv_proj; @@ -167,7 +163,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); + float scol = fres*texture(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; @@ -184,11 +180,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe } #else -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[4]; -#else -#define frag_data gl_FragData -#endif #endif uniform sampler2D diffuseMap; //always in sRGB space @@ -200,7 +192,7 @@ uniform sampler2D bumpMap; #ifdef HAS_SPECULAR_MAP uniform sampler2D specularMap; -VARYING vec2 vary_texcoord2; +in vec2 vary_texcoord2; #endif uniform float env_intensity; @@ -214,13 +206,13 @@ uniform float minimum_alpha; in vec3 vary_normal; in vec3 vary_tangent; flat in float vary_sign; -VARYING vec2 vary_texcoord1; +in vec2 vary_texcoord1; #else -VARYING vec3 vary_normal; +in vec3 vary_normal; #endif -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; +in vec4 vertex_color; +in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); @@ -228,7 +220,7 @@ vec2 encode_normal(vec3 n); vec3 getNormal(inout float glossiness) { #ifdef HAS_NORMAL_MAP - vec4 vNt = texture2D(bumpMap, vary_texcoord1.xy); + vec4 vNt = texture(bumpMap, vary_texcoord1.xy); glossiness *= vNt.a; vNt.xyz = vNt.xyz * 2 - 1; float sign = vary_sign; @@ -247,7 +239,7 @@ vec3 getNormal(inout float glossiness) vec4 getSpecular() { #ifdef HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); + vec4 spec = texture(specularMap, vary_texcoord2.xy); spec.rgb *= specular_color.rgb; #else vec4 spec = vec4(specular_color.rgb, 1.0); @@ -301,7 +293,7 @@ void main() waterClip(); // diffcol == diffuse map combined with vertex color - vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); + vec4 diffcol = texture(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; alphaMask(diffcol.a); @@ -364,7 +356,7 @@ void main() if (glossiness > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); - vec3 dumbshiny = sunlit_linear * shadow * (texture2D(lightFunc, vec2(sa, glossiness)).r); + vec3 dumbshiny = sunlit_linear * shadow * (texture(lightFunc, vec2(sa, glossiness)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; @@ -395,7 +387,7 @@ void main() float gtdenom = 2 * nh; float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); - float scol = shadow*fres*texture2D(lightFunc, vec2(nh, glossiness)).r*gt/(nh*nl); + float scol = shadow*fres*texture(lightFunc, vec2(nh, glossiness)).r*gt/(nh*nl); color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 2da177ea7e..2a096a98ec 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -23,15 +23,9 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform sampler2D depthMap; uniform sampler2D diffuseRect; @@ -49,7 +43,7 @@ uniform vec2 screen_res; uniform float far_z; uniform mat4 inv_proj; -VARYING vec4 vary_fragcoord; +in vec4 vary_fragcoord; 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); float calcLegacyDistanceAttenuation(float distance, float falloff); @@ -88,15 +82,15 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() - vec4 spec = texture2D(specularRect, tc); - vec3 diffuse = texture2D(diffuseRect, tc).rgb; + vec4 spec = texture(specularRect, tc); + vec3 diffuse = texture(diffuseRect, tc).rgb; vec3 h, l, v = -normalize(pos); float nh, nv, vh, lightDist; if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; + vec3 colorEmissive = texture(emissiveRect, tc).rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; @@ -167,7 +161,7 @@ void main() if (nh > 0.0) { - float scol = fres * texture2D(lightFunc, vec2(nh, spec.a)).r * gt / (nh * nl); + float scol = fres * texture(lightFunc, vec2(nh, spec.a)).r * gt / (nh * nl); col += lit * scol * light_col[i].rgb * spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl index 831b3b2684..c2b9ed3d96 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightV.glsl @@ -23,9 +23,9 @@ * $/LicenseInfo$ */ -ATTRIBUTE vec3 position; +in vec3 position; -VARYING vec4 vary_fragcoord; +out vec4 vary_fragcoord; void main() { diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 33715d4d87..23120bbbbe 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -23,16 +23,9 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable -#extension GL_ARB_shader_texture_lod : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform sampler2D diffuseRect; uniform sampler2D specularRect; @@ -67,7 +60,7 @@ uniform float size; uniform vec3 color; uniform float falloff; -VARYING vec4 vary_fragcoord; +in vec4 vary_fragcoord; uniform vec2 screen_res; uniform mat4 inv_proj; @@ -118,7 +111,7 @@ void main() if (proj_shadow_idx >= 0) { - vec4 shd = texture2D(lightMap, tc); + vec4 shd = texture(lightMap, tc); shadow = (proj_shadow_idx==0)?shd.b:shd.a; shadow += shadow_fade; shadow = clamp(shadow, 0.0, 1.0); @@ -139,8 +132,8 @@ void main() float nh, nl, nv, vh, lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); - vec3 diffuse = texture2D(diffuseRect, tc).rgb; - vec4 spec = texture2D(specularRect, tc); + vec3 diffuse = texture(diffuseRect, tc).rgb; + vec4 spec = texture(specularRect, tc); vec3 dlit = vec3(0, 0, 0); vec3 slit = vec3(0, 0, 0); @@ -148,7 +141,7 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; + vec3 colorEmissive = texture(emissiveRect, tc).rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; @@ -223,7 +216,7 @@ void main() if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); + float scol = fres*texture(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); vec3 speccol = dlit*scol*spec.rgb*shadow; speccol = clamp(speccol, vec3(0), vec3(1)); final_color += speccol; diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 7724a6cac9..42ba96148c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -23,15 +23,9 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform sampler2D diffuseRect; uniform sampler2D specularRect; @@ -48,8 +42,8 @@ uniform vec3 color; uniform float falloff; uniform float size; -VARYING vec4 vary_fragcoord; -VARYING vec3 trans_center; +in vec4 vary_fragcoord; +in vec3 trans_center; uniform vec2 screen_res; @@ -83,8 +77,8 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() - vec3 diffuse = texture2D(diffuseRect, tc).rgb; - vec4 spec = texture2D(specularRect, tc); + vec3 diffuse = texture(diffuseRect, tc).rgb; + vec4 spec = texture(specularRect, tc); // Common half vectors calcs vec3 lv = trans_center.xyz-pos; @@ -101,7 +95,7 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; + vec3 colorEmissive = texture(emissiveRect, tc).rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; @@ -141,7 +135,7 @@ void main() if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); + float scol = fres*texture(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); final_color += lit*scol*color.rgb*spec.rgb; } } diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightV.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightV.glsl index d42c8f6cf6..8d23f1b427 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightV.glsl @@ -26,13 +26,13 @@ uniform mat4 modelview_projection_matrix; uniform mat4 modelview_matrix; -ATTRIBUTE vec3 position; +in vec3 position; uniform vec3 center; uniform float size; -VARYING vec4 vary_fragcoord; -VARYING vec3 trans_center; +out vec4 vary_fragcoord; +out vec3 trans_center; void main() { diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl index f1865a77e2..02e724c155 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostF.glsl @@ -23,15 +23,9 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable - /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform vec2 screen_res; uniform mat4 projection_matrix; @@ -39,8 +33,8 @@ uniform mat4 inv_proj; uniform float zNear; uniform float zFar; -VARYING vec2 vary_fragcoord; -VARYING vec3 camera_ray; +in vec2 vary_fragcoord; +in vec3 camera_ray; uniform sampler2D specularRect; uniform sampler2D diffuseRect; @@ -67,10 +61,10 @@ void main() vec3 n; vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() vec3 pos = getPositionWithDepth(tc, getDepth(tc)).xyz; - vec4 spec = texture2D(specularRect, tc); + vec4 spec = texture(specularRect, tc); vec2 hitpixel; - vec4 diffuse = texture2D(diffuseRect, tc); + vec4 diffuse = texture(diffuseRect, tc); vec3 specCol = spec.rgb; vec4 fcol = texture(diffuseMap, tc); diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostV.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostV.glsl index b084094d4d..f7e7268cc3 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostV.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflPostV.glsl @@ -26,12 +26,12 @@ uniform mat4 projection_matrix; uniform mat4 inv_proj; -ATTRIBUTE vec3 position; +in vec3 position; uniform vec2 screen_res; -VARYING vec2 vary_fragcoord; -VARYING vec3 camera_ray; +out vec2 vary_fragcoord; +out vec3 camera_ray; void main() diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index a8d61afeca..2f3efaa94a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -23,19 +23,12 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable -#extension GL_ARB_shader_texture_lod : enable - #define FLT_MAX 3.402823466e+38 #define REFMAP_COUNT 256 #define REF_SAMPLE_COUNT 64 //maximum number of samples to consider -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform sampler2D diffuseRect; uniform sampler2D specularRect; @@ -60,7 +53,7 @@ uniform mat3 env_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; uniform int sun_up_factor; -VARYING vec2 vary_fragcoord; +in vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; @@ -127,16 +120,16 @@ void main() vec2 tc = vary_fragcoord.xy; float depth = getDepth(tc.xy); vec4 pos = getPositionWithDepth(tc, depth); - vec4 norm = texture2D(normalMap, tc); + vec4 norm = texture(normalMap, tc); float envIntensity = norm.z; norm.xyz = getNorm(tc); vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - vec4 baseColor = texture2D(diffuseRect, tc); - vec4 spec = texture2D(specularRect, vary_fragcoord.xy); // NOTE: PBR linear Emissive + vec4 baseColor = texture(diffuseRect, tc); + vec4 spec = texture(specularRect, vary_fragcoord.xy); // NOTE: PBR linear Emissive #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO) - vec2 scol_ambocc = texture2D(lightMap, vary_fragcoord.xy).rg; + vec2 scol_ambocc = texture(lightMap, vary_fragcoord.xy).rg; #endif #if defined(HAS_SUN_SHADOW) @@ -180,12 +173,12 @@ void main() if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 orm = texture2D(specularRect, tc).rgb; + vec3 orm = texture(specularRect, tc).rgb; float perceptualRoughness = orm.g; float metallic = orm.b; float ao = orm.r * ambocc; - vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; + vec3 colorEmissive = texture(emissiveRect, tc).rgb; // PBR IBL float gloss = 1.0 - perceptualRoughness; @@ -211,7 +204,7 @@ void main() else if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS)) { //should only be true of WL sky, just port over base color value - color = texture2D(emissiveRect, tc).rgb; + color = texture(emissiveRect, tc).rgb; color = srgb_to_linear(color); if (sun_up_factor > 0) { @@ -263,7 +256,7 @@ void main() float gtdenom = 2 * nh; float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); - scol *= fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); + scol *= fres*texture(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb; } diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index f2ab585716..1ea801d7d7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -23,9 +23,6 @@ * $/LicenseInfo$ */ -#extension GL_ARB_texture_rectangle : enable -#extension GL_ARB_shader_texture_lod : enable - /*[EXTRA_CODE_HERE]*/ #define DEBUG_ANY_LIGHT_TYPE 0 // Output green light cone @@ -38,11 +35,7 @@ #define DEBUG_SPOT_NL 0 // monochome area effected by light #define DEBUG_SPOT_ZERO 0 // Output zero for spotlight -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform sampler2D diffuseRect; uniform sampler2D specularRect; @@ -75,8 +68,8 @@ uniform float size; uniform vec3 color; uniform float falloff; -VARYING vec3 trans_center; -VARYING vec4 vary_fragcoord; +in vec3 trans_center; +in vec4 vary_fragcoord; uniform vec2 screen_res; uniform mat4 inv_proj; @@ -126,7 +119,7 @@ void main() if (proj_shadow_idx >= 0) { - vec4 shd = texture2D(lightMap, tc); + vec4 shd = texture(lightMap, tc); shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; shadow += shadow_fade; shadow = clamp(shadow, 0.0, 1.0); @@ -147,15 +140,15 @@ void main() float nh, nl, nv, vh, lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); - vec3 diffuse = texture2D(diffuseRect, tc).rgb; - vec4 spec = texture2D(specularRect, tc); + vec3 diffuse = texture(diffuseRect, tc).rgb; + vec4 spec = texture(specularRect, tc); vec3 dlit = vec3(0, 0, 0); vec3 slit = vec3(0, 0, 0); vec3 amb_rgb = vec3(0); if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture2D(emissiveRect, tc).rgb; + vec3 colorEmissive = texture(emissiveRect, tc).rgb; vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; @@ -231,7 +224,7 @@ void main() if (nh > 0.0) { - float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); + float scol = fres*texture(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); vec3 speccol = dlit*scol*spec.rgb*shadow; speccol = clamp(speccol, vec3(0), vec3(1)); final_color += speccol; diff --git a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl index 21c30012ab..e99ad5b474 100644 --- a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl @@ -50,9 +50,9 @@ uniform float waterFogKS; uniform vec2 screenRes; //bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; +in vec4 refCoord; +in vec4 littleWave; +in vec4 view; in vec3 vary_position; vec4 applyWaterFogViewLinearNoClip(vec3 pos, vec4 color, vec3 sunlit); @@ -62,9 +62,9 @@ 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 wave1 = texture(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; + vec3 wave2 = texture(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3 = texture(bumpMap, littleWave.zw).xyz*2.0-1.0; vec3 wavef = normalize(wave1+wave2+wave3); //figure out distortion vector (ripply) @@ -72,7 +72,7 @@ void main() distort = distort+wavef.xy*refScale; #ifdef TRANSPARENT_WATER - vec4 fb = texture2D(screenTex, distort); + vec4 fb = texture(screenTex, distort); #else vec4 fb = vec4(waterFogColorLinear, 0.0); #endif diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 3d4f4fc17b..8fee259933 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -99,9 +99,9 @@ uniform vec3 waterFogColorLinear; //bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; +in vec4 refCoord; +in vec4 littleWave; +in vec4 view; in vec3 vary_position; in vec3 vary_normal; in vec3 vary_tangent; @@ -144,12 +144,12 @@ void main() //get wave normals vec2 bigwave = vec2(refCoord.w, view.w); vec3 wave1_a = texture(bumpMap, bigwave, -2 ).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 wave2_a = texture(bumpMap, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_a = texture(bumpMap, littleWave.zw).xyz*2.0-1.0; vec3 wave1_b = texture(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 wave2_b = texture(bumpMap2, littleWave.xy).xyz*2.0-1.0; + vec3 wave3_b = texture(bumpMap2, littleWave.zw).xyz*2.0-1.0; //wave1_a = wave2_a = wave3_a = wave1_b = wave2_b = wave3_b = vec3(0,0,1); @@ -210,16 +210,16 @@ void main() vec3 sunlit_linear = srgb_to_linear(sunlit); #ifdef TRANSPARENT_WATER - vec4 fb = texture2D(screenTex, distort2); - float depth = texture2D(screenDepth, distort2).r; + vec4 fb = texture(screenTex, distort2); + float depth = texture(screenDepth, distort2).r; vec3 refPos = getPositionWithNDC(vec3(distort2*2.0-vec2(1.0), depth*2.0-1.0)); if (refPos.z > pos.z-0.05) { //we sampled an above water sample, don't distort distort2 = distort; - fb = texture2D(screenTex, distort2); - depth = texture2D(screenDepth, distort2).r; + fb = texture(screenTex, distort2); + depth = texture(screenDepth, distort2).r; refPos = getPositionWithNDC(vec3(distort2 * 2.0 - vec2(1.0), depth * 2.0 - 1.0)); } -- cgit v1.2.3 From da72081582c3fd376e228cf0fceaef2ecb1948a9 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Mon, 22 May 2023 10:42:06 -0700 Subject: Just a couple of tweaks to settings. DRTVWR-583 --- .../app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index 0f1b33f711..f75c69e262 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -320,6 +320,10 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, float vignette = clamp((abs(screenpos.x) * abs(screenpos.y)) * 64,0, 1); vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5) * 16, 0, 1); + float zFar = 32.0; + vignette *= clamp(1.0+(viewPos.z/zFar), 0.0, 1.0); + + vec4 hitpoint; glossiness = 1 - glossiness; -- cgit v1.2.3 From 555f08921c46f1ed575dd6bf1058362e43a82dc5 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Mon, 22 May 2023 11:46:35 -0700 Subject: Address feedback. DRTVWR-583 DRTVWR-559 --- .../app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index f75c69e262..5ad25c325f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -61,7 +61,6 @@ uniform float rayStep; uniform float distanceBias; uniform float depthRejectBias; uniform float glossySampleCount; -uniform float noiseSine; float epsilon = 0.1; -- cgit v1.2.3 From 46e04fe273ce88c52c08a6417a01ec89bd4e89e9 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 23 May 2023 16:11:43 -0500 Subject: DRTVWR-559 Remove RenderReflectionProbeCount (which is bugged) and lean on RenderReflectionProbeLevel for preferences (which works). --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 3 --- 1 file changed, 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 2f3efaa94a..3945e34d7a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -25,9 +25,6 @@ #define FLT_MAX 3.402823466e+38 -#define REFMAP_COUNT 256 -#define REF_SAMPLE_COUNT 64 //maximum number of samples to consider - out vec4 frag_color; uniform sampler2D diffuseRect; -- cgit v1.2.3 From c12712aa9609325ba3247a67354e91e9342106d6 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 25 May 2023 13:09:03 -0500 Subject: DRTVWR-559 Fix for off-color fullbright alpha blinn-phong materials. Scrub some NaNs. --- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 77e3b92385..ba19fe0f19 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -49,6 +49,7 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); vec3 legacy_adjust(vec3 c); +vec3 legacy_adjust_fullbright(vec3 c); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -396,7 +397,7 @@ void main() } #endif - color = mix(color.rgb, diffcol.rgb, emissive); + color = mix(color.rgb, legacy_adjust_fullbright(diffcol.rgb), emissive); if (env > 0.0) { // add environmentmap -- cgit v1.2.3 From cbd17fce86cc30434d6d665338a7d771bddcad8b Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Thu, 25 May 2023 16:09:22 -0400 Subject: Fix underwater fog mismatch between opaque and alpha blend when local lights are nearby (#227) * Fix water fog mismatch between alpha blend and opaque when local light is nearby * Add PBR underwater alpha blend shader --- .../app_settings/shaders/class3/deferred/materialF.glsl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index ba19fe0f19..5fb5647d35 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -38,7 +38,7 @@ uniform float emissive_brightness; // fullbright flag, 1.0 == fullbright, 0.0 o uniform int sun_up_factor; #ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); +vec4 applyWaterFogViewLinear(vec3 pos, vec4 color, vec3 sunlit); #endif vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); @@ -411,6 +411,11 @@ void main() color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); +#ifdef WATER_FOG + vec4 temp = applyWaterFogViewLinear(pos, vec4(color, 0.0), sunlit_linear); + color = temp.rgb; +#endif + vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0, 0, 0); @@ -431,11 +436,6 @@ void main() glare = min(glare, 1.0); float al = max(diffcol.a, glare) * vertex_color.a; -#ifdef WATER_FOG - vec4 temp = applyWaterFogView(pos, vec4(color, 0.0)); - color = temp.rgb; -#endif - frag_color = max(vec4(color, al), vec4(0)); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer -- cgit v1.2.3 From 30311e5229bff107c2722de68aabb656d9b8f097 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 25 May 2023 16:16:20 -0500 Subject: SL-19713 Fix for broken avatar preview render in animation upload. Incidental decruft and camera FoV network spam reduction. --- .../shaders/class3/lighting/lightV.glsl | 10 +--- .../shaders/class3/lighting/sumLightsV.glsl | 67 ---------------------- 2 files changed, 1 insertion(+), 76 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl index 30ad493331..77bbbabfae 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/lightV.glsl @@ -23,21 +23,13 @@ * $/LicenseInfo$ */ - - -// All lights, no specular highlights -vec3 atmosAmbient(); +// used for preview renders only vec4 sumLights(vec3 pos, vec3 norm, vec4 color); -float getAmbientClamp(); vec4 calcLighting(vec3 pos, vec3 norm, vec4 color) { vec4 c = sumLights(pos, norm, color); -#if !defined(AMBIENT_KILL) - c.rgb += atmosAmbient() * color.rgb * getAmbientClamp(); -#endif - return c; } diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl deleted file mode 100644 index 4b663dd5b2..0000000000 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @file class3\lighting\sumLightsV.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$ - */ - - -float calcDirectionalLight(vec3 n, vec3 l); -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight); - -vec3 atmosAffectDirectionalLight(float lightIntensity); -vec3 scaleDownLight(vec3 light); - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -vec4 sumLights(vec3 pos, vec3 norm, vec4 color) -{ - vec4 col = vec4(0.0, 0.0, 0.0, color.a); - - // Collect normal lights (need to be divided by two, as we later multiply by 2) - - // 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); - col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); - col.rgb = scaleDownLight(col.rgb); - -#if defined(LOCAL_LIGHT_KILL) - col.rgb = vec3(0); -#endif - - // Add windlight lights -#if !defined(SUNLIGHT_KILL) - col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); -#endif - - col.rgb = min(col.rgb*color.rgb, 1.0); - - return col; -} - -- cgit v1.2.3 From 47e311d6e8b9996de3e0a1ac75c13724ce7735aa Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Fri, 26 May 2023 16:56:33 -0700 Subject: Addressing some performance related feedback with SSR getting drastically slower. DRTVWR-559 DRTVWR-583 --- .../shaders/class3/deferred/screenSpaceReflUtil.glsl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index 5ad25c325f..d291196059 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -61,6 +61,8 @@ uniform float rayStep; uniform float distanceBias; uniform float depthRejectBias; uniform float glossySampleCount; +uniform float adaptiveStepMultiplier; +uniform float noiseSine; float epsilon = 0.1; @@ -135,7 +137,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float if (isExponentialStepEnabled) { - step *= 1.05; + step *= adaptiveStepMultiplier; } } if(isBinarySearchEnabled) @@ -302,6 +304,10 @@ uniform vec3 POISSON3D_SAMPLES[128] = vec3[128]( vec3(0.2698198, 0.0002266169, 0.3449324) ); +vec3 getPoissonSample(int i) { + return POISSON3D_SAMPLES[i] * 2 - 1; +} + float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness) { collectedColor = vec4(0); @@ -319,7 +325,7 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, float vignette = clamp((abs(screenpos.x) * abs(screenpos.y)) * 64,0, 1); vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5) * 16, 0, 1); - float zFar = 32.0; + float zFar = 128.0; vignette *= clamp(1.0+(viewPos.z/zFar), 0.0, 1.0); @@ -329,17 +335,16 @@ float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, totalSamples = int(max(glossySampleCount, glossySampleCount * glossiness * vignette)); - totalSamples = max(totalSamples, 4); + totalSamples = max(totalSamples, 1); { { for (int i = 0; i < totalSamples; i++) { - vec3 firstBasis = normalize(cross(POISSON3D_SAMPLES[i] * 2 - 1, rayDirection)); + vec3 firstBasis = normalize(cross(getPoissonSample(i), rayDirection)); vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); vec2 coeffs = vec2(random(tc + vec2(0, i)) + random(tc + vec2(i, 0))); - vec3 reflectionDirectionRandomized = rayDirection + ((firstBasis * coeffs.x + secondBasis * coeffs.y) * 0.125 * max(glossiness, 0.025)); - //vec3 reflectionDirectionRandomized = rayDirection + (POISSON3D_SAMPLES[i] * 2 - 1) * 0.125 * max(glossiness, 0.025); + vec3 reflectionDirectionRandomized = rayDirection + ((firstBasis * coeffs.x + secondBasis * coeffs.y) * glossiness); //float hitDepth; -- cgit v1.2.3 From 50ec54831de88926ca13c9a72d89006ceda6c355 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Jun 2023 19:49:23 -0500 Subject: DRTVWR-559 Revert skies to be very close to release and disable tone mapping when probe ambiance is zero. Hack for desaturating legacy materials has been removed for performance and quality reasons. Adds a new setting for auto adjusting legacy skies. This is the PBR "opt out" button. If disabled, legacy skies will disable tonemapping, automatic probe ambiance, and HDR/exposure. If enabled, legacy skies will behave as if probe ambiance and HDR scale are 1.0, and ambient will be cut in half. HDR scale will act as a sky brightener, but will automatically adjust dynamic exposure so the sky will be properly exposed. If you want relatively even exposure all the time, set HDR Scale to 1.0. If you want a high range of exposures between indoor/dark areas and outdoor/bright areas, increase HDR Scale. Also tuned up SSAO (thanks Rye!). Reviewed with Brad. --- .../shaders/class3/deferred/fullbrightShinyF.glsl | 4 +-- .../shaders/class3/deferred/softenLightF.glsl | 36 ++++++++++++++-------- 2 files changed, 25 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index 1c79748b49..0d77e88831 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -42,7 +42,7 @@ uniform samplerCube environmentMap; vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); vec3 legacy_adjust_fullbright(vec3 c); vec3 legacy_adjust(vec3 c); -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); @@ -71,7 +71,7 @@ void main() vec3 additive; vec3 atten; vec3 pos = vary_position; - calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten); float env_intensity = vertex_color.a; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 3945e34d7a..53c5b1b801 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -44,9 +44,14 @@ uniform sampler2D lightFunc; uniform float blur_size; uniform float blur_fidelity; +#if defined(HAS_SSAO) +uniform float ssao_irradiance_scale; +uniform float ssao_irradiance_max; +#endif + // Inputs uniform mat3 env_mat; - +uniform mat3 ssao_effect_mat; uniform vec3 sun_dir; uniform vec3 moon_dir; uniform int sun_up_factor; @@ -112,6 +117,16 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 l); //surface point to light +void adjustIrradiance(inout vec3 irradiance, vec3 amblit_linear, float ambocc) +{ + // use sky settings ambient or irradiance map sample, whichever is brighter + irradiance = max(amblit_linear, irradiance); + +#if defined(HAS_SSAO) + irradiance = mix(ssao_effect_mat * min(irradiance.rgb*ssao_irradiance_scale, vec3(ssao_irradiance_max)), irradiance.rgb, ambocc); +#endif +} + void main() { vec2 tc = vary_fragcoord.xy; @@ -173,7 +188,7 @@ void main() vec3 orm = texture(specularRect, tc).rgb; float perceptualRoughness = orm.g; float metallic = orm.b; - float ao = orm.r * ambocc; + float ao = orm.r; vec3 colorEmissive = texture(emissiveRect, tc).rgb; // PBR IBL @@ -181,9 +196,7 @@ void main() sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss); - // Take maximium of legacy ambient vs irradiance sample as irradiance - // NOTE: ao is applied in pbrIbl (see pbrBaseLight), do not apply here - irradiance = max(amblit_linear,irradiance); + adjustIrradiance(irradiance, amblit_linear, ambocc); vec3 diffuseColor; vec3 specularColor; @@ -203,17 +216,15 @@ void main() //should only be true of WL sky, just port over base color value color = texture(emissiveRect, tc).rgb; color = srgb_to_linear(color); - if (sun_up_factor > 0) - { - color *= sky_hdr_scale + 1.0; - } + color *= sky_hdr_scale; } else { // legacy shaders are still writng sRGB to gbuffer baseColor.rgb = legacy_adjust(baseColor.rgb); - + baseColor.rgb = srgb_to_linear(baseColor.rgb); + spec.rgb = srgb_to_linear(spec.rgb); float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); @@ -224,11 +235,10 @@ void main() sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity); - // use sky settings ambient or irradiance map sample, whichever is brighter - irradiance = max(amblit_linear, irradiance); + adjustIrradiance(irradiance, amblit_linear, ambocc); // apply lambertian IBL only (see pbrIbl) - color.rgb = irradiance * ambocc; + color.rgb = irradiance; vec3 sun_contrib = min(da, scol) * sunlit_linear; color.rgb += sun_contrib; -- cgit v1.2.3 From b0540f8189d28da66c143c5de961deaba7a86f17 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Jun 2023 20:15:35 -0500 Subject: DRTVWR-559 Rebalance PBR against Blinn-Phong. --- indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 53c5b1b801..409b46218b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -203,7 +203,6 @@ void main() calcDiffuseSpecular(baseColor.rgb, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); - color = vec3(1,0,1); color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit_linear, scol, radiance, irradiance, colorEmissive, ao, additive, atten); if (do_atmospherics) -- cgit v1.2.3 From 3581c81328f4a34f62ca867f3052115ef590a6b6 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Wed, 14 Jun 2023 05:35:34 -0700 Subject: More performance addressing. Ditch glossy SSR on semi-transparent surfaces. SL-19784 --- .../shaders/class3/deferred/fullbrightShinyF.glsl | 4 +-- .../shaders/class3/deferred/materialF.glsl | 4 +-- .../shaders/class3/deferred/reflectionProbeF.glsl | 34 +++++++++++++++++----- .../class3/deferred/screenSpaceReflUtil.glsl | 4 +++ .../shaders/class3/deferred/softenLightF.glsl | 8 ++--- 5 files changed, 39 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index 0d77e88831..1537714bb7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -49,7 +49,7 @@ vec3 srgb_to_linear(vec3 c); // reflection probe interface void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent); void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity); @@ -80,7 +80,7 @@ void main() vec3 legacyenv; vec3 norm = normalize(vary_texcoord1.xyz); vec4 spec = vec4(0,0,0,0); - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity, false); color.rgb = legacy_adjust(color.rgb); color.rgb = srgb_to_linear(color.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 5fb5647d35..815069bb6a 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -60,7 +60,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent); 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); @@ -339,7 +339,7 @@ void main() vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env, true); // use sky settings ambient or irradiance map sample, whichever is brighter color = max(amblit_linear, ambenv); diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 53e15bd1a1..6a3a80a779 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -35,6 +35,8 @@ uniform sampler2D sceneMap; uniform int cube_snapshot; uniform float max_probe_lod; +uniform bool transparent_surface; + #define MAX_REFMAP_COUNT 256 // must match LL_MAX_REFLECTION_PROBE_COUNT layout (std140) uniform ReflectionProbes @@ -671,7 +673,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) } void doProbeSample(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent) { // TODO - don't hard code lods float reflection_lods = max_probe_lod; @@ -687,7 +689,16 @@ void doProbeSample(inout vec3 ambenv, inout vec3 glossenv, if (cube_snapshot != 1 && glossiness >= 0.9) { vec4 ssr = vec4(0); - float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap, glossiness); + if (transparent) + { + tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap, 1); + ssr.a *= glossiness; + } + else + { + tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap, glossiness); + } + glossenv = mix(glossenv, ssr.rgb, ssr.a); } @@ -695,10 +706,10 @@ void doProbeSample(inout vec3 ambenv, inout vec3 glossenv, } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent) { preProbeSample(pos); - doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness); + doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness, transparent); } void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, @@ -711,7 +722,7 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, // always include void probe on water probeIndex[probeInfluences++] = 0; - doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness); + doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness, true); // fudge factor to get PBR water at a similar luminance ot legacy water glossenv *= 0.4; @@ -766,7 +777,7 @@ vec4 sampleReflectionProbesDebug(vec3 pos) } void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity) + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent) { float reflection_lods = max_probe_lod; preProbeSample(pos); @@ -790,7 +801,16 @@ void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout if (cube_snapshot != 1) { vec4 ssr = vec4(0); - float w = tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap, glossiness); + + if (transparent) + { + tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap, 1); + ssr.a *= glossiness; + } + else + { + tapScreenSpaceReflection(1, tc, pos, norm, ssr, sceneMap, glossiness); + } glossenv = mix(glossenv, ssr.rgb, ssr.a); legacyenv = mix(legacyenv, ssr.rgb, ssr.a); diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index d291196059..1b822d6a21 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -310,6 +310,10 @@ vec3 getPoissonSample(int i) { float tapScreenSpaceReflection(int totalSamples, vec2 tc, vec3 viewPos, vec3 n, inout vec4 collectedColor, sampler2D source, float glossiness) { +#ifdef TRANSPARENT_SURFACE +collectedColor = vec4(1, 0, 1, 1); + return 0; +#endif collectedColor = vec4(0); int hits = 0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 409b46218b..4ef003e0cb 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -69,9 +69,9 @@ vec3 scaleSoftClipFragLinear(vec3 l); // reflection probe interface void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness); + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent); void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity); + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent); 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); float getDepth(vec2 pos_screen); @@ -194,7 +194,7 @@ void main() // PBR IBL float gloss = 1.0 - perceptualRoughness; - sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss); + sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss, false); adjustIrradiance(irradiance, amblit_linear, ambocc); @@ -232,7 +232,7 @@ void main() vec3 glossenv = vec3(0); vec3 legacyenv = vec3(0); - sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity, false); adjustIrradiance(irradiance, amblit_linear, ambocc); -- cgit v1.2.3 From 7fb024cfc24222df63a0f3335d2266260c7e6a42 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 14 Jun 2023 14:07:11 -0500 Subject: SL-19838 Put local lights back on fullbright objects. Fix assert in modelpreview. --- indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 5fb5647d35..ab40298f44 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -429,13 +429,12 @@ void main() LIGHT_LOOP(6) LIGHT_LOOP(7) - light *= 1.0-emissive; color += light; glare *= 1.0-emissive; glare = min(glare, 1.0); float al = max(diffcol.a, glare) * vertex_color.a; - + frag_color = max(vec4(color, al), vec4(0)); #else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer -- cgit v1.2.3 From 22f83b3436129e3198fcdd24ccb30baf253955c7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Thu, 15 Jun 2023 09:01:39 -0700 Subject: Add missing variable initialization, and make water support glossy SSR again. SL-19784 --- .../newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 6a3a80a779..1b2a34ef01 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -722,7 +722,7 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, // always include void probe on water probeIndex[probeInfluences++] = 0; - doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness, true); + doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness, false); // fudge factor to get PBR water at a similar luminance ot legacy water glossenv *= 0.4; -- cgit v1.2.3 From 5dedf6d75389772b88c140695ac421699b24fd81 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Thu, 15 Jun 2023 09:31:15 -0700 Subject: Skip samples that are in vignette, and glossiness under a value. SL-19784 --- .../class3/deferred/screenSpaceReflUtil.glsl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index 1b822d6a21..b2d1e75d04 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -332,6 +332,7 @@ collectedColor = vec4(1, 0, 1, 1); float zFar = 128.0; vignette *= clamp(1.0+(viewPos.z/zFar), 0.0, 1.0); + vignette *= clamp(glossiness * 3 - 1.7, 0, 1); vec4 hitpoint; @@ -340,8 +341,9 @@ collectedColor = vec4(1, 0, 1, 1); totalSamples = int(max(glossySampleCount, glossySampleCount * glossiness * vignette)); totalSamples = max(totalSamples, 1); - + if (glossiness < 0.35) { + if (vignette > 0) { for (int i = 0; i < totalSamples; i++) { @@ -363,15 +365,15 @@ collectedColor = vec4(1, 0, 1, 1); collectedColor.a += 1; } } - } - - if (hits > 0) - { - collectedColor /= hits; - } - else - { - collectedColor = vec4(0); + + if (hits > 0) + { + collectedColor /= hits; + } + else + { + collectedColor = vec4(0); + } } } float hitAlpha = hits; -- cgit v1.2.3 From 47be24e467a9fe5a2c0466a49f58769f6b81fdc4 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 15 Jun 2023 14:51:57 -0500 Subject: SL-19835 Followup -- fix for emissive alpha objects blocking water rendering --- .../shaders/class3/deferred/materialF.glsl | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index ab40298f44..615a25d2de 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -353,24 +353,6 @@ void main() float glare = 0.0; -#if 0 //wrong implementation - if (glossiness > 0.0) // specular reflection - { - float sa = dot(normalize(refnormpersp), light_dir.xyz); - vec3 dumbshiny = sunlit_linear * shadow * (texture(lightFunc, vec2(sa, glossiness)).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; - - applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); - } -#else //right implementation ported from pointLightF.glsl if (glossiness > 0.0) { vec3 lv = light_dir.xyz; @@ -395,7 +377,6 @@ void main() // add radiance map applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } -#endif color = mix(color.rgb, legacy_adjust_fullbright(diffcol.rgb), emissive); -- cgit v1.2.3 From db485adbeb1c7a7d64fbddd124f7f4c73214ef99 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Fri, 16 Jun 2023 05:18:22 -0700 Subject: Fix for mac artifacting. Also tweak our vignette to help (further) skip samples we don't need, and for further look and feel adjustments. SL-19784 --- .../class3/deferred/screenSpaceReflUtil.glsl | 41 ++++++++++++++-------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl index b2d1e75d04..f14f7eac8d 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/screenSpaceReflUtil.glsl @@ -36,7 +36,7 @@ uniform mat4 inv_modelview_delta; vec4 getPositionWithDepth(vec2 pos_screen, float depth); -float random (vec2 uv) +float random (vec2 uv) { return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 43758.5453123); //simple random function } @@ -75,7 +75,7 @@ float getLinearDepth(vec2 tc) return -pos.z; } -bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) +bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hitDepth, float depth, sampler2D textureFrame) { // transform position and reflection into same coordinate frame as the sceneMap and sceneDepth reflection += position; @@ -93,22 +93,27 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float bool hit = false; hitColor = vec4(0); - int i = 0; - if (depth > depthRejectBias) + if (depth > depthRejectBias) { - for (; i < iterationCount && !hit; i++) + for (; i < iterationCount && !hit; i++) { screenPosition = generateProjectedPosition(marchingPosition); + if (screenPosition.x > 1 || screenPosition.x < 0 || + screenPosition.y > 1 || screenPosition.y < 0) + { + hit = false; + break; + } depthFromScreen = getLinearDepth(screenPosition); delta = abs(marchingPosition.z) - depthFromScreen; - if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) + if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { break; } - if (abs(delta) < distanceBias) + if (abs(delta) < distanceBias) { vec4 color = vec4(1); if(debugDraw) @@ -118,7 +123,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float hit = true; break; } - if (isBinarySearchEnabled && delta > 0) + if (isBinarySearchEnabled && delta > 0) { break; } @@ -130,7 +135,7 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float step = step * (1.0 - rayStep * max(directionSign, 0.0)); marchingPosition += step * (-directionSign); } - else + else { marchingPosition += step; } @@ -148,15 +153,21 @@ bool traceScreenRay(vec3 position, vec3 reflection, out vec4 hitColor, out float marchingPosition = marchingPosition - step * sign(delta); screenPosition = generateProjectedPosition(marchingPosition); + if (screenPosition.x > 1 || screenPosition.x < 0 || + screenPosition.y > 1 || screenPosition.y < 0) + { + hit = false; + break; + } depthFromScreen = getLinearDepth(screenPosition); delta = abs(marchingPosition.z) - depthFromScreen; - if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) + if (depth < depthFromScreen + epsilon && depth > depthFromScreen - epsilon) { break; } - if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias)) + if (abs(delta) < distanceBias && depthFromScreen != (depth - distanceBias)) { vec4 color = vec4(1); if(debugDraw) @@ -326,8 +337,8 @@ collectedColor = vec4(1, 0, 1, 1); float jitter = mod( c, 1.0); vec2 screenpos = 1 - abs(tc * 2 - 1); - float vignette = clamp((abs(screenpos.x) * abs(screenpos.y)) * 64,0, 1); - vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5) * 16, 0, 1); + float vignette = clamp((abs(screenpos.x) * abs(screenpos.y)) * 16,0, 1); + vignette *= clamp((dot(normalize(viewPos), n) * 0.5 + 0.5) * 5.5 - 0.8, 0, 1); float zFar = 128.0; vignette *= clamp(1.0+(viewPos.z/zFar), 0.0, 1.0); @@ -345,7 +356,7 @@ collectedColor = vec4(1, 0, 1, 1); { if (vignette > 0) { - for (int i = 0; i < totalSamples; i++) + for (int i = 0; i < totalSamples; i++) { vec3 firstBasis = normalize(cross(getPoissonSample(i), rayDirection)); vec3 secondBasis = normalize(cross(rayDirection, firstBasis)); @@ -358,7 +369,7 @@ collectedColor = vec4(1, 0, 1, 1); hitpoint.a = 0; - if (hit) + if (hit) { ++hits; collectedColor += hitpoint; -- cgit v1.2.3 From 36949692b63031f70451317445a1a368efbfcaff Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 28 Jun 2023 11:00:10 -0500 Subject: SL-19842 Nudge dynamic exposure coefficient and soften indirect lighting. --- .../shaders/class3/deferred/reflectionProbeF.glsl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 1b2a34ef01..41821def8e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -364,7 +364,8 @@ return texCUBE(envMap, ReflDirectionWS); // dir - ray direction in clip space // i - probe index in refBox/refSphere // d - distance to nearest wall in clip space -vec3 boxIntersect(vec3 origin, vec3 dir, int i, out float d) +// scale - scale of box, default 1.0 +vec3 boxIntersect(vec3 origin, vec3 dir, int i, out float d, float scale) { // Intersection with OBB convert to unit box space // Transform in local unit parallax cube space (scaled and rotated) @@ -375,7 +376,7 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i, out float d) d = 1.0-max(max(abs(PositionLS.x), abs(PositionLS.y)), abs(PositionLS.z)); - vec3 Unitary = vec3(1.0f, 1.0f, 1.0f); + vec3 Unitary = vec3(scale); vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); @@ -387,6 +388,11 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i, out float d) return IntersectPositionCS; } +vec3 boxIntersect(vec3 origin, vec3 dir, int i, out float d) +{ + return boxIntersect(origin, dir, i, d, 1.0); +} + void debugBoxCol(vec3 ro, vec3 rd, float t, vec3 p, inout vec4 col) { vec3 v = ro + rd * t; @@ -531,7 +537,7 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int if (refIndex[i].w < 0) { float d = 0.0; - v = boxIntersect(pos, dir, i, d); + v = boxIntersect(pos, dir, i, d, 3.0); w = max(d, 0.001); } else -- cgit v1.2.3 From 43cd4e84bc01abcf2820b9557abe761fbf5e8432 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 6 Sep 2023 10:31:03 -0500 Subject: SL-19842 WIP -- Change how probe ambiance mixes with sky ambient. --- .../shaders/class3/deferred/fullbrightShinyF.glsl | 4 +-- .../shaders/class3/deferred/materialF.glsl | 7 +++-- .../shaders/class3/deferred/reflectionProbeF.glsl | 31 ++++++++++++---------- .../shaders/class3/deferred/softenLightF.glsl | 16 +++++------ .../shaders/class3/environment/waterF.glsl | 4 +-- 5 files changed, 32 insertions(+), 30 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index 1537714bb7..54a887262b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -49,7 +49,7 @@ vec3 srgb_to_linear(vec3 c); // reflection probe interface void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent); + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent, vec3 amblit_linear); void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity); @@ -80,7 +80,7 @@ void main() vec3 legacyenv; vec3 norm = normalize(vary_texcoord1.xyz); vec4 spec = vec4(0,0,0,0); - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity, false); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity, false, amblit); color.rgb = legacy_adjust(color.rgb); color.rgb = srgb_to_linear(color.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 82e2de0c0f..319f2f25b7 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -60,7 +60,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); #endif void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent); + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent, vec3 amblit_linear); 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); @@ -339,10 +339,9 @@ void main() vec3 ambenv; vec3 glossenv; vec3 legacyenv; - sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env, true); + sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env, true, amblit_linear); - // use sky settings ambient or irradiance map sample, whichever is brighter - color = max(amblit_linear, ambenv); + color = ambenv; float da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0); vec3 sun_contrib = min(da, shadow) * sunlit_linear; diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 41821def8e..906e66ecc8 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -530,7 +530,7 @@ vec3 tapRefMap(vec3 pos, vec3 dir, out float w, out float dw, float lod, vec3 c, // w - weight of sample (distance and angular attenuation) // dw - weight of sample (distance only) // i - index of probe -vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int i) +vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int i, vec3 amblit) { // parallax adjustment vec3 v; @@ -556,9 +556,12 @@ vec3 tapIrradianceMap(vec3 pos, vec3 dir, out float w, out float dw, vec3 c, int v -= c; v = env_mat * v; - { - return textureLod(irradianceProbes, vec4(v.xyz, refIndex[i].x), 0).rgb * refParams[i].x; - } + + vec3 col = textureLod(irradianceProbes, vec4(v.xyz, refIndex[i].x), 0).rgb * refParams[i].x; + + col = mix(amblit, col, min(refParams[i].x, 1.0)); + + return col; } vec3 sampleProbes(vec3 pos, vec3 dir, float lod) @@ -619,7 +622,7 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod) return col[1]+col[0]; } -vec3 sampleProbeAmbient(vec3 pos, vec3 dir) +vec3 sampleProbeAmbient(vec3 pos, vec3 dir, vec3 amblit) { // modified copy/paste of sampleProbes follows, will likely diverge from sampleProbes further // as irradiance map mixing is tuned independently of radiance map mixing @@ -649,7 +652,7 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) float w = 0; float dw = 0; - vec3 refcol = tapIrradianceMap(pos, dir, w, dw, refSphere[i].xyz, i); + vec3 refcol = tapIrradianceMap(pos, dir, w, dw, refSphere[i].xyz, i, amblit); col[p] += refcol*w; wsum[p] += w; @@ -679,14 +682,14 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir) } void doProbeSample(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit) { // TODO - don't hard code lods float reflection_lods = max_probe_lod; vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - ambenv = sampleProbeAmbient(pos, norm); + ambenv = sampleProbeAmbient(pos, norm, amblit); float lod = (1.0-glossiness)*reflection_lods; glossenv = sampleProbes(pos, normalize(refnormpersp), lod); @@ -712,14 +715,14 @@ void doProbeSample(inout vec3 ambenv, inout vec3 glossenv, } void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent) + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit) { preProbeSample(pos); - doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness, transparent); + doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness, transparent, amblit); } void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness) + vec2 tc, vec3 pos, vec3 norm, float glossiness, vec3 amblit) { // don't sample automatic probes for water sample_automatic = false; @@ -728,7 +731,7 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, // always include void probe on water probeIndex[probeInfluences++] = 0; - doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness, false); + doProbeSample(ambenv, glossenv, tc, pos, norm, glossiness, false, amblit); // fudge factor to get PBR water at a similar luminance ot legacy water glossenv *= 0.4; @@ -783,14 +786,14 @@ vec4 sampleReflectionProbesDebug(vec3 pos) } void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent) + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent, vec3 amblit) { float reflection_lods = max_probe_lod; preProbeSample(pos); vec3 refnormpersp = reflect(pos.xyz, norm.xyz); - ambenv = sampleProbeAmbient(pos, norm); + ambenv = sampleProbeAmbient(pos, norm, amblit); if (glossiness > 0.0) { diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 4ef003e0cb..8b0ea23897 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -69,9 +69,9 @@ vec3 scaleSoftClipFragLinear(vec3 l); // reflection probe interface void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent); + vec2 tc, vec3 pos, vec3 norm, float glossiness, bool transparent, vec3 amblit_linear); void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent); + vec2 tc, vec3 pos, vec3 norm, float glossiness, float envIntensity, bool transparent, vec3 amblit_linear); 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); float getDepth(vec2 pos_screen); @@ -117,10 +117,10 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, vec3 l); //surface point to light -void adjustIrradiance(inout vec3 irradiance, vec3 amblit_linear, float ambocc) +void adjustIrradiance(inout vec3 irradiance, float ambocc) { // use sky settings ambient or irradiance map sample, whichever is brighter - irradiance = max(amblit_linear, irradiance); + //irradiance = max(amblit_linear, irradiance); #if defined(HAS_SSAO) irradiance = mix(ssao_effect_mat * min(irradiance.rgb*ssao_irradiance_scale, vec3(ssao_irradiance_max)), irradiance.rgb, ambocc); @@ -194,9 +194,9 @@ void main() // PBR IBL float gloss = 1.0 - perceptualRoughness; - sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss, false); + sampleReflectionProbes(irradiance, radiance, tc, pos.xyz, norm.xyz, gloss, false, amblit_linear); - adjustIrradiance(irradiance, amblit_linear, ambocc); + adjustIrradiance(irradiance, ambocc); vec3 diffuseColor; vec3 specularColor; @@ -232,9 +232,9 @@ void main() vec3 glossenv = vec3(0); vec3 legacyenv = vec3(0); - sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity, false); + sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, tc, pos.xyz, norm.xyz, spec.a, envIntensity, false, amblit_linear); - adjustIrradiance(irradiance, amblit_linear, ambocc); + adjustIrradiance(irradiance, ambocc); // apply lambertian IBL only (see pbrIbl) color.rgb = irradiance; diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 8fee259933..4f79dd1ac5 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -124,7 +124,7 @@ vec3 transform_normal(vec3 vNt) } void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv, - vec2 tc, vec3 pos, vec3 norm, float glossiness); + vec2 tc, vec3 pos, vec3 norm, float glossiness, vec3 amblit_linear); vec3 getPositionWithNDC(vec3 ndc); @@ -237,7 +237,7 @@ void main() vec3 irradiance = vec3(0); vec3 radiance = vec3(0); - sampleReflectionProbesWater(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss); + sampleReflectionProbesWater(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss, amblit); irradiance = vec3(0); -- cgit v1.2.3 From 478703e3c82df7b5751d80007264468bf44cb379 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 11 Oct 2023 14:20:47 -0500 Subject: SL-20440 Fix for projector ambiance destroying PBR shading. Also fix longstanding bug with hard line in projector ambiance lighting. Incidental decruft of legacy_adjust and LOCAL_LIGHT_KILL, etc. --- .../shaders/class3/deferred/fullbrightShinyF.glsl | 6 +- .../shaders/class3/deferred/materialF.glsl | 5 +- .../shaders/class3/deferred/multiPointLightF.glsl | 6 - .../shaders/class3/deferred/multiSpotLightF.glsl | 263 --------------------- .../shaders/class3/deferred/pointLightF.glsl | 2 - .../shaders/class3/deferred/softenLightF.glsl | 3 - .../shaders/class3/deferred/spotLightF.glsl | 106 ++++----- 7 files changed, 46 insertions(+), 345 deletions(-) delete mode 100644 indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl index 54a887262b..5483a4e29c 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl @@ -40,8 +40,6 @@ in vec3 vary_position; uniform samplerCube environmentMap; vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); -vec3 legacy_adjust_fullbright(vec3 c); -vec3 legacy_adjust(vec3 c); void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec3 linear_to_srgb(vec3 c); @@ -82,10 +80,8 @@ void main() vec4 spec = vec4(0,0,0,0); sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, vec2(0), pos.xyz, norm.xyz, spec.a, env_intensity, false, amblit); - color.rgb = legacy_adjust(color.rgb); color.rgb = srgb_to_linear(color.rgb); - color.rgb = legacy_adjust_fullbright(color.rgb); - + applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); color.rgb = atmosFragLighting(color.rgb, additive, atten); #endif diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index 319f2f25b7..acff03ec4b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -48,8 +48,6 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); -vec3 legacy_adjust(vec3 c); -vec3 legacy_adjust_fullbright(vec3 c); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -311,7 +309,6 @@ void main() #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) //forward rendering, output lit linear color - diffcol.rgb = legacy_adjust(diffcol.rgb); diffcol.rgb = srgb_to_linear(diffcol.rgb); spec.rgb = srgb_to_linear(spec.rgb); spec.a = glossiness; // pack glossiness into spec alpha for lighting functions @@ -377,7 +374,7 @@ void main() applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } - color = mix(color.rgb, legacy_adjust_fullbright(diffcol.rgb), emissive); + color = mix(color.rgb, diffcol.rgb, emissive); if (env > 0.0) { // add environmentmap diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 2a096a98ec..dbccfa8597 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -52,7 +52,6 @@ vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensi vec2 getScreenXY(vec4 clip); vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); -vec3 legacy_adjust(vec3 c); // Util vec3 hue_to_rgb(float hue); @@ -67,9 +66,6 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, void main() { -#if defined(LOCAL_LIGHT_KILL) - discard; // Bail immediately -#else vec3 final_color = vec3(0, 0, 0); vec2 tc = getScreenCoord(vary_fragcoord); vec3 pos = getPosition(tc).xyz; @@ -126,7 +122,6 @@ void main() } else { - diffuse.rgb = legacy_adjust(diffuse.rgb); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); @@ -174,7 +169,6 @@ void main() frag_color.rgb = max(final_color, vec3(0)); frag_color.a = 0.0; -#endif // LOCAL_LIGHT_KILL #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 diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl deleted file mode 100644 index 23120bbbbe..0000000000 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ /dev/null @@ -1,263 +0,0 @@ -/** - * @file class3\deferred\multiSpotLightF.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 sampler2D diffuseRect; -uniform sampler2D specularRect; -uniform sampler2D depthMap; -uniform sampler2D normalMap; -uniform sampler2D emissiveRect; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl -uniform samplerCube environmentMap; -uniform sampler2D lightMap; -uniform sampler2D projectionMap; // rgba -uniform sampler2D lightFunc; - -uniform mat4 proj_mat; //screen space to light space -uniform float proj_near; //near clip for projection -uniform vec3 proj_p; //plane projection is emitting from (in screen space) -uniform vec3 proj_n; -uniform float proj_focus; //distance from plane to begin blurring -uniform float proj_lod; //(number of mips in proj map) -uniform float proj_range; //range between near clip and far clip plane of projection -uniform float proj_ambient_lod; -uniform float proj_ambiance; -uniform float near_clip; -uniform float far_clip; - -uniform vec3 proj_origin; //origin of projection to be used for angular attenuation -uniform float sun_wash; -uniform int proj_shadow_idx; -uniform float shadow_fade; - -// Light params -uniform vec3 center; -uniform float size; -uniform vec3 color; -uniform float falloff; - -in vec4 vary_fragcoord; -uniform vec2 screen_res; - -uniform mat4 inv_proj; - -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); -float calcLegacyDistanceAttenuation(float distance, float falloff); -vec3 colorized_dot(float x); -bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); -vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); -vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv); -vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); -vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); -vec2 getScreenXY(vec4 clip); -vec2 getScreenCoord(vec4 clip); -vec3 srgb_to_linear(vec3 cs); -vec3 legacy_adjust(vec3 c); -vec4 texture2DLodSpecular(vec2 tc, float lod); - -vec4 getPosition(vec2 pos_screen); - -const float M_PI = 3.14159265; - -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 - -void main() -{ -#if defined(LOCAL_LIGHT_KILL) - discard; -#else - vec3 final_color = vec3(0,0,0); - vec2 tc = getScreenCoord(vary_fragcoord); - vec3 pos = getPosition(tc).xyz; - - vec3 lv; - vec4 proj_tc; - float dist, l_dist; - if (clipProjectedLightVars(center, pos, dist, l_dist, lv, proj_tc)) - { - discard; - } - - float shadow = 1.0; - - if (proj_shadow_idx >= 0) - { - vec4 shd = texture(lightMap, tc); - shadow = (proj_shadow_idx==0)?shd.b:shd.a; - shadow += shadow_fade; - shadow = clamp(shadow, 0.0, 1.0); - } - - float envIntensity; - vec3 n; - vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); - - float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); - if (dist_atten <= 0.0) - { - discard; - } - - lv = proj_origin-pos.xyz; - vec3 h, l, v = -normalize(pos); - float nh, nl, nv, vh, lightDist; - calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); - - vec3 diffuse = texture(diffuseRect, tc).rgb; - vec4 spec = texture(specularRect, tc); - vec3 dlit = vec3(0, 0, 0); - vec3 slit = vec3(0, 0, 0); - - vec3 amb_rgb = vec3(0); - - if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) - { - vec3 colorEmissive = texture(emissiveRect, tc).rgb; - vec3 orm = spec.rgb; - float perceptualRoughness = orm.g; - float metallic = orm.b; - vec3 f0 = vec3(0.04); - vec3 baseColor = diffuse.rgb; - - vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0); - diffuseColor *= 1.0 - metallic; - - vec3 specularColor = mix(f0, baseColor.rgb, metallic); - - // We need this additional test inside a light's frustum since a spotlight's ambiance can be applied - if (proj_tc.x > 0.0 && proj_tc.x < 1.0 - && proj_tc.y > 0.0 && proj_tc.y < 1.0) - { - float lit = 0.0; - float amb_da = 0.0; - - if (nl > 0.0) - { - amb_da += (nl*0.5 + 0.5) * proj_ambiance; - - dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - - vec3 intensity = dist_atten * dlit * 3.9 * shadow; // Legacy attenuation, magic number to balance with legacy materials - final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); - } - - amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); - final_color += diffuse.rgb * amb_rgb; - } - } - else - { - diffuse = legacy_adjust(diffuse); - diffuse = srgb_to_linear(diffuse); - spec.rgb = srgb_to_linear(spec.rgb); - - if (proj_tc.z > 0.0 && - proj_tc.x < 1.0 && - proj_tc.y < 1.0 && - proj_tc.x > 0.0 && - proj_tc.y > 0.0) - { - float amb_da = 0; - float lit = 0.0; - - if (nl > 0.0) - { - lit = nl * dist_atten; - - dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - - final_color = dlit*lit*diffuse*shadow; - - // unshadowed for consistency between forward and deferred? - amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; - } - - amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); - final_color += diffuse.rgb * amb_rgb; - } - - if (spec.a > 0.0) - { - dlit *= min(nl*6.0, 1.0) * dist_atten; - - float fres = pow(1 - vh, 5)*0.4+0.5; - - float gtdenom = 2 * nh; - float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh)); - - if (nh > 0.0) - { - float scol = fres*texture(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); - vec3 speccol = dlit*scol*spec.rgb*shadow; - speccol = clamp(speccol, vec3(0), vec3(1)); - final_color += speccol; - } - } - - if (envIntensity > 0.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 ds = dot(ref, proj_n); - - if (ds < 0.0) - { - vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - - vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); - - if (stc.z > 0.0) - { - stc /= stc.w; - - if (stc.x < 1.0 && - stc.y < 1.0 && - stc.x > 0.0 && - stc.y > 0.0) - { - final_color += color.rgb * texture2DLodSpecular(stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity; - } - } - } - } - } - - //not sure why, but this line prevents MATBUG-194 - final_color = max(final_color, vec3(0.0)); - - //output linear - frag_color.rgb = final_color; - frag_color.a = 0.0; -#endif // LOCAL_LIGHT_KILL -} diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 42ba96148c..210e944e45 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -57,7 +57,6 @@ vec4 getPosition(vec2 pos_screen); vec2 getScreenXY(vec4 clip); vec2 getScreenCoord(vec4 clip); vec3 srgb_to_linear(vec3 c); -vec3 legacy_adjust(vec3 c); float getDepth(vec2 tc); vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, @@ -116,7 +115,6 @@ void main() { discard; } - diffuse = legacy_adjust(diffuse); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8b0ea23897..35e99c5bd2 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -78,7 +78,6 @@ float getDepth(vec2 pos_screen); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); -vec3 legacy_adjust(vec3 c); uniform vec4 waterPlane; @@ -220,8 +219,6 @@ void main() else { // legacy shaders are still writng sRGB to gbuffer - baseColor.rgb = legacy_adjust(baseColor.rgb); - baseColor.rgb = srgb_to_linear(baseColor.rgb); spec.rgb = srgb_to_linear(spec.rgb); diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 1ea801d7d7..357f3b6e3b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -25,16 +25,6 @@ /*[EXTRA_CODE_HERE]*/ -#define DEBUG_ANY_LIGHT_TYPE 0 // Output green light cone -#define DEBUG_LEG_LIGHT_TYPE 0 // Show Legacy objects in green -#define DEBUG_PBR_LIGHT_TYPE 0 // Show PBR objects in green -#define DEBUG_PBR_SPOT 0 -#define DEBUG_PBR_SPOT_DIFFUSE 0 -#define DEBUG_PBR_SPOT_SPECULAR 0 - -#define DEBUG_SPOT_NL 0 // monochome area effected by light -#define DEBUG_SPOT_ZERO 0 // Output zero for spotlight - out vec4 frag_color; uniform sampler2D diffuseRect; @@ -64,11 +54,16 @@ uniform float sun_wash; uniform int proj_shadow_idx; uniform float shadow_fade; +// Light params +#if defined(MULTI_SPOTLIGHT) +uniform vec3 center; +#else +in vec3 trans_center; +#endif uniform float size; uniform vec3 color; uniform float falloff; -in vec3 trans_center; in vec4 vary_fragcoord; uniform vec2 screen_res; @@ -80,11 +75,8 @@ bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_d vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv); vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); -vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); -vec2 getScreenXY(vec4 clip_point); -vec2 getScreenCoord(vec4 clip_point); -vec3 srgb_to_linear(vec3 c); -vec3 legacy_adjust(vec3 c); +vec2 getScreenCoord(vec4 clip); +vec3 srgb_to_linear(vec3 cs); vec4 texture2DLodSpecular(vec2 tc, float lod); vec4 getPosition(vec2 pos_screen); @@ -100,9 +92,6 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, void main() { -#if defined(LOCAL_LIGHT_KILL) - discard; -#else vec3 final_color = vec3(0,0,0); vec2 tc = getScreenCoord(vary_fragcoord); vec3 pos = getPosition(tc).xyz; @@ -110,24 +99,31 @@ void main() vec3 lv; vec4 proj_tc; float dist, l_dist; - if (clipProjectedLightVars(trans_center, pos, dist, l_dist, lv, proj_tc)) + vec3 c; +#if defined(MULTI_SPOTLIGHT) + c = center; +#else + c = trans_center; +#endif + + if (clipProjectedLightVars(c, pos, dist, l_dist, lv, proj_tc)) { discard; } float shadow = 1.0; - + if (proj_shadow_idx >= 0) { vec4 shd = texture(lightMap, tc); - shadow = (proj_shadow_idx == 0) ? shd.b : shd.a; + shadow = (proj_shadow_idx==0)?shd.b:shd.a; shadow += shadow_fade; - shadow = clamp(shadow, 0.0, 1.0); + shadow = clamp(shadow, 0.0, 1.0); } float envIntensity; vec3 n; - vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() + vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); if (dist_atten <= 0.0) @@ -135,7 +131,7 @@ void main() discard; } - lv = proj_origin-pos.xyz; // NOTE: Re-using lv + lv = proj_origin-pos.xyz; vec3 h, l, v = -normalize(pos); float nh, nl, nv, vh, lightDist; calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); @@ -146,10 +142,11 @@ void main() vec3 slit = vec3(0, 0, 0); vec3 amb_rgb = vec3(0); + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { - vec3 colorEmissive = texture(emissiveRect, tc).rgb; - vec3 orm = spec.rgb; + vec3 colorEmissive = texture(emissiveRect, tc).rgb; + vec3 orm = spec.rgb; float perceptualRoughness = orm.g; float metallic = orm.b; vec3 f0 = vec3(0.04); @@ -173,27 +170,27 @@ void main() dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - vec3 intensity = dist_atten * dlit * 3.9 * shadow; // Legacy attenuation - final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); + vec3 intensity = dist_atten * dlit * 3.9 * shadow; // Legacy attenuation, magic number to balance with legacy materials + lv = normalize(lv); + final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); } amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); - final_color += diffuse.rgb * amb_rgb; + final_color += amb_rgb * pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, -lv); } } else { - diffuse = legacy_adjust(diffuse); diffuse = srgb_to_linear(diffuse); spec.rgb = srgb_to_linear(spec.rgb); - + if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && proj_tc.y < 1.0 && proj_tc.x > 0.0 && proj_tc.y > 0.0) { - float amb_da = proj_ambiance; + float amb_da = 0; float lit = 0.0; if (nl > 0.0) @@ -204,24 +201,23 @@ void main() final_color = dlit*lit*diffuse*shadow; + // unshadowed for consistency between forward and deferred? amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } - - vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); - final_color += diffuse.rgb*amb_rgb; - #if DEBUG_LEG_LIGHT_TYPE - final_color = vec3(0,0.5,0); - #endif + + amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); + final_color += diffuse.rgb * amb_rgb * max(dot(-normalize(lv), n), 0.0); } - + if (spec.a > 0.0) { dlit *= min(nl*6.0, 1.0) * dist_atten; - float fres = pow(1 - dot(h, v), 5)*0.4+0.5; + + float fres = pow(1 - vh, 5)*0.4+0.5; float gtdenom = 2 * nh; float gt = max(0, min(gtdenom * nv / vh, gtdenom * nl / vh)); - + if (nh > 0.0) { float scol = fres*texture(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); @@ -229,26 +225,26 @@ void main() speccol = clamp(speccol, vec3(0), vec3(1)); final_color += speccol; } - } + } if (envIntensity > 0.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 ds = dot(ref, proj_n); - + if (ds < 0.0) { vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; - + vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); if (stc.z > 0.0) { stc /= stc.w; - + if (stc.x < 1.0 && stc.y < 1.0 && stc.x > 0.0 && @@ -261,24 +257,10 @@ void main() } } -#if DEBUG_PBR_SPOT_DIFFUSE - final_color = vec3(nl * dist_atten); -#endif -#if DEBUG_SPOT_NL - final_color = vec3(nl); -#endif -#if DEBUG_SPOT_ZERO - final_color = vec3(0,0,0); -#endif -#if DEBUG_ANY_LIGHT_TYPE - final_color = vec3(0,0.3333,0); -#endif - //not sure why, but this line prevents MATBUG-194 final_color = max(final_color, vec3(0.0)); - //output linear colors as gamma correction happens down stream + //output linear frag_color.rgb = final_color; frag_color.a = 0.0; -#endif // LOCAL_LIGHT_KILL } -- cgit v1.2.3 From ede7b04f87806278ab7615f90958b9e7b2ff9584 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 11 Oct 2023 15:25:43 -0500 Subject: SL-20440 Followup -- fix for non-normalized vector and balance PBR spotlight with legacy spotlight --- indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 357f3b6e3b..d31b37fb60 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -164,18 +164,19 @@ void main() float lit = 0.0; float amb_da = 0.0; + lv = normalize(lv); + if (nl > 0.0) { amb_da += (nl*0.5 + 0.5) * proj_ambiance; dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - vec3 intensity = dist_atten * dlit * 3.9 * shadow; // Legacy attenuation, magic number to balance with legacy materials - lv = normalize(lv); + vec3 intensity = dist_atten * dlit * 3.25 * shadow; // Legacy attenuation, magic number to balance with legacy materials final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); } - amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); + amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ) * 3.25; //magic number to balance with legacy ambiance final_color += amb_rgb * pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, -lv); } } -- cgit v1.2.3 From 0d47ea31e38601683ef7351300950ec075cc35dd Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 11 Oct 2023 15:55:12 -0500 Subject: SL-20440 Followup -- balance PBR point light with legacy point light --- .../newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl | 2 +- indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index dbccfa8597..ec8168465e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -114,7 +114,7 @@ void main() float dist_atten = calcLegacyDistanceAttenuation(dist, falloff); - vec3 intensity = dist_atten * lightColor * 3.9; + vec3 intensity = dist_atten * lightColor * 3.25; final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, lv); } diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 210e944e45..31af1208bd 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -106,7 +106,7 @@ void main() vec3 specularColor = mix(f0, baseColor.rgb, metallic); - vec3 intensity = dist_atten * color * 3.9; // Legacy attenuation, magic number to balance with legacy materials + vec3 intensity = dist_atten * color * 3.25; // Legacy attenuation, magic number to balance with legacy materials final_color += intensity*pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, n.xyz, v, normalize(lv)); } else -- cgit v1.2.3 From 3ea1faf73cfc77c6e6213121e8afe4b101a6e4a6 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Tue, 24 Oct 2023 16:53:27 -0700 Subject: SL-20065: Hack to reduce black spots on shiny water --- indra/newview/app_settings/shaders/class3/environment/waterF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class3') diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl index 4f79dd1ac5..ddade462be 100644 --- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl @@ -280,7 +280,7 @@ void main() f = clamp(f, 0, 1); - color = mix(color, fb.rgb, f); + color = ((1.0 - f) * color) + fb.rgb; color = atmosFragLightingLinear(color, additive, atten); -- cgit v1.2.3