summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorRunitaiLinden <davep@lindenlab.com>2023-06-12 10:10:40 -0500
committerRunitaiLinden <davep@lindenlab.com>2023-06-12 10:10:40 -0500
commitcc9d05545250c989d8b22fd63985a5837162a7c1 (patch)
tree61b1ff8c4b10eb3c85d4c959bae8417dc044f32d /indra
parentc96a00f12f868b9260f517a6a8552bce0b564099 (diff)
parent1ebfc1876ec3383067a2399218037a33601b04d5 (diff)
Merge branch 'DRTVWR-559' of github.com:secondlife/viewer into DRTVWR-559
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl7
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl9
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl44
3 files changed, 54 insertions, 6 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl
index e9515a9187..6b960fae33 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()
@@ -102,9 +103,11 @@ void main()
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 e2c23ac8f0..160ae7a215 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()
{
@@ -91,9 +92,11 @@ void main()
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;
}
@@ -107,8 +110,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);
+}