From c12712aa9609325ba3247a67354e91e9342106d6 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 25 May 2023 13:09:03 -0500 Subject: DRTVWR-559 Fix for off-color fullbright alpha blinn-phong materials. Scrub some NaNs. --- indra/newview/app_settings/shaders/class1/deferred/luminanceF.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/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index ee425f97fc..c8afacf9bb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -47,6 +47,6 @@ void main() tc.y -= 0.1; // HACK - nudge exposure sample down a little bit to favor ground over sky vec3 c = texture(diffuseRect, tc).rgb + texture(emissiveRect, tc).rgb; float L = lum(c); - frag_color = vec4(L); + frag_color = vec4(max(L, 0.0)); } -- cgit v1.2.3 From 50ec54831de88926ca13c9a72d89006ceda6c355 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Jun 2023 19:49:23 -0500 Subject: DRTVWR-559 Revert skies to be very close to release and disable tone mapping when probe ambiance is zero. Hack for desaturating legacy materials has been removed for performance and quality reasons. Adds a new setting for auto adjusting legacy skies. This is the PBR "opt out" button. If disabled, legacy skies will disable tonemapping, automatic probe ambiance, and HDR/exposure. If enabled, legacy skies will behave as if probe ambiance and HDR scale are 1.0, and ambient will be cut in half. HDR scale will act as a sky brightener, but will automatically adjust dynamic exposure so the sky will be properly exposed. If you want relatively even exposure all the time, set HDR Scale to 1.0. If you want a high range of exposures between indoor/dark areas and outdoor/bright areas, increase HDR Scale. Also tuned up SSAO (thanks Rye!). Reviewed with Brad. --- .../shaders/class1/deferred/fullbrightF.glsl | 4 ++-- .../class1/deferred/postDeferredGammaCorrect.glsl | 20 +++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 385cd51969..b752307d13 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -44,7 +44,7 @@ vec3 legacy_adjust_fullbright(vec3 c); vec3 legacy_adjust(vec3 c); vec3 linear_to_srgb(vec3 cl); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); +void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); #ifdef HAS_ALPHA_MASK uniform float minimum_alpha; @@ -85,7 +85,7 @@ void main() vec3 amblit; vec3 additive; vec3 atten; - calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); + calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten); #endif #ifdef WATER_FOG diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index a32296369c..53e4f02314 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -102,16 +102,12 @@ vec3 toneMap(vec3 color) { #ifndef NO_POST float exp_scale = texture(exposureMap, vec2(0.5,0.5)).r; - + color *= exposure * exp_scale; color = toneMapACES_Hill(color); -#else - color *= 0.6; #endif - color = linear_to_srgb(color); - return color; } @@ -158,10 +154,10 @@ float noise(vec2 x) { vec3 legacyGamma(vec3 color) { - color = 1. - clamp(color, vec3(0.), vec3(1.)); - color = 1. - pow(color, vec3(gamma)); // s/b inverted already CPU-side + vec3 c = 1. - clamp(color, vec3(0.), vec3(1.)); + c = 1. - pow(c, vec3(gamma)); // s/b inverted already CPU-side - return color; + return c; } void main() @@ -169,12 +165,14 @@ void main() //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) vec4 diff = texture(diffuseRect, vary_fragcoord); - diff.rgb = toneMap(diff.rgb); - #ifdef LEGACY_GAMMA -#ifndef NO_POST + diff.rgb = linear_to_srgb(diff.rgb); diff.rgb = legacyGamma(diff.rgb); +#else +#ifndef NO_POST + diff.rgb = toneMap(diff.rgb); #endif + diff.rgb = linear_to_srgb(diff.rgb); #endif vec2 tc = vary_fragcoord.xy*screen_res*4.0; -- cgit v1.2.3 From b0540f8189d28da66c143c5de961deaba7a86f17 Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 1 Jun 2023 20:15:35 -0500 Subject: DRTVWR-559 Rebalance PBR against Blinn-Phong. --- indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 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 55e45ce0af..c8eaba6418 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -387,7 +387,7 @@ vec3 pbrIbl(vec3 diffuseColor, { // retrieve a scale and bias to F0. See [1], Figure 3 vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRough); - vec3 diffuseLight = irradiance*1.25; //magic 1.25 to balance with legacy materials + vec3 diffuseLight = irradiance; vec3 specularLight = radiance; vec3 diffuse = diffuseLight * diffuseColor; @@ -563,7 +563,7 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, vec3 ibl_spec; color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness, ibl_spec); - color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir), specContrib) * sunlit * 3.9 * scol; //magic number to balance with legacy materials + color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir), specContrib) * sunlit * 3.0 * scol; //magic number to balance with legacy materials specContrib *= sunlit * 2.75 * scol; specContrib += ibl_spec; -- cgit v1.2.3 From bfdfa8dd93aa29f46060061f308121b23645f5ae Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 2 Jun 2023 11:29:07 -0700 Subject: SL-19808: Fix orientation of PBR normal texture when texture transform and/or texture animation is applied --- .../shaders/class1/deferred/pbralphaV.glsl | 6 ++- .../shaders/class1/deferred/pbropaqueV.glsl | 8 ++-- .../shaders/class1/deferred/textureUtilV.glsl | 44 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl index e9515a9187..81482e2954 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl @@ -71,6 +71,7 @@ flat out float vary_sign; out vec3 vary_normal; vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); void main() @@ -94,12 +95,13 @@ void main() metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + vec3 tex_tangent = tangent_space_transform(tangent, normal.xyz, texture_normal_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 t = (mat*vec4(tex_tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; #else //HAS_SKIN vec3 n = normal_matrix * normal; - vec3 t = normal_matrix * tangent.xyz; + vec3 t = normal_matrix * tex_tangent.xyz; #endif //HAS_SKIN vary_tangent = normalize(t); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl index e2c23ac8f0..2ad2a015fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -61,6 +61,7 @@ flat out float vary_sign; out vec3 vary_normal; vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); +vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform); void main() { @@ -83,12 +84,13 @@ void main() metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); + vec3 tex_tangent = tangent_space_transform(tangent, normal.xyz, texture_normal_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 t = (mat*vec4(tex_tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; #else //HAS_SKIN vec3 n = normal_matrix * normal; - vec3 t = normal_matrix * tangent.xyz; + vec3 t = normal_matrix * tex_tangent.xyz; #endif vary_tangent = normalize(t); @@ -107,8 +109,6 @@ uniform mat4 modelview_projection_matrix; uniform mat4 texture_matrix0; uniform vec4[2] texture_base_color_transform; -uniform vec4[2] texture_normal_transform; -uniform vec4[2] texture_metallic_roughness_transform; uniform vec4[2] texture_emissive_transform; in vec3 position; diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl index 71f7ec52c4..636dfed4ba 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl @@ -76,3 +76,47 @@ vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl return texcoord; } + +// Take the rotation only from both transforms and apply to the tangent. This +// accounts for the change of the topology of the normal texture when a texture +// rotation is applied to it. +// *HACK: Assume the imported GLTF model did not have both normal texture +// transforms and tangent vertices. The use of this function is inconsistent +// with the GLTF sample viewer when that is the case. See getNormalInfo in +// https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Viewer/47a191931461a6f2e14de48d6da0f0eb6ec2d147/source/Renderer/shaders/material_info.glsl +// We may want to account for this case during GLTF model import. +// -Cosmic,2023-06-06 +vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform) +{ + vec2 weights = vec2(0, 1); + + // Apply texture animation first to avoid shearing and other artifacts (rotation only) + mat2 sl_rot_scale; + sl_rot_scale[0][0] = sl_animation_transform[0][0]; + sl_rot_scale[0][1] = sl_animation_transform[0][1]; + sl_rot_scale[1][0] = sl_animation_transform[1][0]; + sl_rot_scale[1][1] = sl_animation_transform[1][1]; + weights = sl_rot_scale * weights; + // Remove scale + weights = normalize(weights); + + // Convert to left-handed coordinate system + weights.y = -weights.y; + + // Apply KHR_texture_transform (rotation only) + float khr_rotation = khr_gltf_transform[0].z; + mat2 khr_rotation_mat = mat2( + cos(khr_rotation),-sin(khr_rotation), + sin(khr_rotation), cos(khr_rotation) + ); + weights = khr_rotation_mat * weights; + + // Convert back to right-handed coordinate system + weights.y = -weights.y; + + // Similar to the MikkTSpace-compatible method of extracting the binormal + // from the normal and tangent, as seen in the fragment shader + vec3 vertex_binormal = vertex_tangent.w * cross(vertex_normal, vertex_tangent.xyz); + + return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz); +} -- cgit v1.2.3 From 3c34ad044cb5cef858d9b0d1708417d4f3dba086 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Wed, 7 Jun 2023 15:05:07 -0700 Subject: SL-19808: Move tangent_space_transform calculation to the very end --- .../app_settings/shaders/class1/deferred/pbralphaV.glsl | 11 ++++++----- .../app_settings/shaders/class1/deferred/pbropaqueV.glsl | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl index 81482e2954..6b960fae33 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl @@ -95,18 +95,19 @@ void main() metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); - vec3 tex_tangent = tangent_space_transform(tangent, normal.xyz, texture_normal_transform, texture_matrix0); #ifdef HAS_SKIN vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; - vec3 t = (mat*vec4(tex_tangent.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 * tex_tangent.xyz; + vec3 t = normal_matrix * tangent.xyz; #endif //HAS_SKIN - vary_tangent = normalize(t); + n = normalize(n); + + vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0)); vary_sign = tangent.w; - vary_normal = normalize(n); + vary_normal = n; vertex_color = diffuse_color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl index 2ad2a015fc..160ae7a215 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -84,18 +84,19 @@ void main() metallic_roughness_texcoord = texture_transform(texcoord0, texture_metallic_roughness_transform, texture_matrix0); emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0); - vec3 tex_tangent = tangent_space_transform(tangent, normal.xyz, texture_normal_transform, texture_matrix0); #ifdef HAS_SKIN vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; - vec3 t = (mat*vec4(tex_tangent.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 * tex_tangent.xyz; + vec3 t = normal_matrix * tangent.xyz; #endif - vary_tangent = normalize(t); + n = normalize(n); + + vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0)); vary_sign = tangent.w; - vary_normal = normalize(n); + vary_normal = n; vertex_color = diffuse_color; } -- cgit v1.2.3