summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2024-06-11 17:10:13 -0500
committerGitHub <noreply@github.com>2024-06-11 17:10:13 -0500
commitf40fbdf4ad27a547e30781cd44cd6847d68d3300 (patch)
treeb26dd135413752a90037bd48ad2217c4dea027ef /indra/newview/app_settings/shaders/class1
parent429c92ad75fd3b3f7b9dfc52ed034b25004a3b9c (diff)
#1718 Add GLTF support for multiple texcoords (#1720)
* Fix for GLTF MeshPrimitiveModes test
Diffstat (limited to 'indra/newview/app_settings/shaders/class1')
-rw-r--r--indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl20
-rw-r--r--indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl92
2 files changed, 89 insertions, 23 deletions
diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl
index 99bfcf70fa..789c00259b 100644
--- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl
+++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl
@@ -37,8 +37,8 @@ uniform sampler2D emissiveMap;
uniform vec3 emissiveColor;
in vec3 vary_position;
in vec4 vertex_color;
-in vec2 base_color_texcoord;
-in vec2 emissive_texcoord;
+in vec2 base_color_uv;
+in vec2 emissive_uv;
uniform float minimum_alpha;
void mirrorClip(vec3 pos);
@@ -59,9 +59,9 @@ uniform float roughnessFactor;
in vec3 vary_normal;
in vec3 vary_tangent;
flat in float vary_sign;
-in vec2 normal_texcoord;
-in vec2 metallic_roughness_texcoord;
-in vec2 occlusion_texcoord;
+in vec2 normal_uv;
+in vec2 metallic_roughness_uv;
+in vec2 occlusion_uv;
#endif
// ==================================
@@ -165,7 +165,7 @@ void main()
vec3 pos = vary_position;
mirrorClip(pos);
- vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba;
+ vec4 basecolor = texture(diffuseMap, base_color_uv.xy).rgba;
basecolor.rgb = srgb_to_linear(basecolor.rgb);
basecolor *= vertex_color;
@@ -175,7 +175,7 @@ void main()
}
vec3 emissive = emissiveColor;
- emissive *= srgb_to_linear(texture(emissiveMap, emissive_texcoord.xy).rgb);
+ emissive *= srgb_to_linear(texture(emissiveMap, emissive_uv.xy).rgb);
// ==================================
// ==================================
@@ -185,7 +185,7 @@ void main()
// ==================================
#ifndef UNLIT
// from mikktspace.com
- vec3 vNt = texture(normalMap, normal_texcoord.xy).xyz*2.0-1.0;
+ vec3 vNt = texture(normalMap, normal_uv.xy).xyz*2.0-1.0;
float sign = vary_sign;
vec3 vN = vary_normal;
vec3 vT = vary_tangent.xyz;
@@ -199,8 +199,8 @@ void main()
// occlusion 1.0
// roughness 0.0
// metal 0.0
- vec3 orm = texture(metallicRoughnessMap, metallic_roughness_texcoord.xy).rgb;
- orm.r = texture(occlusionMap, occlusion_texcoord.xy).r;
+ vec3 orm = texture(metallicRoughnessMap, metallic_roughness_uv.xy).rgb;
+ orm.r = texture(occlusionMap, occlusion_uv.xy).r;
orm.g *= roughnessFactor;
orm.b *= metallicFactor;
#endif
diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl
index bc9a47d41e..aac3dc917f 100644
--- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl
+++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl
@@ -33,7 +33,6 @@ uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
uniform mat4 modelview_projection_matrix;
#endif
-uniform mat4 texture_matrix0;
uniform vec4[2] texture_base_color_transform;
uniform vec4[2] texture_normal_transform;
@@ -44,21 +43,31 @@ uniform vec4[2] texture_occlusion_transform;
in vec3 position;
in vec4 diffuse_color;
in vec2 texcoord0;
-out vec2 base_color_texcoord;
-out vec2 emissive_texcoord;
+out vec2 base_color_uv;
+out vec2 emissive_uv;
out vec4 vertex_color;
out vec3 vary_position;
#ifndef UNLIT
in vec3 normal;
in vec4 tangent;
-out vec2 normal_texcoord;
-out vec2 metallic_roughness_texcoord;
-out vec2 occlusion_texcoord;
+out vec2 normal_uv;
+out vec2 metallic_roughness_uv;
+out vec2 occlusion_uv;
out vec3 vary_tangent;
flat out float vary_sign;
out vec3 vary_normal;
-vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
+#endif
+
+#ifdef MULTI_UV
+in vec2 texcoord1;
+uniform int base_color_texcoord;
+uniform int emissive_texcoord;
+#ifndef UNLIT
+uniform int normal_texcoord;
+uniform int metallic_roughness_texcoord;
+uniform int occlusion_texcoord;
+#endif
#endif
vec2 gltf_texture_transform(vec2 texcoord, vec4[2] p)
@@ -86,6 +95,36 @@ vec2 gltf_texture_transform(vec2 texcoord, vec4[2] p)
return uvTransformed;
}
+#ifndef UNLIT
+vec3 gltf_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform)
+{ //derived from tangent_space_transform in textureUtilV.glsl
+ vec2 weights = vec2(0, 1);
+
+ // 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);
+
+ return vertex_tangent.xyz;
+}
+#endif
+
+
#ifdef ALPHA_BLEND
out vec3 vary_fragcoord;
@@ -161,13 +200,40 @@ void main()
gl_Position = vert;
#endif
- base_color_texcoord = gltf_texture_transform(texcoord0, texture_base_color_transform);
- emissive_texcoord = gltf_texture_transform(texcoord0, texture_emissive_transform);
+ vec2 bcuv;
+ vec2 emuv;
+
+#ifdef MULTI_UV
+ vec2 uv[2];
+ uv[0] = texcoord0;
+ uv[1] = texcoord1;
+
+ bcuv = uv[base_color_texcoord];
+ emuv = uv[emissive_texcoord];
+#else
+ bcuv = texcoord0;
+ emuv = texcoord0;
+#endif
+
+ base_color_uv = gltf_texture_transform(bcuv, texture_base_color_transform);
+ emissive_uv = gltf_texture_transform(emuv, texture_emissive_transform);
#ifndef UNLIT
- normal_texcoord = gltf_texture_transform(texcoord0, texture_normal_transform);
- metallic_roughness_texcoord = gltf_texture_transform(texcoord0, texture_metallic_roughness_transform);
- occlusion_texcoord = gltf_texture_transform(texcoord0, texture_occlusion_transform);
+ vec2 normuv;
+ vec2 rmuv;
+ vec2 ouv;
+#ifdef MULTI_UV
+ normuv = uv[normal_texcoord];
+ rmuv = uv[metallic_roughness_texcoord];
+ ouv = uv[occlusion_texcoord];
+#else
+ normuv = texcoord0;
+ rmuv = texcoord0;
+ ouv = texcoord0;
+#endif
+ normal_uv = gltf_texture_transform(normuv, texture_normal_transform);
+ metallic_roughness_uv = gltf_texture_transform(rmuv, texture_metallic_roughness_transform);
+ occlusion_uv = gltf_texture_transform(ouv, texture_occlusion_transform);
#endif
#ifndef UNLIT
@@ -180,7 +246,7 @@ void main()
#endif
n = normalize(n);
- vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0));
+ vary_tangent = normalize(gltf_tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform));
vary_sign = tangent.w;
vary_normal = n;
#endif