summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders
diff options
context:
space:
mode:
authorDave Parks <davep@lindenlab.com>2024-06-21 13:13:08 -0500
committerGitHub <noreply@github.com>2024-06-21 13:13:08 -0500
commit80ea30af1a8b38360f71c29cc45872c4399dab0d (patch)
treedb07a706a4c896b11b8abca8a7d8815797a8d0be /indra/newview/app_settings/shaders
parent9fb9e8f33cb33a1535f43b4be030009c192ea92b (diff)
#1769 gltf optimization pass (#1816)
#1814 and #1517 Fix mirror update rate and occlusion culling
Diffstat (limited to 'indra/newview/app_settings/shaders')
-rw-r--r--indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl34
-rw-r--r--indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl162
2 files changed, 144 insertions, 52 deletions
diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl
index 789c00259b..ac4ff50552 100644
--- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl
+++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessF.glsl
@@ -28,18 +28,40 @@
// GLTF pbrMetallicRoughness implementation
+uniform int gltf_material_id;
+
+vec3 emissiveColor = vec3(0,0,0);
+float metallicFactor = 1.0;
+float roughnessFactor = 1.0;
+float minimum_alpha = -1.0;
+
+layout (std140) uniform GLTFMaterials
+{
+ // see pbrmetallicroughnessV.glsl for packing
+ vec4 gltf_material_data[MAX_UBO_VEC4S];
+};
+
+void unpackMaterial()
+{
+ if (gltf_material_id > -1)
+ {
+ int idx = gltf_material_id*12;
+ emissiveColor = gltf_material_data[idx+10].rgb;
+ roughnessFactor = gltf_material_data[idx+11].g;
+ metallicFactor = gltf_material_data[idx+11].b;
+ minimum_alpha -= gltf_material_data[idx+11].a;
+ }
+}
// ==================================
// needed by all variants
// ==================================
uniform sampler2D diffuseMap; //always in sRGB space
uniform sampler2D emissiveMap;
-uniform vec3 emissiveColor;
in vec3 vary_position;
in vec4 vertex_color;
in vec2 base_color_uv;
in vec2 emissive_uv;
-uniform float minimum_alpha;
void mirrorClip(vec3 pos);
vec3 linear_to_srgb(vec3 c);
@@ -54,8 +76,6 @@ vec3 srgb_to_linear(vec3 c);
uniform sampler2D normalMap;
uniform sampler2D metallicRoughnessMap;
uniform sampler2D occlusionMap;
-uniform float metallicFactor;
-uniform float roughnessFactor;
in vec3 vary_normal;
in vec3 vary_tangent;
flat in float vary_sign;
@@ -154,7 +174,7 @@ out vec4 frag_data[4];
void main()
{
-
+ unpackMaterial();
// ==================================
// all variants
// mirror clip
@@ -165,6 +185,10 @@ void main()
vec3 pos = vary_position;
mirrorClip(pos);
+#ifdef ALPHA_BLEND
+ //waterClip(pos);
+#endif
+
vec4 basecolor = texture(diffuseMap, base_color_uv.xy).rgba;
basecolor.rgb = srgb_to_linear(basecolor.rgb);
basecolor *= vertex_color;
diff --git a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl
index aac3dc917f..6a628bc852 100644
--- a/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl
+++ b/indra/newview/app_settings/shaders/class1/gltf/pbrmetallicroughnessV.glsl
@@ -26,19 +26,95 @@
// GLTF pbrMetallicRoughness implementation
uniform mat4 modelview_matrix;
-
-#ifdef HAS_SKIN
uniform mat4 projection_matrix;
-#else
-uniform mat3 normal_matrix;
-uniform mat4 modelview_projection_matrix;
+
+#ifdef MULTI_UV
+in vec2 texcoord1;
+int base_color_texcoord = 0;
+int emissive_texcoord = 0;
+#ifndef UNLIT
+int normal_texcoord = 0;
+int metallic_roughness_texcoord = 0;
+int occlusion_texcoord = 0;
+#endif
+#endif
+
+uniform int gltf_material_id;
+
+layout (std140) uniform GLTFMaterials
+{
+ // index by gltf_material_id*12
+
+ // [gltf_material_id + [0-1]] - base color transform
+ // [gltf_material_id + [2-3]] - normal transform
+ // [gltf_material_id + [4-5]] - metallic roughness transform
+ // [gltf_material_id + [6-7]] - emissive transform
+ // [gltf_material_id + [8-9]] - occlusion transform
+ // [gltf_material_id + 10] - emissive factor
+ // [gltf_material_id + 11] - .r unused, .g roughness, .b metalness, .a minimum alpha
+
+ // Transforms are packed as follows
+ // packed[0] = vec4(scale.x, scale.y, rotation, offset.x)
+ // packed[1] = vec4(mScale.y, texcoord, 0, 0)
+ vec4 gltf_material_data[MAX_UBO_VEC4S];
+};
+
+vec4[2] texture_base_color_transform;
+vec4[2] texture_normal_transform;
+vec4[2] texture_metallic_roughness_transform;
+vec4[2] texture_emissive_transform;
+vec4[2] texture_occlusion_transform;
+
+void unpackTextureTransforms()
+{
+ if (gltf_material_id != -1)
+ {
+ int idx = gltf_material_id*12;
+
+ texture_base_color_transform[0] = gltf_material_data[idx+0];
+ texture_base_color_transform[1] = gltf_material_data[idx+1];
+
+ texture_normal_transform[0] = gltf_material_data[idx+2];
+ texture_normal_transform[1] = gltf_material_data[idx+3];
+
+ texture_metallic_roughness_transform[0] = gltf_material_data[idx+4];
+ texture_metallic_roughness_transform[1] = gltf_material_data[idx+5];
+
+ texture_emissive_transform[0] = gltf_material_data[idx+6];
+ texture_emissive_transform[1] = gltf_material_data[idx+7];
+
+ texture_occlusion_transform[0] = gltf_material_data[idx+8];
+ texture_occlusion_transform[1] = gltf_material_data[idx+9];
+
+#ifdef MULTI_UV
+ base_color_texcoord = int(gltf_material_data[idx+1].g);
+ emissive_texcoord = int(gltf_material_data[idx+7].g);
+#ifndef UNLIT
+ normal_texcoord = int(gltf_material_data[idx+3].g);
+ metallic_roughness_texcoord = int(gltf_material_data[idx+5].g);
+ occlusion_texcoord = int(gltf_material_data[idx+9].g);
#endif
+#endif
+ }
+ else
+ {
+ texture_base_color_transform[0] = vec4(1.0, 1.0, 0.0, 0.0);
+ texture_base_color_transform[1] = vec4(0.0, 0.0, 0.0, 0.0);
+
+ texture_normal_transform[0] = vec4(1.0, 1.0, 0.0, 0.0);
+ texture_normal_transform[1] = vec4(0.0, 0.0, 0.0, 0.0);
+
+ texture_metallic_roughness_transform[0] = vec4(1.0, 1.0, 0.0, 0.0);
+ texture_metallic_roughness_transform[1] = vec4(0.0, 0.0, 0.0, 0.0);
+
+ texture_emissive_transform[0] = vec4(1.0, 1.0, 0.0, 0.0);
+ texture_emissive_transform[1] = vec4(0.0, 0.0, 0.0, 0.0);
+
+ texture_occlusion_transform[0] = vec4(1.0, 1.0, 0.0, 0.0);
+ texture_occlusion_transform[1] = vec4(0.0, 0.0, 0.0, 0.0);
+ }
+}
-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;
-uniform vec4[2] texture_occlusion_transform;
in vec3 position;
in vec4 diffuse_color;
@@ -59,17 +135,6 @@ flat out float vary_sign;
out vec3 vary_normal;
#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)
{
texcoord.y = 1.0 - texcoord.y;
@@ -124,23 +189,22 @@ vec3 gltf_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[
}
#endif
-
-
#ifdef ALPHA_BLEND
out vec3 vary_fragcoord;
#endif
#ifdef HAS_SKIN
-in uvec4 joint;
-in vec4 weight4;
layout (std140) uniform GLTFJoints
{
- // list of OBBs for user override probes
- mat3x4 gltf_joints[MAX_JOINTS_PER_GLTF_OBJECT];
+ mat3x4 gltf_joints[MAX_NODES_PER_GLTF_OBJECT];
};
-mat4 getGLTFSkinTransform()
+
+in uvec4 joint;
+in vec4 weight4;
+
+mat4 getGLTFTransform()
{
int i;
@@ -169,21 +233,37 @@ mat4 getGLTFSkinTransform()
ret[3] = vec4(trans, 1.0);
return ret;
+}
-#ifdef IS_AMD_CARD
- // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts.
- mat3x4 dummy1 = gltf_joints[0];
- mat3x4 dummy2 = gltf_joints[MAX_JOINTS_PER_GLTF_OBJECT-1];
-#endif
+#else
+
+layout (std140) uniform GLTFNodes
+{
+ mat3x4 gltf_nodes[MAX_NODES_PER_GLTF_OBJECT];
+};
+
+uniform int gltf_node_id = 0;
+
+mat4 getGLTFTransform()
+{
+ mat4 ret;
+ mat3x4 src = gltf_nodes[gltf_node_id];
+
+ ret[0] = vec4(src[0].xyz, 0);
+ ret[1] = vec4(src[1].xyz, 0);
+ ret[2] = vec4(src[2].xyz, 0);
+
+ ret[3] = vec4(src[0].w, src[1].w, src[2].w, 1);
+ return ret;
}
#endif
void main()
{
-#ifdef HAS_SKIN
- mat4 mat = getGLTFSkinTransform();
+ unpackTextureTransforms();
+ mat4 mat = getGLTFTransform();
mat = modelview_matrix * mat;
@@ -193,13 +273,6 @@ void main()
vec4 vert = projection_matrix * vec4(pos, 1.0);
gl_Position = vert;
-#else
- vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
- //transform vertex
- vec4 vert = modelview_projection_matrix * vec4(position.xyz, 1.0);
- gl_Position = vert;
-#endif
-
vec2 bcuv;
vec2 emuv;
@@ -237,13 +310,8 @@ void main()
#endif
#ifndef UNLIT
-#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;
-#else //HAS_SKIN
- vec3 n = normal_matrix * normal;
- vec3 t = normal_matrix * tangent.xyz;
-#endif
n = normalize(n);
vary_tangent = normalize(gltf_tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform));