diff options
author | Cosmic Linden <cosmic@lindenlab.com> | 2022-10-31 09:42:27 -0700 |
---|---|---|
committer | Cosmic Linden <cosmic@lindenlab.com> | 2022-11-02 12:55:18 -0700 |
commit | 9e7b725c15ea0bfea5246eb81dd7a100b7ac5b6b (patch) | |
tree | bbc065c955992f45933c0f9d83d61761121d589f /indra/newview/app_settings | |
parent | d042ad67ed4db72bf0265804e26610e565f15cf2 (diff) |
SL-18485: Render GLTF materials with extension KHR_texture_transform with approprate texture transforms
Diffstat (limited to 'indra/newview/app_settings')
4 files changed, 80 insertions, 73 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl index d0d76fd0cb..19bca098e8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl @@ -44,29 +44,32 @@ uniform mat4 modelview_projection_matrix; VARYING vec3 vary_position; #endif -uniform mat4 texture_matrix0; +uniform mat3 texture_basecolor_matrix; +uniform mat3 texture_normal_matrix; +uniform mat3 texture_metallic_roughness_matrix; +uniform mat3 texture_emissive_matrix; #ifdef HAS_SUN_SHADOW -VARYING vec3 vary_fragcoord; +out vec3 vary_fragcoord; uniform float near_clip; #endif -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec4 tangent; -ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec2 texcoord1; -ATTRIBUTE vec2 texcoord2; - - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec3 vary_normal; -VARYING vec3 vary_tangent; +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec4 tangent; +in vec2 texcoord0; + +out vec2 basecolor_texcoord; +out vec2 normal_texcoord; +out vec2 metallic_roughness_texcoord; +out vec2 emissive_texcoord; + +out vec4 vertex_color; + +out vec3 vary_tangent; flat out float vary_sign; +out vec3 vary_normal; void main() @@ -89,9 +92,10 @@ void main() vary_fragcoord.xyz = vert.xyz + vec3(0,0,near_clip); #endif - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; - vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; + basecolor_texcoord = (texture_basecolor_matrix * vec3(texcoord0,1)).xy; + normal_texcoord = (texture_normal_matrix * vec3(texcoord0,1)).xy; + metallic_roughness_texcoord = (texture_metallic_roughness_matrix * vec3(texcoord0,1)).xy; + emissive_texcoord = (texture_emissive_matrix * vec3(texcoord0,1)).xy; #ifdef HAS_SKIN vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index 7376e9eb47..39419e9d78 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -36,15 +36,16 @@ uniform sampler2D specularMap; // Packed: Occlusion, Metal, Roughness out vec4 frag_data[4]; -VARYING vec3 vary_position; -VARYING vec4 vertex_color; -VARYING vec3 vary_normal; -VARYING vec3 vary_tangent; +in vec3 vary_position; +in vec4 vertex_color; +in vec3 vary_normal; +in vec3 vary_tangent; flat in float vary_sign; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; +in vec2 basecolor_texcoord; +in vec2 normal_texcoord; +in vec2 metallic_roughness_texcoord; +in vec2 emissive_texcoord; uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() @@ -56,19 +57,16 @@ uniform mat3 normal_matrix; void main() { -// IF .mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; -// vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; -// else - vec4 albedo = texture2D(diffuseMap, vary_texcoord0.xy).rgba; - if (albedo.a < minimum_alpha) + vec4 basecolor = texture2D(diffuseMap, basecolor_texcoord.xy).rgba; + if (basecolor.a < minimum_alpha) { discard; } - vec3 col = vertex_color.rgb * srgb_to_linear(albedo.rgb); + vec3 col = vertex_color.rgb * srgb_to_linear(basecolor.rgb); // from mikktspace.com - vec3 vNt = texture2D(bumpMap, vary_texcoord1.xy).xyz*2.0-1.0; + vec3 vNt = texture2D(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; @@ -81,13 +79,13 @@ void main() // occlusion 1.0 // roughness 0.0 // metal 0.0 - vec3 spec = texture2D(specularMap, vary_texcoord2.xy).rgb; + vec3 spec = texture2D(specularMap, metallic_roughness_texcoord.xy).rgb; spec.g *= roughnessFactor; spec.b *= metallicFactor; vec3 emissive = emissiveColor; - emissive *= srgb_to_linear(texture2D(emissiveMap, vary_texcoord0.xy).rgb); + emissive *= srgb_to_linear(texture2D(emissiveMap, emissive_texcoord.xy).rgb); tnorm *= gl_FrontFacing ? 1.0 : -1.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl index 5573c02a60..25bf19b4ec 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -37,25 +37,27 @@ uniform mat3 normal_matrix; uniform mat4 modelview_projection_matrix; #endif -uniform mat4 texture_matrix0; +uniform mat3 texture_basecolor_matrix; +uniform mat3 texture_normal_matrix; +uniform mat3 texture_metallic_roughness_matrix; +uniform mat3 texture_emissive_matrix; -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec4 tangent; -ATTRIBUTE vec2 texcoord0; -ATTRIBUTE vec2 texcoord1; -ATTRIBUTE vec2 texcoord2; +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec4 tangent; +in vec2 texcoord0; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; +out vec2 basecolor_texcoord; +out vec2 normal_texcoord; +out vec2 metallic_roughness_texcoord; +out vec2 emissive_texcoord; -VARYING vec4 vertex_color; +out vec4 vertex_color; -VARYING vec3 vary_tangent; +out vec3 vary_tangent; flat out float vary_sign; -VARYING vec3 vary_normal; +out vec3 vary_normal; void main() { @@ -73,9 +75,11 @@ void main() gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); #endif - vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; - vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy; - vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy; + basecolor_texcoord = (texture_basecolor_matrix * vec3(texcoord0,1)).xy; + normal_texcoord = (texture_normal_matrix * vec3(texcoord0,1)).xy; + metallic_roughness_texcoord = (texture_metallic_roughness_matrix * vec3(texcoord0,1)).xy; + emissive_texcoord = (texture_emissive_matrix * vec3(texcoord0,1)).xy; + #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; diff --git a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl index b39f834e41..6500c4bb1f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl @@ -45,17 +45,21 @@ uniform vec3 moon_dir; out vec4 frag_color; #ifdef HAS_SUN_SHADOW - VARYING vec3 vary_fragcoord; + in vec3 vary_fragcoord; uniform vec2 screen_res; #endif -VARYING vec3 vary_position; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec3 vary_normal; -VARYING vec3 vary_tangent; +in vec3 vary_position; + +in vec2 basecolor_texcoord; +in vec2 normal_texcoord; +in vec2 metallic_roughness_texcoord; +in vec2 emissive_texcoord; + +in vec4 vertex_color; + +in vec3 vary_normal; +in vec3 vary_tangent; flat in float vary_sign; @@ -155,21 +159,18 @@ void main() waterClip(pos); -// IF .mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels; -// vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb; -// else - vec4 albedo = texture(diffuseMap, vary_texcoord0.xy).rgba; - albedo.rgb = srgb_to_linear(albedo.rgb); + vec4 basecolor = texture(diffuseMap, basecolor_texcoord.xy).rgba; + basecolor.rgb = srgb_to_linear(basecolor.rgb); #ifdef HAS_ALPHA_MASK - if (albedo.a < minimum_alpha) + if (basecolor.a < minimum_alpha) { discard; } #endif - vec3 baseColor = vertex_color.rgb * albedo.rgb; + vec3 col = vertex_color.rgb * basecolor.rgb; - vec3 vNt = texture(bumpMap, vary_texcoord1.xy).xyz*2.0-1.0; + vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; float sign = vary_sign; vec3 vN = vary_normal; vec3 vT = vary_tangent.xyz; @@ -192,7 +193,7 @@ void main() scol = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); #endif - vec3 orm = texture(specularMap, vary_texcoord2.xy).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space + vec3 orm = texture(specularMap, metallic_roughness_texcoord.xy).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space float perceptualRoughness = orm.g * roughnessFactor; float metallic = orm.b * metallicFactor; @@ -201,7 +202,7 @@ void main() // emissiveColor is the emissive color factor from GLTF and is already in linear space vec3 colorEmissive = emissiveColor; // emissiveMap here is a vanilla RGB texture encoded as sRGB, manually convert to linear - colorEmissive *= srgb_to_linear(texture2D(emissiveMap, vary_texcoord0.xy).rgb); + colorEmissive *= srgb_to_linear(texture2D(emissiveMap, emissive_texcoord.xy).rgb); // PBR IBL float gloss = 1.0 - perceptualRoughness; @@ -214,7 +215,7 @@ void main() vec3 diffuseColor; vec3 specularColor; - calcDiffuseSpecular(baseColor.rgb, metallic, diffuseColor, specularColor); + calcDiffuseSpecular(col.rgb, metallic, diffuseColor, specularColor); vec3 v = -normalize(pos.xyz); color = pbrBaseLight(diffuseColor, specularColor, metallic, v, norm.xyz, perceptualRoughness, light_dir, sunlit, scol, radiance, irradiance, colorEmissive, ao, additive, atten); @@ -235,5 +236,5 @@ void main() color.rgb += light.rgb; - frag_color = vec4(color.rgb,albedo.a * vertex_color.a); + frag_color = vec4(color.rgb,basecolor.a * vertex_color.a); } |