From 3553fec2084b8be3f3de86cec293c1e363c1388e Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:57:10 -0700 Subject: DRTVWR-592: (WIP) Separate code path for terrain rendering and shaders. Just copy/paste for now. Use same draw pool --- .../shaders/class1/deferred/pbrterrainF.glsl | 61 +++++++++++++++++ .../shaders/class1/deferred/pbrterrainV.glsl | 77 ++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl create mode 100644 indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl new file mode 100644 index 0000000000..96903aeba8 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -0,0 +1,61 @@ +/** + * @file class1\deferred\terrainF.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +out vec4 frag_data[4]; + +uniform sampler2D detail_0; +uniform sampler2D detail_1; +uniform sampler2D detail_2; +uniform sampler2D detail_3; +uniform sampler2D alpha_ramp; + +in vec3 pos; +in vec3 vary_normal; +in vec4 vary_texcoord0; +in vec4 vary_texcoord1; + +vec2 encode_normal(vec3 n); + +void main() +{ + vec4 color0 = texture2D(detail_0, vary_texcoord0.xy); + vec4 color1 = texture2D(detail_1, vary_texcoord0.xy); + vec4 color2 = texture2D(detail_2, vary_texcoord0.xy); + vec4 color3 = texture2D(detail_3, vary_texcoord0.xy); + + float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; + float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; + float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; + vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); + + outColor.a = 0.0; // yes, downstream atmospherics + + frag_data[0] = outColor; + frag_data[1] = vec4(0.0,0.0,0.0,-1.0); + vec3 nvn = normalize(vary_normal); + frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl new file mode 100644 index 0000000000..e8747a1f6b --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -0,0 +1,77 @@ +/** + * @file class1\environment\pbrterrainV.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +uniform mat3 normal_matrix; +uniform mat4 texture_matrix0; +uniform mat4 modelview_projection_matrix; + +in vec3 position; +in vec3 normal; +in vec4 diffuse_color; +in vec2 texcoord0; +in vec2 texcoord1; + +out vec3 pos; +out vec3 vary_normal; +out vec4 vary_texcoord0; +out vec4 vary_texcoord1; + +uniform vec4 object_plane_s; +uniform vec4 object_plane_t; + +vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) +{ + vec4 tcoord; + + tcoord.x = dot(vpos, tp0); + tcoord.y = dot(vpos, tp1); + tcoord.z = tc.z; + tcoord.w = tc.w; + + tcoord = mat * tcoord; + + return tcoord; +} + +void main() +{ + //transform vertex + vec4 pre_pos = vec4(position.xyz, 1.0); + vec4 t_pos = modelview_projection_matrix * pre_pos; + + gl_Position = t_pos; + pos = t_pos.xyz; + + vary_normal = normalize(normal_matrix * normal); + + // Transform and pass tex coords + vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; + + vec4 t = vec4(texcoord1,0,1); + + vary_texcoord0.zw = t.xy; + vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); + vary_texcoord1.zw = t.xy-vec2(1.0, 0.0); +} -- cgit v1.2.3 From 49a5b79c2b1ba5f4b909d1bfab89bb7ad9c1e888 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:57:24 -0700 Subject: DRTVWR-592: (WIP) Debugging, rethinking --- .../newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 3 +++ .../newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl | 7 +++++++ 2 files changed, 10 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 96903aeba8..2426199056 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -33,6 +33,8 @@ uniform sampler2D alpha_ramp; in vec3 pos; in vec3 vary_normal; +in vec3 vary_tangent; // TODO: Decide if we want to keep this +flat in float vary_sign; // TODO: Decide if we want to keep this in vec4 vary_texcoord0; in vec4 vary_texcoord1; @@ -53,6 +55,7 @@ void main() outColor.a = 0.0; // yes, downstream atmospherics frag_data[0] = outColor; + frag_data[0] = vec4((0.5 * (1.0 + vary_sign)) * vary_tangent.xyz, 1.0); // TODO: Remove frag_data[1] = vec4(0.0,0.0,0.0,-1.0); vec3 nvn = normalize(vary_normal); frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index e8747a1f6b..fcc4448a80 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -29,15 +29,20 @@ uniform mat4 modelview_projection_matrix; in vec3 position; in vec3 normal; +in vec4 tangent; in vec4 diffuse_color; in vec2 texcoord0; in vec2 texcoord1; out vec3 pos; out vec3 vary_normal; +out vec3 vary_tangent; // TODO: Decide if we want to keep this +flat out float vary_sign; // TODO: Decide if we want to keep this out vec4 vary_texcoord0; out vec4 vary_texcoord1; +out vec4 debug_tangent; // TODO: Remove + uniform vec4 object_plane_s; uniform vec4 object_plane_t; @@ -65,6 +70,8 @@ void main() pos = t_pos.xyz; vary_normal = normalize(normal_matrix * normal); + vary_tangent = normalize(normal_matrix * tangent.xyz); // TODO: Decide if we want to keep this + vary_sign = tangent.w; // TODO: Decide if we want to keep this // Transform and pass tex coords vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; -- cgit v1.2.3 From 7376b3e4b9c03f3ff3aa0c431c66916ac655a692 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:57:40 -0700 Subject: DRTVWR-592: (WIP) (does not run) PBR terrain rendering - begin work on shaders, uniforms --- .../shaders/class1/deferred/pbrterrainF.glsl | 142 ++++++++++++++++++--- .../shaders/class1/deferred/pbrterrainV.glsl | 21 ++- 2 files changed, 130 insertions(+), 33 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 2426199056..f355b8ef98 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -25,40 +25,140 @@ out vec4 frag_data[4]; -uniform sampler2D detail_0; -uniform sampler2D detail_1; -uniform sampler2D detail_2; -uniform sampler2D detail_3; uniform sampler2D alpha_ramp; -in vec3 pos; +// TODO: Bind the right textures and uniforms during shader setup +// *TODO: Configurable quality level which disables PBR features on machines +// with limited texture availability +// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#additional-textures +uniform sampler2D detail_0_base_color; +uniform sampler2D detail_1_base_color; +uniform sampler2D detail_2_base_color; +uniform sampler2D detail_3_base_color; +uniform sampler2D detail_0_normal; +uniform sampler2D detail_1_normal; +uniform sampler2D detail_2_normal; +uniform sampler2D detail_3_normal; +uniform sampler2D detail_0_metallic_roughness; +uniform sampler2D detail_1_metallic_roughness; +uniform sampler2D detail_2_metallic_roughness; +uniform sampler2D detail_3_metallic_roughness; +uniform sampler2D detail_0_emissive; +uniform sampler2D detail_1_emissive; +uniform sampler2D detail_2_emissive; +uniform sampler2D detail_3_emissive; + +// TODO: Needs new uniforms +// *TODO: More efficient packing? +uniform vec4 metallicFactors; +uniform vec4 roughnessFactors; +uniform vec3[4] emissiveColors; +uniform vec4 minimum_alphas; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() + in vec3 vary_normal; -in vec3 vary_tangent; // TODO: Decide if we want to keep this -flat in float vary_sign; // TODO: Decide if we want to keep this +in vec3 vary_tangent; +flat in float vary_sign; in vec4 vary_texcoord0; in vec4 vary_texcoord1; vec2 encode_normal(vec3 n); +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); -void main() +// TODO: This mixing function feels like it can be optimized. The terrain code's use of texcoord1 is dubious. It feels like the same thing can be accomplished with less memory bandwidth by calculating the offsets on-the-fly +float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) +{ + return mix( mix(samples.w, samples.z, alpha2), mix(samples.y, samples.x, alpha1), alphaFinal ); +} + +vec3 terrain_mix(vec3[4] samples, float alpha1, float alpha2, float alphaFinal) +{ + return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); +} + +vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) +{ + return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); +} + +vec4 sample_and_mix_color(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + vec4[4] samples; + samples[0] = srgb_to_linear(texture2D(tex0, texcoord)); + samples[1] = srgb_to_linear(texture2D(tex1, texcoord)); + samples[2] = srgb_to_linear(texture2D(tex2, texcoord)); + samples[3] = srgb_to_linear(texture2D(tex3, texcoord)); + return terrain_mix(samples, alpha1, alpha2, alphaFinal); +} + +vec4 sample_and_mix_vector(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - vec4 color0 = texture2D(detail_0, vary_texcoord0.xy); - vec4 color1 = texture2D(detail_1, vary_texcoord0.xy); - vec4 color2 = texture2D(detail_2, vary_texcoord0.xy); - vec4 color3 = texture2D(detail_3, vary_texcoord0.xy); + vec4[4] samples; + samples[0] = texture2D(tex0, texcoord); + samples[1] = texture2D(tex1, texcoord); + samples[2] = texture2D(tex2, texcoord); + samples[3] = texture2D(tex3, texcoord); + return terrain_mix(samples, alpha1, alpha2, alphaFinal); +} +// TODO: Implement +// TODO: Don't forget calls to srgb_to_linear during texture sampling +// TODO: Wherever base color alpha is not 1.0, blend with black +void main() +{ float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; - vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal ); - - outColor.a = 0.0; // yes, downstream atmospherics + + vec4 base_color = sample_and_mix_color(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_basecolor, detail_1_basecolor, detail_2_basecolor, detail_3_basecolor); + vec4 normal_texture = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); + vec4 metallic_roughness = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); + vec4 emissive_texture = sample_and_mix_color(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); + + float metallicFactor = terrain_mix(metallicFactors, alpha1, alpha2, alphaFinal); + float roughnessFactor = terrain_mix(roughnessFactors, alpha1, alpha2, alphaFinal); + vec3 emissiveColor = terrain_mix(emissiveColors, alpha1, alpha2, alphaFinal); + float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); + + // TODO: OOh, we need blending for every GLTF uniform too + // TODO: Unfork + if (base_color.a < minimum_alpha) + { + base_color.rgb *= vec3(0.0); + } + + vec3 col = base_color.rgb; + + // from mikktspace.com + vec3 vNt = normal_texture.xyz*2.0-1.0; + float sign = vary_sign; + vec3 vN = vary_normal; + vec3 vT = vary_tangent.xyz; + + vec3 vB = sign * cross(vN, vT); + vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); + + // RGB = Occlusion, Roughness, Metal + // default values, see LLViewerTexture::sDefaultPBRORMImagep + // occlusion 1.0 + // roughness 0.0 + // metal 0.0 + vec3 spec = metallic_roughness.rgb; - frag_data[0] = outColor; - frag_data[0] = vec4((0.5 * (1.0 + vary_sign)) * vary_tangent.xyz, 1.0); // TODO: Remove - frag_data[1] = vec4(0.0,0.0,0.0,-1.0); - vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); - frag_data[3] = vec4(0); + spec.g *= roughness_factor; + spec.b *= metallic_factor; + + vec3 emissive = emssive_color; + emissive *= emissive_texture.rgb; + + tnorm *= gl_FrontFacing ? 1.0 : -1.0; + + + frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse + // TODO: What is packed into vertex_color.a? + frag_data[1] = max(vec4(spec.rgb,vertex_color.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. + // TODO: What is environment intensity and do we want it? + frag_data[2] = max(vec4(encode_normal(tnorm), 0.0, GBUFFER_FLAG_HAS_PBR | GBUFFER_FLAG_HAS_ATMOS), vec4(0)); // normal, environment intensity, flags + frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index fcc4448a80..cbfe9f3ea5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -34,15 +34,12 @@ in vec4 diffuse_color; in vec2 texcoord0; in vec2 texcoord1; -out vec3 pos; out vec3 vary_normal; -out vec3 vary_tangent; // TODO: Decide if we want to keep this -flat out float vary_sign; // TODO: Decide if we want to keep this +out vec3 vary_tangent; +flat out float vary_sign; out vec4 vary_texcoord0; out vec4 vary_texcoord1; -out vec4 debug_tangent; // TODO: Remove - uniform vec4 object_plane_s; uniform vec4 object_plane_t; @@ -63,17 +60,17 @@ vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) void main() { //transform vertex - vec4 pre_pos = vec4(position.xyz, 1.0); - vec4 t_pos = modelview_projection_matrix * pre_pos; + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - gl_Position = t_pos; - pos = t_pos.xyz; + vec3 n = normal_matrix * normal; + vec3 t = normal_matrix * tangent.xyz; - vary_normal = normalize(normal_matrix * normal); - vary_tangent = normalize(normal_matrix * tangent.xyz); // TODO: Decide if we want to keep this - vary_sign = tangent.w; // TODO: Decide if we want to keep this + vary_tangent = normalize(t); + vary_sign = tangent.w; + vary_normal = normalize(n); // Transform and pass tex coords + // *NOTE: KHR texture transform is ignored for now vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; vec4 t = vec4(texcoord1,0,1); -- cgit v1.2.3 From a7cd5f6ef9d80e77eaf87cfc605d32605f0916f1 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:57:48 -0700 Subject: DRTVWR-592: (WIP) (does not run) PBR terrain rendering - more work on shaders, uniforms --- .../shaders/class1/deferred/pbrterrainF.glsl | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index f355b8ef98..4a0b324558 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -48,8 +48,8 @@ uniform sampler2D detail_1_emissive; uniform sampler2D detail_2_emissive; uniform sampler2D detail_3_emissive; -// TODO: Needs new uniforms // *TODO: More efficient packing? +uniform vec4[4] baseColorFactors; // See also vertex_color in pbropaqueV.glsl uniform vec4 metallicFactors; uniform vec4 roughnessFactors; uniform vec3[4] emissiveColors; @@ -101,9 +101,6 @@ vec4 sample_and_mix_vector(float alpha1, float alpha2, float alphaFinal, vec2 te return terrain_mix(samples, alpha1, alpha2, alphaFinal); } -// TODO: Implement -// TODO: Don't forget calls to srgb_to_linear during texture sampling -// TODO: Wherever base color alpha is not 1.0, blend with black void main() { float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; @@ -111,23 +108,22 @@ void main() float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; vec4 base_color = sample_and_mix_color(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_basecolor, detail_1_basecolor, detail_2_basecolor, detail_3_basecolor); + float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); + if (base_color.a < minimum_alpha) + { + discard; + } + vec4 normal_texture = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); vec4 metallic_roughness = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); vec4 emissive_texture = sample_and_mix_color(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); + vec4 baseColorFactor = terrain_mix(baseColorFactors, alpha1, alpha2, alphaFinal); float metallicFactor = terrain_mix(metallicFactors, alpha1, alpha2, alphaFinal); float roughnessFactor = terrain_mix(roughnessFactors, alpha1, alpha2, alphaFinal); vec3 emissiveColor = terrain_mix(emissiveColors, alpha1, alpha2, alphaFinal); - float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); - - // TODO: OOh, we need blending for every GLTF uniform too - // TODO: Unfork - if (base_color.a < minimum_alpha) - { - base_color.rgb *= vec3(0.0); - } - vec3 col = base_color.rgb; + vec3 col = baseColorFactor.rgb * srgb_to_linear(basecolor.rgb); // from mikktspace.com vec3 vNt = normal_texture.xyz*2.0-1.0; @@ -155,10 +151,8 @@ void main() frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse - // TODO: What is packed into vertex_color.a? - frag_data[1] = max(vec4(spec.rgb,vertex_color.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - // TODO: What is environment intensity and do we want it? - frag_data[2] = max(vec4(encode_normal(tnorm), 0.0, GBUFFER_FLAG_HAS_PBR | GBUFFER_FLAG_HAS_ATMOS), vec4(0)); // normal, environment intensity, flags + frag_data[1] = max(vec4(spec.rgb,baseColorFactor.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. + frag_data[2] = max(vec4(encode_normal(tnorm), baseColorFactor.a, GBUFFER_FLAG_HAS_PBR | GBUFFER_FLAG_HAS_ATMOS), vec4(0)); // normal, environment intensity, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } -- cgit v1.2.3 From 5d046d8835563fcad9e8dcf948d889d9ccec41d7 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:57:57 -0700 Subject: DRTVWR-592: (WIP) (does not work) PBR terrain rendering - compiles, but doesn't render properly just yet --- .../shaders/class1/deferred/pbrterrainF.glsl | 41 ++++++++++++++-------- .../shaders/class1/deferred/pbrterrainV.glsl | 8 ++--- 2 files changed, 31 insertions(+), 18 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 4a0b324558..60e5776bc6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -27,7 +27,6 @@ out vec4 frag_data[4]; uniform sampler2D alpha_ramp; -// TODO: Bind the right textures and uniforms during shader setup // *TODO: Configurable quality level which disables PBR features on machines // with limited texture availability // https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#additional-textures @@ -65,7 +64,7 @@ vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); -// TODO: This mixing function feels like it can be optimized. The terrain code's use of texcoord1 is dubious. It feels like the same thing can be accomplished with less memory bandwidth by calculating the offsets on-the-fly +// *TODO: This mixing function feels like it can be optimized. The terrain code's use of texcoord1 is dubious. It feels like the same thing can be accomplished with less memory bandwidth by calculating the offsets on-the-fly float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) { return mix( mix(samples.w, samples.z, alpha2), mix(samples.y, samples.x, alpha1), alphaFinal ); @@ -81,13 +80,27 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); } -vec4 sample_and_mix_color(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + vec3[4] samples; + samples[0] = srgb_to_linear(texture2D(tex0, texcoord).xyz); + samples[1] = srgb_to_linear(texture2D(tex1, texcoord).xyz); + samples[2] = srgb_to_linear(texture2D(tex2, texcoord).xyz); + samples[3] = srgb_to_linear(texture2D(tex3, texcoord).xyz); + return terrain_mix(samples, alpha1, alpha2, alphaFinal); +} + +vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec4[4] samples; - samples[0] = srgb_to_linear(texture2D(tex0, texcoord)); - samples[1] = srgb_to_linear(texture2D(tex1, texcoord)); - samples[2] = srgb_to_linear(texture2D(tex2, texcoord)); - samples[3] = srgb_to_linear(texture2D(tex3, texcoord)); + samples[0] = texture2D(tex0, texcoord); + samples[1] = texture2D(tex1, texcoord); + samples[2] = texture2D(tex2, texcoord); + samples[3] = texture2D(tex3, texcoord); + samples[0].xyz = srgb_to_linear(samples[0].xyz); + samples[1].xyz = srgb_to_linear(samples[1].xyz); + samples[2].xyz = srgb_to_linear(samples[2].xyz); + samples[3].xyz = srgb_to_linear(samples[3].xyz); return terrain_mix(samples, alpha1, alpha2, alphaFinal); } @@ -107,7 +120,7 @@ void main() float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; - vec4 base_color = sample_and_mix_color(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_basecolor, detail_1_basecolor, detail_2_basecolor, detail_3_basecolor); + vec4 base_color = sample_and_mix_color4(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_base_color, detail_1_base_color, detail_2_base_color, detail_3_base_color); float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); if (base_color.a < minimum_alpha) { @@ -116,14 +129,14 @@ void main() vec4 normal_texture = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); vec4 metallic_roughness = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); - vec4 emissive_texture = sample_and_mix_color(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); + vec3 emissive_texture = sample_and_mix_color3(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); vec4 baseColorFactor = terrain_mix(baseColorFactors, alpha1, alpha2, alphaFinal); float metallicFactor = terrain_mix(metallicFactors, alpha1, alpha2, alphaFinal); float roughnessFactor = terrain_mix(roughnessFactors, alpha1, alpha2, alphaFinal); vec3 emissiveColor = terrain_mix(emissiveColors, alpha1, alpha2, alphaFinal); - vec3 col = baseColorFactor.rgb * srgb_to_linear(basecolor.rgb); + vec3 col = baseColorFactor.rgb * srgb_to_linear(base_color.rgb); // from mikktspace.com vec3 vNt = normal_texture.xyz*2.0-1.0; @@ -141,10 +154,10 @@ void main() // metal 0.0 vec3 spec = metallic_roughness.rgb; - spec.g *= roughness_factor; - spec.b *= metallic_factor; + spec.g *= roughnessFactor; + spec.b *= metallicFactor; - vec3 emissive = emssive_color; + vec3 emissive = emissiveColor; emissive *= emissive_texture.rgb; tnorm *= gl_FrontFacing ? 1.0 : -1.0; @@ -152,7 +165,7 @@ void main() frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb,baseColorFactor.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = max(vec4(encode_normal(tnorm), baseColorFactor.a, GBUFFER_FLAG_HAS_PBR | GBUFFER_FLAG_HAS_ATMOS), vec4(0)); // normal, environment intensity, flags + frag_data[2] = max(vec4(encode_normal(tnorm), baseColorFactor.a, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index cbfe9f3ea5..6037a58c0d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -73,9 +73,9 @@ void main() // *NOTE: KHR texture transform is ignored for now vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; - vec4 t = vec4(texcoord1,0,1); + vec4 tc = vec4(texcoord1,0,1); - vary_texcoord0.zw = t.xy; - vary_texcoord1.xy = t.xy-vec2(2.0, 0.0); - vary_texcoord1.zw = t.xy-vec2(1.0, 0.0); + vary_texcoord0.zw = tc.xy; + vary_texcoord1.xy = tc.xy-vec2(2.0, 0.0); + vary_texcoord1.zw = tc.xy-vec2(1.0, 0.0); } -- cgit v1.2.3 From 039116abd4166903005b8de6fa5d64f0fdf75422 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:58:05 -0700 Subject: DRTVWR-592: (WIP) Roughly working draft of PBR terrain --- .../shaders/class1/deferred/pbrterrainF.glsl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 60e5776bc6..4de6b9609c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -97,10 +97,11 @@ vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, vec2 te samples[1] = texture2D(tex1, texcoord); samples[2] = texture2D(tex2, texcoord); samples[3] = texture2D(tex3, texcoord); - samples[0].xyz = srgb_to_linear(samples[0].xyz); - samples[1].xyz = srgb_to_linear(samples[1].xyz); - samples[2].xyz = srgb_to_linear(samples[2].xyz); - samples[3].xyz = srgb_to_linear(samples[3].xyz); + // TODO: Why is this needed for pbropaqueF but not here? (and is there different behavior with base color vs emissive color, that also needs to be corrected?) + //samples[0].xyz = srgb_to_linear(samples[0].xyz); + //samples[1].xyz = srgb_to_linear(samples[1].xyz); + //samples[2].xyz = srgb_to_linear(samples[2].xyz); + //samples[3].xyz = srgb_to_linear(samples[3].xyz); return terrain_mix(samples, alpha1, alpha2, alphaFinal); } @@ -116,20 +117,23 @@ vec4 sample_and_mix_vector(float alpha1, float alpha2, float alphaFinal, vec2 te void main() { + // Adjust the texture repeats for a more sensible default. + float texture_density_factor = 2.0; + vec2 terrain_texcoord = texture_density_factor * vary_texcoord0.xy; float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; - vec4 base_color = sample_and_mix_color4(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_base_color, detail_1_base_color, detail_2_base_color, detail_3_base_color); + vec4 base_color = sample_and_mix_color4(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_base_color, detail_1_base_color, detail_2_base_color, detail_3_base_color); float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); if (base_color.a < minimum_alpha) { discard; } - vec4 normal_texture = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); - vec4 metallic_roughness = sample_and_mix_vector(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); - vec3 emissive_texture = sample_and_mix_color3(alpha1, alpha2, alphaFinal, vary_texcoord0.xy, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); + vec4 normal_texture = sample_and_mix_vector(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); + vec4 metallic_roughness = sample_and_mix_vector(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); + vec3 emissive_texture = sample_and_mix_color3(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); vec4 baseColorFactor = terrain_mix(baseColorFactors, alpha1, alpha2, alphaFinal); float metallicFactor = terrain_mix(metallicFactors, alpha1, alpha2, alphaFinal); -- cgit v1.2.3 From 1820f23b96a50962a3a6a3d48de1aff8e1acb2c0 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:58:35 -0700 Subject: DRTVWR-592: Fix issues with blending of materials, for example when fading out an emissive texture. Also affects base color and ORM --- .../shaders/class1/deferred/pbrterrainF.glsl | 105 ++++++++++++--------- 1 file changed, 62 insertions(+), 43 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 4de6b9609c..85691ae9b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -80,38 +80,63 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); } -vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec3[4] samples; - samples[0] = srgb_to_linear(texture2D(tex0, texcoord).xyz); - samples[1] = srgb_to_linear(texture2D(tex1, texcoord).xyz); - samples[2] = srgb_to_linear(texture2D(tex2, texcoord).xyz); - samples[3] = srgb_to_linear(texture2D(tex3, texcoord).xyz); + samples[0] = texture2D(tex0, texcoord).xyz; + samples[1] = texture2D(tex1, texcoord).xyz; + samples[2] = texture2D(tex2, texcoord).xyz; + samples[3] = texture2D(tex3, texcoord).xyz; + samples[0] = srgb_to_linear(samples[0]); + samples[1] = srgb_to_linear(samples[1]); + samples[2] = srgb_to_linear(samples[2]); + samples[3] = srgb_to_linear(samples[3]); + samples[0] *= factors[0]; + samples[1] *= factors[1]; + samples[2] *= factors[2]; + samples[3] *= factors[3]; return terrain_mix(samples, alpha1, alpha2, alphaFinal); } -vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec4[4] samples; samples[0] = texture2D(tex0, texcoord); samples[1] = texture2D(tex1, texcoord); samples[2] = texture2D(tex2, texcoord); samples[3] = texture2D(tex3, texcoord); - // TODO: Why is this needed for pbropaqueF but not here? (and is there different behavior with base color vs emissive color, that also needs to be corrected?) - //samples[0].xyz = srgb_to_linear(samples[0].xyz); - //samples[1].xyz = srgb_to_linear(samples[1].xyz); - //samples[2].xyz = srgb_to_linear(samples[2].xyz); - //samples[3].xyz = srgb_to_linear(samples[3].xyz); + samples[0].xyz = srgb_to_linear(samples[0].xyz); + samples[1].xyz = srgb_to_linear(samples[1].xyz); + samples[2].xyz = srgb_to_linear(samples[2].xyz); + samples[3].xyz = srgb_to_linear(samples[3].xyz); + samples[0] *= factors[0]; + samples[1] *= factors[1]; + samples[2] *= factors[2]; + samples[3] *= factors[3]; return terrain_mix(samples, alpha1, alpha2, alphaFinal); } -vec4 sample_and_mix_vector(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - vec4[4] samples; - samples[0] = texture2D(tex0, texcoord); - samples[1] = texture2D(tex1, texcoord); - samples[2] = texture2D(tex2, texcoord); - samples[3] = texture2D(tex3, texcoord); + vec3[4] samples; + samples[0] = texture2D(tex0, texcoord).xyz; + samples[1] = texture2D(tex1, texcoord).xyz; + samples[2] = texture2D(tex2, texcoord).xyz; + samples[3] = texture2D(tex3, texcoord).xyz; + samples[0] *= factors[0]; + samples[1] *= factors[1]; + samples[2] *= factors[2]; + samples[3] *= factors[3]; + return terrain_mix(samples, alpha1, alpha2, alphaFinal); +} + +vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + vec3[4] samples; + samples[0] = texture2D(tex0, texcoord).xyz; + samples[1] = texture2D(tex1, texcoord).xyz; + samples[2] = texture2D(tex2, texcoord).xyz; + samples[3] = texture2D(tex3, texcoord).xyz; return terrain_mix(samples, alpha1, alpha2, alphaFinal); } @@ -124,23 +149,30 @@ void main() float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; - vec4 base_color = sample_and_mix_color4(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_base_color, detail_1_base_color, detail_2_base_color, detail_3_base_color); + vec4 col = sample_and_mix_color4(alpha1, alpha2, alphaFinal, terrain_texcoord, baseColorFactors, detail_0_base_color, detail_1_base_color, detail_2_base_color, detail_3_base_color); float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); - if (base_color.a < minimum_alpha) + if (col.a < minimum_alpha) { discard; } - vec4 normal_texture = sample_and_mix_vector(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); - vec4 metallic_roughness = sample_and_mix_vector(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); - vec3 emissive_texture = sample_and_mix_color3(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); + vec3 normal_texture = sample_and_mix_vector3_no_scale(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); - vec4 baseColorFactor = terrain_mix(baseColorFactors, alpha1, alpha2, alphaFinal); - float metallicFactor = terrain_mix(metallicFactors, alpha1, alpha2, alphaFinal); - float roughnessFactor = terrain_mix(roughnessFactors, alpha1, alpha2, alphaFinal); - vec3 emissiveColor = terrain_mix(emissiveColors, alpha1, alpha2, alphaFinal); + vec3[4] orm_factors; + orm_factors[0] = vec3(1.0, roughnessFactors.x, metallicFactors.x); + orm_factors[1] = vec3(1.0, roughnessFactors.y, metallicFactors.y); + orm_factors[2] = vec3(1.0, roughnessFactors.z, metallicFactors.z); + orm_factors[3] = vec3(1.0, roughnessFactors.w, metallicFactors.w); + // RGB = Occlusion, Roughness, Metal + // default values, see LLViewerTexture::sDefaultPBRORMImagep + // occlusion 1.0 + // roughness 0.0 + // metal 0.0 + vec3 spec = sample_and_mix_vector3(alpha1, alpha2, alphaFinal, terrain_texcoord, orm_factors, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); - vec3 col = baseColorFactor.rgb * srgb_to_linear(base_color.rgb); + vec3 emissive = sample_and_mix_color3(alpha1, alpha2, alphaFinal, terrain_texcoord, emissiveColors, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); + + float base_color_factor_alpha = terrain_mix(vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z), alpha1, alpha2, alphaFinal); // from mikktspace.com vec3 vNt = normal_texture.xyz*2.0-1.0; @@ -151,25 +183,12 @@ void main() vec3 vB = sign * cross(vN, vT); vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); - // RGB = Occlusion, Roughness, Metal - // default values, see LLViewerTexture::sDefaultPBRORMImagep - // occlusion 1.0 - // roughness 0.0 - // metal 0.0 - vec3 spec = metallic_roughness.rgb; - - spec.g *= roughnessFactor; - spec.b *= metallicFactor; - - vec3 emissive = emissiveColor; - emissive *= emissive_texture.rgb; - tnorm *= gl_FrontFacing ? 1.0 : -1.0; - frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse - frag_data[1] = max(vec4(spec.rgb,baseColorFactor.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = max(vec4(encode_normal(tnorm), baseColorFactor.a, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags + frag_data[0] = max(vec4(col.xyz, 0.0), vec4(0)); // Diffuse + frag_data[1] = max(vec4(spec.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. + frag_data[2] = max(vec4(encode_normal(tnorm), base_color_factor_alpha, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } -- cgit v1.2.3 From dfa19c5e436edb102d8bd121c853153303631b4d Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:33:16 -0700 Subject: DRTVWR-592: PBR terrain fallback for Mac/Intel: Drop emissive texture. Bump featuretable. --- .../app_settings/shaders/class1/deferred/pbrterrainF.glsl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 85691ae9b6..344c342189 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +#define TERRAIN_PBR_DETAIL_EMISSIVE 0 + out vec4 frag_data[4]; uniform sampler2D alpha_ramp; @@ -42,16 +44,20 @@ uniform sampler2D detail_0_metallic_roughness; uniform sampler2D detail_1_metallic_roughness; uniform sampler2D detail_2_metallic_roughness; uniform sampler2D detail_3_metallic_roughness; +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) uniform sampler2D detail_0_emissive; uniform sampler2D detail_1_emissive; uniform sampler2D detail_2_emissive; uniform sampler2D detail_3_emissive; +#endif // *TODO: More efficient packing? uniform vec4[4] baseColorFactors; // See also vertex_color in pbropaqueV.glsl uniform vec4 metallicFactors; uniform vec4 roughnessFactors; +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) uniform vec3[4] emissiveColors; +#endif uniform vec4 minimum_alphas; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() in vec3 vary_normal; @@ -170,7 +176,11 @@ void main() // metal 0.0 vec3 spec = sample_and_mix_vector3(alpha1, alpha2, alphaFinal, terrain_texcoord, orm_factors, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) vec3 emissive = sample_and_mix_color3(alpha1, alpha2, alphaFinal, terrain_texcoord, emissiveColors, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); +#else + vec3 emissive = vec3(0); +#endif float base_color_factor_alpha = terrain_mix(vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z), alpha1, alpha2, alphaFinal); -- cgit v1.2.3 From a65c9dad5521d8e8d375003220e362533a142250 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:33:21 -0700 Subject: DRTVWR-592: Another attempt to fix Mac build: remove deprecated use of texture2D --- .../shaders/class1/deferred/pbrterrainF.glsl | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 344c342189..73d4d9e3bc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -89,10 +89,10 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec3[4] samples; - samples[0] = texture2D(tex0, texcoord).xyz; - samples[1] = texture2D(tex1, texcoord).xyz; - samples[2] = texture2D(tex2, texcoord).xyz; - samples[3] = texture2D(tex3, texcoord).xyz; + samples[0] = texture(tex0, texcoord).xyz; + samples[1] = texture(tex1, texcoord).xyz; + samples[2] = texture(tex2, texcoord).xyz; + samples[3] = texture(tex3, texcoord).xyz; samples[0] = srgb_to_linear(samples[0]); samples[1] = srgb_to_linear(samples[1]); samples[2] = srgb_to_linear(samples[2]); @@ -107,10 +107,10 @@ vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, vec2 te vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec4[4] samples; - samples[0] = texture2D(tex0, texcoord); - samples[1] = texture2D(tex1, texcoord); - samples[2] = texture2D(tex2, texcoord); - samples[3] = texture2D(tex3, texcoord); + samples[0] = texture(tex0, texcoord); + samples[1] = texture(tex1, texcoord); + samples[2] = texture(tex2, texcoord); + samples[3] = texture(tex3, texcoord); samples[0].xyz = srgb_to_linear(samples[0].xyz); samples[1].xyz = srgb_to_linear(samples[1].xyz); samples[2].xyz = srgb_to_linear(samples[2].xyz); @@ -125,10 +125,10 @@ vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, vec2 te vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec3[4] samples; - samples[0] = texture2D(tex0, texcoord).xyz; - samples[1] = texture2D(tex1, texcoord).xyz; - samples[2] = texture2D(tex2, texcoord).xyz; - samples[3] = texture2D(tex3, texcoord).xyz; + samples[0] = texture(tex0, texcoord).xyz; + samples[1] = texture(tex1, texcoord).xyz; + samples[2] = texture(tex2, texcoord).xyz; + samples[3] = texture(tex3, texcoord).xyz; samples[0] *= factors[0]; samples[1] *= factors[1]; samples[2] *= factors[2]; @@ -139,10 +139,10 @@ vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, vec2 t vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec3[4] samples; - samples[0] = texture2D(tex0, texcoord).xyz; - samples[1] = texture2D(tex1, texcoord).xyz; - samples[2] = texture2D(tex2, texcoord).xyz; - samples[3] = texture2D(tex3, texcoord).xyz; + samples[0] = texture(tex0, texcoord).xyz; + samples[1] = texture(tex1, texcoord).xyz; + samples[2] = texture(tex2, texcoord).xyz; + samples[3] = texture(tex3, texcoord).xyz; return terrain_mix(samples, alpha1, alpha2, alphaFinal); } @@ -151,9 +151,9 @@ void main() // Adjust the texture repeats for a more sensible default. float texture_density_factor = 2.0; vec2 terrain_texcoord = texture_density_factor * vary_texcoord0.xy; - float alpha1 = texture2D(alpha_ramp, vary_texcoord0.zw).a; - float alpha2 = texture2D(alpha_ramp,vary_texcoord1.xy).a; - float alphaFinal = texture2D(alpha_ramp, vary_texcoord1.zw).a; + float alpha1 = texture(alpha_ramp, vary_texcoord0.zw).a; + float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a; + float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a; vec4 col = sample_and_mix_color4(alpha1, alpha2, alphaFinal, terrain_texcoord, baseColorFactors, detail_0_base_color, detail_1_base_color, detail_2_base_color, detail_3_base_color); float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); -- cgit v1.2.3 From b9ba57fd0004751dfbcbea90264a6e16c5849e5e Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:38:42 -0700 Subject: DRTVWR-592: (WIP) Fix terrain PBR texture repeat seam. Legacy terrain texture repeats currently broken --- .../shaders/class1/deferred/pbrterrainF.glsl | 25 +++++++++++++++++++--- .../shaders/class1/deferred/pbrterrainV.glsl | 22 +++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 73d4d9e3bc..5f94855963 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -70,6 +70,7 @@ vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); +in vec4 debug_pos; // TODO: Remove // *TODO: This mixing function feels like it can be optimized. The terrain code's use of texcoord1 is dubious. It feels like the same thing can be accomplished with less memory bandwidth by calculating the offsets on-the-fly float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) { @@ -148,9 +149,8 @@ vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFina void main() { - // Adjust the texture repeats for a more sensible default. - float texture_density_factor = 2.0; - vec2 terrain_texcoord = texture_density_factor * vary_texcoord0.xy; + vec2 terrain_texcoord = vary_texcoord0.xy; + terrain_texcoord -= vec2(21.0);// TODO: Remove float alpha1 = texture(alpha_ramp, vary_texcoord0.zw).a; float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a; @@ -162,6 +162,25 @@ void main() discard; } + // TODO: Remove all of this + float debug_pos_x = debug_pos.x; + //float debug_pos_x = terrain_texcoord.y; + float debug_metric = debug_pos_x; + debug_metric = debug_metric - floor(debug_metric); + debug_metric *= debug_metric; + float debug_metric2 = debug_pos_x / 4.0; + debug_metric2 = debug_metric2 - floor(debug_metric2); + debug_metric2 *= debug_metric2; + debug_metric2 *= debug_metric2; + debug_metric2 *= 16.0; + float debug_metric3 = debug_pos_x / 16.0; + debug_metric3 = debug_metric3 - floor(debug_metric3); + debug_metric3 *= debug_metric3; + debug_metric3 *= debug_metric3; + debug_metric3 *= debug_metric3; + debug_metric3 *= 16.0; + //col.xyz = vec3(debug_metric3, debug_metric2, debug_metric);// TODO: Remove + vec3 normal_texture = sample_and_mix_vector3_no_scale(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); vec3[4] orm_factors; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index 6037a58c0d..fd80d1bb2c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -43,24 +43,27 @@ out vec4 vary_texcoord1; uniform vec4 object_plane_s; uniform vec4 object_plane_t; -vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) +vec4 texgen_object_pbr(vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) { vec4 tcoord; - tcoord.x = dot(vpos, tp0); - tcoord.y = dot(vpos, tp1); - tcoord.z = tc.z; - tcoord.w = tc.w; + tcoord.x = dot(tc, tp0); + tcoord.y = dot(tc, tp1); + tcoord.z = tcoord.z; + tcoord.w = tcoord.w; tcoord = mat * tcoord; - return tcoord; + return tcoord; } +out vec4 debug_pos; // TODO: Remove + void main() { //transform vertex gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + debug_pos = vec4(texcoord0, 0.0, 1.0); vec3 n = normal_matrix * normal; vec3 t = normal_matrix * tangent.xyz; @@ -71,7 +74,12 @@ void main() // Transform and pass tex coords // *NOTE: KHR texture transform is ignored for now - vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; + vary_texcoord0.xy = texgen_object_pbr(vec4(texcoord0, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; + // Adjust the texture repeats for a more sensible default. + // *TODO: Remove this extra factor when KHR texture transform is added + float texture_density_factor = 3.0; + //texture_density_factor /= 256.0; // TODO: Remove + vary_texcoord0.xy *= texture_density_factor; vec4 tc = vec4(texcoord1,0,1); -- cgit v1.2.3 From 35d889f7af9686b79fe0e5255121a444a044beab Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:38:48 -0700 Subject: DRTVWR-592: Create separate config option for terrain repeats. Clean up debug --- .../shaders/class1/deferred/pbrterrainF.glsl | 21 --------------------- .../shaders/class1/deferred/pbrterrainV.glsl | 12 ++---------- 2 files changed, 2 insertions(+), 31 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 5f94855963..e6261ca85e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -70,7 +70,6 @@ vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); -in vec4 debug_pos; // TODO: Remove // *TODO: This mixing function feels like it can be optimized. The terrain code's use of texcoord1 is dubious. It feels like the same thing can be accomplished with less memory bandwidth by calculating the offsets on-the-fly float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) { @@ -150,7 +149,6 @@ vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFina void main() { vec2 terrain_texcoord = vary_texcoord0.xy; - terrain_texcoord -= vec2(21.0);// TODO: Remove float alpha1 = texture(alpha_ramp, vary_texcoord0.zw).a; float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a; @@ -162,25 +160,6 @@ void main() discard; } - // TODO: Remove all of this - float debug_pos_x = debug_pos.x; - //float debug_pos_x = terrain_texcoord.y; - float debug_metric = debug_pos_x; - debug_metric = debug_metric - floor(debug_metric); - debug_metric *= debug_metric; - float debug_metric2 = debug_pos_x / 4.0; - debug_metric2 = debug_metric2 - floor(debug_metric2); - debug_metric2 *= debug_metric2; - debug_metric2 *= debug_metric2; - debug_metric2 *= 16.0; - float debug_metric3 = debug_pos_x / 16.0; - debug_metric3 = debug_metric3 - floor(debug_metric3); - debug_metric3 *= debug_metric3; - debug_metric3 *= debug_metric3; - debug_metric3 *= debug_metric3; - debug_metric3 *= 16.0; - //col.xyz = vec3(debug_metric3, debug_metric2, debug_metric);// TODO: Remove - vec3 normal_texture = sample_and_mix_vector3_no_scale(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); vec3[4] orm_factors; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index fd80d1bb2c..1653cc1a90 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -52,18 +52,15 @@ vec4 texgen_object_pbr(vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) tcoord.z = tcoord.z; tcoord.w = tcoord.w; - tcoord = mat * tcoord; + tcoord = mat * tcoord; return tcoord; } -out vec4 debug_pos; // TODO: Remove - void main() { //transform vertex gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - debug_pos = vec4(texcoord0, 0.0, 1.0); vec3 n = normal_matrix * normal; vec3 t = normal_matrix * tangent.xyz; @@ -71,15 +68,10 @@ void main() vary_tangent = normalize(t); vary_sign = tangent.w; vary_normal = normalize(n); - + // Transform and pass tex coords // *NOTE: KHR texture transform is ignored for now vary_texcoord0.xy = texgen_object_pbr(vec4(texcoord0, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; - // Adjust the texture repeats for a more sensible default. - // *TODO: Remove this extra factor when KHR texture transform is added - float texture_density_factor = 3.0; - //texture_density_factor /= 256.0; // TODO: Remove - vary_texcoord0.xy *= texture_density_factor; vec4 tc = vec4(texcoord1,0,1); -- cgit v1.2.3 From 754fe9d4b72c3a22fb18e32bd48daaa2ae7b02f7 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:39:09 -0700 Subject: DRTVWR-592: (WIP) Triplanar mapping --- .../shaders/class1/deferred/pbrterrainF.glsl | 98 +++----------- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 148 +++++++++++++++++++++ .../shaders/class1/deferred/pbrterrainV.glsl | 9 +- 3 files changed, 177 insertions(+), 78 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index e6261ca85e..5bf20a3020 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -25,6 +25,15 @@ #define TERRAIN_PBR_DETAIL_EMISSIVE 0 +#define TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT 3 // TODO: Move definition to config + +// TODO: Should be able to define this in another file and have it included in this one... +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 +#define TerrainCoord vec4[2] +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 +#define TerrainCoord vec2 +#endif + out vec4 frag_data[4]; uniform sampler2D alpha_ramp; @@ -60,6 +69,7 @@ uniform vec3[4] emissiveColors; #endif uniform vec4 minimum_alphas; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() +in vec4[2] vary_coords; in vec3 vary_normal; in vec3 vary_tangent; flat in float vary_sign; @@ -67,88 +77,22 @@ in vec4 vary_texcoord0; in vec4 vary_texcoord1; vec2 encode_normal(vec3 n); -vec3 linear_to_srgb(vec3 c); -vec3 srgb_to_linear(vec3 c); - -// *TODO: This mixing function feels like it can be optimized. The terrain code's use of texcoord1 is dubious. It feels like the same thing can be accomplished with less memory bandwidth by calculating the offsets on-the-fly -float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) -{ - return mix( mix(samples.w, samples.z, alpha2), mix(samples.y, samples.x, alpha1), alphaFinal ); -} - -vec3 terrain_mix(vec3[4] samples, float alpha1, float alpha2, float alphaFinal) -{ - return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); -} - -vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) -{ - return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); -} -vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - vec3[4] samples; - samples[0] = texture(tex0, texcoord).xyz; - samples[1] = texture(tex1, texcoord).xyz; - samples[2] = texture(tex2, texcoord).xyz; - samples[3] = texture(tex3, texcoord).xyz; - samples[0] = srgb_to_linear(samples[0]); - samples[1] = srgb_to_linear(samples[1]); - samples[2] = srgb_to_linear(samples[2]); - samples[3] = srgb_to_linear(samples[3]); - samples[0] *= factors[0]; - samples[1] *= factors[1]; - samples[2] *= factors[2]; - samples[3] *= factors[3]; - return terrain_mix(samples, alpha1, alpha2, alphaFinal); -} - -vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - vec4[4] samples; - samples[0] = texture(tex0, texcoord); - samples[1] = texture(tex1, texcoord); - samples[2] = texture(tex2, texcoord); - samples[3] = texture(tex3, texcoord); - samples[0].xyz = srgb_to_linear(samples[0].xyz); - samples[1].xyz = srgb_to_linear(samples[1].xyz); - samples[2].xyz = srgb_to_linear(samples[2].xyz); - samples[3].xyz = srgb_to_linear(samples[3].xyz); - samples[0] *= factors[0]; - samples[1] *= factors[1]; - samples[2] *= factors[2]; - samples[3] *= factors[3]; - return terrain_mix(samples, alpha1, alpha2, alphaFinal); -} +float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal); +vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); +vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); +vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); +vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); -vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +void main() { - vec3[4] samples; - samples[0] = texture(tex0, texcoord).xyz; - samples[1] = texture(tex1, texcoord).xyz; - samples[2] = texture(tex2, texcoord).xyz; - samples[3] = texture(tex3, texcoord).xyz; - samples[0] *= factors[0]; - samples[1] *= factors[1]; - samples[2] *= factors[2]; - samples[3] *= factors[3]; - return terrain_mix(samples, alpha1, alpha2, alphaFinal); -} -vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFinal, vec2 texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - vec3[4] samples; - samples[0] = texture(tex0, texcoord).xyz; - samples[1] = texture(tex1, texcoord).xyz; - samples[2] = texture(tex2, texcoord).xyz; - samples[3] = texture(tex3, texcoord).xyz; - return terrain_mix(samples, alpha1, alpha2, alphaFinal); -} +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 + TerrainCoord terrain_texcoord = vary_coords; +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 + TerrainCoord terrain_texcoord = vary_texcoord0.xy; +#endif -void main() -{ - vec2 terrain_texcoord = vary_texcoord0.xy; float alpha1 = texture(alpha_ramp, vary_texcoord0.zw).a; float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl new file mode 100644 index 0000000000..4f337b5ce1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -0,0 +1,148 @@ +/** + * @file class1\deferred\pbrterrainUtilF.glsl + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +/** + * Triplanar mapping implementation adapted from Inigo Quilez' example shader, + * MIT license. + * https://www.shadertoy.com/view/MtsGWH + * Copyright © 2015 Inigo Quilez + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: The above copyright + * notice and this permission notice shall be included in all copies or + * substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", + * WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED + * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +in vec3 vary_vertex_normal; + +vec3 srgb_to_linear(vec3 c); + +float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) +{ + return mix( mix(samples.w, samples.z, alpha2), mix(samples.y, samples.x, alpha1), alphaFinal ); +} + +vec3 terrain_mix(vec3[4] samples, float alpha1, float alpha2, float alphaFinal) +{ + return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); +} + +vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) +{ + return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); +} + +#define TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT 3 // TODO: Move definition to config + +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 +// Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, zx, unused) +#define TerrainCoord vec4[2] +// Triplanar mapping +vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) +{ + vec4 x = texture(tex, terrain_coord[0].zw); + vec4 y = texture(tex, terrain_coord[1].xy); + vec4 z = texture(tex, terrain_coord[0].xy); + float sharpness = 8.0; + vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); + return ((x * weight.x) + (y * weight.y) + (z * weight.z)) / (weight.x + weight.y + weight.z); +} +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 +#define TerrainCoord vec2 +vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) +{ + return texture(tex, terrain_coord); +} +#endif + +vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + vec3[4] samples; + samples[0] = terrain_texture(tex0, texcoord).xyz; + samples[1] = terrain_texture(tex1, texcoord).xyz; + samples[2] = terrain_texture(tex2, texcoord).xyz; + samples[3] = terrain_texture(tex3, texcoord).xyz; + samples[0] = srgb_to_linear(samples[0]); + samples[1] = srgb_to_linear(samples[1]); + samples[2] = srgb_to_linear(samples[2]); + samples[3] = srgb_to_linear(samples[3]); + samples[0] *= factors[0]; + samples[1] *= factors[1]; + samples[2] *= factors[2]; + samples[3] *= factors[3]; + return terrain_mix(samples, alpha1, alpha2, alphaFinal); +} + +vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + vec4[4] samples; + samples[0] = terrain_texture(tex0, texcoord); + samples[1] = terrain_texture(tex1, texcoord); + samples[2] = terrain_texture(tex2, texcoord); + samples[3] = terrain_texture(tex3, texcoord); + samples[0].xyz = srgb_to_linear(samples[0].xyz); + samples[1].xyz = srgb_to_linear(samples[1].xyz); + samples[2].xyz = srgb_to_linear(samples[2].xyz); + samples[3].xyz = srgb_to_linear(samples[3].xyz); + samples[0] *= factors[0]; + samples[1] *= factors[1]; + samples[2] *= factors[2]; + samples[3] *= factors[3]; + return terrain_mix(samples, alpha1, alpha2, alphaFinal); +} + +vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + vec3[4] samples; + samples[0] = terrain_texture(tex0, texcoord).xyz; + samples[1] = terrain_texture(tex1, texcoord).xyz; + samples[2] = terrain_texture(tex2, texcoord).xyz; + samples[3] = terrain_texture(tex3, texcoord).xyz; + samples[0] *= factors[0]; + samples[1] *= factors[1]; + samples[2] *= factors[2]; + samples[3] *= factors[3]; + return terrain_mix(samples, alpha1, alpha2, alphaFinal); +} + +vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + vec3[4] samples; + samples[0] = terrain_texture(tex0, texcoord).xyz; + samples[1] = terrain_texture(tex1, texcoord).xyz; + samples[2] = terrain_texture(tex2, texcoord).xyz; + samples[3] = terrain_texture(tex3, texcoord).xyz; + return terrain_mix(samples, alpha1, alpha2, alphaFinal); +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index 1653cc1a90..991783d242 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -34,6 +34,8 @@ in vec4 diffuse_color; in vec2 texcoord0; in vec2 texcoord1; +out vec4[2] vary_coords; +out vec3 vary_vertex_normal; // Used by pbrterrainUtilF.glsl out vec3 vary_normal; out vec3 vary_tangent; flat out float vary_sign; @@ -63,6 +65,8 @@ void main() gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vec3 n = normal_matrix * normal; + // *TODO: Looks like terrain normals are per-vertex when they should be per-triangle instead, causing incorrect values on triangles touching steep edges of terrain + vary_vertex_normal = normal; vec3 t = normal_matrix * tangent.xyz; vary_tangent = normalize(t); @@ -73,7 +77,10 @@ void main() // *NOTE: KHR texture transform is ignored for now vary_texcoord0.xy = texgen_object_pbr(vec4(texcoord0, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; - vec4 tc = vec4(texcoord1,0,1); + vec4 tc = vec4(texcoord1,0,1); // TODO: This is redundant. Better to just use position and ignore texcoord? (We still need to decide how to handle alpha ramp, though...) + vary_coords[0].xy = texgen_object_pbr(vec4(position.xy, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; + vary_coords[0].zw = texgen_object_pbr(vec4(position.yz, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; + vary_coords[1].xy = texgen_object_pbr(vec4(position.zx, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; vary_texcoord0.zw = tc.xy; vary_texcoord1.xy = tc.xy-vec2(2.0, 0.0); -- cgit v1.2.3 From 2dc3f3ade165d7d15d8579a0f04b72f6aa56c7fe Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:39:16 -0700 Subject: DRTVWR-592: Add triplanar mapping setting, gate to High graphics setting or higher, bump feature table --- indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 3 --- .../newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 2 -- 2 files changed, 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 5bf20a3020..b9073a9361 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -25,9 +25,6 @@ #define TERRAIN_PBR_DETAIL_EMISSIVE 0 -#define TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT 3 // TODO: Move definition to config - -// TODO: Should be able to define this in another file and have it included in this one... #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 #define TerrainCoord vec4[2] #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 4f337b5ce1..b0b77398df 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -64,8 +64,6 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); } -#define TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT 3 // TODO: Move definition to config - #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 // Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, zx, unused) #define TerrainCoord vec4[2] -- cgit v1.2.3 From ed973f4cbc58b5460513be709a0a23f0caa1120c Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:39:22 -0700 Subject: DRTVWR-592: Add test config for triplanar mapping blend strength --- indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index b0b77398df..ef2d030320 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -73,7 +73,7 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) vec4 x = texture(tex, terrain_coord[0].zw); vec4 y = texture(tex, terrain_coord[1].xy); vec4 z = texture(tex, terrain_coord[0].xy); - float sharpness = 8.0; + float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); return ((x * weight.x) + (y * weight.y) + (z * weight.z)) / (weight.x + weight.y + weight.z); } -- cgit v1.2.3 From db4bc52829ec041ca0366069d07e942f0d32aacd Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:39:34 -0700 Subject: DRTVWR-592: (WIP) PBR Terrain: Improve orientation of textures and normal maps for triplanar mapping, minor cleanup --- .../shaders/class1/deferred/pbrterrainF.glsl | 10 ++-- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 68 ++++++++++++++++++---- .../shaders/class1/deferred/pbrterrainV.glsl | 52 +++++++++-------- .../shaders/class1/deferred/textureUtilV.glsl | 2 +- 4 files changed, 93 insertions(+), 39 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index b9073a9361..7febbe280e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -35,7 +35,7 @@ out vec4 frag_data[4]; uniform sampler2D alpha_ramp; -// *TODO: Configurable quality level which disables PBR features on machines +// *TODO: More configurable quality level which disables PBR features on machines // with limited texture availability // https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#additional-textures uniform sampler2D detail_0_base_color; @@ -57,7 +57,6 @@ uniform sampler2D detail_2_emissive; uniform sampler2D detail_3_emissive; #endif -// *TODO: More efficient packing? uniform vec4[4] baseColorFactors; // See also vertex_color in pbropaqueV.glsl uniform vec4 metallicFactors; uniform vec4 roughnessFactors; @@ -66,7 +65,9 @@ uniform vec3[4] emissiveColors; #endif uniform vec4 minimum_alphas; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 in vec4[2] vary_coords; +#endif in vec3 vary_normal; in vec3 vary_tangent; flat in float vary_sign; @@ -79,7 +80,7 @@ float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal); vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); -vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); +vec3 sample_and_mix_normal(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); void main() { @@ -101,7 +102,6 @@ void main() discard; } - vec3 normal_texture = sample_and_mix_vector3_no_scale(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); vec3[4] orm_factors; orm_factors[0] = vec3(1.0, roughnessFactors.x, metallicFactors.x); @@ -124,7 +124,7 @@ void main() float base_color_factor_alpha = terrain_mix(vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z), alpha1, alpha2, alphaFinal); // from mikktspace.com - vec3 vNt = normal_texture.xyz*2.0-1.0; + vec3 vNt = sample_and_mix_normal(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index ef2d030320..a9155cc629 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -65,14 +65,56 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) } #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 -// Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, zx, unused) -#define TerrainCoord vec4[2] // Triplanar mapping + +// Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused) +#define TerrainCoord vec4[2] + +vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign) +{ + // If the vertex normal is negative, flip the texture back + // right-side up. + vec2 uv = uv_unflipped * vec2(sign, 1); + return texture(tex, uv); +} + +vec3 _t_texture_n(sampler2D tex, vec2 uv_unflipped, float sign) +{ + // Unpack normal from pixel to vector + vec3 n = _t_texture(tex, uv_unflipped, sign).xyz*2.0-1.0; + // If the sign is negative, rotate normal by 180 degrees + n.xy = (min(0, sign) * n.xy) + (min(0, -sign) * -n.xy); + return n; +} + vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) { - vec4 x = texture(tex, terrain_coord[0].zw); - vec4 y = texture(tex, terrain_coord[1].xy); - vec4 z = texture(tex, terrain_coord[0].xy); + // Multiplying the UVs by the sign of the normal flips the texture upright. + vec4 x = _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)); + vec4 y = _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)); + vec4 z = _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)); + float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; + vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); + return ((x * weight.x) + (y * weight.y) + (z * weight.z)) / (weight.x + weight.y + weight.z); +} + +// Specialized triplanar normal texture sampling implementation, taking into +// account how the rotation of the texture affects the lighting and trying to +// negate that. +// *TODO: Decide if we want this. It may be better to just calculate the +// tangents on-the-fly here rather than messing with the normals, due to the +// subtleties of the effects of triplanar mapping on UVs. These sampled normals +// are only valid on the faces of a cube, and the pregenerated tangents are +// only valid for uv = xy. +// *NOTE: Bottom face has not been tested +vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) +{ + vec3 x = _t_texture_n(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)); + x.xy = vec2(-x.y, x.x); + vec3 y = _t_texture_n(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)); + y.xy = -y.xy; + vec3 z = _t_texture_n(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)); + float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); return ((x * weight.x) + (y * weight.y) + (z * weight.z)) / (weight.x + weight.y + weight.z); @@ -83,6 +125,11 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) { return texture(tex, terrain_coord); } + +vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) +{ + return texture(tex, terrain_coord).xyz; +} #endif vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) @@ -135,12 +182,13 @@ vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, Terrai return terrain_mix(samples, alpha1, alpha2, alphaFinal); } -vec3 sample_and_mix_vector3_no_scale(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +// Returns the unpacked normal texture in range [-1, 1] +vec3 sample_and_mix_normal(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec3[4] samples; - samples[0] = terrain_texture(tex0, texcoord).xyz; - samples[1] = terrain_texture(tex1, texcoord).xyz; - samples[2] = terrain_texture(tex2, texcoord).xyz; - samples[3] = terrain_texture(tex3, texcoord).xyz; + samples[0] = terrain_texture_normal(tex0, texcoord).xyz; + samples[1] = terrain_texture_normal(tex1, texcoord).xyz; + samples[2] = terrain_texture_normal(tex2, texcoord).xyz; + samples[3] = terrain_texture_normal(tex3, texcoord).xyz; return terrain_mix(samples, alpha1, alpha2, alphaFinal); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index 991783d242..2df5faf037 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -34,7 +34,9 @@ in vec4 diffuse_color; in vec2 texcoord0; in vec2 texcoord1; +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 out vec4[2] vary_coords; +#endif out vec3 vary_vertex_normal; // Used by pbrterrainUtilF.glsl out vec3 vary_normal; out vec3 vary_tangent; @@ -42,22 +44,13 @@ flat out float vary_sign; out vec4 vary_texcoord0; out vec4 vary_texcoord1; -uniform vec4 object_plane_s; -uniform vec4 object_plane_t; +// *HACK: tangent_space_transform should use texture_normal_transform, or maybe +// we shouldn't use tangent_space_transform at all. See the call to +// tangent_space_transform below. +uniform vec4[2] texture_base_color_transform; -vec4 texgen_object_pbr(vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) -{ - vec4 tcoord; - - tcoord.x = dot(tc, tp0); - tcoord.y = dot(tc, tp1); - tcoord.z = tcoord.z; - tcoord.w = tcoord.w; - - tcoord = mat * tcoord; - - return tcoord; -} +vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); void main() { @@ -65,23 +58,36 @@ void main() gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vec3 n = normal_matrix * normal; - // *TODO: Looks like terrain normals are per-vertex when they should be per-triangle instead, causing incorrect values on triangles touching steep edges of terrain vary_vertex_normal = normal; vec3 t = normal_matrix * tangent.xyz; vary_tangent = normalize(t); + // *TODO: Decide if we want this. It may be better to just calculate the + // tangents on-the-fly in the fragment shader, due to the subtleties of the + // effect of triplanar mapping on UVs. + // *HACK: Should be using texture_normal_transform here. The KHR texture + // transform spec requires handling texture transforms separately for each + // individual texture. + vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_base_color_transform, texture_matrix0)); vary_sign = tangent.w; vary_normal = normalize(n); // Transform and pass tex coords - // *NOTE: KHR texture transform is ignored for now - vary_texcoord0.xy = texgen_object_pbr(vec4(texcoord0, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; - - vec4 tc = vec4(texcoord1,0,1); // TODO: This is redundant. Better to just use position and ignore texcoord? (We still need to decide how to handle alpha ramp, though...) - vary_coords[0].xy = texgen_object_pbr(vec4(position.xy, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; - vary_coords[0].zw = texgen_object_pbr(vec4(position.yz, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; - vary_coords[1].xy = texgen_object_pbr(vec4(position.zx, 0, 1), texture_matrix0, object_plane_s, object_plane_t).xy; + // *HACK: texture_base_color_transform is used for all of these here, but + // the KHR texture transform spec requires handling texture transforms + // separately for each individual texture. +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 + // xy + vary_coords[0].xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0); + // yz + vary_coords[0].zw = texture_transform(position.yz, texture_base_color_transform, texture_matrix0); + // (-x)z + vary_coords[1].xy = texture_transform(position.xz * vec2(-1, 1), texture_base_color_transform, texture_matrix0); +#elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 + vary_texcoord0.xy = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); +#endif + vec4 tc = vec4(texcoord1,0,1); vary_texcoord0.zw = tc.xy; vary_texcoord1.xy = tc.xy-vec2(2.0, 0.0); vary_texcoord1.zw = tc.xy-vec2(1.0, 0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl index 636dfed4ba..732333311c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -65,7 +65,7 @@ vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl // Apply texture animation first to avoid shearing and other artifacts texcoord = (sl_animation_transform * vec4(texcoord, 0, 1)).xy; // Convert to left-handed coordinate system. The offset of 1 is necessary - // for rotations to be applied correctly. + // for rotation and scale to be applied correctly. texcoord.y = 1.0 - texcoord.y; texcoord = khr_texture_transform(texcoord, khr_gltf_transform[0].xy, khr_gltf_transform[0].z, khr_gltf_transform[1].xy); // Convert back to right-handed coordinate system -- cgit v1.2.3 From 3e3a3c1c5262e65df3edf27c4e27a6bbc8d49a01 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:39:40 -0700 Subject: DRTVWR-592: Fix terrain normal sampling in non-triplanar case --- indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index a9155cc629..a89bc6f211 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -128,7 +128,7 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) { - return texture(tex, terrain_coord).xyz; + return texture(tex, terrain_coord).xyz*2.0-1.0; } #endif -- cgit v1.2.3 From 2895b7bf81c3d076a8ceaa4ce77037e870069365 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:39:45 -0700 Subject: DRTVWR-592: Triplanar performance pass --- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 63 ++++++++++++++++++++-- 1 file changed, 58 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index a89bc6f211..1b13bc8836 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -109,14 +109,67 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) // *NOTE: Bottom face has not been tested vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) { - vec3 x = _t_texture_n(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)); + float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; + vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); + float threshold = 0.01; + vec3 significant = max(vec3(0), sign(weight - threshold)); + int sample_type = (int(significant.x) << 2) | + (int(significant.y) << 1) | + (int(significant.z) << 0); + + #define SAMPLE_X 1 << 2 + #define SAMPLE_Y 1 << 1 + #define SAMPLE_Z 1 << 0 + #define terrain_coord_x terrain_coord[0].zw + #define terrain_coord_y terrain_coord[1].xy + #define terrain_coord_z terrain_coord[0].xy + vec3 x; + vec3 y; + vec3 z; + switch (sample_type) + { + case SAMPLE_X | SAMPLE_Y | SAMPLE_Z: + x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x)); + y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y)); + z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + break; + case SAMPLE_X | SAMPLE_Y: + x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x)); + y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y)); + z = vec3(0); + break; + case SAMPLE_X | SAMPLE_Z: + x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x)); + y = vec3(0); + z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + break; + case SAMPLE_Y | SAMPLE_Z: + x = vec3(0); + y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y)); + z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + break; + case SAMPLE_X: + x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x)); + y = vec3(0); + z = vec3(0); + break; + case SAMPLE_Y: + x = vec3(0); + y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y)); + z = vec3(0); + break; + case SAMPLE_Z: + default: + x = vec3(0); + y = vec3(0); + z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + break; + } + + // *HACK: Transform normals according to orientation of the UVs x.xy = vec2(-x.y, x.x); - vec3 y = _t_texture_n(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)); y.xy = -y.xy; - vec3 z = _t_texture_n(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)); - float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; - vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); return ((x * weight.x) + (y * weight.y) + (z * weight.z)) / (weight.x + weight.y + weight.z); } #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 -- cgit v1.2.3 From a8d69a4baecfae81b4adb68992f02e3ebc47b876 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:39:50 -0700 Subject: DRTVWR-592: Fix weights --- .../app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 1b13bc8836..e69ee54a8c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -112,10 +112,10 @@ vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); float threshold = 0.01; - vec3 significant = max(vec3(0), sign(weight - threshold)); - int sample_type = (int(significant.x) << 2) | - (int(significant.y) << 1) | - (int(significant.z) << 0); + weight = max(vec3(0), sign(weight - threshold)); + int sample_type = (int(weight.x) << 2) | + (int(weight.y) << 1) | + (int(weight.z) << 0); #define SAMPLE_X 1 << 2 #define SAMPLE_Y 1 << 1 -- cgit v1.2.3 From bb0ae367d705e6d45f21526b26caa962824d6375 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:39:56 -0700 Subject: DRTVWR-592: (WIP) Test impact of higher threshold on performance and visuals --- indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index e69ee54a8c..4f2619f811 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -111,7 +111,7 @@ vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) { float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); - float threshold = 0.01; + float threshold = 0.1; weight = max(vec3(0), sign(weight - threshold)); int sample_type = (int(weight.x) << 2) | (int(weight.y) << 1) | -- cgit v1.2.3 From e6777d566fddc79d1194a2090e5df5b609285d89 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:40:02 -0700 Subject: DRTVWR-592: Fix not thresholding texture lookups for non-normal textures. Also decrease threshold to (hopefully) reasonable level --- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 72 +++++++++++++++++++--- 1 file changed, 62 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 4f2619f811..b89edc9731 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -69,6 +69,7 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) // Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused) #define TerrainCoord vec4[2] +#define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01 vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign) { @@ -89,12 +90,63 @@ vec3 _t_texture_n(sampler2D tex, vec2 uv_unflipped, float sign) vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) { - // Multiplying the UVs by the sign of the normal flips the texture upright. - vec4 x = _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)); - vec4 y = _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)); - vec4 z = _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)); float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; - vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); + vec3 weight = normalize(pow(abs(vary_vertex_normal), vec3(sharpness))); + float threshold = TERRAIN_TRIPLANAR_MIX_THRESHOLD; + weight = max(vec3(0), sign(weight - threshold)); + + #define SAMPLE_X 1 << 2 + #define SAMPLE_Y 1 << 1 + #define SAMPLE_Z 1 << 0 + int sample_type = (int(weight.x) * SAMPLE_X) | + (int(weight.y) * SAMPLE_Y) | + (int(weight.z) * SAMPLE_Z); + #define terrain_coord_x terrain_coord[0].zw + #define terrain_coord_y terrain_coord[1].xy + #define terrain_coord_z terrain_coord[0].xy + vec4 x; + vec4 y; + vec4 z; + switch (sample_type) + { + case SAMPLE_X | SAMPLE_Y | SAMPLE_Z: + x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); + y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); + z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + break; + case SAMPLE_X | SAMPLE_Y: + x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); + y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); + z = vec4(0); + break; + case SAMPLE_X | SAMPLE_Z: + x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); + y = vec4(0); + z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + break; + case SAMPLE_Y | SAMPLE_Z: + x = vec4(0); + y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); + z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + break; + case SAMPLE_X: + x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); + y = vec4(0); + z = vec4(0); + break; + case SAMPLE_Y: + x = vec4(0); + y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); + z = vec4(0); + break; + case SAMPLE_Z: + default: + x = vec4(0); + y = vec4(0); + z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + break; + } + return ((x * weight.x) + (y * weight.y) + (z * weight.z)) / (weight.x + weight.y + weight.z); } @@ -110,16 +162,16 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) { float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; - vec3 weight = pow(abs(vary_vertex_normal), vec3(sharpness)); - float threshold = 0.1; + vec3 weight = normalize(pow(abs(vary_vertex_normal), vec3(sharpness))); + float threshold = TERRAIN_TRIPLANAR_MIX_THRESHOLD; weight = max(vec3(0), sign(weight - threshold)); - int sample_type = (int(weight.x) << 2) | - (int(weight.y) << 1) | - (int(weight.z) << 0); #define SAMPLE_X 1 << 2 #define SAMPLE_Y 1 << 1 #define SAMPLE_Z 1 << 0 + int sample_type = (int(weight.x) * SAMPLE_X) | + (int(weight.y) * SAMPLE_Y) | + (int(weight.z) * SAMPLE_Z); #define terrain_coord_x terrain_coord[0].zw #define terrain_coord_y terrain_coord[1].xy #define terrain_coord_z terrain_coord[0].xy -- cgit v1.2.3 From 53a5055ab72c3fb77892a3e43c769c3b19c1e97d Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:40:07 -0700 Subject: DRTVWR-592: (WIP) (has debug) Convert colors to linear before triplanar blending. General refactor. --- .../shaders/class1/deferred/pbrterrainF.glsl | 11 + .../shaders/class1/deferred/pbrterrainUtilF.glsl | 249 ++++++++++++--------- 2 files changed, 160 insertions(+), 100 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 7febbe280e..ba917416ce 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -135,6 +135,17 @@ void main() tnorm *= gl_FrontFacing ? 1.0 : -1.0; +#if 0 // TODO: Remove debug + //col.xyz = (tnorm + 1.0) / 2.0;// TODO: Remove + //col.xyz = (vary_normal + 1.0) / 2.0;// TODO: Remove + //col.xyz = spec; // TODO: Remove + //col.xyz = vec3(1); // TODO: Remove + //float weight = 1.0; spec.rgb = (weight * spec.rgb) + ((1 - weight) * vec3(1.0, 1.0, 1.0)); // TODO: Remove + tnorm = vary_normal; // TODO: Remove + spec.r = 1.0; // TODO: Remove + spec.gb = vec2(1.0, 0.0); // TODO: Remove + emissive.rgb = vec3(0); // TODO: Remove +#endif frag_data[0] = max(vec4(col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. frag_data[2] = max(vec4(encode_normal(tnorm), base_color_factor_alpha, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index b89edc9731..c72bc65cca 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -69,7 +69,15 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) // Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused) #define TerrainCoord vec4[2] +#if 0 // TODO: Revert #define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01 +#else +#define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01 +#endif + +// Positive value prevents artifacts when weights are close to zero +// TODO: Wait a minute... this doesn't prevent artifacts :( (or does it?) +#define TERRAIN_TRIPLANAR_OVERDRAW_THRESHOLD 0.0 vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign) { @@ -79,35 +87,60 @@ vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign) return texture(tex, uv); } -vec3 _t_texture_n(sampler2D tex, vec2 uv_unflipped, float sign) +vec4 _t_texture_c(sampler2D tex, vec2 uv_unflipped, float sign) { - // Unpack normal from pixel to vector - vec3 n = _t_texture(tex, uv_unflipped, sign).xyz*2.0-1.0; - // If the sign is negative, rotate normal by 180 degrees - n.xy = (min(0, sign) * n.xy) + (min(0, -sign) * -n.xy); - return n; + vec4 c = _t_texture(tex, uv_unflipped, sign); + c.xyz = srgb_to_linear(c.xyz); + return c; } -vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) +#define SAMPLE_X 1 << 2 +#define SAMPLE_Y 1 << 1 +#define SAMPLE_Z 1 << 0 +#define terrain_coord_x terrain_coord[0].zw +#define terrain_coord_y terrain_coord[1].xy +#define terrain_coord_z terrain_coord[0].xy +#define TERRAIN_DEBUG 1 // TODO: Remove debug +struct TerrainWeight +{ + vec3 weight; +#if TERRAIN_DEBUG + vec3 usage; +#endif + int type; +}; + +TerrainWeight _t_weight(TerrainCoord terrain_coord) { float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; - vec3 weight = normalize(pow(abs(vary_vertex_normal), vec3(sharpness))); float threshold = TERRAIN_TRIPLANAR_MIX_THRESHOLD; - weight = max(vec3(0), sign(weight - threshold)); - - #define SAMPLE_X 1 << 2 - #define SAMPLE_Y 1 << 1 - #define SAMPLE_Z 1 << 0 - int sample_type = (int(weight.x) * SAMPLE_X) | - (int(weight.y) * SAMPLE_Y) | - (int(weight.z) * SAMPLE_Z); - #define terrain_coord_x terrain_coord[0].zw - #define terrain_coord_y terrain_coord[1].xy - #define terrain_coord_z terrain_coord[0].xy + vec3 weight_signed = normalize(pow(abs(vary_vertex_normal), vec3(sharpness))); + weight_signed -= vec3(threshold); + TerrainWeight tw; + tw.weight = max(vec3(0), weight_signed); + vec3 usage = max(vec3(0), sign(weight_signed + TERRAIN_TRIPLANAR_OVERDRAW_THRESHOLD)); +#if TERRAIN_DEBUG + tw.usage = usage; +#endif + tw.type = (int(usage.x) * SAMPLE_X) | + (int(usage.y) * SAMPLE_Y) | + (int(usage.z) * SAMPLE_Z); + return tw; +} + +struct TerrainSample +{ vec4 x; vec4 y; vec4 z; - switch (sample_type) +}; + +TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight tw) +{ + vec4 x; + vec4 y; + vec4 z; + switch (tw.type) { case SAMPLE_X | SAMPLE_Y | SAMPLE_Z: x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); @@ -117,37 +150,98 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) case SAMPLE_X | SAMPLE_Y: x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - z = vec4(0); + z = x; break; case SAMPLE_X | SAMPLE_Z: x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - y = vec4(0); z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + y = x; break; case SAMPLE_Y | SAMPLE_Z: - x = vec4(0); y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + x = y; break; case SAMPLE_X: x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - y = vec4(0); - z = vec4(0); + y = x; + z = x; break; case SAMPLE_Y: - x = vec4(0); y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - z = vec4(0); + x = y; + z = y; break; case SAMPLE_Z: + z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + x = z; + y = z; + break; default: x = vec4(0); - y = vec4(0); - z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + y = x; + z = x; break; } - return ((x * weight.x) + (y * weight.y) + (z * weight.z)) / (weight.x + weight.y + weight.z); + TerrainSample ts; + ts.x = x; + ts.y = y; + ts.z = z; + return ts; +} + +struct TerrainSampleNormal +{ + vec3 x; + vec3 y; + vec3 z; +}; + +TerrainSampleNormal _t_sample_n(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight tw) +{ + TerrainSample ts = _t_sample(tex, terrain_coord, tw); + TerrainSampleNormal tsn; + tsn.x = ts.x.xyz; + tsn.y = ts.y.xyz; + tsn.z = ts.z.xyz; + vec3 ns = sign(vary_vertex_normal); + // If the sign is negative, rotate normal by 180 degrees + tsn.x.xy = (min(0, ns.x) * tsn.x.xy) + (min(0, -ns.x) * -tsn.x.xy); + tsn.y.xy = (min(0, ns.y) * tsn.y.xy) + (min(0, -ns.y) * -tsn.y.xy); + tsn.z.xy = (min(0, ns.z) * tsn.z.xy) + (min(0, -ns.z) * -tsn.z.xy); + // *HACK: Transform normals according to orientation of the UVs + tsn.x.xy = vec2(-tsn.x.y, tsn.x.x); + tsn.y.xy = -tsn.y.xy; + return tsn; +} + +TerrainSample _t_sample_c(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight tw) +{ + TerrainSample ts = _t_sample(tex, terrain_coord, tw); + ts.x.xyz = srgb_to_linear(ts.x.xyz); + ts.y.xyz = srgb_to_linear(ts.y.xyz); + ts.z.xyz = srgb_to_linear(ts.z.xyz); + return ts; +} + +vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) +{ + TerrainWeight tw = _t_weight(terrain_coord); + + TerrainSample ts = _t_sample(tex, terrain_coord, tw); + +#if 1 + return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); +#else // TODO: Remove debug + //return vec4(((tw.usage - normalize(tw.weight))) / 0.5, 1.0); +#if 1 + return vec4(tw.usage, 1.0); +#else + //return vec4(tw.usage, 1.0); + return vec4((tw.usage + weight) / 2.0, 1.0); +#endif +#endif } // Specialized triplanar normal texture sampling implementation, taking into @@ -156,74 +250,26 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) // *TODO: Decide if we want this. It may be better to just calculate the // tangents on-the-fly here rather than messing with the normals, due to the // subtleties of the effects of triplanar mapping on UVs. These sampled normals -// are only valid on the faces of a cube, and the pregenerated tangents are -// only valid for uv = xy. +// are only valid on the faces of a cube. // *NOTE: Bottom face has not been tested vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) { - float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; - vec3 weight = normalize(pow(abs(vary_vertex_normal), vec3(sharpness))); - float threshold = TERRAIN_TRIPLANAR_MIX_THRESHOLD; - weight = max(vec3(0), sign(weight - threshold)); - - #define SAMPLE_X 1 << 2 - #define SAMPLE_Y 1 << 1 - #define SAMPLE_Z 1 << 0 - int sample_type = (int(weight.x) * SAMPLE_X) | - (int(weight.y) * SAMPLE_Y) | - (int(weight.z) * SAMPLE_Z); - #define terrain_coord_x terrain_coord[0].zw - #define terrain_coord_y terrain_coord[1].xy - #define terrain_coord_z terrain_coord[0].xy - vec3 x; - vec3 y; - vec3 z; - switch (sample_type) - { - case SAMPLE_X | SAMPLE_Y | SAMPLE_Z: - x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z)); - break; - case SAMPLE_X | SAMPLE_Y: - x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - z = vec3(0); - break; - case SAMPLE_X | SAMPLE_Z: - x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - y = vec3(0); - z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z)); - break; - case SAMPLE_Y | SAMPLE_Z: - x = vec3(0); - y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z)); - break; - case SAMPLE_X: - x = _t_texture_n(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - y = vec3(0); - z = vec3(0); - break; - case SAMPLE_Y: - x = vec3(0); - y = _t_texture_n(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - z = vec3(0); - break; - case SAMPLE_Z: - default: - x = vec3(0); - y = vec3(0); - z = _t_texture_n(tex, terrain_coord_z, sign(vary_vertex_normal.z)); - break; - } + TerrainWeight tw = _t_weight(terrain_coord); - // *HACK: Transform normals according to orientation of the UVs - x.xy = vec2(-x.y, x.x); - y.xy = -y.xy; + TerrainSampleNormal ts = _t_sample_n(tex, terrain_coord, tw); - return ((x * weight.x) + (y * weight.y) + (z * weight.z)) / (weight.x + weight.y + weight.z); + return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); } + +vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) +{ + TerrainWeight tw = _t_weight(terrain_coord); + + TerrainSample ts = _t_sample_c(tex, terrain_coord, tw); + + return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); +} + #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 #define TerrainCoord vec2 vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) @@ -235,6 +281,13 @@ vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) { return texture(tex, terrain_coord).xyz*2.0-1.0; } + +vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) +{ + vec4 col = texture(tex, terrain_coord); + col.xyz = srgb_to_linear(col.xyz); + return col; +} #endif vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) @@ -258,14 +311,10 @@ vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, Terrain vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { vec4[4] samples; - samples[0] = terrain_texture(tex0, texcoord); - samples[1] = terrain_texture(tex1, texcoord); - samples[2] = terrain_texture(tex2, texcoord); - samples[3] = terrain_texture(tex3, texcoord); - samples[0].xyz = srgb_to_linear(samples[0].xyz); - samples[1].xyz = srgb_to_linear(samples[1].xyz); - samples[2].xyz = srgb_to_linear(samples[2].xyz); - samples[3].xyz = srgb_to_linear(samples[3].xyz); + samples[0] = terrain_texture_color(tex0, texcoord); + samples[1] = terrain_texture_color(tex1, texcoord); + samples[2] = terrain_texture_color(tex2, texcoord); + samples[3] = terrain_texture_color(tex3, texcoord); samples[0] *= factors[0]; samples[1] *= factors[1]; samples[2] *= factors[2]; -- cgit v1.2.3 From a9a08f72be2c30a40f7c6565bb82e7356245e8ec Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:40:13 -0700 Subject: DRTVWR-592: (WIP) Cleanup --- .../shaders/class1/deferred/pbrterrainF.glsl | 8 +-- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 77 ++++++++++------------ 2 files changed, 37 insertions(+), 48 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index ba917416ce..10a147a039 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -141,10 +141,10 @@ void main() //col.xyz = spec; // TODO: Remove //col.xyz = vec3(1); // TODO: Remove //float weight = 1.0; spec.rgb = (weight * spec.rgb) + ((1 - weight) * vec3(1.0, 1.0, 1.0)); // TODO: Remove - tnorm = vary_normal; // TODO: Remove - spec.r = 1.0; // TODO: Remove - spec.gb = vec2(1.0, 0.0); // TODO: Remove - emissive.rgb = vec3(0); // TODO: Remove + //tnorm = vary_normal; // TODO: Remove + //spec.r = 1.0; // TODO: Remove + //spec.gb = vec2(1.0, 0.0); // TODO: Remove + //emissive.rgb = vec3(0); // TODO: Remove #endif frag_data[0] = max(vec4(col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index c72bc65cca..1f8b0b97c7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -87,19 +87,9 @@ vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign) return texture(tex, uv); } -vec4 _t_texture_c(sampler2D tex, vec2 uv_unflipped, float sign) -{ - vec4 c = _t_texture(tex, uv_unflipped, sign); - c.xyz = srgb_to_linear(c.xyz); - return c; -} - #define SAMPLE_X 1 << 2 #define SAMPLE_Y 1 << 1 #define SAMPLE_Z 1 << 0 -#define terrain_coord_x terrain_coord[0].zw -#define terrain_coord_y terrain_coord[1].xy -#define terrain_coord_z terrain_coord[0].xy #define TERRAIN_DEBUG 1 // TODO: Remove debug struct TerrainWeight { @@ -137,57 +127,55 @@ struct TerrainSample TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight tw) { - vec4 x; - vec4 y; - vec4 z; + TerrainSample ts; + +#define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)); +#define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)); +#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)); switch (tw.type) { case SAMPLE_X | SAMPLE_Y | SAMPLE_Z: - x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); + ts.x = do_sample_x(); + ts.y = do_sample_y(); + ts.z = do_sample_z(); break; case SAMPLE_X | SAMPLE_Y: - x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - z = x; + ts.x = do_sample_x(); + ts.y = do_sample_y(); + ts.z = ts.x; break; case SAMPLE_X | SAMPLE_Z: - x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); - y = x; + ts.x = do_sample_x(); + ts.z = do_sample_z(); + ts.y = ts.x; break; case SAMPLE_Y | SAMPLE_Z: - y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); - x = y; + ts.y = do_sample_y(); + ts.z = do_sample_z(); + ts.x = ts.y; break; case SAMPLE_X: - x = _t_texture(tex, terrain_coord_x, sign(vary_vertex_normal.x)); - y = x; - z = x; + ts.x = do_sample_x(); + ts.y = ts.x; + ts.z = ts.x; break; case SAMPLE_Y: - y = _t_texture(tex, terrain_coord_y, sign(vary_vertex_normal.y)); - x = y; - z = y; + ts.y = do_sample_y(); + ts.x = ts.y; + ts.z = ts.y; break; case SAMPLE_Z: - z = _t_texture(tex, terrain_coord_z, sign(vary_vertex_normal.z)); - x = z; - y = z; + ts.z = do_sample_z(); + ts.x = ts.z; + ts.y = ts.z; break; default: - x = vec4(0); - y = x; - z = x; + ts.x = vec4(0); + ts.y = ts.x; + ts.z = ts.x; break; } - TerrainSample ts; - ts.x = x; - ts.y = y; - ts.z = z; return ts; } @@ -202,9 +190,9 @@ TerrainSampleNormal _t_sample_n(sampler2D tex, TerrainCoord terrain_coord, Terra { TerrainSample ts = _t_sample(tex, terrain_coord, tw); TerrainSampleNormal tsn; - tsn.x = ts.x.xyz; - tsn.y = ts.y.xyz; - tsn.z = ts.z.xyz; + tsn.x = ts.x.xyz*2.0-1.0; + tsn.y = ts.y.xyz*2.0-1.0; + tsn.z = ts.z.xyz*2.0-1.0; vec3 ns = sign(vary_vertex_normal); // If the sign is negative, rotate normal by 180 degrees tsn.x.xy = (min(0, ns.x) * tsn.x.xy) + (min(0, -ns.x) * -tsn.x.xy); @@ -261,6 +249,7 @@ vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); } +// Triplanar sampling of colors. Colors are converted to linear space before blending. vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) { TerrainWeight tw = _t_weight(terrain_coord); -- cgit v1.2.3 From d745b6321306a44ae9bbd5afc6fff376ebaf12e9 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:40:19 -0700 Subject: DRTVWR-592: (DEBUG) (broken) Strange sampling behavior survives weight bypass --- .../shaders/class1/deferred/pbrterrainF.glsl | 10 +++++----- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 10a147a039..19de8568b8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -135,16 +135,16 @@ void main() tnorm *= gl_FrontFacing ? 1.0 : -1.0; -#if 0 // TODO: Remove debug +#if 1 // TODO: Remove debug //col.xyz = (tnorm + 1.0) / 2.0;// TODO: Remove //col.xyz = (vary_normal + 1.0) / 2.0;// TODO: Remove //col.xyz = spec; // TODO: Remove //col.xyz = vec3(1); // TODO: Remove //float weight = 1.0; spec.rgb = (weight * spec.rgb) + ((1 - weight) * vec3(1.0, 1.0, 1.0)); // TODO: Remove - //tnorm = vary_normal; // TODO: Remove - //spec.r = 1.0; // TODO: Remove - //spec.gb = vec2(1.0, 0.0); // TODO: Remove - //emissive.rgb = vec3(0); // TODO: Remove + tnorm = vary_normal; // TODO: Remove + spec.r = 1.0; // TODO: Remove + spec.gb = vec2(1.0, 0.0); // TODO: Remove + emissive.rgb = vec3(0); // TODO: Remove #endif frag_data[0] = max(vec4(col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 1f8b0b97c7..327d23d2e7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -129,8 +129,13 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight { TerrainSample ts; -#define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)); -#define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)); +#if 0 +#define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) +#define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) +#else // TODO: Remove debug +#define do_sample_x() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) +#define do_sample_y() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) +#endif #define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)); switch (tw.type) { @@ -219,15 +224,15 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) TerrainSample ts = _t_sample(tex, terrain_coord, tw); -#if 1 +#if 0 return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); #else // TODO: Remove debug //return vec4(((tw.usage - normalize(tw.weight))) / 0.5, 1.0); -#if 1 +#if 0 return vec4(tw.usage, 1.0); #else //return vec4(tw.usage, 1.0); - return vec4((tw.usage + weight) / 2.0, 1.0); + return vec4((tw.usage + tw.weight) / 2.0, 1.0); #endif #endif } @@ -256,7 +261,11 @@ vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) TerrainSample ts = _t_sample_c(tex, terrain_coord, tw); +#if 0 return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); +#else // TODO: Remove debug + return ts.x; +#endif } #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 -- cgit v1.2.3 From aba9185f3a27221f71aa53001b45db0337a0b904 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:40:24 -0700 Subject: DRTVWR-592: (DEBUG) (broken) Strange sampling behavior isolated to switch..case blocks --- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 179 ++++++++++++++++++--- 1 file changed, 155 insertions(+), 24 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 327d23d2e7..5067e94efe 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -79,12 +79,29 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) // TODO: Wait a minute... this doesn't prevent artifacts :( (or does it?) #define TERRAIN_TRIPLANAR_OVERDRAW_THRESHOLD 0.0 -vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign) +vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign_or_zero) { + // Handle case where sign is 0 + // TODO: Why didn't this fix the seams? +#if 0 + float sign = (2.0*sign_or_zero) + 1.0; + sign /= sign; // If the vertex normal is negative, flip the texture back // right-side up. vec2 uv = uv_unflipped * vec2(sign, 1); return texture(tex, uv); +#else // TODO: Remove debug +#if 0 + // Name mangling test + float l_sign = (2.0*sign_or_zero) + 1.0; + l_sign /= l_sign; + vec2 l_uv = uv_unflipped * vec2(l_sign, 1); + return texture(tex, l_uv); +#else + // Simplified uv test + return texture(tex, uv_unflipped); +#endif +#endif } #define SAMPLE_X 1 << 2 @@ -94,10 +111,11 @@ vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign) struct TerrainWeight { vec3 weight; + int type; #if TERRAIN_DEBUG + vec3 weight_signed; vec3 usage; #endif - int type; }; TerrainWeight _t_weight(TerrainCoord terrain_coord) @@ -109,12 +127,13 @@ TerrainWeight _t_weight(TerrainCoord terrain_coord) TerrainWeight tw; tw.weight = max(vec3(0), weight_signed); vec3 usage = max(vec3(0), sign(weight_signed + TERRAIN_TRIPLANAR_OVERDRAW_THRESHOLD)); -#if TERRAIN_DEBUG - tw.usage = usage; -#endif tw.type = (int(usage.x) * SAMPLE_X) | (int(usage.y) * SAMPLE_Y) | (int(usage.z) * SAMPLE_Z); +#if TERRAIN_DEBUG + tw.weight_signed = weight_signed; + tw.usage = usage; +#endif return tw; } @@ -129,32 +148,44 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight { TerrainSample ts; -#if 0 +#if 1 +#if 1 +#if 1 #define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) #define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) #else // TODO: Remove debug +// Still an error despite sampling the same texture three times from the same location #define do_sample_x() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) #define do_sample_y() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) #endif -#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)); +#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) +#else // TODO: Remove? + vec2 coord_z = terrain_coord[0].xy; + vec2 coord_z_2 = terrain_coord[0].xy; + vec2 coord_z_3 = terrain_coord[0].xy; +#define do_sample_x() texture(tex, coord_z) +#define do_sample_y() texture(tex, coord_z_2) +#define do_sample_z() texture(tex, coord_z_3) +#endif +#if 0 switch (tw.type) { - case SAMPLE_X | SAMPLE_Y | SAMPLE_Z: + case (SAMPLE_X | SAMPLE_Y | SAMPLE_Z): ts.x = do_sample_x(); ts.y = do_sample_y(); ts.z = do_sample_z(); break; - case SAMPLE_X | SAMPLE_Y: + case (SAMPLE_X | SAMPLE_Y): ts.x = do_sample_x(); ts.y = do_sample_y(); ts.z = ts.x; break; - case SAMPLE_X | SAMPLE_Z: + case (SAMPLE_X | SAMPLE_Z): ts.x = do_sample_x(); ts.z = do_sample_z(); ts.y = ts.x; break; - case SAMPLE_Y | SAMPLE_Z: + case (SAMPLE_Y | SAMPLE_Z): ts.y = do_sample_y(); ts.z = do_sample_z(); ts.x = ts.y; @@ -175,11 +206,114 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight ts.y = ts.z; break; default: - ts.x = vec4(0); + ts.x = vec4(1.0, 0.0, 1.0, 1.0); + ts.y = ts.x; + ts.z = ts.x; + break; + } +#else // TODO: Remove debug +#if 0 + // This case works - no ant trails despite using a switch...case statement + switch (tw.type) + { + case (SAMPLE_X | SAMPLE_Y | SAMPLE_Z): + ts.x = vec4(1.0, 0.0, 0.0, 1.0); + ts.y = vec4(0.0, 1.0, 0.0, 1.0); + ts.z = vec4(0.0, 0.0, 1.0, 1.0); + break; + case (SAMPLE_X | SAMPLE_Y): + ts.x = vec4(1.0, 0.0, 0.0, 1.0); + ts.y = vec4(0.0, 1.0, 0.0, 1.0); + ts.z = ts.x; + break; + case (SAMPLE_X | SAMPLE_Z): + ts.x = vec4(1.0, 0.0, 0.0, 1.0); + ts.z = vec4(0.0, 0.0, 1.0, 1.0); + ts.y = ts.x; + break; + case (SAMPLE_Y | SAMPLE_Z): + ts.y = vec4(0.0, 1.0, 0.0, 1.0); + ts.z = vec4(0.0, 0.0, 1.0, 1.0); + ts.x = ts.y; + break; + case SAMPLE_X: + ts.x = vec4(1.0, 0.0, 0.0, 1.0); + ts.y = ts.x; + ts.z = ts.x; + break; + case SAMPLE_Y: + ts.y = vec4(0.0, 1.0, 0.0, 1.0); + ts.x = ts.y; + ts.z = ts.y; + break; + case SAMPLE_Z: + ts.z = vec4(0.0, 0.0, 1.0, 1.0); + ts.x = ts.z; + ts.y = ts.z; + break; + default: + ts.x = vec4(1.0, 0.0, 1.0, 1.0); + ts.y = ts.x; + ts.z = ts.x; + break; + } +#else +// This shows the bug: case of sampling beforehand, assigning in switch..case + vec4 x = do_sample_x(); + vec4 y = do_sample_y(); + vec4 z = do_sample_z(); + switch (tw.type) + { + case (SAMPLE_X | SAMPLE_Y | SAMPLE_Z): + ts.x = x; + ts.y = y; + ts.z = z; + break; + case (SAMPLE_X | SAMPLE_Y): + ts.x = x; + ts.y = y; + ts.z = ts.x; + break; + case (SAMPLE_X | SAMPLE_Z): + ts.x = x; + ts.z = z; + ts.y = ts.x; + break; + case (SAMPLE_Y | SAMPLE_Z): + ts.y = y; + ts.z = z; + ts.x = ts.y; + break; + case SAMPLE_X: + ts.x = x; + ts.y = ts.x; + ts.z = ts.x; + break; + case SAMPLE_Y: + ts.y = y; + ts.x = ts.y; + ts.z = ts.y; + break; + case SAMPLE_Z: + ts.z = z; + ts.x = ts.z; + ts.y = ts.z; + break; + default: + ts.x = vec4(1.0, 0.0, 1.0, 1.0); ts.y = ts.x; ts.z = ts.x; break; } +#endif +#endif +#else // TODO: Remove debug +// No error +#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)); +ts.z = do_sample_z(); +ts.x = ts.z; +ts.y = ts.z; +#endif return ts; } @@ -218,23 +352,14 @@ TerrainSample _t_sample_c(sampler2D tex, TerrainCoord terrain_coord, TerrainWeig return ts; } +// Triplanar sampling of things that are neither colors nor normals (i.e. orm) vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) { TerrainWeight tw = _t_weight(terrain_coord); TerrainSample ts = _t_sample(tex, terrain_coord, tw); -#if 0 return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); -#else // TODO: Remove debug - //return vec4(((tw.usage - normalize(tw.weight))) / 0.5, 1.0); -#if 0 - return vec4(tw.usage, 1.0); -#else - //return vec4(tw.usage, 1.0); - return vec4((tw.usage + tw.weight) / 2.0, 1.0); -#endif -#endif } // Specialized triplanar normal texture sampling implementation, taking into @@ -261,10 +386,16 @@ vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) TerrainSample ts = _t_sample_c(tex, terrain_coord, tw); -#if 0 +#if 1 return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); #else // TODO: Remove debug - return ts.x; + //return vec4(vec3(isnan(ts.x)), 1.0); + //return ts.x; +#if 0 + return vec4(1.0+sign(vary_vertex_normal)/2.0, 1.0); +#else + return vec4(isnan(tw.weight_signed), 1.0); +#endif #endif } -- cgit v1.2.3 From fb12fb4bf7bbbf457b4f81356b0d0fadf2b42664 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:40:29 -0700 Subject: DRTVWR-592: (DEBUG) (broken) Clean up a few debug cases not used for reproducing the bug --- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 100 +++------------------ 1 file changed, 12 insertions(+), 88 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 5067e94efe..a40f70a9e2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -69,39 +69,22 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) // Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused) #define TerrainCoord vec4[2] -#if 0 // TODO: Revert +// TODO: Decide if we want this threshold +#if 0 #define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01 -#else +#else // TODO: Remove debug #define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01 #endif -// Positive value prevents artifacts when weights are close to zero -// TODO: Wait a minute... this doesn't prevent artifacts :( (or does it?) -#define TERRAIN_TRIPLANAR_OVERDRAW_THRESHOLD 0.0 - vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign_or_zero) { // Handle case where sign is 0 - // TODO: Why didn't this fix the seams? -#if 0 float sign = (2.0*sign_or_zero) + 1.0; sign /= sign; // If the vertex normal is negative, flip the texture back // right-side up. vec2 uv = uv_unflipped * vec2(sign, 1); return texture(tex, uv); -#else // TODO: Remove debug -#if 0 - // Name mangling test - float l_sign = (2.0*sign_or_zero) + 1.0; - l_sign /= l_sign; - vec2 l_uv = uv_unflipped * vec2(l_sign, 1); - return texture(tex, l_uv); -#else - // Simplified uv test - return texture(tex, uv_unflipped); -#endif -#endif } #define SAMPLE_X 1 << 2 @@ -126,7 +109,7 @@ TerrainWeight _t_weight(TerrainCoord terrain_coord) weight_signed -= vec3(threshold); TerrainWeight tw; tw.weight = max(vec3(0), weight_signed); - vec3 usage = max(vec3(0), sign(weight_signed + TERRAIN_TRIPLANAR_OVERDRAW_THRESHOLD)); + vec3 usage = max(vec3(0), sign(weight_signed)); tw.type = (int(usage.x) * SAMPLE_X) | (int(usage.y) * SAMPLE_Y) | (int(usage.z) * SAMPLE_Z); @@ -149,25 +132,16 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight TerrainSample ts; #if 1 -#if 1 -#if 1 +// This demonstrates the case when the bug occurs: Sampling in switch..case +#if 0 #define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) #define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) #else // TODO: Remove debug -// Still an error despite sampling the same texture three times from the same location +// Bug still occurs despite sampling the same texture three times from the same location #define do_sample_x() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) #define do_sample_y() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) #endif #define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) -#else // TODO: Remove? - vec2 coord_z = terrain_coord[0].xy; - vec2 coord_z_2 = terrain_coord[0].xy; - vec2 coord_z_3 = terrain_coord[0].xy; -#define do_sample_x() texture(tex, coord_z) -#define do_sample_y() texture(tex, coord_z_2) -#define do_sample_z() texture(tex, coord_z_3) -#endif -#if 0 switch (tw.type) { case (SAMPLE_X | SAMPLE_Y | SAMPLE_Z): @@ -212,53 +186,11 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight break; } #else // TODO: Remove debug -#if 0 - // This case works - no ant trails despite using a switch...case statement - switch (tw.type) - { - case (SAMPLE_X | SAMPLE_Y | SAMPLE_Z): - ts.x = vec4(1.0, 0.0, 0.0, 1.0); - ts.y = vec4(0.0, 1.0, 0.0, 1.0); - ts.z = vec4(0.0, 0.0, 1.0, 1.0); - break; - case (SAMPLE_X | SAMPLE_Y): - ts.x = vec4(1.0, 0.0, 0.0, 1.0); - ts.y = vec4(0.0, 1.0, 0.0, 1.0); - ts.z = ts.x; - break; - case (SAMPLE_X | SAMPLE_Z): - ts.x = vec4(1.0, 0.0, 0.0, 1.0); - ts.z = vec4(0.0, 0.0, 1.0, 1.0); - ts.y = ts.x; - break; - case (SAMPLE_Y | SAMPLE_Z): - ts.y = vec4(0.0, 1.0, 0.0, 1.0); - ts.z = vec4(0.0, 0.0, 1.0, 1.0); - ts.x = ts.y; - break; - case SAMPLE_X: - ts.x = vec4(1.0, 0.0, 0.0, 1.0); - ts.y = ts.x; - ts.z = ts.x; - break; - case SAMPLE_Y: - ts.y = vec4(0.0, 1.0, 0.0, 1.0); - ts.x = ts.y; - ts.z = ts.y; - break; - case SAMPLE_Z: - ts.z = vec4(0.0, 0.0, 1.0, 1.0); - ts.x = ts.z; - ts.y = ts.z; - break; - default: - ts.x = vec4(1.0, 0.0, 1.0, 1.0); - ts.y = ts.x; - ts.z = ts.x; - break; - } -#else -// This shows the bug: case of sampling beforehand, assigning in switch..case +// This demonstrates the case when the bug does not occur: Sampling beforehand and assigning in switch..case +// This otherwise uses the same logic as in the case that reproduces the bug. +#define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) +#define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) +#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) vec4 x = do_sample_x(); vec4 y = do_sample_y(); vec4 z = do_sample_z(); @@ -305,14 +237,6 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight ts.z = ts.x; break; } -#endif -#endif -#else // TODO: Remove debug -// No error -#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)); -ts.z = do_sample_z(); -ts.x = ts.z; -ts.y = ts.z; #endif return ts; -- cgit v1.2.3 From be39e92f7d3c6df80eeb1f183723978ce1bf1b52 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:41:19 -0700 Subject: DRTVWR-592: (WIP) (has debug) Fix "ant trail" seams in terrain caused by multiple texture lookups in a switch..case block --- .../shaders/class1/deferred/pbrterrainF.glsl | 2 +- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 44 +++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 19de8568b8..ba917416ce 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -135,7 +135,7 @@ void main() tnorm *= gl_FrontFacing ? 1.0 : -1.0; -#if 1 // TODO: Remove debug +#if 0 // TODO: Remove debug //col.xyz = (tnorm + 1.0) / 2.0;// TODO: Remove //col.xyz = (vary_normal + 1.0) / 2.0;// TODO: Remove //col.xyz = spec; // TODO: Remove diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index a40f70a9e2..fc04afe513 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -131,7 +131,7 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight { TerrainSample ts; -#if 1 +#if 0 // This demonstrates the case when the bug occurs: Sampling in switch..case #if 0 #define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) @@ -142,7 +142,12 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight #define do_sample_y() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) #endif #define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) +#if 0 switch (tw.type) +#else // TODO: Remove debug +// Bug still occurs when the type is masked + switch (tw.type & (SAMPLE_X | SAMPLE_Y | SAMPLE_Z)) +#endif { case (SAMPLE_X | SAMPLE_Y | SAMPLE_Z): ts.x = do_sample_x(); @@ -186,6 +191,7 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight break; } #else // TODO: Remove debug +#if 0 // This demonstrates the case when the bug does not occur: Sampling beforehand and assigning in switch..case // This otherwise uses the same logic as in the case that reproduces the bug. #define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) @@ -237,6 +243,42 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight ts.z = ts.x; break; } +#else // TODO: Keep? +// Test case where the switch..case is broken up into three parts +// This fixes unexplained, "ant trail" seams in terrain. (as seen on Nvidia/Windows 10) +// The extra two branches are not free, but it's still a performance win +// compared to sampling along all three axes for every terrain fragment. +#define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) +#define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) +#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) +switch (tw.type & SAMPLE_X) +{ + case SAMPLE_X: + ts.x = do_sample_x(); + break; + default: + ts.x = vec4(1.0, 0.0, 1.0, 1.0); + break; +} +switch (tw.type & SAMPLE_Y) +{ + case SAMPLE_Y: + ts.y = do_sample_y(); + break; + default: + ts.y = vec4(1.0, 0.0, 1.0, 1.0); + break; +} +switch (tw.type & SAMPLE_Z) +{ + case SAMPLE_Z: + ts.z = do_sample_z(); + break; + default: + ts.z = vec4(1.0, 0.0, 1.0, 1.0); + break; +} +#endif #endif return ts; -- cgit v1.2.3 From 823fcddcb508fac6d1f819633f6a91230f06b114 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:02 -0700 Subject: DRTVWR-592: (WIP) (has debug) Fix removing axial sign flip of normal texture during zero check, add another zero check --- .../app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index fc04afe513..c5de74604f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -80,7 +80,7 @@ vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign_or_zero) { // Handle case where sign is 0 float sign = (2.0*sign_or_zero) + 1.0; - sign /= sign; + sign /= abs(sign); // If the vertex normal is negative, flip the texture back // right-side up. vec2 uv = uv_unflipped * vec2(sign, 1); @@ -190,8 +190,8 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight ts.z = ts.x; break; } -#else // TODO: Remove debug -#if 0 +#else +#if 0 // TODO: Remove debug // This demonstrates the case when the bug does not occur: Sampling beforehand and assigning in switch..case // This otherwise uses the same logic as in the case that reproduces the bug. #define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) @@ -295,10 +295,15 @@ TerrainSampleNormal _t_sample_n(sampler2D tex, TerrainCoord terrain_coord, Terra { TerrainSample ts = _t_sample(tex, terrain_coord, tw); TerrainSampleNormal tsn; + // Unpack normals tsn.x = ts.x.xyz*2.0-1.0; tsn.y = ts.y.xyz*2.0-1.0; tsn.z = ts.z.xyz*2.0-1.0; + // Get sign vec3 ns = sign(vary_vertex_normal); + // Handle case where sign is 0 + ns = (2.0*ns) + 1.0; + ns /= abs(ns); // If the sign is negative, rotate normal by 180 degrees tsn.x.xy = (min(0, ns.x) * tsn.x.xy) + (min(0, -ns.x) * -tsn.x.xy); tsn.y.xy = (min(0, ns.y) * tsn.y.xy) + (min(0, -ns.y) * -tsn.y.xy); -- cgit v1.2.3 From c48837ef9b7cd016577b2f54f3f6b52764c32e17 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:07 -0700 Subject: DRTVWR-592: (WIP) (has debug) More rigorous definition of usage vector for triplanar that avoids possible case where 1 = 0.9999, which gets rounded down to 0 on int cast --- .../app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index c5de74604f..1ea1ced45b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -97,7 +97,7 @@ struct TerrainWeight int type; #if TERRAIN_DEBUG vec3 weight_signed; - vec3 usage; + ivec3 usage; #endif }; @@ -109,10 +109,10 @@ TerrainWeight _t_weight(TerrainCoord terrain_coord) weight_signed -= vec3(threshold); TerrainWeight tw; tw.weight = max(vec3(0), weight_signed); - vec3 usage = max(vec3(0), sign(weight_signed)); - tw.type = (int(usage.x) * SAMPLE_X) | - (int(usage.y) * SAMPLE_Y) | - (int(usage.z) * SAMPLE_Z); + ivec3 usage = ivec3(round(max(vec3(0), sign(weight_signed)))); + tw.type = ((usage.x) * SAMPLE_X) | + ((usage.y) * SAMPLE_Y) | + ((usage.z) * SAMPLE_Z); #if TERRAIN_DEBUG tw.weight_signed = weight_signed; tw.usage = usage; -- cgit v1.2.3 From fa11e94c3cf4fad439dc10db630c747c8da42dd8 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:12 -0700 Subject: DRTVWR-592: Clean up debug and test cases for ant trails artifact. Fix whitespace --- .../shaders/class1/deferred/pbrterrainF.glsl | 11 -- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 182 +++------------------ 2 files changed, 24 insertions(+), 169 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index ba917416ce..7febbe280e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -135,17 +135,6 @@ void main() tnorm *= gl_FrontFacing ? 1.0 : -1.0; -#if 0 // TODO: Remove debug - //col.xyz = (tnorm + 1.0) / 2.0;// TODO: Remove - //col.xyz = (vary_normal + 1.0) / 2.0;// TODO: Remove - //col.xyz = spec; // TODO: Remove - //col.xyz = vec3(1); // TODO: Remove - //float weight = 1.0; spec.rgb = (weight * spec.rgb) + ((1 - weight) * vec3(1.0, 1.0, 1.0)); // TODO: Remove - tnorm = vary_normal; // TODO: Remove - spec.r = 1.0; // TODO: Remove - spec.gb = vec2(1.0, 0.0); // TODO: Remove - emissive.rgb = vec3(0); // TODO: Remove -#endif frag_data[0] = max(vec4(col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. frag_data[2] = max(vec4(encode_normal(tnorm), base_color_factor_alpha, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 1ea1ced45b..e2d6cdb2d6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -69,12 +69,7 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) // Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused) #define TerrainCoord vec4[2] -// TODO: Decide if we want this threshold -#if 0 #define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01 -#else // TODO: Remove debug -#define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01 -#endif vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign_or_zero) { @@ -90,15 +85,10 @@ vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign_or_zero) #define SAMPLE_X 1 << 2 #define SAMPLE_Y 1 << 1 #define SAMPLE_Z 1 << 0 -#define TERRAIN_DEBUG 1 // TODO: Remove debug struct TerrainWeight { vec3 weight; int type; -#if TERRAIN_DEBUG - vec3 weight_signed; - ivec3 usage; -#endif }; TerrainWeight _t_weight(TerrainCoord terrain_coord) @@ -131,155 +121,41 @@ TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight { TerrainSample ts; -#if 0 -// This demonstrates the case when the bug occurs: Sampling in switch..case -#if 0 -#define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) -#define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) -#else // TODO: Remove debug -// Bug still occurs despite sampling the same texture three times from the same location -#define do_sample_x() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) -#define do_sample_y() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) -#endif -#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) -#if 0 - switch (tw.type) -#else // TODO: Remove debug -// Bug still occurs when the type is masked - switch (tw.type & (SAMPLE_X | SAMPLE_Y | SAMPLE_Z)) -#endif + // The switch..case is broken up into three parts deliberately. A single + // switch..case caused unexplained, "ant trail" seams in terrain. (as seen + // on Nvidia/Windows 10). The extra two branches are not free, but it's + // still a performance win compared to sampling along all three axes for + // every terrain fragment. + #define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) + #define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) + #define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) + switch (tw.type & SAMPLE_X) { - case (SAMPLE_X | SAMPLE_Y | SAMPLE_Z): - ts.x = do_sample_x(); - ts.y = do_sample_y(); - ts.z = do_sample_z(); - break; - case (SAMPLE_X | SAMPLE_Y): - ts.x = do_sample_x(); - ts.y = do_sample_y(); - ts.z = ts.x; - break; - case (SAMPLE_X | SAMPLE_Z): - ts.x = do_sample_x(); - ts.z = do_sample_z(); - ts.y = ts.x; - break; - case (SAMPLE_Y | SAMPLE_Z): - ts.y = do_sample_y(); - ts.z = do_sample_z(); - ts.x = ts.y; - break; case SAMPLE_X: ts.x = do_sample_x(); - ts.y = ts.x; - ts.z = ts.x; - break; - case SAMPLE_Y: - ts.y = do_sample_y(); - ts.x = ts.y; - ts.z = ts.y; - break; - case SAMPLE_Z: - ts.z = do_sample_z(); - ts.x = ts.z; - ts.y = ts.z; - break; + break; default: ts.x = vec4(1.0, 0.0, 1.0, 1.0); - ts.y = ts.x; - ts.z = ts.x; - break; + break; } -#else -#if 0 // TODO: Remove debug -// This demonstrates the case when the bug does not occur: Sampling beforehand and assigning in switch..case -// This otherwise uses the same logic as in the case that reproduces the bug. -#define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) -#define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) -#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) - vec4 x = do_sample_x(); - vec4 y = do_sample_y(); - vec4 z = do_sample_z(); - switch (tw.type) + switch (tw.type & SAMPLE_Y) { - case (SAMPLE_X | SAMPLE_Y | SAMPLE_Z): - ts.x = x; - ts.y = y; - ts.z = z; - break; - case (SAMPLE_X | SAMPLE_Y): - ts.x = x; - ts.y = y; - ts.z = ts.x; - break; - case (SAMPLE_X | SAMPLE_Z): - ts.x = x; - ts.z = z; - ts.y = ts.x; - break; - case (SAMPLE_Y | SAMPLE_Z): - ts.y = y; - ts.z = z; - ts.x = ts.y; - break; - case SAMPLE_X: - ts.x = x; - ts.y = ts.x; - ts.z = ts.x; - break; case SAMPLE_Y: - ts.y = y; - ts.x = ts.y; - ts.z = ts.y; - break; + ts.y = do_sample_y(); + break; + default: + ts.y = vec4(1.0, 0.0, 1.0, 1.0); + break; + } + switch (tw.type & SAMPLE_Z) + { case SAMPLE_Z: - ts.z = z; - ts.x = ts.z; - ts.y = ts.z; - break; + ts.z = do_sample_z(); + break; default: - ts.x = vec4(1.0, 0.0, 1.0, 1.0); - ts.y = ts.x; - ts.z = ts.x; - break; + ts.z = vec4(1.0, 0.0, 1.0, 1.0); + break; } -#else // TODO: Keep? -// Test case where the switch..case is broken up into three parts -// This fixes unexplained, "ant trail" seams in terrain. (as seen on Nvidia/Windows 10) -// The extra two branches are not free, but it's still a performance win -// compared to sampling along all three axes for every terrain fragment. -#define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) -#define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) -#define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) -switch (tw.type & SAMPLE_X) -{ - case SAMPLE_X: - ts.x = do_sample_x(); - break; - default: - ts.x = vec4(1.0, 0.0, 1.0, 1.0); - break; -} -switch (tw.type & SAMPLE_Y) -{ - case SAMPLE_Y: - ts.y = do_sample_y(); - break; - default: - ts.y = vec4(1.0, 0.0, 1.0, 1.0); - break; -} -switch (tw.type & SAMPLE_Z) -{ - case SAMPLE_Z: - ts.z = do_sample_z(); - break; - default: - ts.z = vec4(1.0, 0.0, 1.0, 1.0); - break; -} -#endif -#endif return ts; } @@ -357,17 +233,7 @@ vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) TerrainSample ts = _t_sample_c(tex, terrain_coord, tw); -#if 1 return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); -#else // TODO: Remove debug - //return vec4(vec3(isnan(ts.x)), 1.0); - //return ts.x; -#if 0 - return vec4(1.0+sign(vary_vertex_normal)/2.0, 1.0); -#else - return vec4(isnan(tw.weight_signed), 1.0); -#endif -#endif } #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 -- cgit v1.2.3 From b1a3a274ffe539ea61d9fd7aa6f95f44049964e2 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:18 -0700 Subject: DRTVWR-592: Don't read UVs for PBR terrain in single-plane case - works out to be more expensive than triplanar in some cases, and UVs are already trivial --- indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index 2df5faf037..64ab3bbb13 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -84,7 +84,7 @@ void main() // (-x)z vary_coords[1].xy = texture_transform(position.xz * vec2(-1, 1), texture_base_color_transform, texture_matrix0); #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 - vary_texcoord0.xy = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); + vary_texcoord0.xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0); #endif vec4 tc = vec4(texcoord1,0,1); -- cgit v1.2.3 From 6e949e5d63c56a899b6a7745fcca04e0cd2f9639 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:24 -0700 Subject: DRTVWR-592: Remove shader cruft --- .../app_settings/shaders/class1/deferred/pbrterrainV.glsl | 1 - indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index 64ab3bbb13..dbb9404219 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -31,7 +31,6 @@ in vec3 position; in vec3 normal; in vec4 tangent; in vec4 diffuse_color; -in vec2 texcoord0; in vec2 texcoord1; #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl index f6d3b59e85..33a78fd26d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl @@ -30,7 +30,6 @@ uniform mat4 modelview_projection_matrix; in vec3 position; in vec3 normal; in vec4 diffuse_color; -in vec2 texcoord0; in vec2 texcoord1; out vec3 pos; @@ -41,18 +40,16 @@ out vec4 vary_texcoord1; uniform vec4 object_plane_s; uniform vec4 object_plane_t; -vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1) +vec2 texgen_object(vec4 vpos, mat4 mat, vec4 tp0, vec4 tp1) { vec4 tcoord; tcoord.x = dot(vpos, tp0); tcoord.y = dot(vpos, tp1); - tcoord.z = tc.z; - tcoord.w = tc.w; tcoord = mat * tcoord; - return tcoord; + return tcoord.xy; } void main() @@ -67,7 +64,7 @@ void main() vary_normal = normalize(normal_matrix * normal); // Transform and pass tex coords - vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy; + vary_texcoord0.xy = texgen_object(vec4(position, 1.0), texture_matrix0, object_plane_s, object_plane_t); vec4 t = vec4(texcoord1,0,1); -- cgit v1.2.3 From 1d885181d850388feb89c92a018cb591b5cc7f18 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:29 -0700 Subject: DRTVWR-592: (WIP) (has debug) Apply triplanar optimization technique to PBR material sampling. Use slightly different alpha ramp to hide unused materials --- .../shaders/class1/deferred/pbrterrainF.glsl | 61 ++++- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 288 +++++++++++++++++---- 2 files changed, 301 insertions(+), 48 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 7febbe280e..7b5eba14b7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -82,6 +82,19 @@ vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, Terrain vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); vec3 sample_and_mix_normal(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); +#if 1 // TODO: Remove +#define TERRAIN_DEBUG 1 // TODO: Remove debug +struct TerrainMix +{ + vec4 weight; + int type; +#if TERRAIN_DEBUG + ivec4 usage; +#endif +}; +TerrainMix _t_mix(float alpha1, float alpha2, float alphaFinal); +#endif + void main() { @@ -125,16 +138,60 @@ void main() // from mikktspace.com vec3 vNt = sample_and_mix_normal(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); - float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; - vec3 vB = sign * cross(vN, vT); + vec3 vB = vary_sign * cross(vN, vT); vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); tnorm *= gl_FrontFacing ? 1.0 : -1.0; +#if 0 // TODO: Remove (terrain weights visualization) + TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); +#if 1 + // Show full usage and weights + float uw = 0.3; +#if 1 +#if 0 + vec4 mix_usage = vec4(tm.usage); +#else + vec4 mix_usage = vec4(tm.weight); +#endif +#else + // Version with easier-to-see boundaries of weights vs usage + vec4 mix_usage = mix(vec4(tm.usage), + mix(max(vec4(0.0), sign(tm.weight - 0.01)), + max(vec4(0.0), sign(tm.weight - 0.005)), + 0.5), + uw); +#endif + col.xyz = mix_usage.xyz; + col.x = max(col.x, mix_usage.w); + //col.y = 0.0; + //col.z = 0.0; +#else + // Show places where weight > usage + tolerance + float tolerance = 0.005; + vec4 weight_gt_usage = sign( + max( + vec4(0.0), + (tm.weight - (vec4(tm.usage) + vec4(tolerance))) + ) + ); + col.xyz = weight_gt_usage.xyz; + col.x = max(col.x, weight_gt_usage.w); +#endif +#endif +#if 0 // TODO: Remove (material channel discriminator) + //col.rgb = vec3(0.0, 1.0, 0.0); + //col.rgb = spec.rgb; + //col.rgb = (vNt + 1.0) / 2.0; + col.rgb = (tnorm + 1.0) / 2.0; + spec.rgb = vec3(1.0, 1.0, 0.0); + tnorm = vary_normal; + emissive = vec3(0); +#endif frag_data[0] = max(vec4(col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. frag_data[2] = max(vec4(encode_normal(tnorm), base_color_factor_alpha, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index e2d6cdb2d6..59b273afc3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -49,11 +49,62 @@ in vec3 vary_vertex_normal; vec3 srgb_to_linear(vec3 c); +// A relatively agressive threshold ensures that only one or two materials are used in most places +#define TERRAIN_RAMP_MIX_THRESHOLD 0.1 + +#define MIX_X 1 << 3 +#define MIX_Y 1 << 2 +#define MIX_Z 1 << 1 +#define MIX_W 1 << 0 + +#define TERRAIN_DEBUG 1 // TODO: Remove debug +struct TerrainMix +{ + vec4 weight; + int type; +#if TERRAIN_DEBUG + ivec4 usage; +#endif +}; + +#define TerrainMixSample vec4[4] +#define TerrainMixSample3 vec3[4] + +TerrainMix _t_mix(float alpha1, float alpha2, float alphaFinal) +{ + TerrainMix tm; + vec4 sample_x = vec4(1,0,0,0); + vec4 sample_y = vec4(0,1,0,0); + vec4 sample_z = vec4(0,0,1,0); + vec4 sample_w = vec4(0,0,0,1); + + tm.weight = mix( mix(sample_w, sample_z, alpha2), mix(sample_y, sample_x, alpha1), alphaFinal ); + tm.weight -= TERRAIN_RAMP_MIX_THRESHOLD; + ivec4 usage = max(ivec4(0), ivec4(ceil(tm.weight))); + // Prevent negative weights and keep weights balanced + tm.weight = normalize(tm.weight*vec4(usage)); + + tm.type = (usage.x * MIX_X) | + (usage.y * MIX_Y) | + (usage.z * MIX_Z) | + (usage.w * MIX_W); +#if TERRAIN_DEBUG // TODO: Remove debug + tm.usage = usage; +#endif + return tm; +} + float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) { - return mix( mix(samples.w, samples.z, alpha2), mix(samples.y, samples.x, alpha1), alphaFinal ); + TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + // Assume weights are normalized + return tm.weight.x * samples.x + + tm.weight.y * samples.y + + tm.weight.z * samples.z + + tm.weight.w * samples.w; } +#if 0 // TODO: Decide if still needed, and if so, use _t_mix internally for weights vec3 terrain_mix(vec3[4] samples, float alpha1, float alpha2, float alphaFinal) { return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); @@ -63,6 +114,25 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) { return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); } +#endif + +vec4 terrain_mix(TerrainMix tm, TerrainMixSample tms) +{ + // Assume weights are normalized + return tm.weight.x * tms[0] + + tm.weight.y * tms[1] + + tm.weight.z * tms[2] + + tm.weight.w * tms[3]; +} + +vec3 terrain_mix(TerrainMix tm, TerrainMixSample3 tms3) +{ + // Assume weights are normalized + return tm.weight.x * tms3[0] + + tm.weight.y * tms3[1] + + tm.weight.z * tms3[2] + + tm.weight.w * tms3[3]; +} #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 // Triplanar mapping @@ -98,15 +168,12 @@ TerrainWeight _t_weight(TerrainCoord terrain_coord) vec3 weight_signed = normalize(pow(abs(vary_vertex_normal), vec3(sharpness))); weight_signed -= vec3(threshold); TerrainWeight tw; - tw.weight = max(vec3(0), weight_signed); + // *NOTE: Make sure the threshold doesn't affect the materials + tw.weight = normalize(max(vec3(0), weight_signed)); ivec3 usage = ivec3(round(max(vec3(0), sign(weight_signed)))); tw.type = ((usage.x) * SAMPLE_X) | ((usage.y) * SAMPLE_Y) | ((usage.z) * SAMPLE_Z); -#if TERRAIN_DEBUG - tw.weight_signed = weight_signed; - tw.usage = usage; -#endif return tw; } @@ -256,59 +323,188 @@ vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) } #endif +// The goal of _tmix_sample and related functions is to only sample textures when necessary, ignoring if the weights are low. +// *TODO: Currently, there is much more switch..case branching than needed. This could be simplified by branching per-material rather than per-texture. + +TerrainMixSample _tmix_sample(TerrainMix tm, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + TerrainMixSample tms; + + switch (tm.type & MIX_X) + { + case MIX_X: + tms[0] = terrain_texture(tex0, texcoord); + break; + default: + tms[0] = vec4(1.0, 0.0, 1.0, 1.0); + break; + } + switch (tm.type & MIX_Y) + { + case MIX_Y: + tms[1] = terrain_texture(tex1, texcoord); + break; + default: + tms[1] = vec4(1.0, 0.0, 1.0, 1.0); + break; + } + switch (tm.type & MIX_Z) + { + case MIX_Z: + tms[2] = terrain_texture(tex2, texcoord); + break; + default: + tms[2] = vec4(1.0, 0.0, 1.0, 1.0); + break; + } + switch (tm.type & MIX_W) + { + case MIX_W: + tms[3] = terrain_texture(tex3, texcoord); + break; + default: + tms[3] = vec4(1.0, 0.0, 1.0, 1.0); + break; + } + + return tms; +} + +TerrainMixSample _tmix_sample_color(TerrainMix tm, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + TerrainMixSample tmix; + + switch (tm.type & MIX_X) + { + case MIX_X: + tmix[0] = terrain_texture_color(tex0, texcoord); + break; + default: + tmix[0] = vec4(1.0, 0.0, 1.0, 1.0); + break; + } + switch (tm.type & MIX_Y) + { + case MIX_Y: + tmix[1] = terrain_texture_color(tex1, texcoord); + break; + default: + tmix[1] = vec4(1.0, 0.0, 1.0, 1.0); + break; + } + switch (tm.type & MIX_Z) + { + case MIX_Z: + tmix[2] = terrain_texture_color(tex2, texcoord); + break; + default: + tmix[2] = vec4(1.0, 0.0, 1.0, 1.0); + break; + } + switch (tm.type & MIX_W) + { + case MIX_W: + tmix[3] = terrain_texture_color(tex3, texcoord); + break; + default: + tmix[3] = vec4(1.0, 0.0, 1.0, 1.0); + break; + } + + return tmix; +} + +TerrainMixSample3 _tmix_sample_normal(TerrainMix tm, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) +{ + TerrainMixSample3 tmix3; + + switch (tm.type & MIX_X) + { + case MIX_X: + tmix3[0] = terrain_texture_normal(tex0, texcoord); + break; + default: + tmix3[0] = vec3(1.0, 0.0, 1.0); + break; + } + switch (tm.type & MIX_Y) + { + case MIX_Y: + tmix3[1] = terrain_texture_normal(tex1, texcoord); + break; + default: + tmix3[1] = vec3(1.0, 0.0, 1.0); + break; + } + switch (tm.type & MIX_Z) + { + case MIX_Z: + tmix3[2] = terrain_texture_normal(tex2, texcoord); + break; + default: + tmix3[2] = vec3(1.0, 0.0, 1.0); + break; + } + switch (tm.type & MIX_W) + { + case MIX_W: + tmix3[3] = terrain_texture_normal(tex3, texcoord); + break; + default: + tmix3[3] = vec3(1.0, 0.0, 1.0); + break; + } + + return tmix3; +} + vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - vec3[4] samples; - samples[0] = terrain_texture(tex0, texcoord).xyz; - samples[1] = terrain_texture(tex1, texcoord).xyz; - samples[2] = terrain_texture(tex2, texcoord).xyz; - samples[3] = terrain_texture(tex3, texcoord).xyz; - samples[0] = srgb_to_linear(samples[0]); - samples[1] = srgb_to_linear(samples[1]); - samples[2] = srgb_to_linear(samples[2]); - samples[3] = srgb_to_linear(samples[3]); - samples[0] *= factors[0]; - samples[1] *= factors[1]; - samples[2] *= factors[2]; - samples[3] *= factors[3]; - return terrain_mix(samples, alpha1, alpha2, alphaFinal); + TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + TerrainMixSample tms = _tmix_sample_color(tm, texcoord, tex0, tex1, tex2, tex3); + vec3[4] tms3; + tms3[0] = tms[0].xyz; + tms3[1] = tms[1].xyz; + tms3[2] = tms[2].xyz; + tms3[3] = tms[3].xyz; + tms3[0] *= factors[0]; + tms3[1] *= factors[1]; + tms3[2] *= factors[2]; + tms3[3] *= factors[3]; + return terrain_mix(tm, tms3); } vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - vec4[4] samples; - samples[0] = terrain_texture_color(tex0, texcoord); - samples[1] = terrain_texture_color(tex1, texcoord); - samples[2] = terrain_texture_color(tex2, texcoord); - samples[3] = terrain_texture_color(tex3, texcoord); - samples[0] *= factors[0]; - samples[1] *= factors[1]; - samples[2] *= factors[2]; - samples[3] *= factors[3]; - return terrain_mix(samples, alpha1, alpha2, alphaFinal); + TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + TerrainMixSample tms = _tmix_sample_color(tm, texcoord, tex0, tex1, tex2, tex3); + tms[0] *= factors[0]; + tms[1] *= factors[1]; + tms[2] *= factors[2]; + tms[3] *= factors[3]; + return terrain_mix(tm, tms); } vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - vec3[4] samples; - samples[0] = terrain_texture(tex0, texcoord).xyz; - samples[1] = terrain_texture(tex1, texcoord).xyz; - samples[2] = terrain_texture(tex2, texcoord).xyz; - samples[3] = terrain_texture(tex3, texcoord).xyz; - samples[0] *= factors[0]; - samples[1] *= factors[1]; - samples[2] *= factors[2]; - samples[3] *= factors[3]; - return terrain_mix(samples, alpha1, alpha2, alphaFinal); + TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + TerrainMixSample tms = _tmix_sample(tm, texcoord, tex0, tex1, tex2, tex3); + vec3[4] tms3; + tms3[0] = tms[0].xyz; + tms3[1] = tms[1].xyz; + tms3[2] = tms[2].xyz; + tms3[3] = tms[3].xyz; + tms3[0] *= factors[0]; + tms3[1] *= factors[1]; + tms3[2] *= factors[2]; + tms3[3] *= factors[3]; + return terrain_mix(tm, tms3); } // Returns the unpacked normal texture in range [-1, 1] vec3 sample_and_mix_normal(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - vec3[4] samples; - samples[0] = terrain_texture_normal(tex0, texcoord).xyz; - samples[1] = terrain_texture_normal(tex1, texcoord).xyz; - samples[2] = terrain_texture_normal(tex2, texcoord).xyz; - samples[3] = terrain_texture_normal(tex3, texcoord).xyz; - return terrain_mix(samples, alpha1, alpha2, alphaFinal); + TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + TerrainMixSample3 tms3 = _tmix_sample_normal(tm, texcoord, tex0, tex1, tex2, tex3); + return terrain_mix(tm, tms3); } -- cgit v1.2.3 From 86f0c9faa83ce4917ce7820a3295b39369d994ee Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:35 -0700 Subject: DRTVWR-592: (WIP) (has debug) Fix PBR terrain material mixing and triplanar mapping using wrong mix, causing bright spots --- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 59b273afc3..13f3934689 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -82,7 +82,8 @@ TerrainMix _t_mix(float alpha1, float alpha2, float alphaFinal) tm.weight -= TERRAIN_RAMP_MIX_THRESHOLD; ivec4 usage = max(ivec4(0), ivec4(ceil(tm.weight))); // Prevent negative weights and keep weights balanced - tm.weight = normalize(tm.weight*vec4(usage)); + tm.weight = tm.weight*vec4(usage); + tm.weight /= (tm.weight.x + tm.weight.y + tm.weight.z + tm.weight.w); tm.type = (usage.x * MIX_X) | (usage.y * MIX_Y) | @@ -97,7 +98,7 @@ TerrainMix _t_mix(float alpha1, float alpha2, float alphaFinal) float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) { TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); - // Assume weights are normalized + // Assume weights add to 1 return tm.weight.x * samples.x + tm.weight.y * samples.y + tm.weight.z * samples.z + @@ -118,7 +119,7 @@ vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) vec4 terrain_mix(TerrainMix tm, TerrainMixSample tms) { - // Assume weights are normalized + // Assume weights add to 1 return tm.weight.x * tms[0] + tm.weight.y * tms[1] + tm.weight.z * tms[2] + @@ -127,7 +128,7 @@ vec4 terrain_mix(TerrainMix tm, TerrainMixSample tms) vec3 terrain_mix(TerrainMix tm, TerrainMixSample3 tms3) { - // Assume weights are normalized + // Assume weights add to 1 return tm.weight.x * tms3[0] + tm.weight.y * tms3[1] + tm.weight.z * tms3[2] + @@ -165,11 +166,13 @@ TerrainWeight _t_weight(TerrainCoord terrain_coord) { float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; float threshold = TERRAIN_TRIPLANAR_MIX_THRESHOLD; - vec3 weight_signed = normalize(pow(abs(vary_vertex_normal), vec3(sharpness))); + vec3 weight_signed = pow(abs(vary_vertex_normal), vec3(sharpness)); + weight_signed /= (weight_signed.x + weight_signed.y + weight_signed.z); weight_signed -= vec3(threshold); TerrainWeight tw; // *NOTE: Make sure the threshold doesn't affect the materials - tw.weight = normalize(max(vec3(0), weight_signed)); + tw.weight = max(vec3(0), weight_signed); + tw.weight /= (tw.weight.x + tw.weight.y + tw.weight.z); ivec3 usage = ivec3(round(max(vec3(0), sign(weight_signed)))); tw.type = ((usage.x) * SAMPLE_X) | ((usage.y) * SAMPLE_Y) | -- cgit v1.2.3 From 00d56e2607a671b9478bf06b7df808b2f4141395 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:39 -0700 Subject: DRTVWR-592: Disable (but do not remove) shader debug --- .../shaders/class1/deferred/pbrterrainF.glsl | 9 ++++++--- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 16 +++------------- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 7b5eba14b7..f788b46aa7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -82,7 +82,7 @@ vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, Terrain vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); vec3 sample_and_mix_normal(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); -#if 1 // TODO: Remove +#if 0 // TODO: Remove #define TERRAIN_DEBUG 1 // TODO: Remove debug struct TerrainMix { @@ -147,6 +147,7 @@ void main() tnorm *= gl_FrontFacing ? 1.0 : -1.0; +#if TERRAIN_DEBUG // TODO: Remove #if 0 // TODO: Remove (terrain weights visualization) TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); #if 1 @@ -187,10 +188,12 @@ void main() //col.rgb = vec3(0.0, 1.0, 0.0); //col.rgb = spec.rgb; //col.rgb = (vNt + 1.0) / 2.0; - col.rgb = (tnorm + 1.0) / 2.0; - spec.rgb = vec3(1.0, 1.0, 0.0); + //col.rgb = (tnorm + 1.0) / 2.0; + //spec.rgb = vec3(1.0, 1.0, 0.0); + col.rgb = spec.rgb; tnorm = vary_normal; emissive = vec3(0); +#endif #endif frag_data[0] = max(vec4(col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 13f3934689..9d1990bd4a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -57,7 +57,9 @@ vec3 srgb_to_linear(vec3 c); #define MIX_Z 1 << 1 #define MIX_W 1 << 0 -#define TERRAIN_DEBUG 1 // TODO: Remove debug +#if 0 // TODO: Remove debug +#define TERRAIN_DEBUG 1 +#endif struct TerrainMix { vec4 weight; @@ -105,18 +107,6 @@ float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) tm.weight.w * samples.w; } -#if 0 // TODO: Decide if still needed, and if so, use _t_mix internally for weights -vec3 terrain_mix(vec3[4] samples, float alpha1, float alpha2, float alphaFinal) -{ - return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); -} - -vec4 terrain_mix(vec4[4] samples, float alpha1, float alpha2, float alphaFinal) -{ - return mix( mix(samples[3], samples[2], alpha2), mix(samples[1], samples[0], alpha1), alphaFinal ); -} -#endif - vec4 terrain_mix(TerrainMix tm, TerrainMixSample tms) { // Assume weights add to 1 -- cgit v1.2.3 From b163f72ecc2ebdb553b312e5e399d103f00eaf34 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:44 -0700 Subject: DRTVWR-592: (WIP) (has debug) Add new functions for mixing PBR materials. Not yet used. --- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 286 ++++++++++++++++++--- 1 file changed, 252 insertions(+), 34 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 9d1990bd4a..a8d8b1a91d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -44,18 +44,99 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#define TERRAIN_PBR_DETAIL_EMISSIVE 0 in vec3 vary_vertex_normal; vec3 srgb_to_linear(vec3 c); -// A relatively agressive threshold ensures that only one or two materials are used in most places +// A relatively agressive threshold for terrain material mixing sampling +// cutoff. This ensures that only one or two materials are used in most places, +// making PBR terrain blending more performant. Should be greater than 0 to work. #define TERRAIN_RAMP_MIX_THRESHOLD 0.1 +// A small threshold for triplanar mapping sampling cutoff. This and +// TERRAIN_TRIPLANAR_BLEND_FACTOR together ensures that only one or two samples +// per texture are used in most places, making triplanar mapping more +// performant. Should be greater than 0 to work. +// There's also an artistic design choice in the use of these factors, and the +// use of triplanar generally. Don't take these triplanar constants for granted. +#define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01 + +#define SAMPLE_X 1 << 0 +#define SAMPLE_Y 1 << 1 +#define SAMPLE_Z 1 << 2 +#define MIX_X 1 << 3 +#define MIX_Y 1 << 4 +#define MIX_Z 1 << 5 +#define MIX_W 1 << 6 + +struct PBRMix +{ + vec4 col; // RGB color with alpha, linear space + vec3 orm; // Occlusion, roughness, metallic + vec3 vNt; // Unpacked normal texture sample, vector +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + vec3 emissive; // RGB emissive color, linear space +#endif +}; -#define MIX_X 1 << 3 -#define MIX_Y 1 << 2 -#define MIX_Z 1 << 1 -#define MIX_W 1 << 0 +PBRMix init_pbr_mix() +{ + PBRMix mix; + mix.col = vec4(0); + mix.orm = vec3(0); + mix.vNt = vec3(0); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + mix.emissive = vec3(0); +#endif + return mix; +} + +// Usage example, for two weights: +// vec2 weights = ... // Weights must add up to 1 +// PBRMix mix = init_pbr_mix(); +// PBRMix mix1 = ... +// mix = mix_pbr(mix, mix1, weights.x); +// PBRMix mix2 = ... +// mix = mix_pbr(mix, mix2, weights.y); +PBRMix mix_pbr(PBRMix mix1, PBRMix mix2, float mix2_weight) +{ + PBRMix mix; + mix.col = mix1.col + (mix2.col * mix2_weight); + mix.orm = mix1.orm + (mix2.orm * mix2_weight); + mix.vNt = mix1.vNt + (mix2.vNt * mix2_weight); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + mix.emissive = mix1.emissive + (mix2.emissive * mix2_weight); +#endif + return mix; +} + +PBRMix sample_pbr( + vec2 uv + , sampler2D tex_col + , sampler2D tex_orm + , sampler2D tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , sampler2D tex_emissive +#endif + ) +{ + PBRMix mix; + mix.col = texture(tex_col, uv); + mix.col.rgb = srgb_to_linear(mix.col.rgb); + mix.orm = texture(tex_orm, uv).xyz; + mix.vNt = texture(tex_vNt, uv).xyz*2.0-1.0; +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + mix.emissive = srgb_to_linear(texture(tex_emissive, uv).xyz); +#endif + return mix; +} + +struct TerrainTriplanar +{ + vec3 weight; + int type; +}; #if 0 // TODO: Remove debug #define TERRAIN_DEBUG 1 @@ -97,6 +178,24 @@ TerrainMix _t_mix(float alpha1, float alpha2, float alphaFinal) return tm; } +TerrainTriplanar _t_triplanar() +{ + float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; + float threshold = TERRAIN_TRIPLANAR_MIX_THRESHOLD; + vec3 weight_signed = pow(abs(vary_vertex_normal), vec3(sharpness)); + weight_signed /= (weight_signed.x + weight_signed.y + weight_signed.z); + weight_signed -= vec3(threshold); + TerrainTriplanar tw; + // *NOTE: Make sure the threshold doesn't affect the materials + tw.weight = max(vec3(0), weight_signed); + tw.weight /= (tw.weight.x + tw.weight.y + tw.weight.z); + ivec3 usage = ivec3(round(max(vec3(0), sign(weight_signed)))); + tw.type = ((usage.x) * SAMPLE_X) | + ((usage.y) * SAMPLE_Y) | + ((usage.z) * SAMPLE_Z); + return tw; +} + float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) { TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); @@ -130,7 +229,6 @@ vec3 terrain_mix(TerrainMix tm, TerrainMixSample3 tms3) // Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused) #define TerrainCoord vec4[2] -#define TERRAIN_TRIPLANAR_MIX_THRESHOLD 0.01 vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign_or_zero) { @@ -143,31 +241,50 @@ vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign_or_zero) return texture(tex, uv); } -#define SAMPLE_X 1 << 2 -#define SAMPLE_Y 1 << 1 -#define SAMPLE_Z 1 << 0 -struct TerrainWeight +vec2 _t_uv(vec2 uv_unflipped, float sign_or_zero) { - vec3 weight; - int type; -}; + // Handle case where sign is 0 + float sign = (2.0*sign_or_zero) + 1.0; + sign /= abs(sign); + // If the vertex normal is negative, flip the texture back + // right-side up. + vec2 uv = uv_unflipped * vec2(sign, 1); + return uv; +} -TerrainWeight _t_weight(TerrainCoord terrain_coord) +vec3 _t_normal_post_1(vec3 vNt0, float sign_or_zero) { - float sharpness = TERRAIN_TRIPLANAR_BLEND_FACTOR; - float threshold = TERRAIN_TRIPLANAR_MIX_THRESHOLD; - vec3 weight_signed = pow(abs(vary_vertex_normal), vec3(sharpness)); - weight_signed /= (weight_signed.x + weight_signed.y + weight_signed.z); - weight_signed -= vec3(threshold); - TerrainWeight tw; - // *NOTE: Make sure the threshold doesn't affect the materials - tw.weight = max(vec3(0), weight_signed); - tw.weight /= (tw.weight.x + tw.weight.y + tw.weight.z); - ivec3 usage = ivec3(round(max(vec3(0), sign(weight_signed)))); - tw.type = ((usage.x) * SAMPLE_X) | - ((usage.y) * SAMPLE_Y) | - ((usage.z) * SAMPLE_Z); - return tw; + // Assume normal is unpacked + vec3 vNt1 = vNt0; + // Get sign + float sign = sign_or_zero; + // Handle case where sign is 0 + sign = (2.0*sign) + 1.0; + sign /= abs(sign); + // If the sign is negative, rotate normal by 180 degrees + vNt1.xy = (min(0, sign) * vNt1.xy) + (min(0, -sign) * -vNt1.xy); + return vNt1; +} + +// Triplanar-specific normal texture fixes +vec3 _t_normal_post_x(vec3 vNt0) +{ + vec3 vNt_x = _t_normal_post_1(vNt0, sign(vary_vertex_normal.x)); + // *HACK: Transform normals according to orientation of the UVs + vNt_x.xy = vec2(-vNt_x.y, vNt_x.x); + return vNt_x; +} +vec3 _t_normal_post_y(vec3 vNt0) +{ + vec3 vNt_y = _t_normal_post_1(vNt0, sign(vary_vertex_normal.y)); + // *HACK: Transform normals according to orientation of the UVs + vNt_y.xy = -vNt_y.xy; + return vNt_y; +} +vec3 _t_normal_post_z(vec3 vNt0) +{ + vec3 vNt_z = _t_normal_post_1(vNt0, sign(vary_vertex_normal.z)); + return vNt_z; } struct TerrainSample @@ -177,7 +294,7 @@ struct TerrainSample vec4 z; }; -TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight tw) +TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainTriplanar tw) { TerrainSample ts; @@ -227,7 +344,7 @@ struct TerrainSampleNormal vec3 z; }; -TerrainSampleNormal _t_sample_n(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight tw) +TerrainSampleNormal _t_sample_n(sampler2D tex, TerrainCoord terrain_coord, TerrainTriplanar tw) { TerrainSample ts = _t_sample(tex, terrain_coord, tw); TerrainSampleNormal tsn; @@ -250,7 +367,7 @@ TerrainSampleNormal _t_sample_n(sampler2D tex, TerrainCoord terrain_coord, Terra return tsn; } -TerrainSample _t_sample_c(sampler2D tex, TerrainCoord terrain_coord, TerrainWeight tw) +TerrainSample _t_sample_c(sampler2D tex, TerrainCoord terrain_coord, TerrainTriplanar tw) { TerrainSample ts = _t_sample(tex, terrain_coord, tw); ts.x.xyz = srgb_to_linear(ts.x.xyz); @@ -262,7 +379,7 @@ TerrainSample _t_sample_c(sampler2D tex, TerrainCoord terrain_coord, TerrainWeig // Triplanar sampling of things that are neither colors nor normals (i.e. orm) vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) { - TerrainWeight tw = _t_weight(terrain_coord); + TerrainTriplanar tw = _t_triplanar(); TerrainSample ts = _t_sample(tex, terrain_coord, tw); @@ -279,7 +396,7 @@ vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) // *NOTE: Bottom face has not been tested vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) { - TerrainWeight tw = _t_weight(terrain_coord); + TerrainTriplanar tw = _t_triplanar(); TerrainSampleNormal ts = _t_sample_n(tex, terrain_coord, tw); @@ -289,13 +406,92 @@ vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) // Triplanar sampling of colors. Colors are converted to linear space before blending. vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) { - TerrainWeight tw = _t_weight(terrain_coord); + TerrainTriplanar tw = _t_triplanar(); TerrainSample ts = _t_sample_c(tex, terrain_coord, tw); return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); } +PBRMix terrain_sample_pbr( + TerrainCoord terrain_coord + , TerrainTriplanar tw + , sampler2D tex_col + , sampler2D tex_orm + , sampler2D tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , sampler2D tex_emissive +#endif + ) +{ + PBRMix mix = init_pbr_mix(); + + #define get_uv_x() _t_uv(terrain_coord[0].zw, sign(vary_vertex_normal.x)) + #define get_uv_y() _t_uv(terrain_coord[1].xy, sign(vary_vertex_normal.y)) + #define get_uv_z() _t_uv(terrain_coord[0].xy, sign(vary_vertex_normal.z)) + switch (tw.type & SAMPLE_X) + { + case SAMPLE_X: + PBRMix mix_x = sample_pbr( + get_uv_x() + , tex_col + , tex_orm + , tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , tex_emissive +#endif + ); + // Triplanar-specific normal texture fix + mix_x.vNt = _t_normal_post_x(mix_x.vNt); + mix = mix_pbr(mix, mix_x, tw.weight.x); + break; + default: + break; + } + + switch (tw.type & SAMPLE_Y) + { + case SAMPLE_Y: + PBRMix mix_y = sample_pbr( + get_uv_y() + , tex_col + , tex_orm + , tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , tex_emissive +#endif + ); + // Triplanar-specific normal texture fix + mix_y.vNt = _t_normal_post_y(mix_y.vNt); + mix = mix_pbr(mix, mix_y, tw.weight.y); + break; + default: + break; + } + + switch (tw.type & SAMPLE_Z) + { + case SAMPLE_Z: + PBRMix mix_z = sample_pbr( + get_uv_z() + , tex_col + , tex_orm + , tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , tex_emissive +#endif + ); + // Triplanar-specific normal texture fix + mix_z.vNt = _t_normal_post_z(mix_z.vNt); + mix = mix_pbr(mix, mix_z, tw.weight.z); + break; + default: + break; + } + + return mix; +} + #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 #define TerrainCoord vec2 vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) @@ -314,6 +510,28 @@ vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) col.xyz = srgb_to_linear(col.xyz); return col; } + +// TODO: Implement this for the more complex triplanar case +PBRMix terrain_sample_pbr( + TerrainCoord terrain_coord + , sampler2D tex_col + , sampler2D tex_orm + , sampler2D tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , sampler2D tex_emissive +#endif + ) +{ + return sample_pbr( + terrain_coord + , tex_col + , tex_orm + , tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , tex_emissive +#endif + ); +} #endif // The goal of _tmix_sample and related functions is to only sample textures when necessary, ignoring if the weights are low. -- cgit v1.2.3 From b162ff3cae482a443f93d818125f6e22d647451f Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:50 -0700 Subject: DRTVWR-592: Implement reduced branching terrain shader --- .../shaders/class1/deferred/pbrterrainF.glsl | 207 ++++++++++++--------- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 70 ++++++- 2 files changed, 186 insertions(+), 91 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index f788b46aa7..22071421de 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -31,6 +31,52 @@ #define TerrainCoord vec2 #endif +#if 0 // TODO: Remove debug +#define TERRAIN_DEBUG 1 +#endif + +// TODO: Decide if this struct needs to be declared +struct TerrainMix +{ + vec4 weight; + int type; +#if TERRAIN_DEBUG + ivec4 usage; +#endif +}; + +TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal); + +// TODO: Decide if this struct needs to be declared +struct PBRMix +{ + vec4 col; // RGB color with alpha, linear space + vec3 orm; // Occlusion, roughness, metallic + vec3 vNt; // Unpacked normal texture sample, vector +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + vec3 emissive; // RGB emissive color, linear space +#endif +}; + +PBRMix init_pbr_mix(); + +PBRMix terrain_sample_and_multiply_pbr( + TerrainCoord terrain_coord + , sampler2D tex_col + , sampler2D tex_orm + , sampler2D tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , sampler2D tex_emissive +#endif + , vec4 factor_col + , vec3 factor_orm +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , vec3 factor_emissive +#endif + ); + +PBRMix mix_pbr(PBRMix mix1, PBRMix mix2, float mix2_weight); + out vec4 frag_data[4]; uniform sampler2D alpha_ramp; @@ -82,19 +128,6 @@ vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, Terrain vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); vec3 sample_and_mix_normal(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); -#if 0 // TODO: Remove -#define TERRAIN_DEBUG 1 // TODO: Remove debug -struct TerrainMix -{ - vec4 weight; - int type; -#if TERRAIN_DEBUG - ivec4 usage; -#endif -}; -TerrainMix _t_mix(float alpha1, float alpha2, float alphaFinal); -#endif - void main() { @@ -108,36 +141,91 @@ void main() float alpha2 = texture(alpha_ramp,vary_texcoord1.xy).a; float alphaFinal = texture(alpha_ramp, vary_texcoord1.zw).a; - vec4 col = sample_and_mix_color4(alpha1, alpha2, alphaFinal, terrain_texcoord, baseColorFactors, detail_0_base_color, detail_1_base_color, detail_2_base_color, detail_3_base_color); - float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); - if (col.a < minimum_alpha) - { - discard; - } + TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); - - vec3[4] orm_factors; - orm_factors[0] = vec3(1.0, roughnessFactors.x, metallicFactors.x); - orm_factors[1] = vec3(1.0, roughnessFactors.y, metallicFactors.y); - orm_factors[2] = vec3(1.0, roughnessFactors.z, metallicFactors.z); - orm_factors[3] = vec3(1.0, roughnessFactors.w, metallicFactors.w); // RGB = Occlusion, Roughness, Metal // default values, see LLViewerTexture::sDefaultPBRORMImagep // occlusion 1.0 // roughness 0.0 // metal 0.0 - vec3 spec = sample_and_mix_vector3(alpha1, alpha2, alphaFinal, terrain_texcoord, orm_factors, detail_0_metallic_roughness, detail_1_metallic_roughness, detail_2_metallic_roughness, detail_3_metallic_roughness); + vec3[4] orm_factors; + orm_factors[0] = vec3(1.0, roughnessFactors.x, metallicFactors.x); + orm_factors[1] = vec3(1.0, roughnessFactors.y, metallicFactors.y); + orm_factors[2] = vec3(1.0, roughnessFactors.z, metallicFactors.z); + orm_factors[3] = vec3(1.0, roughnessFactors.w, metallicFactors.w); -#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - vec3 emissive = sample_and_mix_color3(alpha1, alpha2, alphaFinal, terrain_texcoord, emissiveColors, detail_0_emissive, detail_1_emissive, detail_2_emissive, detail_3_emissive); -#else - vec3 emissive = vec3(0); -#endif + PBRMix mix = init_pbr_mix(); + PBRMix mix2; + mix2 = terrain_sample_and_multiply_pbr( + terrain_texcoord + , detail_0_base_color + , detail_0_metallic_roughness + , detail_0_normal + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , detail_0_emissive + #endif + , baseColorFactors[0] + , orm_factors[0] + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , emissiveColors[0] + #endif + ); + mix = mix_pbr(mix, mix2, tm.weight[0]); + mix2 = terrain_sample_and_multiply_pbr( + terrain_texcoord + , detail_1_base_color + , detail_1_metallic_roughness + , detail_1_normal + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , detail_1_emissive + #endif + , baseColorFactors[1] + , orm_factors[1] + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , emissiveColors[1] + #endif + ); + mix = mix_pbr(mix, mix2, tm.weight[1]); + mix2 = terrain_sample_and_multiply_pbr( + terrain_texcoord + , detail_2_base_color + , detail_2_metallic_roughness + , detail_2_normal + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , detail_2_emissive + #endif + , baseColorFactors[2] + , orm_factors[2] + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , emissiveColors[2] + #endif + ); + mix = mix_pbr(mix, mix2, tm.weight[2]); + mix2 = terrain_sample_and_multiply_pbr( + terrain_texcoord + , detail_3_base_color + , detail_3_metallic_roughness + , detail_3_normal + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , detail_3_emissive + #endif + , baseColorFactors[3] + , orm_factors[3] + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , emissiveColors[3] + #endif + ); + mix = mix_pbr(mix, mix2, tm.weight[3]); + float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); + if (mix.col.a < minimum_alpha) + { + discard; + } float base_color_factor_alpha = terrain_mix(vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z), alpha1, alpha2, alphaFinal); // from mikktspace.com - vec3 vNt = sample_and_mix_normal(alpha1, alpha2, alphaFinal, terrain_texcoord, detail_0_normal, detail_1_normal, detail_2_normal, detail_3_normal); + vec3 vNt = mix.vNt; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; @@ -145,59 +233,10 @@ void main() vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); tnorm *= gl_FrontFacing ? 1.0 : -1.0; - -#if TERRAIN_DEBUG // TODO: Remove -#if 0 // TODO: Remove (terrain weights visualization) - TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); -#if 1 - // Show full usage and weights - float uw = 0.3; -#if 1 -#if 0 - vec4 mix_usage = vec4(tm.usage); -#else - vec4 mix_usage = vec4(tm.weight); -#endif -#else - // Version with easier-to-see boundaries of weights vs usage - vec4 mix_usage = mix(vec4(tm.usage), - mix(max(vec4(0.0), sign(tm.weight - 0.01)), - max(vec4(0.0), sign(tm.weight - 0.005)), - 0.5), - uw); -#endif - col.xyz = mix_usage.xyz; - col.x = max(col.x, mix_usage.w); - //col.y = 0.0; - //col.z = 0.0; -#else - // Show places where weight > usage + tolerance - float tolerance = 0.005; - vec4 weight_gt_usage = sign( - max( - vec4(0.0), - (tm.weight - (vec4(tm.usage) + vec4(tolerance))) - ) - ); - col.xyz = weight_gt_usage.xyz; - col.x = max(col.x, weight_gt_usage.w); -#endif -#endif -#if 0 // TODO: Remove (material channel discriminator) - //col.rgb = vec3(0.0, 1.0, 0.0); - //col.rgb = spec.rgb; - //col.rgb = (vNt + 1.0) / 2.0; - //col.rgb = (tnorm + 1.0) / 2.0; - //spec.rgb = vec3(1.0, 1.0, 0.0); - col.rgb = spec.rgb; - tnorm = vary_normal; - emissive = vec3(0); -#endif -#endif - frag_data[0] = max(vec4(col.xyz, 0.0), vec4(0)); // Diffuse - frag_data[1] = max(vec4(spec.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. + frag_data[0] = max(vec4(mix.col.xyz, 0.0), vec4(0)); // Diffuse + frag_data[1] = max(vec4(mix.orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. frag_data[2] = max(vec4(encode_normal(tnorm), base_color_factor_alpha, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags - frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive + frag_data[3] = max(vec4(mix.emissive,0), vec4(0)); // PBR sRGB Emissive } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index a8d8b1a91d..a87927786c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -153,7 +153,7 @@ struct TerrainMix #define TerrainMixSample vec4[4] #define TerrainMixSample3 vec3[4] -TerrainMix _t_mix(float alpha1, float alpha2, float alphaFinal) +TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal) { TerrainMix tm; vec4 sample_x = vec4(1,0,0,0); @@ -198,7 +198,7 @@ TerrainTriplanar _t_triplanar() float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) { - TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); // Assume weights add to 1 return tm.weight.x * samples.x + tm.weight.y * samples.y + @@ -511,7 +511,6 @@ vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) return col; } -// TODO: Implement this for the more complex triplanar case PBRMix terrain_sample_pbr( TerrainCoord terrain_coord , sampler2D tex_col @@ -671,7 +670,7 @@ TerrainMixSample3 _tmix_sample_normal(TerrainMix tm, TerrainCoord texcoord, samp vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); TerrainMixSample tms = _tmix_sample_color(tm, texcoord, tex0, tex1, tex2, tex3); vec3[4] tms3; tms3[0] = tms[0].xyz; @@ -687,7 +686,7 @@ vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, Terrain vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); TerrainMixSample tms = _tmix_sample_color(tm, texcoord, tex0, tex1, tex2, tex3); tms[0] *= factors[0]; tms[1] *= factors[1]; @@ -698,7 +697,7 @@ vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, Terrain vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); TerrainMixSample tms = _tmix_sample(tm, texcoord, tex0, tex1, tex2, tex3); vec3[4] tms3; tms3[0] = tms[0].xyz; @@ -715,7 +714,64 @@ vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, Terrai // Returns the unpacked normal texture in range [-1, 1] vec3 sample_and_mix_normal(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) { - TerrainMix tm = _t_mix(alpha1, alpha2, alphaFinal); + TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); TerrainMixSample3 tms3 = _tmix_sample_normal(tm, texcoord, tex0, tex1, tex2, tex3); return terrain_mix(tm, tms3); } + +PBRMix multiply_factors_pbr( + PBRMix mix_in + , vec4 factor_col + , vec3 factor_orm +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , vec3 factor_emissive +#endif + ) +{ + PBRMix mix = mix_in; + mix.col *= factor_col; + mix.orm *= factor_orm; +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + mix.emissive *= factor_emissive; +#endif + return mix; +} + +PBRMix terrain_sample_and_multiply_pbr( + TerrainCoord terrain_coord + , sampler2D tex_col + , sampler2D tex_orm + , sampler2D tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , sampler2D tex_emissive +#endif + , vec4 factor_col + , vec3 factor_orm +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , vec3 factor_emissive +#endif + ) +{ + PBRMix mix = terrain_sample_pbr( + terrain_coord +#if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 + , _t_triplanar() +#endif + , tex_col + , tex_orm + , tex_vNt +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , tex_emissive +#endif + ); + + mix = multiply_factors_pbr(mix + , factor_col + , factor_orm +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , factor_emissive +#endif + ); + + return mix; +} -- cgit v1.2.3 From be38adebbe46d62bc07d504a70556062f4e55101 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:42:56 -0700 Subject: DRTVWR-592: Add missing branching for terrain sampling. Jury is still out on which version is faster --- .../shaders/class1/deferred/pbrterrainF.glsl | 154 +++++++++++++-------- 1 file changed, 94 insertions(+), 60 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 22071421de..0a7c58451d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -31,6 +31,11 @@ #define TerrainCoord vec2 #endif +#define MIX_X 1 << 3 +#define MIX_Y 1 << 4 +#define MIX_Z 1 << 5 +#define MIX_W 1 << 6 + #if 0 // TODO: Remove debug #define TERRAIN_DEBUG 1 #endif @@ -123,6 +128,7 @@ in vec4 vary_texcoord1; vec2 encode_normal(vec3 n); float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal); +// TODO: Clean these up vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); @@ -156,66 +162,94 @@ void main() PBRMix mix = init_pbr_mix(); PBRMix mix2; - mix2 = terrain_sample_and_multiply_pbr( - terrain_texcoord - , detail_0_base_color - , detail_0_metallic_roughness - , detail_0_normal - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , detail_0_emissive - #endif - , baseColorFactors[0] - , orm_factors[0] - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , emissiveColors[0] - #endif - ); - mix = mix_pbr(mix, mix2, tm.weight[0]); - mix2 = terrain_sample_and_multiply_pbr( - terrain_texcoord - , detail_1_base_color - , detail_1_metallic_roughness - , detail_1_normal - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , detail_1_emissive - #endif - , baseColorFactors[1] - , orm_factors[1] - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , emissiveColors[1] - #endif - ); - mix = mix_pbr(mix, mix2, tm.weight[1]); - mix2 = terrain_sample_and_multiply_pbr( - terrain_texcoord - , detail_2_base_color - , detail_2_metallic_roughness - , detail_2_normal - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , detail_2_emissive - #endif - , baseColorFactors[2] - , orm_factors[2] - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , emissiveColors[2] - #endif - ); - mix = mix_pbr(mix, mix2, tm.weight[2]); - mix2 = terrain_sample_and_multiply_pbr( - terrain_texcoord - , detail_3_base_color - , detail_3_metallic_roughness - , detail_3_normal - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , detail_3_emissive - #endif - , baseColorFactors[3] - , orm_factors[3] - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , emissiveColors[3] - #endif - ); - mix = mix_pbr(mix, mix2, tm.weight[3]); + switch (tm.type & MIX_X) + { + case MIX_X: + mix2 = terrain_sample_and_multiply_pbr( + terrain_texcoord + , detail_0_base_color + , detail_0_metallic_roughness + , detail_0_normal + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , detail_0_emissive + #endif + , baseColorFactors[0] + , orm_factors[0] + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , emissiveColors[0] + #endif + ); + mix = mix_pbr(mix, mix2, tm.weight.x); + break; + default: + break; + } + switch (tm.type & MIX_Y) + { + case MIX_Y: + mix2 = terrain_sample_and_multiply_pbr( + terrain_texcoord + , detail_1_base_color + , detail_1_metallic_roughness + , detail_1_normal + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , detail_1_emissive + #endif + , baseColorFactors[1] + , orm_factors[1] + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , emissiveColors[1] + #endif + ); + mix = mix_pbr(mix, mix2, tm.weight.y); + break; + default: + break; + } + switch (tm.type & MIX_Z) + { + case MIX_Z: + mix2 = terrain_sample_and_multiply_pbr( + terrain_texcoord + , detail_2_base_color + , detail_2_metallic_roughness + , detail_2_normal + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , detail_2_emissive + #endif + , baseColorFactors[2] + , orm_factors[2] + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , emissiveColors[2] + #endif + ); + mix = mix_pbr(mix, mix2, tm.weight.z); + break; + default: + break; + } + switch (tm.type & MIX_W) + { + case MIX_W: + mix2 = terrain_sample_and_multiply_pbr( + terrain_texcoord + , detail_3_base_color + , detail_3_metallic_roughness + , detail_3_normal + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , detail_3_emissive + #endif + , baseColorFactors[3] + , orm_factors[3] + #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) + , emissiveColors[3] + #endif + ); + mix = mix_pbr(mix, mix2, tm.weight.w); + break; + default: + break; + } float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); if (mix.col.a < minimum_alpha) -- cgit v1.2.3 From f9bd70efc9ab25dfc1ab0b9aa10d16aec271410b Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:43:02 -0700 Subject: DRTVWR-592: Fix non-triplanar being slower somehow in some cases. --- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index a87927786c..078c753a35 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -511,26 +511,8 @@ vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) return col; } -PBRMix terrain_sample_pbr( - TerrainCoord terrain_coord - , sampler2D tex_col - , sampler2D tex_orm - , sampler2D tex_vNt -#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , sampler2D tex_emissive -#endif - ) -{ - return sample_pbr( - terrain_coord - , tex_col - , tex_orm - , tex_vNt -#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) - , tex_emissive -#endif - ); -} +#define terrain_sample_pbr sample_pbr + #endif // The goal of _tmix_sample and related functions is to only sample textures when necessary, ignoring if the weights are low. -- cgit v1.2.3 From f3c98a548a688199114763cfc4eb90bb3d2fbd5c Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:43:08 -0700 Subject: DRTVWR-592: Clean up --- .../shaders/class1/deferred/pbrterrainF.glsl | 50 +-- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 387 +-------------------- 2 files changed, 30 insertions(+), 407 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 0a7c58451d..18f8c4aa73 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -36,18 +36,11 @@ #define MIX_Z 1 << 5 #define MIX_W 1 << 6 -#if 0 // TODO: Remove debug -#define TERRAIN_DEBUG 1 -#endif - // TODO: Decide if this struct needs to be declared struct TerrainMix { vec4 weight; int type; -#if TERRAIN_DEBUG - ivec4 usage; -#endif }; TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal); @@ -127,12 +120,7 @@ in vec4 vary_texcoord1; vec2 encode_normal(vec3 n); -float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal); -// TODO: Clean these up -vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); -vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); -vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); -vec3 sample_and_mix_normal(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3); +float terrain_mix(TerrainMix tm, vec4 tms4); void main() { @@ -170,14 +158,14 @@ void main() , detail_0_base_color , detail_0_metallic_roughness , detail_0_normal - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , detail_0_emissive - #endif +#endif , baseColorFactors[0] , orm_factors[0] - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , emissiveColors[0] - #endif +#endif ); mix = mix_pbr(mix, mix2, tm.weight.x); break; @@ -192,14 +180,14 @@ void main() , detail_1_base_color , detail_1_metallic_roughness , detail_1_normal - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , detail_1_emissive - #endif +#endif , baseColorFactors[1] , orm_factors[1] - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , emissiveColors[1] - #endif +#endif ); mix = mix_pbr(mix, mix2, tm.weight.y); break; @@ -214,14 +202,14 @@ void main() , detail_2_base_color , detail_2_metallic_roughness , detail_2_normal - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , detail_2_emissive - #endif +#endif , baseColorFactors[2] , orm_factors[2] - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , emissiveColors[2] - #endif +#endif ); mix = mix_pbr(mix, mix2, tm.weight.z); break; @@ -236,14 +224,14 @@ void main() , detail_3_base_color , detail_3_metallic_roughness , detail_3_normal - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , detail_3_emissive - #endif +#endif , baseColorFactors[3] , orm_factors[3] - #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , emissiveColors[3] - #endif +#endif ); mix = mix_pbr(mix, mix2, tm.weight.w); break; @@ -251,12 +239,12 @@ void main() break; } - float minimum_alpha = terrain_mix(minimum_alphas, alpha1, alpha2, alphaFinal); + float minimum_alpha = terrain_mix(tm, minimum_alphas); if (mix.col.a < minimum_alpha) { discard; } - float base_color_factor_alpha = terrain_mix(vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z), alpha1, alpha2, alphaFinal); + float base_color_factor_alpha = terrain_mix(tm, vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z)); // from mikktspace.com vec3 vNt = mix.vNt; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 078c753a35..c18cf832f8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -138,16 +138,10 @@ struct TerrainTriplanar int type; }; -#if 0 // TODO: Remove debug -#define TERRAIN_DEBUG 1 -#endif struct TerrainMix { vec4 weight; int type; -#if TERRAIN_DEBUG - ivec4 usage; -#endif }; #define TerrainMixSample vec4[4] @@ -172,9 +166,6 @@ TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal) (usage.y * MIX_Y) | (usage.z * MIX_Z) | (usage.w * MIX_W); -#if TERRAIN_DEBUG // TODO: Remove debug - tm.usage = usage; -#endif return tm; } @@ -196,32 +187,13 @@ TerrainTriplanar _t_triplanar() return tw; } -float terrain_mix(vec4 samples, float alpha1, float alpha2, float alphaFinal) -{ - TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); - // Assume weights add to 1 - return tm.weight.x * samples.x + - tm.weight.y * samples.y + - tm.weight.z * samples.z + - tm.weight.w * samples.w; -} - -vec4 terrain_mix(TerrainMix tm, TerrainMixSample tms) -{ - // Assume weights add to 1 - return tm.weight.x * tms[0] + - tm.weight.y * tms[1] + - tm.weight.z * tms[2] + - tm.weight.w * tms[3]; -} - -vec3 terrain_mix(TerrainMix tm, TerrainMixSample3 tms3) +// Assume weights add to 1 +float terrain_mix(TerrainMix tm, vec4 tms4) { - // Assume weights add to 1 - return tm.weight.x * tms3[0] + - tm.weight.y * tms3[1] + - tm.weight.z * tms3[2] + - tm.weight.w * tms3[3]; + return (tm.weight.x * tms4[0]) + + (tm.weight.y * tms4[1]) + + (tm.weight.z * tms4[2]) + + (tm.weight.w * tms4[3]); } #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 @@ -230,17 +202,6 @@ vec3 terrain_mix(TerrainMix tm, TerrainMixSample3 tms3) // Pre-transformed texture coordinates for each axial uv slice (Packing: xy, yz, (-x)z, unused) #define TerrainCoord vec4[2] -vec4 _t_texture(sampler2D tex, vec2 uv_unflipped, float sign_or_zero) -{ - // Handle case where sign is 0 - float sign = (2.0*sign_or_zero) + 1.0; - sign /= abs(sign); - // If the vertex normal is negative, flip the texture back - // right-side up. - vec2 uv = uv_unflipped * vec2(sign, 1); - return texture(tex, uv); -} - vec2 _t_uv(vec2 uv_unflipped, float sign_or_zero) { // Handle case where sign is 0 @@ -287,132 +248,6 @@ vec3 _t_normal_post_z(vec3 vNt0) return vNt_z; } -struct TerrainSample -{ - vec4 x; - vec4 y; - vec4 z; -}; - -TerrainSample _t_sample(sampler2D tex, TerrainCoord terrain_coord, TerrainTriplanar tw) -{ - TerrainSample ts; - - // The switch..case is broken up into three parts deliberately. A single - // switch..case caused unexplained, "ant trail" seams in terrain. (as seen - // on Nvidia/Windows 10). The extra two branches are not free, but it's - // still a performance win compared to sampling along all three axes for - // every terrain fragment. - #define do_sample_x() _t_texture(tex, terrain_coord[0].zw, sign(vary_vertex_normal.x)) - #define do_sample_y() _t_texture(tex, terrain_coord[1].xy, sign(vary_vertex_normal.y)) - #define do_sample_z() _t_texture(tex, terrain_coord[0].xy, sign(vary_vertex_normal.z)) - switch (tw.type & SAMPLE_X) - { - case SAMPLE_X: - ts.x = do_sample_x(); - break; - default: - ts.x = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - switch (tw.type & SAMPLE_Y) - { - case SAMPLE_Y: - ts.y = do_sample_y(); - break; - default: - ts.y = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - switch (tw.type & SAMPLE_Z) - { - case SAMPLE_Z: - ts.z = do_sample_z(); - break; - default: - ts.z = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - - return ts; -} - -struct TerrainSampleNormal -{ - vec3 x; - vec3 y; - vec3 z; -}; - -TerrainSampleNormal _t_sample_n(sampler2D tex, TerrainCoord terrain_coord, TerrainTriplanar tw) -{ - TerrainSample ts = _t_sample(tex, terrain_coord, tw); - TerrainSampleNormal tsn; - // Unpack normals - tsn.x = ts.x.xyz*2.0-1.0; - tsn.y = ts.y.xyz*2.0-1.0; - tsn.z = ts.z.xyz*2.0-1.0; - // Get sign - vec3 ns = sign(vary_vertex_normal); - // Handle case where sign is 0 - ns = (2.0*ns) + 1.0; - ns /= abs(ns); - // If the sign is negative, rotate normal by 180 degrees - tsn.x.xy = (min(0, ns.x) * tsn.x.xy) + (min(0, -ns.x) * -tsn.x.xy); - tsn.y.xy = (min(0, ns.y) * tsn.y.xy) + (min(0, -ns.y) * -tsn.y.xy); - tsn.z.xy = (min(0, ns.z) * tsn.z.xy) + (min(0, -ns.z) * -tsn.z.xy); - // *HACK: Transform normals according to orientation of the UVs - tsn.x.xy = vec2(-tsn.x.y, tsn.x.x); - tsn.y.xy = -tsn.y.xy; - return tsn; -} - -TerrainSample _t_sample_c(sampler2D tex, TerrainCoord terrain_coord, TerrainTriplanar tw) -{ - TerrainSample ts = _t_sample(tex, terrain_coord, tw); - ts.x.xyz = srgb_to_linear(ts.x.xyz); - ts.y.xyz = srgb_to_linear(ts.y.xyz); - ts.z.xyz = srgb_to_linear(ts.z.xyz); - return ts; -} - -// Triplanar sampling of things that are neither colors nor normals (i.e. orm) -vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) -{ - TerrainTriplanar tw = _t_triplanar(); - - TerrainSample ts = _t_sample(tex, terrain_coord, tw); - - return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); -} - -// Specialized triplanar normal texture sampling implementation, taking into -// account how the rotation of the texture affects the lighting and trying to -// negate that. -// *TODO: Decide if we want this. It may be better to just calculate the -// tangents on-the-fly here rather than messing with the normals, due to the -// subtleties of the effects of triplanar mapping on UVs. These sampled normals -// are only valid on the faces of a cube. -// *NOTE: Bottom face has not been tested -vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) -{ - TerrainTriplanar tw = _t_triplanar(); - - TerrainSampleNormal ts = _t_sample_n(tex, terrain_coord, tw); - - return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); -} - -// Triplanar sampling of colors. Colors are converted to linear space before blending. -vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) -{ - TerrainTriplanar tw = _t_triplanar(); - - TerrainSample ts = _t_sample_c(tex, terrain_coord, tw); - - return ((ts.x * tw.weight.x) + (ts.y * tw.weight.y) + (ts.z * tw.weight.z)) / (tw.weight.x + tw.weight.y + tw.weight.z); -} - PBRMix terrain_sample_pbr( TerrainCoord terrain_coord , TerrainTriplanar tw @@ -426,9 +261,9 @@ PBRMix terrain_sample_pbr( { PBRMix mix = init_pbr_mix(); - #define get_uv_x() _t_uv(terrain_coord[0].zw, sign(vary_vertex_normal.x)) - #define get_uv_y() _t_uv(terrain_coord[1].xy, sign(vary_vertex_normal.y)) - #define get_uv_z() _t_uv(terrain_coord[0].xy, sign(vary_vertex_normal.z)) +#define get_uv_x() _t_uv(terrain_coord[0].zw, sign(vary_vertex_normal.x)) +#define get_uv_y() _t_uv(terrain_coord[1].xy, sign(vary_vertex_normal.y)) +#define get_uv_z() _t_uv(terrain_coord[0].xy, sign(vary_vertex_normal.z)) switch (tw.type & SAMPLE_X) { case SAMPLE_X: @@ -482,6 +317,7 @@ PBRMix terrain_sample_pbr( #endif ); // Triplanar-specific normal texture fix + // *NOTE: Bottom face has not been tested mix_z.vNt = _t_normal_post_z(mix_z.vNt); mix = mix_pbr(mix, mix_z, tw.weight.z); break; @@ -493,214 +329,13 @@ PBRMix terrain_sample_pbr( } #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 -#define TerrainCoord vec2 -vec4 terrain_texture(sampler2D tex, TerrainCoord terrain_coord) -{ - return texture(tex, terrain_coord); -} - -vec3 terrain_texture_normal(sampler2D tex, TerrainCoord terrain_coord) -{ - return texture(tex, terrain_coord).xyz*2.0-1.0; -} -vec4 terrain_texture_color(sampler2D tex, TerrainCoord terrain_coord) -{ - vec4 col = texture(tex, terrain_coord); - col.xyz = srgb_to_linear(col.xyz); - return col; -} +#define TerrainCoord vec2 #define terrain_sample_pbr sample_pbr #endif -// The goal of _tmix_sample and related functions is to only sample textures when necessary, ignoring if the weights are low. -// *TODO: Currently, there is much more switch..case branching than needed. This could be simplified by branching per-material rather than per-texture. - -TerrainMixSample _tmix_sample(TerrainMix tm, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - TerrainMixSample tms; - - switch (tm.type & MIX_X) - { - case MIX_X: - tms[0] = terrain_texture(tex0, texcoord); - break; - default: - tms[0] = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - switch (tm.type & MIX_Y) - { - case MIX_Y: - tms[1] = terrain_texture(tex1, texcoord); - break; - default: - tms[1] = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - switch (tm.type & MIX_Z) - { - case MIX_Z: - tms[2] = terrain_texture(tex2, texcoord); - break; - default: - tms[2] = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - switch (tm.type & MIX_W) - { - case MIX_W: - tms[3] = terrain_texture(tex3, texcoord); - break; - default: - tms[3] = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - - return tms; -} - -TerrainMixSample _tmix_sample_color(TerrainMix tm, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - TerrainMixSample tmix; - - switch (tm.type & MIX_X) - { - case MIX_X: - tmix[0] = terrain_texture_color(tex0, texcoord); - break; - default: - tmix[0] = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - switch (tm.type & MIX_Y) - { - case MIX_Y: - tmix[1] = terrain_texture_color(tex1, texcoord); - break; - default: - tmix[1] = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - switch (tm.type & MIX_Z) - { - case MIX_Z: - tmix[2] = terrain_texture_color(tex2, texcoord); - break; - default: - tmix[2] = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - switch (tm.type & MIX_W) - { - case MIX_W: - tmix[3] = terrain_texture_color(tex3, texcoord); - break; - default: - tmix[3] = vec4(1.0, 0.0, 1.0, 1.0); - break; - } - - return tmix; -} - -TerrainMixSample3 _tmix_sample_normal(TerrainMix tm, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - TerrainMixSample3 tmix3; - - switch (tm.type & MIX_X) - { - case MIX_X: - tmix3[0] = terrain_texture_normal(tex0, texcoord); - break; - default: - tmix3[0] = vec3(1.0, 0.0, 1.0); - break; - } - switch (tm.type & MIX_Y) - { - case MIX_Y: - tmix3[1] = terrain_texture_normal(tex1, texcoord); - break; - default: - tmix3[1] = vec3(1.0, 0.0, 1.0); - break; - } - switch (tm.type & MIX_Z) - { - case MIX_Z: - tmix3[2] = terrain_texture_normal(tex2, texcoord); - break; - default: - tmix3[2] = vec3(1.0, 0.0, 1.0); - break; - } - switch (tm.type & MIX_W) - { - case MIX_W: - tmix3[3] = terrain_texture_normal(tex3, texcoord); - break; - default: - tmix3[3] = vec3(1.0, 0.0, 1.0); - break; - } - - return tmix3; -} - -vec3 sample_and_mix_color3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); - TerrainMixSample tms = _tmix_sample_color(tm, texcoord, tex0, tex1, tex2, tex3); - vec3[4] tms3; - tms3[0] = tms[0].xyz; - tms3[1] = tms[1].xyz; - tms3[2] = tms[2].xyz; - tms3[3] = tms[3].xyz; - tms3[0] *= factors[0]; - tms3[1] *= factors[1]; - tms3[2] *= factors[2]; - tms3[3] *= factors[3]; - return terrain_mix(tm, tms3); -} - -vec4 sample_and_mix_color4(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec4[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); - TerrainMixSample tms = _tmix_sample_color(tm, texcoord, tex0, tex1, tex2, tex3); - tms[0] *= factors[0]; - tms[1] *= factors[1]; - tms[2] *= factors[2]; - tms[3] *= factors[3]; - return terrain_mix(tm, tms); -} - -vec3 sample_and_mix_vector3(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, vec3[4] factors, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); - TerrainMixSample tms = _tmix_sample(tm, texcoord, tex0, tex1, tex2, tex3); - vec3[4] tms3; - tms3[0] = tms[0].xyz; - tms3[1] = tms[1].xyz; - tms3[2] = tms[2].xyz; - tms3[3] = tms[3].xyz; - tms3[0] *= factors[0]; - tms3[1] *= factors[1]; - tms3[2] *= factors[2]; - tms3[3] *= factors[3]; - return terrain_mix(tm, tms3); -} - -// Returns the unpacked normal texture in range [-1, 1] -vec3 sample_and_mix_normal(float alpha1, float alpha2, float alphaFinal, TerrainCoord texcoord, sampler2D tex0, sampler2D tex1, sampler2D tex2, sampler2D tex3) -{ - TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); - TerrainMixSample3 tms3 = _tmix_sample_normal(tm, texcoord, tex0, tex1, tex2, tex3); - return terrain_mix(tm, tms3); -} - PBRMix multiply_factors_pbr( PBRMix mix_in , vec4 factor_col -- cgit v1.2.3 From 8d9933b37057a67652512d949cedb24b9b087810 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:43:13 -0700 Subject: DRTVWR-592: EXTRA_CODE_HERE is actually important - bring that back --- indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 2 ++ indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl | 2 ++ 2 files changed, 4 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 18f8c4aa73..4bb9758224 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + #define TERRAIN_PBR_DETAIL_EMISSIVE 0 #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index c18cf832f8..316b751590 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -23,6 +23,8 @@ * $/LicenseInfo$ */ +/*[EXTRA_CODE_HERE]*/ + /** * Triplanar mapping implementation adapted from Inigo Quilez' example shader, * MIT license. -- cgit v1.2.3 From cc0f831aaa960552b218da436da57b44cb2dfe0f Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:43:18 -0700 Subject: DRTVWR-592: Fix PBR terrain shader compile crash when emissive textures are disabled --- .../newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 4bb9758224..db03e0885c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -258,9 +258,15 @@ void main() tnorm *= gl_FrontFacing ? 1.0 : -1.0; + +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) +#define emissive mix.emissive +#else +#define emissive vec3(0) +#endif frag_data[0] = max(vec4(mix.col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(mix.orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. frag_data[2] = max(vec4(encode_normal(tnorm), base_color_factor_alpha, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags - frag_data[3] = max(vec4(mix.emissive,0), vec4(0)); // PBR sRGB Emissive + frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } -- cgit v1.2.3 From e841c73a9972fc184487c061e8a80add3a18aff1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Mon, 16 Oct 2023 08:45:48 -0700 Subject: Tons of masking changes and tweaks. We now support masking mirrors in the GBuffer. We also now support the concept of one arbitrary clip plane. DRTVWR-583 --- .../shaders/class1/deferred/materialV.glsl | 17 ++++---------- .../shaders/class1/deferred/pbropaqueF.glsl | 27 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 7cdddfe8db..65706e2c3f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -28,25 +28,18 @@ #define DIFFUSE_ALPHA_MODE_MASK 2 #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -#ifdef HAS_SKIN uniform mat4 modelview_matrix; uniform mat4 projection_matrix; +uniform mat4 modelview_projection_matrix; + +#ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); #else uniform mat3 normal_matrix; -uniform mat4 modelview_projection_matrix; -#endif - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - -#if !defined(HAS_SKIN) -uniform mat4 modelview_matrix; #endif out vec3 vary_position; -#endif - uniform mat4 texture_matrix0; in vec3 position; @@ -133,10 +126,8 @@ void main() vertex_color = diffuse_color; -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #if !defined(HAS_SKIN) - vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; -#endif + vary_position = (projection_matrix*vec4(position.xyz, 1.0)).xyz; #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index faa273b834..9b98a37925 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -58,10 +58,37 @@ vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); +uniform vec4 clipPlane; +uniform float clipSign; +uniform float mirror_flag; +void applyClip(vec3 pos) +{ + if (mirror_flag > 0) + { + // TODO: make this less branchy + if (clipSign > 0) + { + if ((dot(pos.xyz, clipPlane.xyz) + clipPlane.w) < 0.0) + { + discard; + } + } + else + { + if ((dot(pos.xyz, clipPlane.xyz) + clipPlane.w) > 0.0) + { + discard; + } + } + } +} + uniform mat3 normal_matrix; void main() { + applyClip(vary_position); + vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; if (basecolor.a < minimum_alpha) { -- cgit v1.2.3 From 476cbaed6a876c308baa057b50af2631668f7293 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Wed, 31 Jan 2024 15:54:14 -0800 Subject: #677 Some clipping WIP --- indra/newview/app_settings/shaders/class1/deferred/materialV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 65706e2c3f..41112bce30 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -127,7 +127,7 @@ void main() vertex_color = diffuse_color; #if !defined(HAS_SKIN) - vary_position = (projection_matrix*vec4(position.xyz, 1.0)).xyz; + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; #endif } -- cgit v1.2.3 From b2462355a39a8473065c279c66daba307f1fa9bf Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Feb 2024 13:19:20 -0600 Subject: #677 WIP -- add mirror clipping to more shaders --- .../shaders/class1/deferred/bumpF.glsl | 4 ++ .../shaders/class1/deferred/bumpV.glsl | 5 ++- .../shaders/class1/deferred/diffuseF.glsl | 3 ++ .../shaders/class1/deferred/diffuseIndexedF.glsl | 3 ++ .../shaders/class1/deferred/diffuseV.glsl | 7 +++- .../shaders/class1/deferred/fullbrightF.glsl | 4 +- .../shaders/class1/deferred/globalF.glsl | 45 ++++++++++++++++++++++ .../shaders/class1/deferred/pbropaqueF.glsl | 26 ++----------- 8 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/globalF.glsl (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 35f483f633..a22c174349 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -37,11 +37,15 @@ in vec3 vary_mat2; in vec4 vertex_color; in vec2 vary_texcoord0; +in vec3 vary_position; vec2 encode_normal(vec3 n); +void mirrorClip(vec3 pos); void main() { + mirrorClip(vary_position); + vec4 col = texture(diffuseMap, vary_texcoord0.xy); if(col.a < minimum_alpha) diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl index 3af2eab1e4..74319349f6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl @@ -23,6 +23,7 @@ * $/LicenseInfo$ */ +uniform mat4 modelview_matrix; uniform mat3 normal_matrix; uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; @@ -38,11 +39,11 @@ out vec3 vary_mat1; out vec3 vary_mat2; out vec4 vertex_color; out vec2 vary_texcoord0; +out vec3 vary_position; #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); uniform mat4 projection_matrix; -uniform mat4 modelview_matrix; #endif void main() @@ -52,11 +53,13 @@ void main() mat4 mat = getObjectSkinnedTransform(); mat = modelview_matrix * mat; vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz; + vary_position = pos; gl_Position = projection_matrix*vec4(pos, 1.0); vec3 n = normalize((mat * vec4(normal.xyz+position.xyz, 1.0)).xyz-pos.xyz); vec3 t = normalize((mat * vec4(tangent.xyz+position.xyz, 1.0)).xyz-pos.xyz); #else + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vec3 n = normalize(normal_matrix * normal); vec3 t = normalize(normal_matrix * tangent.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 68fb8bf499..76776ede2c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -32,11 +32,14 @@ uniform sampler2D diffuseMap; in vec3 vary_normal; in vec4 vertex_color; in vec2 vary_texcoord0; +in vec3 vary_position; vec2 encode_normal(vec3 n); +void mirrorClip(vec3 pos); void main() { + mirrorClip(vary_position); vec3 col = vertex_color.rgb * texture(diffuseMap, vary_texcoord0.xy).rgb; frag_data[0] = vec4(col, 0.0); frag_data[1] = vertex_color.aaaa; // spec diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 93d561504e..b983acf657 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -30,12 +30,15 @@ out vec4 frag_data[4]; in vec3 vary_normal; in vec4 vertex_color; in vec2 vary_texcoord0; +in vec3 vary_position; +void mirrorClip(vec3 pos); vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); void main() { + mirrorClip(vary_position); vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; vec3 spec; diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl index 2402cc3b70..64230dc680 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl @@ -36,13 +36,16 @@ out vec3 vary_normal; out vec4 vertex_color; out vec2 vary_texcoord0; +out vec3 vary_position; void passTextureIndex(); +uniform mat4 modelview_matrix; + #ifdef HAS_SKIN mat4 getObjectSkinnedTransform(); uniform mat4 projection_matrix; -uniform mat4 modelview_matrix; + #endif void main() @@ -51,9 +54,11 @@ void main() mat4 mat = getObjectSkinnedTransform(); mat = modelview_matrix * mat; vec4 pos = mat * vec4(position.xyz, 1.0); + vary_position = pos.xyz; gl_Position = projection_matrix * pos; vary_normal = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); #else + vary_position = (modelview_matrix * vec4(position.xyz, 1.0)).xyz; gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vary_normal = normalize(normal_matrix * normal); #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index a6fab10791..52dfed06ae 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -50,9 +50,11 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color); #endif +void mirrorClip(vec3 pos); + void main() { - + mirrorClip(vary_position); #ifdef IS_ALPHA waterClip(vary_position.xyz); #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl b/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl new file mode 100644 index 0000000000..7e3e7d9271 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/globalF.glsl @@ -0,0 +1,45 @@ +/** + * @file class1/deferred/globalF.glsl + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2024, 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$ + */ + + + // Global helper functions included in every fragment shader + // DO NOT declare sampler uniforms here as OS X doesn't compile + // them out + +uniform float mirror_flag; +uniform vec4 clipPlane; +uniform float clipSign; + +void mirrorClip(vec3 pos) +{ + if (mirror_flag > 0) + { + if ((dot(pos.xyz, clipPlane.xyz) + clipPlane.w) < 0.0) + { + discard; + } + } +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index 9b98a37925..0683236460 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -60,34 +60,14 @@ vec3 srgb_to_linear(vec3 c); uniform vec4 clipPlane; uniform float clipSign; -uniform float mirror_flag; -void applyClip(vec3 pos) -{ - if (mirror_flag > 0) - { - // TODO: make this less branchy - if (clipSign > 0) - { - if ((dot(pos.xyz, clipPlane.xyz) + clipPlane.w) < 0.0) - { - discard; - } - } - else - { - if ((dot(pos.xyz, clipPlane.xyz) + clipPlane.w) > 0.0) - { - discard; - } - } - } -} + +void mirrorClip(vec3 pos); uniform mat3 normal_matrix; void main() { - applyClip(vary_position); + mirrorClip(vary_position); vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; if (basecolor.a < minimum_alpha) -- cgit v1.2.3 From 169562bf13ca6ed47dac1e73c6d8e72cd89861eb Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Feb 2024 13:50:47 -0600 Subject: #677 WIP -- Add clipping to alpha and pbr (not working on PBR for some reason) --- indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl index 160ae7a215..5e0141910b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -28,8 +28,9 @@ //deferred opaque implementation -#ifdef HAS_SKIN uniform mat4 modelview_matrix; + +#ifdef HAS_SKIN uniform mat4 projection_matrix; mat4 getObjectSkinnedTransform(); #else @@ -59,6 +60,7 @@ out vec4 vertex_color; out vec3 vary_tangent; flat out float vary_sign; out vec3 vary_normal; +out vec3 vary_position; vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); @@ -71,10 +73,11 @@ void main() mat = modelview_matrix * mat; vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; - + vary_position = pos; gl_Position = projection_matrix*vec4(pos,1.0); #else + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; //transform vertex gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); #endif -- cgit v1.2.3 From b1410c8b679c14432038a62bff2de772f490bc4a Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Feb 2024 14:00:40 -0600 Subject: #677 WIP -- fix PBR and avatar mirror clipping. --- indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl | 4 ++++ indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl | 2 ++ 2 files changed, 6 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index 6ebe4ce251..c0607d0149 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -33,11 +33,15 @@ uniform float minimum_alpha; in vec3 vary_normal; in vec2 vary_texcoord0; +in vec3 vary_position; vec2 encode_normal(vec3 n); +void mirrorClip(vec3 pos); void main() { + mirrorClip(vary_position); + vec4 diff = texture(diffuseMap, vary_texcoord0.xy); if (diff.a < minimum_alpha) diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl index bc0c11ec46..5cc2846156 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl @@ -35,6 +35,7 @@ in vec4 weight; out vec3 vary_normal; out vec2 vary_texcoord0; +out vec3 vary_position; void main() { @@ -57,6 +58,7 @@ void main() vary_normal = norm; + vary_position = pos.xyz; gl_Position = projection_matrix * pos; } -- cgit v1.2.3 From aab98046b9971717ecdc739b2230377278c83da3 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Thu, 1 Feb 2024 13:03:28 -0800 Subject: #677 More clipping fixes. --- indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index f6d509e2c6..2dba7cb9d9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -39,9 +39,11 @@ in vec4 vary_texcoord0; in vec4 vary_texcoord1; vec2 encode_normal(vec3 n); +void mirrorClip(vec3 position); void main() { + mirrorClip(pos); /// Note: This should duplicate the blending functionality currently used for the terrain rendering. vec4 color0 = texture(detail_0, vary_texcoord0.xy); -- cgit v1.2.3 From 6846600e3ef1eec7fade19f61d2d45614ae1a8b0 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 2 Feb 2024 13:49:06 -0600 Subject: #677 Fix terrain clipping and tweak hero probe mixing with radiance --- indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl index 33a78fd26d..8e1e4b54d5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl @@ -25,6 +25,7 @@ uniform mat3 normal_matrix; uniform mat4 texture_matrix0; +uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; in vec3 position; @@ -59,7 +60,7 @@ void main() vec4 t_pos = modelview_projection_matrix * pre_pos; gl_Position = t_pos; - pos = t_pos.xyz; + pos = (modelview_matrix*pre_pos).xyz; vary_normal = normalize(normal_matrix * normal); -- cgit v1.2.3 From 4e61152ca2fc2fdaedc9e27c4d1a16e248b59d9a Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 5 Feb 2024 12:00:38 -0600 Subject: #677 Add clipping to trees and alpha masked blinn-phong --- .../app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl | 6 ++++++ .../shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl | 5 +++++ indra/newview/app_settings/shaders/class1/deferred/treeF.glsl | 3 +++ indra/newview/app_settings/shaders/class1/deferred/treeV.glsl | 4 ++++ 4 files changed, 18 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index 6f3b94f734..e8ead91504 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -31,14 +31,20 @@ uniform float minimum_alpha; uniform sampler2D diffuseMap; +in vec3 vary_position; + in vec3 vary_normal; in vec4 vertex_color; in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); +void mirrorClip(vec3 pos); + void main() { + mirrorClip(vary_position); + vec4 col = texture(diffuseMap, vary_texcoord0.xy) * vertex_color; if (col.a < minimum_alpha) diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index e5f2af2c53..a07c892d8e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -28,6 +28,7 @@ out vec4 frag_data[4]; in vec3 vary_normal; +in vec3 vary_position; uniform float minimum_alpha; @@ -36,8 +37,12 @@ in vec2 vary_texcoord0; vec2 encode_normal(vec3 n); +void mirrorClip(vec3 pos); + void main() { + mirrorClip(vary_position); + vec4 col = diffuseLookup(vary_texcoord0.xy) * vertex_color; if (col.a < minimum_alpha) diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index e2d87e68fa..f108faf283 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -32,13 +32,16 @@ uniform sampler2D diffuseMap; in vec4 vertex_color; in vec3 vary_normal; in vec2 vary_texcoord0; +in vec3 vary_position; uniform float minimum_alpha; vec2 encode_normal(vec3 n); +void mirrorClip(vec3 pos); void main() { + mirrorClip(vary_position); vec4 col = texture(diffuseMap, vary_texcoord0.xy); if (col.a < minimum_alpha) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl index ce8a10712c..c84fccd4c6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl @@ -24,6 +24,7 @@ */ uniform mat4 texture_matrix0; +uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; uniform mat3 normal_matrix; @@ -34,11 +35,14 @@ in vec2 texcoord0; out vec3 vary_normal; out vec4 vertex_color; out vec2 vary_texcoord0; +out vec3 vary_position; void main() { //transform vertex gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; vary_normal = normalize(normal_matrix * normal); -- cgit v1.2.3 From 0e91d18da3f203bcef681d3134b736978114c2bd Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Mon, 5 Feb 2024 15:36:42 -0600 Subject: #677 Add mirror clipping to rigged shaders --- indra/newview/app_settings/shaders/class1/deferred/materialV.glsl | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 41112bce30..ddf878ae60 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -78,9 +78,7 @@ void main() vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) vary_position = pos; -#endif gl_Position = projection_matrix*vec4(pos,1.0); -- cgit v1.2.3 From 139c10dbeb4270259160e8e7988c6d916033c32e Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Wed, 31 Jan 2024 17:50:04 -0800 Subject: secondlife/viewer#711: Add more options to drop textures from terrain, not yet used --- .../shaders/class1/deferred/pbrterrainF.glsl | 80 +++++++++++++++++++++- .../shaders/class1/deferred/pbrterrainUtilF.glsl | 77 +++++++++++++++++++++ 2 files changed, 154 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index db03e0885c..adb3319934 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -26,6 +26,9 @@ /*[EXTRA_CODE_HERE]*/ #define TERRAIN_PBR_DETAIL_EMISSIVE 0 +#define TERRAIN_PBR_DETAIL_OCCLUSION -1 +#define TERRAIN_PBR_DETAIL_NORMAL -2 +#define TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS -3 #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 #define TerrainCoord vec4[2] @@ -51,8 +54,14 @@ TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal) struct PBRMix { vec4 col; // RGB color with alpha, linear space +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) vec3 orm; // Occlusion, roughness, metallic +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + vec2 rm; // Roughness, metallic +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) vec3 vNt; // Unpacked normal texture sample, vector +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) vec3 emissive; // RGB emissive color, linear space #endif @@ -63,13 +72,21 @@ PBRMix init_pbr_mix(); PBRMix terrain_sample_and_multiply_pbr( TerrainCoord terrain_coord , sampler2D tex_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , sampler2D tex_orm +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , sampler2D tex_vNt +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , sampler2D tex_emissive #endif , vec4 factor_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) , vec3 factor_orm +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + , vec2 factor_rm +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , vec3 factor_emissive #endif @@ -81,21 +98,23 @@ out vec4 frag_data[4]; uniform sampler2D alpha_ramp; -// *TODO: More configurable quality level which disables PBR features on machines -// with limited texture availability // https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#additional-textures uniform sampler2D detail_0_base_color; uniform sampler2D detail_1_base_color; uniform sampler2D detail_2_base_color; uniform sampler2D detail_3_base_color; +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) uniform sampler2D detail_0_normal; uniform sampler2D detail_1_normal; uniform sampler2D detail_2_normal; uniform sampler2D detail_3_normal; +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) uniform sampler2D detail_0_metallic_roughness; uniform sampler2D detail_1_metallic_roughness; uniform sampler2D detail_2_metallic_roughness; uniform sampler2D detail_3_metallic_roughness; +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) uniform sampler2D detail_0_emissive; uniform sampler2D detail_1_emissive; @@ -104,8 +123,10 @@ uniform sampler2D detail_3_emissive; #endif uniform vec4[4] baseColorFactors; // See also vertex_color in pbropaqueV.glsl +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) uniform vec4 metallicFactors; uniform vec4 roughnessFactors; +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) uniform vec3[4] emissiveColors; #endif @@ -139,6 +160,7 @@ void main() TerrainMix tm = get_terrain_mix_weights(alpha1, alpha2, alphaFinal); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) // RGB = Occlusion, Roughness, Metal // default values, see LLViewerTexture::sDefaultPBRORMImagep // occlusion 1.0 @@ -149,6 +171,13 @@ void main() orm_factors[1] = vec3(1.0, roughnessFactors.y, metallicFactors.y); orm_factors[2] = vec3(1.0, roughnessFactors.z, metallicFactors.z); orm_factors[3] = vec3(1.0, roughnessFactors.w, metallicFactors.w); +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + vec2[4] rm_factors; + rm_factors[0] = vec2(roughnessFactors.x, metallicFactors.x); + rm_factors[1] = vec2(roughnessFactors.y, metallicFactors.y); + rm_factors[2] = vec2(roughnessFactors.z, metallicFactors.z); + rm_factors[3] = vec2(roughnessFactors.w, metallicFactors.w); +#endif PBRMix mix = init_pbr_mix(); PBRMix mix2; @@ -158,13 +187,21 @@ void main() mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord , detail_0_base_color +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , detail_0_metallic_roughness +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , detail_0_normal +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , detail_0_emissive #endif , baseColorFactors[0] +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) , orm_factors[0] +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + , rm_factors[0] +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , emissiveColors[0] #endif @@ -180,13 +217,21 @@ void main() mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord , detail_1_base_color +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , detail_1_metallic_roughness +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , detail_1_normal +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , detail_1_emissive #endif , baseColorFactors[1] +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) , orm_factors[1] +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + , rm_factors[1] +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , emissiveColors[1] #endif @@ -202,13 +247,21 @@ void main() mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord , detail_2_base_color +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , detail_2_metallic_roughness +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , detail_2_normal +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , detail_2_emissive #endif , baseColorFactors[2] +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) , orm_factors[2] +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + , rm_factors[2] +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , emissiveColors[2] #endif @@ -224,13 +277,21 @@ void main() mix2 = terrain_sample_and_multiply_pbr( terrain_texcoord , detail_3_base_color +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , detail_3_metallic_roughness +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , detail_3_normal +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , detail_3_emissive #endif , baseColorFactors[3] +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) , orm_factors[3] +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + , rm_factors[3] +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , emissiveColors[3] #endif @@ -248,6 +309,7 @@ void main() } float base_color_factor_alpha = terrain_mix(tm, vec4(baseColorFactors[0].z, baseColorFactors[1].z, baseColorFactors[2].z, baseColorFactors[3].z)); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) // from mikktspace.com vec3 vNt = mix.vNt; vec3 vN = vary_normal; @@ -257,15 +319,27 @@ void main() vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); tnorm *= gl_FrontFacing ? 1.0 : -1.0; +#else + vec3 tnorm = vary_normal; + tnorm *= gl_FrontFacing ? 1.0 : -1.0; +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) #define emissive mix.emissive #else #define emissive vec3(0) +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) +#define orm mix.orm +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) +#define orm vec3(1.0, mix.rm) +#else +// Matte plastic potato terrain +#define orm vec3(1.0, 1.0, 0.0) #endif frag_data[0] = max(vec4(mix.col.xyz, 0.0), vec4(0)); // Diffuse - frag_data[1] = max(vec4(mix.orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. + frag_data[1] = max(vec4(orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. frag_data[2] = max(vec4(encode_normal(tnorm), base_color_factor_alpha, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl index 316b751590..935c3f9301 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainUtilF.glsl @@ -47,6 +47,9 @@ */ #define TERRAIN_PBR_DETAIL_EMISSIVE 0 +#define TERRAIN_PBR_DETAIL_OCCLUSION -1 +#define TERRAIN_PBR_DETAIL_NORMAL -2 +#define TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS -3 in vec3 vary_vertex_normal; @@ -75,8 +78,14 @@ vec3 srgb_to_linear(vec3 c); struct PBRMix { vec4 col; // RGB color with alpha, linear space +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) vec3 orm; // Occlusion, roughness, metallic +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + vec2 rm; // Roughness, metallic +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) vec3 vNt; // Unpacked normal texture sample, vector +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) vec3 emissive; // RGB emissive color, linear space #endif @@ -86,8 +95,14 @@ PBRMix init_pbr_mix() { PBRMix mix; mix.col = vec4(0); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) mix.orm = vec3(0); +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + mix.rm = vec2(0); +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) mix.vNt = vec3(0); +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) mix.emissive = vec3(0); #endif @@ -105,8 +120,14 @@ PBRMix mix_pbr(PBRMix mix1, PBRMix mix2, float mix2_weight) { PBRMix mix; mix.col = mix1.col + (mix2.col * mix2_weight); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) mix.orm = mix1.orm + (mix2.orm * mix2_weight); +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + mix.rm = mix1.rm + (mix2.rm * mix2_weight); +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) mix.vNt = mix1.vNt + (mix2.vNt * mix2_weight); +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) mix.emissive = mix1.emissive + (mix2.emissive * mix2_weight); #endif @@ -116,8 +137,12 @@ PBRMix mix_pbr(PBRMix mix1, PBRMix mix2, float mix2_weight) PBRMix sample_pbr( vec2 uv , sampler2D tex_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , sampler2D tex_orm +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , sampler2D tex_vNt +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , sampler2D tex_emissive #endif @@ -126,8 +151,14 @@ PBRMix sample_pbr( PBRMix mix; mix.col = texture(tex_col, uv); mix.col.rgb = srgb_to_linear(mix.col.rgb); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) mix.orm = texture(tex_orm, uv).xyz; +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + mix.rm = texture(tex_orm, uv).yz; +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) mix.vNt = texture(tex_vNt, uv).xyz*2.0-1.0; +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) mix.emissive = srgb_to_linear(texture(tex_emissive, uv).xyz); #endif @@ -254,8 +285,12 @@ PBRMix terrain_sample_pbr( TerrainCoord terrain_coord , TerrainTriplanar tw , sampler2D tex_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , sampler2D tex_orm +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , sampler2D tex_vNt +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , sampler2D tex_emissive #endif @@ -272,14 +307,20 @@ PBRMix terrain_sample_pbr( PBRMix mix_x = sample_pbr( get_uv_x() , tex_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , tex_orm +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , tex_vNt +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , tex_emissive #endif ); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) // Triplanar-specific normal texture fix mix_x.vNt = _t_normal_post_x(mix_x.vNt); +#endif mix = mix_pbr(mix, mix_x, tw.weight.x); break; default: @@ -292,14 +333,20 @@ PBRMix terrain_sample_pbr( PBRMix mix_y = sample_pbr( get_uv_y() , tex_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , tex_orm +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , tex_vNt +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , tex_emissive #endif ); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) // Triplanar-specific normal texture fix mix_y.vNt = _t_normal_post_y(mix_y.vNt); +#endif mix = mix_pbr(mix, mix_y, tw.weight.y); break; default: @@ -312,15 +359,21 @@ PBRMix terrain_sample_pbr( PBRMix mix_z = sample_pbr( get_uv_z() , tex_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , tex_orm +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , tex_vNt +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , tex_emissive #endif ); +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) // Triplanar-specific normal texture fix // *NOTE: Bottom face has not been tested mix_z.vNt = _t_normal_post_z(mix_z.vNt); +#endif mix = mix_pbr(mix, mix_z, tw.weight.z); break; default: @@ -341,7 +394,11 @@ PBRMix terrain_sample_pbr( PBRMix multiply_factors_pbr( PBRMix mix_in , vec4 factor_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) , vec3 factor_orm +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + , vec2 factor_rm +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , vec3 factor_emissive #endif @@ -349,7 +406,11 @@ PBRMix multiply_factors_pbr( { PBRMix mix = mix_in; mix.col *= factor_col; +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) mix.orm *= factor_orm; +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + mix.rm *= factor_rm; +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) mix.emissive *= factor_emissive; #endif @@ -359,13 +420,21 @@ PBRMix multiply_factors_pbr( PBRMix terrain_sample_and_multiply_pbr( TerrainCoord terrain_coord , sampler2D tex_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , sampler2D tex_orm +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , sampler2D tex_vNt +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , sampler2D tex_emissive #endif , vec4 factor_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) , vec3 factor_orm +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + , vec2 factor_rm +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , vec3 factor_emissive #endif @@ -377,8 +446,12 @@ PBRMix terrain_sample_and_multiply_pbr( , _t_triplanar() #endif , tex_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) , tex_orm +#endif +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) , tex_vNt +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , tex_emissive #endif @@ -386,7 +459,11 @@ PBRMix terrain_sample_and_multiply_pbr( mix = multiply_factors_pbr(mix , factor_col +#if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) , factor_orm +#elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) + , factor_rm +#endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) , factor_emissive #endif -- cgit v1.2.3 From c790fe58e63b851a730c1aaedde62e3ffbdf064a Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Wed, 7 Feb 2024 09:34:52 -0800 Subject: secondlife/viewer#711: Reduce PBR terrain textures at low graphics settings --- indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index adb3319934..c83a6be85d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -41,7 +41,6 @@ #define MIX_Z 1 << 5 #define MIX_W 1 << 6 -// TODO: Decide if this struct needs to be declared struct TerrainMix { vec4 weight; @@ -50,7 +49,6 @@ struct TerrainMix TerrainMix get_terrain_mix_weights(float alpha1, float alpha2, float alphaFinal); -// TODO: Decide if this struct needs to be declared struct PBRMix { vec4 col; // RGB color with alpha, linear space -- cgit v1.2.3 From 589910f445efa9690b543a37b9e2e14792a0e133 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Wed, 21 Feb 2024 12:53:10 -0800 Subject: secondlife/viewer-issues#72: Fix material preview affecting exposure on main screen --- indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl index 9ac4ceb37e..eff7221ae7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/exposureF.glsl @@ -28,7 +28,9 @@ out vec4 frag_color; uniform sampler2D emissiveRect; +#ifdef USE_LAST_EXPOSURE uniform sampler2D exposureMap; +#endif uniform float dt; uniform vec2 noiseVec; @@ -51,10 +53,12 @@ void main() L /= max_L; L = pow(L, 2.0); float s = mix(dynamic_exposure_params.z, dynamic_exposure_params.y, L); - + +#ifdef USE_LAST_EXPOSURE float prev = texture(exposureMap, vec2(0.5,0.5)).r; s = mix(prev, s, min(dt*2.0*abs(prev-s), 0.04)); +#endif frag_color = max(vec4(s, s, s, dt), vec4(0.0)); } -- cgit v1.2.3 From 5557254c93582166b2ab2ac4ec27b6f60e4b232e Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Fri, 23 Feb 2024 14:21:52 -0800 Subject: Fix for deferred avatar eyes shader failing to link on Intel GPU. --- indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl index 83b0ba096c..43863dd37a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl @@ -26,6 +26,7 @@ uniform mat3 normal_matrix; uniform mat4 texture_matrix0; uniform mat4 modelview_projection_matrix; +uniform mat4 modelview_matrix; in vec3 position; in vec3 normal; @@ -35,10 +36,12 @@ in vec2 texcoord0; out vec3 vary_normal; out vec4 vertex_color; out vec2 vary_texcoord0; +out vec3 vary_position; void main() { //transform vertex + vary_position = (modelview_matrix * vec4(position.xyz, 1.0)).xyz; gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -- cgit v1.2.3 From 1fc45a50ff15e6f31a4554da83256b7f59b1af15 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Geenz\" Goodman" Date: Wed, 6 Mar 2024 17:56:16 -0800 Subject: #681 Add probe blending for mirrors. --- indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl | 4 ++++ indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl | 3 +++ 2 files changed, 7 insertions(+) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index c83a6be85d..57c0a6024f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -133,6 +133,7 @@ uniform vec4 minimum_alphas; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlpha #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 in vec4[2] vary_coords; #endif +in vec3 vary_position; in vec3 vary_normal; in vec3 vary_tangent; flat in float vary_sign; @@ -140,11 +141,14 @@ in vec4 vary_texcoord0; in vec4 vary_texcoord1; vec2 encode_normal(vec3 n); +void mirrorClip(vec3 position); float terrain_mix(TerrainMix tm, vec4 tms4); void main() { + // Make sure we clip the terrain if we're in a mirror. + mirrorClip(vary_position); #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 TerrainCoord terrain_texcoord = vary_coords; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index dbb9404219..489fc26e3f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -25,6 +25,7 @@ uniform mat3 normal_matrix; uniform mat4 texture_matrix0; +uniform mat4 modelview_matrix; uniform mat4 modelview_projection_matrix; in vec3 position; @@ -42,6 +43,7 @@ out vec3 vary_tangent; flat out float vary_sign; out vec4 vary_texcoord0; out vec4 vary_texcoord1; +out vec3 vary_position; // *HACK: tangent_space_transform should use texture_normal_transform, or maybe // we shouldn't use tangent_space_transform at all. See the call to @@ -55,6 +57,7 @@ void main() { //transform vertex gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; vec3 n = normal_matrix * normal; vary_vertex_normal = normal; -- cgit v1.2.3 From c1bde75768e1374d4f094936d52ed29f6f5d3cba Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 8 Mar 2024 12:01:20 -0600 Subject: HDRI Local Preview (#953) * #926 WIP - HDRI import prototype v0 * #926 WIP -- add OpenEXR to autobuild.xml * #926 WIP -- Add OpenEXR cmake * #926 WIP -- Attempt at using OpenEXR autobuild package and don't hard code .exr file to load * #926 Unmangle autobuild.xml and get dll's in the right place (thanks, Caladbolg!) * implement mac shared libs plumbing for OpenEXR for secondlife/viewer#926 * Fix Xcode/clang compile error regarding new[]/delete[] mismatch * #926 HDRI Preview finishing touches. - Full ACES when HDRI is enabled - Fix for probes getting stuck paused - Add exposure and rotation controls --------- Co-authored-by: Brad Linden --- .../class1/deferred/postDeferredGammaCorrect.glsl | 3 ++- .../app_settings/shaders/class1/deferred/skyF.glsl | 23 +++++++++++++++++++++- .../app_settings/shaders/class1/deferred/skyV.glsl | 8 ++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 3443785e1a..d89377326e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -97,6 +97,7 @@ vec3 toneMapACES_Hill(vec3 color) uniform float exposure; uniform float gamma; +uniform float aces_mix; vec3 toneMap(vec3 color) { @@ -106,7 +107,7 @@ vec3 toneMap(vec3 color) color *= exposure * exp_scale; // mix ACES and Linear here as a compromise to avoid over-darkening legacy content - color = mix(toneMapACES_Hill(color), color, 0.3); + color = mix(toneMapACES_Hill(color), color, aces_mix); #endif return color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 9d9ba49d82..cc5280d929 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -27,6 +27,13 @@ in vec3 vary_HazeColor; in float vary_LightNormPosDot; +#ifdef HAS_HDRI +in vec3 vary_position; +uniform float sky_hdr_scale; +uniform mat3 env_mat; +uniform sampler2D environmentMap; +#endif + uniform sampler2D rainbow_map; uniform sampler2D halo_map; @@ -37,6 +44,9 @@ uniform float ice_level; out vec4 frag_data[4]; vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); + +#define PI 3.14159265 ///////////////////////////////////////////////////////////////////////// // The fragment shader for the sky @@ -71,6 +81,14 @@ vec3 halo22(float d) void main() { +#ifdef HAS_HDRI + vec3 pos = normalize(vary_position); + pos = env_mat * pos; + vec2 texCoord = vec2(atan(pos.z, pos.x) + PI, acos(pos.y)) / vec2(2.0 * PI, PI); + vec3 color = textureLod(environmentMap, texCoord.xy, 0).rgb * sky_hdr_scale; + color = min(color, vec3(8192*8192*16)); +#else + // Potential Fill-rate optimization. Add cloud calculation // back in and output alpha of 0 (so that alpha culling kills // the fragment) if the sky wouldn't show up because the clouds @@ -86,9 +104,12 @@ void main() color.rgb *= 2.; color.rgb = clamp(color.rgb, vec3(0), vec3(5)); +#endif + frag_data[0] = vec4(0); frag_data[1] = vec4(0); - frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); //1.0 in norm.w masks off fog + frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); frag_data[3] = vec4(color.rgb, 1.0); + } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 17ce2dee5b..bbe9a5a838 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -35,6 +35,10 @@ in vec3 position; out vec3 vary_HazeColor; out float vary_LightNormPosDot; +#ifdef HAS_HDRI +out vec3 vary_position; +#endif + // Inputs uniform vec3 camPosLocal; @@ -72,6 +76,10 @@ void main() // Get relative position vec3 rel_pos = position.xyz - camPosLocal.xyz + vec3(0, 50, 0); +#ifdef HAS_HDRI + vary_position = rel_pos; +#endif + // Adj position vector to clamp altitude if (rel_pos.y > 0.) { -- cgit v1.2.3 From 457b720fd9b2ced6f288d4bbc71045cefaed4a49 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 12 Mar 2024 14:26:21 -0500 Subject: #965 Fix for EEP skies being too bright --- indra/newview/app_settings/shaders/class1/deferred/skyF.glsl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index cc5280d929..596e9321e8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -86,7 +86,9 @@ void main() pos = env_mat * pos; vec2 texCoord = vec2(atan(pos.z, pos.x) + PI, acos(pos.y)) / vec2(2.0 * PI, PI); vec3 color = textureLod(environmentMap, texCoord.xy, 0).rgb * sky_hdr_scale; - color = min(color, vec3(8192*8192*16)); + color = min(color, vec3(8192*8192*16)); // stupidly large value arrived at by binary search -- avoids framebuffer corruption from some HDRIs + + frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_HAS_HDRI); #else // Potential Fill-rate optimization. Add cloud calculation @@ -104,12 +106,11 @@ void main() color.rgb *= 2.; color.rgb = clamp(color.rgb, vec3(0), vec3(5)); + frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); #endif frag_data[0] = vec4(0); frag_data[1] = vec4(0); - frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); frag_data[3] = vec4(color.rgb, 1.0); - } -- cgit v1.2.3 From d909e7243861320b43634ab9cafd2bb5a8dc558b Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 13 Mar 2024 12:27:33 -0500 Subject: #975 Add RenderHDRISplitScreen debug setting (#976) * #975 Add RenderHDRISplitScreen debug setting * Create hdri_local_preview.md --- .../app_settings/shaders/class1/deferred/skyF.glsl | 60 ++++++++++++---------- .../app_settings/shaders/class1/deferred/skyV.glsl | 6 ++- 2 files changed, 38 insertions(+), 28 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 596e9321e8..785c748234 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -28,8 +28,10 @@ in vec3 vary_HazeColor; in float vary_LightNormPosDot; #ifdef HAS_HDRI -in vec3 vary_position; +in vec4 vary_position; +in vec3 vary_rel_pos; uniform float sky_hdr_scale; +uniform float hdri_split_screen; uniform mat3 env_mat; uniform sampler2D environmentMap; #endif @@ -81,33 +83,39 @@ vec3 halo22(float d) void main() { + vec3 color; #ifdef HAS_HDRI - vec3 pos = normalize(vary_position); - pos = env_mat * pos; - vec2 texCoord = vec2(atan(pos.z, pos.x) + PI, acos(pos.y)) / vec2(2.0 * PI, PI); - vec3 color = textureLod(environmentMap, texCoord.xy, 0).rgb * sky_hdr_scale; - color = min(color, vec3(8192*8192*16)); // stupidly large value arrived at by binary search -- avoids framebuffer corruption from some HDRIs - - frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_HAS_HDRI); -#else - - // Potential Fill-rate optimization. Add cloud calculation - // back in and output alpha of 0 (so that alpha culling kills - // the fragment) if the sky wouldn't show up because the clouds - // are fully opaque. - - vec3 color = vary_HazeColor; - - float rel_pos_lightnorm = vary_LightNormPosDot; - float optic_d = rel_pos_lightnorm; - vec3 halo_22 = halo22(optic_d); - color.rgb += rainbow(optic_d); - color.rgb += halo_22; - color.rgb *= 2.; - color.rgb = clamp(color.rgb, vec3(0), vec3(5)); - - frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); + vec3 frag_coord = vary_position.xyz/vary_position.w; + if (-frag_coord.x > ((1.0-hdri_split_screen)*2.0-1.0)) + { + vec3 pos = normalize(vary_rel_pos); + pos = env_mat * pos; + vec2 texCoord = vec2(atan(pos.z, pos.x) + PI, acos(pos.y)) / vec2(2.0 * PI, PI); + color = textureLod(environmentMap, texCoord.xy, 0).rgb * sky_hdr_scale; + color = min(color, vec3(8192*8192*16)); // stupidly large value arrived at by binary search -- avoids framebuffer corruption from some HDRIs + + frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_HAS_HDRI); + } + else #endif + { + // Potential Fill-rate optimization. Add cloud calculation + // back in and output alpha of 0 (so that alpha culling kills + // the fragment) if the sky wouldn't show up because the clouds + // are fully opaque. + + color = vary_HazeColor; + + float rel_pos_lightnorm = vary_LightNormPosDot; + float optic_d = rel_pos_lightnorm; + vec3 halo_22 = halo22(optic_d); + color.rgb += rainbow(optic_d); + color.rgb += halo_22; + color.rgb *= 2.; + color.rgb = clamp(color.rgb, vec3(0), vec3(5)); + + frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); + } frag_data[0] = vec4(0); frag_data[1] = vec4(0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index bbe9a5a838..e48f69dab5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -36,7 +36,8 @@ out vec3 vary_HazeColor; out float vary_LightNormPosDot; #ifdef HAS_HDRI -out vec3 vary_position; +out vec4 vary_position; +out vec3 vary_rel_pos; #endif // Inputs @@ -77,7 +78,8 @@ void main() vec3 rel_pos = position.xyz - camPosLocal.xyz + vec3(0, 50, 0); #ifdef HAS_HDRI - vary_position = rel_pos; + vary_rel_pos = rel_pos; + vary_position = pos; #endif // Adj position vector to clamp altitude -- cgit v1.2.3 From 617436b7cb9a574c08e49974046c330da1b706e0 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 28 Mar 2024 14:06:11 -0500 Subject: #1046 Tweak auto-exposure to not underexpose bright scenes (#1084) --- .../shaders/class1/deferred/luminanceF.glsl | 18 +++++++++++++++++- .../class1/deferred/postDeferredGammaCorrect.glsl | 12 +++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index c8afacf9bb..95b2f80e06 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -34,6 +34,8 @@ in vec2 vary_fragcoord; uniform sampler2D diffuseRect; uniform sampler2D emissiveRect; +uniform sampler2D normalMap; +uniform float diffuse_luminance_scale; float lum(vec3 col) { @@ -45,7 +47,21 @@ void main() { vec2 tc = vary_fragcoord*0.6+0.2; tc.y -= 0.1; // HACK - nudge exposure sample down a little bit to favor ground over sky - vec3 c = texture(diffuseRect, tc).rgb + texture(emissiveRect, tc).rgb; + vec3 c = texture(diffuseRect, tc).rgb; + + vec4 norm = texture(normalMap, tc); + + if (!GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_HDRI) && + !GET_GBUFFER_FLAG(GBUFFER_FLAG_SKIP_ATMOS)) + { + // Apply the diffuse luminance scale to objects but not the sky + // Prevents underexposing when looking at bright environments + // while still allowing for realistically bright skies. + c *= diffuse_luminance_scale; + } + + c += texture(emissiveRect, tc).rgb; + float L = lum(c); frag_color = vec4(max(L, 0.0)); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index d89377326e..1629ed91c8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -153,6 +153,15 @@ float noise(vec2 x) { //============================= +void debugExposure(inout vec3 color) +{ + float exp_scale = texture(exposureMap, vec2(0.5,0.5)).r; + exp_scale *= 0.5; + if (abs(vary_fragcoord.y-exp_scale) < 0.01 && vary_fragcoord.x < 0.1) + { + color = vec3(1,0,0); + } +} vec3 legacyGamma(vec3 color) { @@ -181,7 +190,8 @@ void main() vec3 seed = (diff.rgb+vec3(1.0))*vec3(tc.xy, tc.x+tc.y); vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb)); diff.rgb += nz*0.003; - + + //debugExposure(diff.rgb); frag_color = max(diff, vec4(0)); } -- cgit v1.2.3 From 43e605b8339105151fa7e97b27359d87479a3461 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 28 Mar 2024 16:07:09 -0500 Subject: #731 Fix for divide by zero when haze density set to zero (#1085) --- indra/newview/app_settings/shaders/class1/deferred/skyV.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index e48f69dab5..24d2db2183 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -108,7 +108,7 @@ void main() vec3 light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights - vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density)); + vec3 combined_haze = max(abs(blue_density) + vec3(abs(haze_density)), vec3(1e-6)); vec3 blue_weight = blue_density / combined_haze; vec3 haze_weight = haze_density / combined_haze; -- cgit v1.2.3 From 2880e5ceeeacbf4024167b2a4e0f1d2ce129eb6f Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Fri, 19 Apr 2024 11:59:28 -0500 Subject: #1139 Fix for world going black/white in some scenes (NaNs) (#1273) * #1139 Fix for world going black/white in some scenes (NaNs) NaNs were coming from normal encode/decode. Take advantage of available gbuffer space to send full normal instead of encoding. * #1139 Cleanup remove now unused encodeNormF.glsl * #1139 Remove final reference to encodeNormF * #1139 Fix for getNormalEnvIntensityFlags referencing wrong sampler for env intensity * Mac build fix --- .../shaders/class1/deferred/avatarF.glsl | 6 +++--- .../app_settings/shaders/class1/deferred/bumpF.glsl | 6 ++---- .../shaders/class1/deferred/deferredUtil.glsl | 20 ++++++-------------- .../shaders/class1/deferred/diffuseAlphaMaskF.glsl | 4 +--- .../class1/deferred/diffuseAlphaMaskIndexedF.glsl | 4 +--- .../class1/deferred/diffuseAlphaMaskNoColorF.glsl | 4 +--- .../shaders/class1/deferred/diffuseF.glsl | 5 ++--- .../shaders/class1/deferred/diffuseIndexedF.glsl | 5 ++--- .../shaders/class1/deferred/impostorF.glsl | 3 +-- .../shaders/class1/deferred/pbropaqueF.glsl | 3 +-- .../shaders/class1/deferred/pbrterrainF.glsl | 3 +-- .../shaders/class1/deferred/terrainF.glsl | 3 +-- .../app_settings/shaders/class1/deferred/treeF.glsl | 4 +--- 13 files changed, 23 insertions(+), 47 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index c0607d0149..db7597dd74 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -25,7 +25,7 @@ /*[EXTRA_CODE_HERE]*/ -out vec4 frag_data[3]; +out vec4 frag_data[4]; uniform sampler2D diffuseMap; @@ -35,7 +35,6 @@ in vec3 vary_normal; in vec2 vary_texcoord0; in vec3 vary_position; -vec2 encode_normal(vec3 n); void mirrorClip(vec3 pos); void main() @@ -52,6 +51,7 @@ void main() frag_data[0] = vec4(diff.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index a22c174349..8483f257fa 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -39,8 +39,6 @@ in vec4 vertex_color; in vec2 vary_texcoord0; in vec3 vary_position; -vec2 encode_normal(vec3 n); - void mirrorClip(vec3 pos); void main() { @@ -64,6 +62,6 @@ void main() frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(tnorm); - frag_data[2] = vec4(encode_normal(nvn), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); - frag_data[3] = vec4(0); + frag_data[2] = vec4(nvn, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(vertex_color.a, 0, 0, 0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index f9ebf33b4a..065fcec45a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -50,6 +50,7 @@ SOFTWARE. uniform sampler2D normalMap; uniform sampler2D depthMap; +uniform sampler2D emissiveRect; uniform sampler2D projectionMap; // rgba uniform sampler2D brdfLut; @@ -140,18 +141,9 @@ vec2 getScreenCoordinate(vec2 screenpos) return sc - vec2(1.0, 1.0); } -// See: https://aras-p.info/texts/CompactNormalStorage.html -// Method #4: Spheremap Transform, Lambert Azimuthal Equal-Area projection vec3 getNorm(vec2 screenpos) { - vec2 enc = texture(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; + return texture(normalMap, screenpos.xy).rgb; } vec3 getNormalFromPacked(vec4 packedNormalEnvIntensityFlags) @@ -170,10 +162,10 @@ vec3 getNormalFromPacked(vec4 packedNormalEnvIntensityFlags) // See: C++: addDeferredAttachments(), GLSL: softenLightF vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity) { - vec4 packedNormalEnvIntensityFlags = texture(normalMap, screenpos.xy); - n = getNormalFromPacked( packedNormalEnvIntensityFlags ); - envIntensity = packedNormalEnvIntensityFlags.z; - return packedNormalEnvIntensityFlags; + n = texture(normalMap, screenpos.xy).rgb; + envIntensity = texture(emissiveRect, screenpos.xy).r; + + return vec4(n, envIntensity); } // get linear depth value given a depth buffer sample d and znear and zfar values diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index e8ead91504..82d5d363d2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -37,8 +37,6 @@ in vec3 vary_normal; in vec4 vertex_color; in vec2 vary_texcoord0; -vec2 encode_normal(vec3 n); - void mirrorClip(vec3 pos); void main() @@ -55,7 +53,7 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index a07c892d8e..788ea633fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -35,8 +35,6 @@ uniform float minimum_alpha; in vec4 vertex_color; in vec2 vary_texcoord0; -vec2 encode_normal(vec3 n); - void mirrorClip(vec3 pos); void main() @@ -53,6 +51,6 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index 234f096ed5..22e6d60419 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -34,8 +34,6 @@ uniform sampler2D diffuseMap; in vec3 vary_normal; in vec2 vary_texcoord0; -vec2 encode_normal(vec3 n); - void main() { vec4 col = texture(diffuseMap, vary_texcoord0.xy); @@ -48,7 +46,7 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 76776ede2c..799fc62a42 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -34,7 +34,6 @@ in vec4 vertex_color; in vec2 vary_texcoord0; in vec3 vary_position; -vec2 encode_normal(vec3 n); void mirrorClip(vec3 pos); void main() @@ -45,7 +44,7 @@ void main() frag_data[1] = vertex_color.aaaa; // spec //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); - frag_data[3] = vec4(0); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(vertex_color.a, 0, 0, 0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index b983acf657..3362a180c6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -33,7 +33,6 @@ in vec2 vary_texcoord0; in vec3 vary_position; void mirrorClip(vec3 pos); -vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); void main() @@ -47,6 +46,6 @@ void main() frag_data[0] = vec4(col, 0.0); frag_data[1] = vec4(spec, vertex_color.a); // spec vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS); - frag_data[3] = vec4(0); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[3] = vec4(vertex_color.a, 0, 0, 0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index aae595f619..c64f65e32c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -37,7 +37,6 @@ uniform sampler2D specularMap; in vec2 vary_texcoord0; vec3 linear_to_srgb(vec3 c); -vec2 encode_normal (vec3 n); void main() { @@ -53,6 +52,6 @@ void main() frag_data[0] = vec4(col.rgb, 0.0); frag_data[1] = spec; - frag_data[2] = vec4(encode_normal(norm.xyz),0,GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = vec4(norm.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index 0683236460..55fc94b7f5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -54,7 +54,6 @@ in vec2 emissive_texcoord; uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() -vec2 encode_normal(vec3 n); vec3 linear_to_srgb(vec3 c); vec3 srgb_to_linear(vec3 c); @@ -110,7 +109,7 @@ void main() // See: C++: addDeferredAttachments(), GLSL: softenLightF frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb,vertex_color.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = max(vec4(encode_normal(tnorm), vertex_color.a, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags + frag_data[2] = max(vec4(tnorm, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 57c0a6024f..025ecb64df 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -140,7 +140,6 @@ flat in float vary_sign; in vec4 vary_texcoord0; in vec4 vary_texcoord1; -vec2 encode_normal(vec3 n); void mirrorClip(vec3 position); float terrain_mix(TerrainMix tm, vec4 tms4); @@ -342,7 +341,7 @@ void main() #endif frag_data[0] = max(vec4(mix.col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = max(vec4(encode_normal(tnorm), base_color_factor_alpha, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags + frag_data[2] = max(vec4(tnorm, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 2dba7cb9d9..5f598f84a7 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -38,7 +38,6 @@ in vec3 vary_normal; in vec4 vary_texcoord0; in vec4 vary_texcoord1; -vec2 encode_normal(vec3 n); void mirrorClip(vec3 position); void main() @@ -61,7 +60,7 @@ void main() frag_data[0] = outColor; frag_data[1] = vec4(0.0,0.0,0.0,-1.0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index f108faf283..708acd0194 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -36,8 +36,6 @@ in vec3 vary_position; uniform float minimum_alpha; -vec2 encode_normal(vec3 n); - void mirrorClip(vec3 pos); void main() { @@ -51,6 +49,6 @@ void main() frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0); frag_data[1] = vec4(0,0,0,0); vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } -- cgit v1.2.3 From f1b7e806eb30a343876036eff5caef7c03309aa6 Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Sun, 21 Apr 2024 20:40:13 -0400 Subject: Fix sampling normals from gbuffer and cleanup redundant gbuffer samples (#1294) * Fix sampling normals from gbuffer and cleanup redundant gbuffer samples * Allow negative normals in gbuffer to fix broken material rendering --- .../shaders/class1/deferred/blurLightF.glsl | 4 ++-- .../shaders/class1/deferred/deferredUtil.glsl | 21 +++++---------------- .../shaders/class1/deferred/pbropaqueF.glsl | 2 +- .../shaders/class1/deferred/pbrterrainF.glsl | 2 +- 4 files changed, 9 insertions(+), 20 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 08baf98686..8627ab1852 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -40,12 +40,12 @@ uniform float kern_scale; in vec2 vary_fragcoord; vec4 getPosition(vec2 pos_screen); -vec3 getNorm(vec2 pos_screen); +vec4 getNorm(vec2 pos_screen); void main() { vec2 tc = vary_fragcoord.xy; - vec3 norm = getNorm(tc); + vec4 norm = getNorm(tc); vec3 pos = getPosition(tc).xyz; vec4 ccol = texture(lightMap, tc).rgba; diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 065fcec45a..f6696e270c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -141,31 +141,20 @@ vec2 getScreenCoordinate(vec2 screenpos) return sc - vec2(1.0, 1.0); } -vec3 getNorm(vec2 screenpos) +vec4 getNorm(vec2 screenpos) { - return texture(normalMap, screenpos.xy).rgb; -} - -vec3 getNormalFromPacked(vec4 packedNormalEnvIntensityFlags) -{ - vec2 enc = packedNormalEnvIntensityFlags.xy; - vec2 fenc = enc*4-2; - float f = dot(fenc,fenc); - float g = sqrt(1-f/4); - vec3 n; - n.xy = fenc*g; - n.z = 1-f/2; - return normalize(n); // TODO: Is this normalize redundant? + return texture(normalMap, screenpos.xy); } // return packedNormalEnvIntensityFlags since GBUFFER_FLAG_HAS_PBR needs .w // See: C++: addDeferredAttachments(), GLSL: softenLightF vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity) { - n = texture(normalMap, screenpos.xy).rgb; + vec4 norm = texture(normalMap, screenpos.xy); + n = norm.xyz; envIntensity = texture(emissiveRect, screenpos.xy).r; - return vec4(n, envIntensity); + return norm; } // get linear depth value given a depth buffer sample d and znear and zfar values diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index 55fc94b7f5..1d5f810cf3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -109,7 +109,7 @@ void main() // See: C++: addDeferredAttachments(), GLSL: softenLightF frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(spec.rgb,vertex_color.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = max(vec4(tnorm, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, environment intensity, flags + frag_data[2] = vec4(tnorm, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index 025ecb64df..de4745c1c4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -341,7 +341,7 @@ void main() #endif frag_data[0] = max(vec4(mix.col.xyz, 0.0), vec4(0)); // Diffuse frag_data[1] = max(vec4(orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. - frag_data[2] = max(vec4(tnorm, GBUFFER_FLAG_HAS_PBR), vec4(0)); // normal, flags + frag_data[2] = vec4(tnorm, GBUFFER_FLAG_HAS_PBR); // normal, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } -- cgit v1.2.3 From 1514edc58a498fde9533136f86bb20a9e5ef9a37 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 30 Apr 2024 18:01:13 -0500 Subject: Fix for black moon. (#1369) --- indra/newview/app_settings/shaders/class1/deferred/moonF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 183354b9bd..6ef556d7e8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -55,7 +55,7 @@ void main() frag_data[0] = vec4(0); frag_data[1] = vec4(0.0); - frag_data[2] = vec4(0.0, 0.0, 0.0, GBUFFER_FLAG_HAS_ATMOS); + frag_data[2] = vec4(0.0, 0.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); frag_data[3] = vec4(c.rgb, c.a); // Added and commented out for a ground truth. Do not uncomment - Geenz -- cgit v1.2.3 From b06a99f7c76950484972e25d9dbbee8660a6a6c3 Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Wed, 15 May 2024 12:47:27 +0300 Subject: Post-merge spaces fix --- .../shaders/class1/deferred/avatarEyesV.glsl | 24 +-- .../shaders/class1/deferred/avatarF.glsl | 34 ++-- .../shaders/class1/deferred/avatarV.glsl | 52 +++---- .../shaders/class1/deferred/bumpF.glsl | 50 +++--- .../shaders/class1/deferred/bumpV.glsl | 42 ++--- .../shaders/class1/deferred/deferredUtil.glsl | 172 ++++++++++----------- .../shaders/class1/deferred/diffuseAlphaMaskF.glsl | 34 ++-- .../class1/deferred/diffuseAlphaMaskIndexedF.glsl | 34 ++-- .../class1/deferred/diffuseAlphaMaskNoColorF.glsl | 36 ++--- .../shaders/class1/deferred/diffuseF.glsl | 26 ++-- .../shaders/class1/deferred/diffuseIndexedF.glsl | 26 ++-- .../shaders/class1/deferred/diffuseV.glsl | 22 +-- .../shaders/class1/deferred/impostorF.glsl | 32 ++-- .../shaders/class1/deferred/materialV.glsl | 54 +++---- .../shaders/class1/deferred/pbropaqueV.glsl | 42 ++--- .../shaders/class1/deferred/pbrterrainV.glsl | 18 +-- .../class1/deferred/postDeferredGammaCorrect.glsl | 66 ++++---- .../shaders/class1/deferred/treeF.glsl | 30 ++-- .../shaders/class1/deferred/treeV.glsl | 22 +-- 19 files changed, 408 insertions(+), 408 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl index 43863dd37a..d3ca3ec8c1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file avatarEyesV.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$ */ @@ -40,12 +40,12 @@ out vec3 vary_position; void main() { - //transform vertex - vary_position = (modelview_matrix * vec4(position.xyz, 1.0)).xyz; - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - - vary_normal = normalize(normal_matrix * normal); + //transform vertex + vary_position = (modelview_matrix * vec4(position.xyz, 1.0)).xyz; + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + vary_normal = normalize(normal_matrix * normal); - vertex_color = diffuse_color; + vertex_color = diffuse_color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index db7597dd74..b904df3a1b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file avatarF.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$ */ @@ -37,21 +37,21 @@ in vec3 vary_position; void mirrorClip(vec3 pos); -void main() +void main() { mirrorClip(vary_position); - vec4 diff = texture(diffuseMap, vary_texcoord0.xy); - - if (diff.a < minimum_alpha) - { - discard; - } - - frag_data[0] = vec4(diff.rgb, 0.0); - frag_data[1] = vec4(0,0,0,0); - vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + vec4 diff = texture(diffuseMap, vary_texcoord0.xy); + + if (diff.a < minimum_alpha) + { + discard; + } + + frag_data[0] = vec4(diff.rgb, 0.0); + frag_data[1] = vec4(0,0,0,0); + vec3 nvn = normalize(vary_normal); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl index 5cc2846156..aabbbac12a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl @@ -1,28 +1,28 @@ -/** +/** * @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; in vec3 position; @@ -39,27 +39,27 @@ out vec3 vary_position; void main() { - vary_texcoord0 = texcoord0; - - vec4 pos; - 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); - - vary_normal = norm; - + vary_texcoord0 = texcoord0; + + vec4 pos; + 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); + + vary_normal = norm; + vary_position = pos.xyz; - gl_Position = projection_matrix * pos; + gl_Position = projection_matrix * pos; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index 8483f257fa..2cc3085cd0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -1,30 +1,30 @@ -/** +/** * @file bumpF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ /*[EXTRA_CODE_HERE]*/ - + out vec4 frag_data[4]; uniform float minimum_alpha; @@ -40,28 +40,28 @@ in vec2 vary_texcoord0; in vec3 vary_position; void mirrorClip(vec3 pos); -void main() +void main() { mirrorClip(vary_position); - vec4 col = texture(diffuseMap, vary_texcoord0.xy); - - if(col.a < minimum_alpha) - { - discard; - } - col *= vertex_color; - - vec3 norm = texture(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0; + vec4 col = texture(diffuseMap, vary_texcoord0.xy); + + if(col.a < minimum_alpha) + { + discard; + } + col *= vertex_color; + + vec3 norm = texture(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0; + + vec3 tnorm = vec3(dot(norm,vary_mat0), + dot(norm,vary_mat1), + dot(norm,vary_mat2)); - vec3 tnorm = vec3(dot(norm,vary_mat0), - dot(norm,vary_mat1), - dot(norm,vary_mat2)); - - frag_data[0] = vec4(col.rgb, 0.0); - frag_data[1] = vertex_color.aaaa; // spec - //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested - vec3 nvn = normalize(tnorm); - frag_data[2] = vec4(nvn, GBUFFER_FLAG_HAS_ATMOS); + frag_data[0] = vec4(col.rgb, 0.0); + frag_data[1] = vertex_color.aaaa; // spec + //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested + vec3 nvn = normalize(tnorm); + frag_data[2] = vec4(nvn, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(vertex_color.a, 0, 0, 0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl index 74319349f6..a381392f6c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file bumpV.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$ */ @@ -48,29 +48,29 @@ uniform mat4 projection_matrix; void main() { - //transform vertex + //transform vertex #ifdef HAS_SKIN mat4 mat = getObjectSkinnedTransform(); - mat = modelview_matrix * mat; - vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz; + mat = modelview_matrix * mat; + vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz; vary_position = pos; - gl_Position = projection_matrix*vec4(pos, 1.0); + gl_Position = projection_matrix*vec4(pos, 1.0); - vec3 n = normalize((mat * vec4(normal.xyz+position.xyz, 1.0)).xyz-pos.xyz); - vec3 t = normalize((mat * vec4(tangent.xyz+position.xyz, 1.0)).xyz-pos.xyz); + vec3 n = normalize((mat * vec4(normal.xyz+position.xyz, 1.0)).xyz-pos.xyz); + vec3 t = normalize((mat * vec4(tangent.xyz+position.xyz, 1.0)).xyz-pos.xyz); #else vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); - vec3 n = normalize(normal_matrix * normal); - vec3 t = normalize(normal_matrix * tangent.xyz); + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + vec3 n = normalize(normal_matrix * normal); + vec3 t = normalize(normal_matrix * tangent.xyz); #endif - vec3 b = cross(n, t) * tangent.w; - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + vec3 b = cross(n, t) * tangent.w; + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + vary_mat0 = vec3(t.x, b.x, n.x); + vary_mat1 = vec3(t.y, b.y, n.y); + vary_mat2 = vec3(t.z, b.z, n.z); - vary_mat0 = vec3(t.x, b.x, n.x); - vary_mat1 = vec3(t.y, b.y, n.y); - vary_mat2 = vec3(t.z, b.z, n.z); - - vertex_color = diffuse_color; + vertex_color = diffuse_color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index f6696e270c..385920f622 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -1,24 +1,24 @@ -/** +/** * @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$ */ @@ -366,14 +366,14 @@ vec3 pbrIbl(vec3 diffuseColor, float perceptualRough) { // retrieve a scale and bias to F0. See [1], Figure 3 - vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRough); - vec3 diffuseLight = irradiance; - vec3 specularLight = radiance; - - vec3 diffuse = diffuseLight * diffuseColor; - vec3 specular = specularLight * (specularColor * brdf.x + brdf.y); + vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRough); + vec3 diffuseLight = irradiance; + vec3 specularLight = radiance; - return (diffuse + specular) * ao; + vec3 diffuse = diffuseLight * diffuseColor; + vec3 specular = specularLight * (specularColor * brdf.x + brdf.y); + + return (diffuse + specular) * ao; } @@ -382,18 +382,18 @@ vec3 pbrIbl(vec3 diffuseColor, // of the shading terms, outlined in the Readme.MD Appendix. struct PBRInfo { - float NdotL; // cos angle between normal and light direction - float NdotV; // cos angle between normal and view direction - float NdotH; // cos angle between normal and half vector - float LdotH; // cos angle between light direction and half vector - float VdotH; // cos angle between view direction and half vector - float perceptualRoughness; // roughness value, as authored by the model creator (input to shader) - float metalness; // metallic value at the surface - vec3 reflectance0; // full reflectance color (normal incidence angle) - vec3 reflectance90; // reflectance color at grazing angle - float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2]) - vec3 diffuseColor; // color contribution from diffuse lighting - vec3 specularColor; // color contribution from specular lighting + float NdotL; // cos angle between normal and light direction + float NdotV; // cos angle between normal and view direction + float NdotH; // cos angle between normal and half vector + float LdotH; // cos angle between light direction and half vector + float VdotH; // cos angle between view direction and half vector + float perceptualRoughness; // roughness value, as authored by the model creator (input to shader) + float metalness; // metallic value at the surface + vec3 reflectance0; // full reflectance color (normal incidence angle) + vec3 reflectance90; // reflectance color at grazing angle + float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2]) + vec3 diffuseColor; // color contribution from diffuse lighting + vec3 specularColor; // color contribution from specular lighting }; // Basic Lambertian diffuse @@ -401,14 +401,14 @@ struct PBRInfo // See also [1], Equation 1 vec3 diffuse(PBRInfo pbrInputs) { - return pbrInputs.diffuseColor / M_PI; + return pbrInputs.diffuseColor / M_PI; } // The following equation models the Fresnel reflectance term of the spec equation (aka F()) // Implementation of fresnel from [4], Equation 15 vec3 specularReflection(PBRInfo pbrInputs) { - return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0); + return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0); } // This calculates the specular geometric attenuation (aka G()), @@ -417,13 +417,13 @@ vec3 specularReflection(PBRInfo pbrInputs) // alphaRoughness as input as originally proposed in [2]. float geometricOcclusion(PBRInfo pbrInputs) { - float NdotL = pbrInputs.NdotL; - float NdotV = pbrInputs.NdotV; - float r = pbrInputs.alphaRoughness; + float NdotL = pbrInputs.NdotL; + float NdotV = pbrInputs.NdotV; + float r = pbrInputs.alphaRoughness; - float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL))); - float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV))); - return attenuationL * attenuationV; + float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL))); + float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV))); + return attenuationL * attenuationV; } // The following equation(s) model the distribution of microfacet normals across the area being drawn (aka D()) @@ -431,13 +431,13 @@ float geometricOcclusion(PBRInfo pbrInputs) // Follows the distribution function recommended in the SIGGRAPH 2013 course notes from EPIC Games [1], Equation 3. float microfacetDistribution(PBRInfo pbrInputs) { - float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness; - float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0; - return roughnessSq / (M_PI * f * f); + float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness; + float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0; + return roughnessSq / (M_PI * f * f); } -vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, - float perceptualRoughness, +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, + float perceptualRoughness, float metallic, vec3 n, // normal vec3 v, // surface point to camera @@ -445,53 +445,53 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, { // make sure specular highlights from punctual lights don't fall off of polished surfaces perceptualRoughness = max(perceptualRoughness, 8.0/255.0); - - float alphaRoughness = perceptualRoughness * perceptualRoughness; - - // Compute reflectance. - float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b); - - // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect. - // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%. - float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0); - vec3 specularEnvironmentR0 = specularColor.rgb; - vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90; - - vec3 h = normalize(l+v); // Half vector between both l and v - vec3 reflection = -normalize(reflect(v, n)); - reflection.y *= -1.0f; - - float NdotL = clamp(dot(n, l), 0.001, 1.0); - float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0); - float NdotH = clamp(dot(n, h), 0.0, 1.0); - float LdotH = clamp(dot(l, h), 0.0, 1.0); - float VdotH = clamp(dot(v, h), 0.0, 1.0); - - PBRInfo pbrInputs = PBRInfo( - NdotL, - NdotV, - NdotH, - LdotH, - VdotH, - perceptualRoughness, - metallic, - specularEnvironmentR0, - specularEnvironmentR90, - alphaRoughness, - diffuseColor, - specularColor - ); - - // Calculate the shading terms for the microfacet specular shading model - vec3 F = specularReflection(pbrInputs); - float G = geometricOcclusion(pbrInputs); - float D = microfacetDistribution(pbrInputs); - - // Calculation of analytical lighting contribution - vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs); - vec3 specContrib = F * G * D / (4.0 * NdotL * NdotV); - // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) - vec3 color = NdotL * (diffuseContrib + specContrib); + + float alphaRoughness = perceptualRoughness * perceptualRoughness; + + // Compute reflectance. + float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b); + + // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect. + // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%. + float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0); + vec3 specularEnvironmentR0 = specularColor.rgb; + vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90; + + vec3 h = normalize(l+v); // Half vector between both l and v + vec3 reflection = -normalize(reflect(v, n)); + reflection.y *= -1.0f; + + float NdotL = clamp(dot(n, l), 0.001, 1.0); + float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0); + float NdotH = clamp(dot(n, h), 0.0, 1.0); + float LdotH = clamp(dot(l, h), 0.0, 1.0); + float VdotH = clamp(dot(v, h), 0.0, 1.0); + + PBRInfo pbrInputs = PBRInfo( + NdotL, + NdotV, + NdotH, + LdotH, + VdotH, + perceptualRoughness, + metallic, + specularEnvironmentR0, + specularEnvironmentR90, + alphaRoughness, + diffuseColor, + specularColor + ); + + // Calculate the shading terms for the microfacet specular shading model + vec3 F = specularReflection(pbrInputs); + float G = geometricOcclusion(pbrInputs); + float D = microfacetDistribution(pbrInputs); + + // Calculation of analytical lighting contribution + vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs); + vec3 specContrib = F * G * D / (4.0 * NdotL * NdotV); + // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) + vec3 color = NdotL * (diffuseContrib + specContrib); return clamp(color, vec3(0), vec3(10)); } @@ -509,9 +509,9 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, vec3 color = vec3(0); float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); - + color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); - + color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir)) * sunlit * 3.0 * scol; //magic number to balance with legacy materials color += colorEmissive; diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index 82d5d363d2..1751e17814 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file diffuseAlphaMaskF.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$ */ @@ -39,21 +39,21 @@ in vec2 vary_texcoord0; void mirrorClip(vec3 pos); -void main() +void main() { mirrorClip(vary_position); - vec4 col = texture(diffuseMap, vary_texcoord0.xy) * vertex_color; - - if (col.a < minimum_alpha) - { - discard; - } - - frag_data[0] = vec4(col.rgb, 0.0); - frag_data[1] = vec4(0,0,0,0); // spec - vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + vec4 col = texture(diffuseMap, vary_texcoord0.xy) * vertex_color; + + if (col.a < minimum_alpha) + { + discard; + } + + frag_data[0] = vec4(col.rgb, 0.0); + frag_data[1] = vec4(0,0,0,0); // spec + vec3 nvn = normalize(vary_normal); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index 788ea633fc..f5b517a8ea 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file diffuseAlphaMaskIndexedF.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$ */ @@ -37,20 +37,20 @@ in vec2 vary_texcoord0; void mirrorClip(vec3 pos); -void main() +void main() { mirrorClip(vary_position); - vec4 col = diffuseLookup(vary_texcoord0.xy) * vertex_color; - - if (col.a < minimum_alpha) - { - discard; - } - - frag_data[0] = vec4(col.rgb, 0.0); - frag_data[1] = vec4(0,0,0,0); - vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + vec4 col = diffuseLookup(vary_texcoord0.xy) * vertex_color; + + if (col.a < minimum_alpha) + { + discard; + } + + frag_data[0] = vec4(col.rgb, 0.0); + frag_data[1] = vec4(0,0,0,0); + vec3 nvn = normalize(vary_normal); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index 22e6d60419..89ea0c1710 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -1,28 +1,28 @@ -/** +/** * @file diffuseAlphaMaskNoColorF.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]*/ out vec4 frag_data[4]; @@ -34,19 +34,19 @@ uniform sampler2D diffuseMap; in vec3 vary_normal; in vec2 vary_texcoord0; -void main() +void main() { - vec4 col = texture(diffuseMap, vary_texcoord0.xy); - - if (col.a < minimum_alpha) - { - discard; - } - - frag_data[0] = vec4(col.rgb, 0.0); - frag_data[1] = vec4(0,0,0,0); // spec - vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + vec4 col = texture(diffuseMap, vary_texcoord0.xy); + + if (col.a < minimum_alpha) + { + discard; + } + + frag_data[0] = vec4(col.rgb, 0.0); + frag_data[1] = vec4(0,0,0,0); // spec + vec3 nvn = normalize(vary_normal); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 799fc62a42..7f056a51e8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -1,30 +1,30 @@ -/** +/** * @file diffuseF.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ /*[EXTRA_CODE_HERE]*/ - + out vec4 frag_data[4]; uniform sampler2D diffuseMap; @@ -36,15 +36,15 @@ in vec3 vary_position; void mirrorClip(vec3 pos); -void main() +void main() { mirrorClip(vary_position); - vec3 col = vertex_color.rgb * texture(diffuseMap, vary_texcoord0.xy).rgb; - frag_data[0] = vec4(col, 0.0); - frag_data[1] = vertex_color.aaaa; // spec - //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested - vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + vec3 col = vertex_color.rgb * texture(diffuseMap, vary_texcoord0.xy).rgb; + frag_data[0] = vec4(col, 0.0); + frag_data[1] = vertex_color.aaaa; // spec + //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested + vec3 nvn = normalize(vary_normal); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(vertex_color.a, 0, 0, 0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index 3362a180c6..5c73878ba9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file diffuseIndexedF.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$ */ @@ -35,17 +35,17 @@ in vec3 vary_position; void mirrorClip(vec3 pos); vec3 linear_to_srgb(vec3 c); -void main() +void main() { mirrorClip(vary_position); - vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; + vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; - vec3 spec; - spec.rgb = vec3(vertex_color.a); + vec3 spec; + spec.rgb = vec3(vertex_color.a); - frag_data[0] = vec4(col, 0.0); - frag_data[1] = vec4(spec, vertex_color.a); // spec - vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[0] = vec4(col, 0.0); + frag_data[1] = vec4(spec, vertex_color.a); // spec + vec3 nvn = normalize(vary_normal); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(vertex_color.a, 0, 0, 0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl index 64230dc680..4bd31cef9e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file diffuseV.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$ */ @@ -59,13 +59,13 @@ void main() vary_normal = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); #else vary_position = (modelview_matrix * vec4(position.xyz, 1.0)).xyz; - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vary_normal = normalize(normal_matrix * normal); #endif - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - - passTextureIndex(); - vertex_color = diffuse_color; + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + passTextureIndex(); + + vertex_color = diffuse_color; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index c64f65e32c..99cb23839a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file impostorF.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$ */ @@ -38,20 +38,20 @@ in vec2 vary_texcoord0; vec3 linear_to_srgb(vec3 c); -void main() +void main() { - vec4 col = texture(diffuseMap, vary_texcoord0.xy); + vec4 col = texture(diffuseMap, vary_texcoord0.xy); - if (col.a < minimum_alpha) - { - discard; - } + if (col.a < minimum_alpha) + { + discard; + } - vec4 norm = texture(normalMap, vary_texcoord0.xy); - vec4 spec = texture(specularMap, vary_texcoord0.xy); + vec4 norm = texture(normalMap, vary_texcoord0.xy); + vec4 spec = texture(specularMap, vary_texcoord0.xy); - frag_data[0] = vec4(col.rgb, 0.0); - frag_data[1] = spec; - frag_data[2] = vec4(norm.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[0] = vec4(col.rgb, 0.0); + frag_data[1] = spec; + frag_data[2] = vec4(norm.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index ddf878ae60..b6528dfcf8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file materialV.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$ */ @@ -65,67 +65,67 @@ out vec3 vary_normal; in vec2 texcoord2; out vec2 vary_texcoord2; #endif - + out vec4 vertex_color; out vec2 vary_texcoord0; void main() { #ifdef HAS_SKIN - mat4 mat = getObjectSkinnedTransform(); + mat4 mat = getObjectSkinnedTransform(); - mat = modelview_matrix * mat; + mat = modelview_matrix * mat; - vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; + vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; - vary_position = pos; + vary_position = pos; - gl_Position = projection_matrix*vec4(pos,1.0); + gl_Position = projection_matrix*vec4(pos,1.0); #else - //transform vertex - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + //transform vertex + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); #endif - - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - + + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + #ifdef HAS_NORMAL_MAP - vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; + vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; #endif #ifdef HAS_SPECULAR_MAP - vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; + vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; #endif #ifdef HAS_SKIN - vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); + vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz); #ifdef HAS_NORMAL_MAP - vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz); + vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz); vary_tangent = t; vary_sign = tangent.w; vary_normal = n; #else //HAS_NORMAL_MAP - vary_normal = n; + vary_normal = n; #endif //HAS_NORMAL_MAP #else //HAS_SKIN - vec3 n = normalize(normal_matrix * normal); + vec3 n = normalize(normal_matrix * normal); #ifdef HAS_NORMAL_MAP - vec3 t = normalize(normal_matrix * tangent.xyz); + vec3 t = normalize(normal_matrix * tangent.xyz); vary_tangent = t; vary_sign = tangent.w; vary_normal = n; #else //HAS_NORMAL_MAP - vary_normal = n; + vary_normal = n; #endif //HAS_NORMAL_MAP #endif //HAS_SKIN - - vertex_color = diffuse_color; + + vertex_color = diffuse_color; #if !defined(HAS_SKIN) - vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; + vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; #endif } diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl index 5e0141910b..fd020afd57 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file pbropaqueV.glsl * * $LicenseInfo:firstyear=2022&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2022, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -54,7 +54,7 @@ out vec2 base_color_texcoord; out vec2 normal_texcoord; out vec2 metallic_roughness_texcoord; out vec2 emissive_texcoord; - + out vec4 vertex_color; out vec3 vary_tangent; @@ -68,18 +68,18 @@ vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] kh void main() { #ifdef HAS_SKIN - mat4 mat = getObjectSkinnedTransform(); + mat4 mat = getObjectSkinnedTransform(); - mat = modelview_matrix * mat; + mat = modelview_matrix * mat; - vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; + vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; vary_position = pos; - gl_Position = projection_matrix*vec4(pos,1.0); + gl_Position = projection_matrix*vec4(pos,1.0); #else vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; - //transform vertex - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + //transform vertex + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); #endif base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); @@ -88,11 +88,11 @@ void main() emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); #ifdef HAS_SKIN - vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; - vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; + vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; + vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; #else //HAS_SKIN - vec3 n = normal_matrix * normal; - vec3 t = normal_matrix * tangent.xyz; + vec3 n = normal_matrix * normal; + vec3 t = normal_matrix * tangent.xyz; #endif n = normalize(n); @@ -100,11 +100,11 @@ void main() vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0)); vary_sign = tangent.w; vary_normal = n; - - vertex_color = diffuse_color; + + vertex_color = diffuse_color; } -#else +#else // fullbright HUD implementation @@ -121,7 +121,7 @@ in vec2 texcoord0; out vec2 base_color_texcoord; out vec2 emissive_texcoord; - + out vec4 vertex_color; vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); @@ -129,7 +129,7 @@ vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl void main() { //transform vertex - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0); emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index 489fc26e3f..4efb9a1f53 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file class1\environment\pbrterrainV.glsl * * $LicenseInfo:firstyear=2023&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2023, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -56,12 +56,12 @@ vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] kh void main() { //transform vertex - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; - vec3 n = normal_matrix * normal; + vec3 n = normal_matrix * normal; vary_vertex_normal = normal; - vec3 t = normal_matrix * tangent.xyz; + vec3 t = normal_matrix * tangent.xyz; vary_tangent = normalize(t); // *TODO: Decide if we want this. It may be better to just calculate the @@ -88,7 +88,7 @@ void main() #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 vary_texcoord0.xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0); #endif - + vec4 tc = vec4(texcoord1,0,1); vary_texcoord0.zw = tc.xy; vary_texcoord1.xy = tc.xy-vec2(2.0, 0.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 1629ed91c8..a0eb6cfbb8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -1,28 +1,28 @@ -/** +/** * @file postDeferredGammaCorrect.glsl * * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2007, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - + /*[EXTRA_CODE_HERE]*/ out vec4 frag_color; @@ -79,7 +79,7 @@ vec3 RRTAndODTFit(vec3 color) } -// tone mapping +// tone mapping vec3 toneMapACES_Hill(vec3 color) { color = ACESInputMat * color; @@ -103,7 +103,7 @@ vec3 toneMap(vec3 color) { #ifndef NO_POST float exp_scale = texture(exposureMap, vec2(0.5,0.5)).r; - + color *= exposure * exp_scale; // mix ACES and Linear here as a compromise to avoid over-darkening legacy content @@ -117,38 +117,38 @@ vec3 toneMap(vec3 color) //================================= // borrowed noise from: -// -// By Morgan McGuire @morgan3d, http://graphicscodex.com +// +// By Morgan McGuire @morgan3d, http://graphicscodex.com // float hash(float n) { return fract(sin(n) * 1e4); } float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); } float noise(float x) { - float i = floor(x); - float f = fract(x); - float u = f * f * (3.0 - 2.0 * f); - return mix(hash(i), hash(i + 1.0), u); + float i = floor(x); + float f = fract(x); + float u = f * f * (3.0 - 2.0 * f); + return mix(hash(i), hash(i + 1.0), u); } float noise(vec2 x) { - vec2 i = floor(x); - vec2 f = fract(x); - - // Four corners in 2D of a tile - float a = hash(i); - float b = hash(i + vec2(1.0, 0.0)); - float c = hash(i + vec2(0.0, 1.0)); - float d = hash(i + vec2(1.0, 1.0)); - - // Simple 2D lerp using smoothstep envelope between the values. - // return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)), - // mix(c, d, smoothstep(0.0, 1.0, f.x)), - // smoothstep(0.0, 1.0, f.y))); - - // Same code, with the clamps in smoothstep and common subexpressions - // optimized away. - vec2 u = f * f * (3.0 - 2.0 * f); - return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; + vec2 i = floor(x); + vec2 f = fract(x); + + // Four corners in 2D of a tile + float a = hash(i); + float b = hash(i + vec2(1.0, 0.0)); + float c = hash(i + vec2(0.0, 1.0)); + float d = hash(i + vec2(1.0, 1.0)); + + // Simple 2D lerp using smoothstep envelope between the values. + // return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)), + // mix(c, d, smoothstep(0.0, 1.0, f.x)), + // smoothstep(0.0, 1.0, f.y))); + + // Same code, with the clamps in smoothstep and common subexpressions + // optimized away. + vec2 u = f * f * (3.0 - 2.0 * f); + return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; } //============================= @@ -171,7 +171,7 @@ vec3 legacyGamma(vec3 color) return c; } -void main() +void main() { //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) vec4 diff = texture(diffuseRect, vary_fragcoord); diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index 708acd0194..05922ecb1a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -1,24 +1,24 @@ -/** +/** * @file treeF.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$ */ @@ -37,18 +37,18 @@ in vec3 vary_position; uniform float minimum_alpha; void mirrorClip(vec3 pos); -void main() +void main() { mirrorClip(vary_position); - vec4 col = texture(diffuseMap, vary_texcoord0.xy); - if (col.a < minimum_alpha) - { - discard; - } + vec4 col = texture(diffuseMap, vary_texcoord0.xy); + if (col.a < minimum_alpha) + { + discard; + } - frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0); - frag_data[1] = vec4(0,0,0,0); - vec3 nvn = normalize(vary_normal); - frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); + frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0); + frag_data[1] = vec4(0,0,0,0); + vec3 nvn = normalize(vary_normal); + frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS); frag_data[3] = vec4(0); } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl index c84fccd4c6..ef5602f1e5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl @@ -1,24 +1,24 @@ -/** +/** * @file treeV.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$ */ @@ -39,13 +39,13 @@ out vec3 vary_position; void main() { - //transform vertex - gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); + //transform vertex + gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - - vary_normal = normalize(normal_matrix * normal); + vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; + + vary_normal = normalize(normal_matrix * normal); - vertex_color = vec4(1,1,1,1); + vertex_color = vec4(1,1,1,1); } -- cgit v1.2.3 From ae6a402b7a26aa4ec3258b3e0b68919602e03d23 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Wed, 15 May 2024 09:55:55 -0700 Subject: secondlife/viewer#1474: Remove small texture offset from PBR terrain --- .../shaders/class1/deferred/pbrterrainV.glsl | 14 ++++----- .../shaders/class1/deferred/textureUtilV.glsl | 35 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl index 489fc26e3f..d7c8fe1861 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl @@ -50,8 +50,8 @@ out vec3 vary_position; // tangent_space_transform below. uniform vec4[2] texture_base_color_transform; -vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); -vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform); +vec3 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform); void main() { @@ -70,7 +70,7 @@ void main() // *HACK: Should be using texture_normal_transform here. The KHR texture // transform spec requires handling texture transforms separately for each // individual texture. - vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_base_color_transform, texture_matrix0)); + vary_tangent = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, texture_base_color_transform)); vary_sign = tangent.w; vary_normal = normalize(n); @@ -80,13 +80,13 @@ void main() // separately for each individual texture. #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3 // xy - vary_coords[0].xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0); + vary_coords[0].xy = terrain_texture_transform(position.xy, texture_base_color_transform); // yz - vary_coords[0].zw = texture_transform(position.yz, texture_base_color_transform, texture_matrix0); + vary_coords[0].zw = terrain_texture_transform(position.yz, texture_base_color_transform); // (-x)z - vary_coords[1].xy = texture_transform(position.xz * vec2(-1, 1), texture_base_color_transform, texture_matrix0); + vary_coords[1].xy = terrain_texture_transform(position.xz * vec2(-1, 1), texture_base_color_transform); #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1 - vary_texcoord0.xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0); + vary_texcoord0.xy = terrain_texture_transform(position.xy, texture_base_color_transform); #endif vec4 tc = vec4(texcoord1,0,1); diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl index 732333311c..7c02cb9d4a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -77,6 +77,19 @@ vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl return texcoord; } +// Similar to texture_transform but no offset during coordinate system +// conversion, and no texture animation support. +vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform) +{ + vec2 texcoord = vertex_texcoord; + + texcoord.y = -texcoord.y; + texcoord = khr_texture_transform(texcoord, khr_gltf_transform[0].xy, khr_gltf_transform[0].z, khr_gltf_transform[1].xy); + texcoord.y = -texcoord.y; + + return texcoord; +} + // Take the rotation only from both transforms and apply to the tangent. This // accounts for the change of the topology of the normal texture when a texture // rotation is applied to it. @@ -120,3 +133,25 @@ vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] kh return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz); } + +// Similar to tangent_space_transform but no no texture animation support. +vec3 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform) +{ + // Immediately convert to left-handed coordinate system ((0,1) -> (0, -1)) + vec2 weights = vec2(0, -1); + + // Apply KHR_texture_transform (rotation only) + float khr_rotation = khr_gltf_transform[0].z; + mat2 khr_rotation_mat = mat2( + cos(khr_rotation),-sin(khr_rotation), + sin(khr_rotation), cos(khr_rotation) + ); + weights = khr_rotation_mat * weights; + + // Convert back to right-handed coordinate system + weights.y = -weights.y; + + vec3 vertex_binormal = vertex_tangent.w * cross(vertex_normal, vertex_tangent.xyz); + + return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz); +} -- cgit v1.2.3 From 29be88d60d654193926add496d2d851f7c217356 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 15 May 2024 15:40:55 -0500 Subject: #1267 Fix for alpha cutoff of zero and base color factor alpha of zero making objects disappear (#1485) --- .../app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl | 2 +- .../newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl index 1d1545be7e..35b7602569 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl @@ -35,7 +35,7 @@ uniform float minimum_alpha; void main() { - float alpha = texture(diffuseMap,vary_texcoord0.xy).a; + float alpha = texture(diffuseMap,vary_texcoord0.xy).a * vertex_color.a; if (alpha < minimum_alpha) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index 1d5f810cf3..380d493636 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -69,12 +69,16 @@ void main() mirrorClip(vary_position); vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba; + basecolor.rgb = srgb_to_linear(basecolor.rgb); + + basecolor *= vertex_color; + if (basecolor.a < minimum_alpha) { discard; } - vec3 col = vertex_color.rgb * srgb_to_linear(basecolor.rgb); + vec3 col = basecolor.rgb; // from mikktspace.com vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; @@ -108,7 +112,7 @@ void main() //emissive = tnorm*0.5+0.5; // See: C++: addDeferredAttachments(), GLSL: softenLightF frag_data[0] = max(vec4(col, 0.0), vec4(0)); // Diffuse - frag_data[1] = max(vec4(spec.rgb,vertex_color.a), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. + frag_data[1] = max(vec4(spec.rgb,0.0), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. frag_data[2] = vec4(tnorm, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive } -- cgit v1.2.3 From 5f3a6bdd7f122688aff5c0e63f03928fa15bb0c9 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Tue, 28 May 2024 13:25:02 -0700 Subject: secondlife/viewer#1531: Attempt to fix PBR terrain fragment shader. --- .../shaders/class1/deferred/pbrterrainF.glsl | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl index de4745c1c4..0de2d348c3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl @@ -180,7 +180,7 @@ void main() rm_factors[3] = vec2(roughnessFactors.w, metallicFactors.w); #endif - PBRMix mix = init_pbr_mix(); + PBRMix pbr_mix = init_pbr_mix(); PBRMix mix2; switch (tm.type & MIX_X) { @@ -207,7 +207,7 @@ void main() , emissiveColors[0] #endif ); - mix = mix_pbr(mix, mix2, tm.weight.x); + pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.x); break; default: break; @@ -237,7 +237,7 @@ void main() , emissiveColors[1] #endif ); - mix = mix_pbr(mix, mix2, tm.weight.y); + pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.y); break; default: break; @@ -267,7 +267,7 @@ void main() , emissiveColors[2] #endif ); - mix = mix_pbr(mix, mix2, tm.weight.z); + pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.z); break; default: break; @@ -297,14 +297,14 @@ void main() , emissiveColors[3] #endif ); - mix = mix_pbr(mix, mix2, tm.weight.w); + pbr_mix = mix_pbr(pbr_mix, mix2, tm.weight.w); break; default: break; } float minimum_alpha = terrain_mix(tm, minimum_alphas); - if (mix.col.a < minimum_alpha) + if (pbr_mix.col.a < minimum_alpha) { discard; } @@ -312,7 +312,7 @@ void main() #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_NORMAL) // from mikktspace.com - vec3 vNt = mix.vNt; + vec3 vNt = pbr_mix.vNt; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; @@ -327,21 +327,21 @@ void main() #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_EMISSIVE) -#define emissive mix.emissive +#define mix_emissive pbr_mix.emissive #else -#define emissive vec3(0) +#define mix_emissive vec3(0) #endif #if (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_OCCLUSION) -#define orm mix.orm +#define mix_orm pbr_mix.orm #elif (TERRAIN_PBR_DETAIL >= TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS) -#define orm vec3(1.0, mix.rm) +#define mix_orm vec3(1.0, pbr_mix.rm) #else // Matte plastic potato terrain -#define orm vec3(1.0, 1.0, 0.0) +#define mix_orm vec3(1.0, 1.0, 0.0) #endif - frag_data[0] = max(vec4(mix.col.xyz, 0.0), vec4(0)); // Diffuse - frag_data[1] = max(vec4(orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. + frag_data[0] = max(vec4(pbr_mix.col.xyz, 0.0), vec4(0)); // Diffuse + frag_data[1] = max(vec4(mix_orm.rgb, base_color_factor_alpha), vec4(0)); // PBR linear packed Occlusion, Roughness, Metal. frag_data[2] = vec4(tnorm, GBUFFER_FLAG_HAS_PBR); // normal, flags - frag_data[3] = max(vec4(emissive,0), vec4(0)); // PBR sRGB Emissive + frag_data[3] = max(vec4(mix_emissive,0), vec4(0)); // PBR sRGB Emissive } -- cgit v1.2.3 From 83f9885d73a7ffb3c87ae29bcad6b01d0530eeb4 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Tue, 4 Jun 2024 10:26:34 -0500 Subject: #1614 Fix for moire pattern in specular highlights. Incidental cleanup. --- .../app_settings/shaders/class1/deferred/deferredUtil.glsl | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 385920f622..01543732d0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -142,18 +142,9 @@ vec2 getScreenCoordinate(vec2 screenpos) } vec4 getNorm(vec2 screenpos) -{ - return texture(normalMap, screenpos.xy); -} - -// return packedNormalEnvIntensityFlags since GBUFFER_FLAG_HAS_PBR needs .w -// See: C++: addDeferredAttachments(), GLSL: softenLightF -vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity) { vec4 norm = texture(normalMap, screenpos.xy); - n = norm.xyz; - envIntensity = texture(emissiveRect, screenpos.xy).r; - + norm.xyz = normalize(norm.xyz); return norm; } -- cgit v1.2.3 From 9f97ff7286aceef5be4e7589ca4af911edf30f12 Mon Sep 17 00:00:00 2001 From: Brad Linden <46733234+brad-linden@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:09:03 -0700 Subject: #989 Fix for blurry terrain on Mac (#1633) Co-authored-by: Dave Parks --- indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl index 8e1e4b54d5..b4ab7cd169 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainV.glsl @@ -47,7 +47,9 @@ vec2 texgen_object(vec4 vpos, mat4 mat, vec4 tp0, vec4 tp1) tcoord.x = dot(vpos, tp0); tcoord.y = dot(vpos, tp1); - + tcoord.z = 0; + tcoord.w = 1; + tcoord = mat * tcoord; return tcoord.xy; -- cgit v1.2.3