diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llprimitive/llgltfmaterial.cpp | 22 | ||||
-rw-r--r-- | indra/llprimitive/llgltfmaterial.h | 3 | ||||
-rw-r--r-- | indra/llrender/llshadermgr.cpp | 10 | ||||
-rw-r--r-- | indra/llrender/llshadermgr.h | 4 | ||||
-rw-r--r-- | indra/llrender/llvertexbuffer.cpp | 92 | ||||
-rw-r--r-- | indra/llrender/llvertexbuffer.h | 24 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl | 44 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl | 30 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl | 38 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class2/deferred/pbralphaF.glsl | 41 | ||||
-rw-r--r-- | indra/newview/llface.cpp | 6 | ||||
-rw-r--r-- | indra/newview/llfetchedgltfmaterial.cpp | 9 |
12 files changed, 243 insertions, 80 deletions
diff --git a/indra/llprimitive/llgltfmaterial.cpp b/indra/llprimitive/llgltfmaterial.cpp index 172cbdb7ce..649d4dbe8f 100644 --- a/indra/llprimitive/llgltfmaterial.cpp +++ b/indra/llprimitive/llgltfmaterial.cpp @@ -39,6 +39,28 @@ const char* GLTF_FILE_EXTENSION_TRANSFORM_ROTATION = "rotation"; // special UUID that indicates a null UUID in override data static const LLUUID GLTF_OVERRIDE_NULL_UUID = LLUUID("ffffffff-ffff-ffff-ffff-ffffffffffff"); +// https://github.com/KhronosGroup/glTF/tree/main/extensions/3.0/Khronos/KHR_texture_transform +LLMatrix3 LLGLTFMaterial::TextureTransform::asMatrix() +{ + LLMatrix3 scale; + scale.mMatrix[0][0] = mScale[0]; + scale.mMatrix[1][1] = mScale[1]; + + LLMatrix3 rotation; + const F32 cos_r = cos(mRotation); + const F32 sin_r = sin(mRotation); + rotation.mMatrix[0][0] = cos_r; + rotation.mMatrix[0][1] = sin_r; + rotation.mMatrix[1][0] = -sin_r; + rotation.mMatrix[1][1] = cos_r; + + LLMatrix3 offset; + offset.mMatrix[2][0] = mOffset[0]; + offset.mMatrix[2][1] = mOffset[1]; + + return offset * rotation * scale; +} + LLGLTFMaterial::LLGLTFMaterial(const LLGLTFMaterial& rhs) { *this = rhs; diff --git a/indra/llprimitive/llgltfmaterial.h b/indra/llprimitive/llgltfmaterial.h index 9489837de7..60116fd423 100644 --- a/indra/llprimitive/llgltfmaterial.h +++ b/indra/llprimitive/llgltfmaterial.h @@ -28,6 +28,7 @@ #include "llrefcount.h" #include "llmemory.h" +#include "m3math.h" #include "v4color.h" #include "v3color.h" #include "v2math.h" @@ -53,6 +54,8 @@ public: LLVector2 mOffset = { 0.f, 0.f }; LLVector2 mScale = { 1.f, 1.f }; F32 mRotation = 0.f; + + LLMatrix3 asMatrix(); }; enum AlphaMode diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 7f7829c18e..e8cf7ec758 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1163,6 +1163,10 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedAttribs.push_back("weight4"); mReservedAttribs.push_back("clothing"); mReservedAttribs.push_back("texture_index"); + mReservedAttribs.push_back("basecolor_texcoord"); // GLTF + mReservedAttribs.push_back("normal_texcoord"); // GLTF + mReservedAttribs.push_back("metallic_roughness_texcoord"); // GLTF + mReservedAttribs.push_back("emissive_texcoord"); // GLTF //matrix state mReservedUniforms.push_back("modelview_matrix"); @@ -1177,7 +1181,11 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("texture_matrix3"); mReservedUniforms.push_back("object_plane_s"); mReservedUniforms.push_back("object_plane_t"); - llassert(mReservedUniforms.size() == LLShaderMgr::OBJECT_PLANE_T+1); + mReservedUniforms.push_back("texture_basecolor_matrix"); // GLTF + mReservedUniforms.push_back("texture_normal_matrix"); // GLTF + mReservedUniforms.push_back("texture_metallic_roughness_matrix"); // GLTF + mReservedUniforms.push_back("texture_emissive_matrix"); // GLTF + llassert(mReservedUniforms.size() == LLShaderMgr::TEXTURE_EMISSIVE_MATRIX+1); mReservedUniforms.push_back("viewport"); diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 6d2138f405..e1fb60eccf 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -51,6 +51,10 @@ public: TEXTURE_MATRIX3, // "texture_matrix3" OBJECT_PLANE_S, // "object_plane_s" OBJECT_PLANE_T, // "object_plane_t" + TEXTURE_BASECOLOR_MATRIX, // "texture_basecolor_matrix" (GLTF) + TEXTURE_NORMAL_MATRIX, // "texture_normal_matrix" (GLTF) + TEXTURE_METALLIC_ROUGHNESS_MATRIX, // "texture_metallic_roughness_matrix" (GLTF) + TEXTURE_EMISSIVE_MATRIX, // "texture_emissive_matrix" (GLTF) VIEWPORT, // "viewport" LIGHT_POSITION, // "light_position" LIGHT_DIRECTION, // "light_direction" diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index f51000b9a6..b33708cae6 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -358,6 +358,10 @@ const S32 LLVertexBuffer::sTypeSize[LLVertexBuffer::TYPE_MAX] = sizeof(LLVector4), // TYPE_WEIGHT4, sizeof(LLVector4), // TYPE_CLOTHWEIGHT, sizeof(LLVector4), // TYPE_TEXTURE_INDEX (actually exists as position.w), no extra data, but stride is 16 bytes + sizeof(LLVector2), // TYPE_BASECOLOR_TEXCOORD, + sizeof(LLVector2), // TYPE_NORMAL_TEXCOORD, + sizeof(LLVector2), // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + sizeof(LLVector2), // TYPE_EMISSIVE_TEXCOORD, }; static const std::string vb_type_name[] = @@ -375,6 +379,10 @@ static const std::string vb_type_name[] = "TYPE_WEIGHT4", "TYPE_CLOTHWEIGHT", "TYPE_TEXTURE_INDEX", + "TYPE_BASECOLOR_TEXCOORD", + "TYPE_NORMAL_TEXCOORD", + "TYPE_METALLIC_ROUGHNESS_TEXCOORD", + "TYPE_EMISSIVE_TEXCOORD", "TYPE_MAX", "TYPE_INDEX", }; @@ -1270,6 +1278,10 @@ void LLVertexBuffer::setupVertexArray() 4, //TYPE_WEIGHT4, 4, //TYPE_CLOTHWEIGHT, 1, //TYPE_TEXTURE_INDEX + 2, // TYPE_BASECOLOR_TEXCOORD, + 2, // TYPE_NORMAL_TEXCOORD, + 2, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + 2, // TYPE_EMISSIVE_TEXCOORD, }; static const U32 attrib_type[] = @@ -1287,6 +1299,10 @@ void LLVertexBuffer::setupVertexArray() GL_FLOAT, //TYPE_WEIGHT4, GL_FLOAT, //TYPE_CLOTHWEIGHT, GL_UNSIGNED_INT, //TYPE_TEXTURE_INDEX + GL_FLOAT, // TYPE_BASECOLOR_TEXCOORD, + GL_FLOAT, // TYPE_NORMAL_TEXCOORD, + GL_FLOAT, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + GL_FLOAT, // TYPE_EMISSIVE_TEXCOORD, }; static const bool attrib_integer[] = @@ -1304,6 +1320,10 @@ void LLVertexBuffer::setupVertexArray() false, //TYPE_WEIGHT4, false, //TYPE_CLOTHWEIGHT, true, //TYPE_TEXTURE_INDEX + false, // TYPE_BASECOLOR_TEXCOORD, + false, // TYPE_NORMAL_TEXCOORD, + false, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + false, // TYPE_EMISSIVE_TEXCOORD, }; static const U32 attrib_normalized[] = @@ -1321,6 +1341,10 @@ void LLVertexBuffer::setupVertexArray() GL_FALSE, //TYPE_WEIGHT4, GL_FALSE, //TYPE_CLOTHWEIGHT, GL_FALSE, //TYPE_TEXTURE_INDEX + GL_FALSE, // TYPE_BASECOLOR_TEXCOORD, + GL_FALSE, // TYPE_NORMAL_TEXCOORD, + GL_FALSE, // TYPE_METALLIC_ROUGHNESS_TEXCOORD, + GL_FALSE, // TYPE_EMISSIVE_TEXCOORD, }; bindGLBuffer(true); @@ -1961,6 +1985,26 @@ bool LLVertexBuffer::getClothWeightStrider(LLStrider<LLVector4>& strider, S32 in return VertexBufferStrider<LLVector4,TYPE_CLOTHWEIGHT>::get(*this, strider, index, count, map_range); } +bool LLVertexBuffer::getBasecolorTexcoordStrider(LLStrider<LLVector2>& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider<LLVector2,TYPE_BASECOLOR_TEXCOORD>::get(*this, strider, index, count, map_range); +} + +bool LLVertexBuffer::getNormalTexcoordStrider(LLStrider<LLVector2>& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider<LLVector2,TYPE_NORMAL_TEXCOORD>::get(*this, strider, index, count, map_range); +} + +bool LLVertexBuffer::getMetallicRoughnessTexcoordStrider(LLStrider<LLVector2>& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider<LLVector2,TYPE_METALLIC_ROUGHNESS_TEXCOORD>::get(*this, strider, index, count, map_range); +} + +bool LLVertexBuffer::getEmissiveTexcoordStrider(LLStrider<LLVector2>& strider, S32 index, S32 count, bool map_range) +{ + return VertexBufferStrider<LLVector2,TYPE_EMISSIVE_TEXCOORD>::get(*this, strider, index, count, map_range); +} + //---------------------------------------------------------------------------- bool LLVertexBuffer::bindGLArray() @@ -2379,6 +2423,30 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); glVertexAttribPointer(loc, 3,GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } + if (data_mask & MAP_BASECOLOR_TEXCOORD) + { + S32 loc = TYPE_BASECOLOR_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_BASECOLOR_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_BASECOLOR_TEXCOORD], ptr); + } + if (data_mask & MAP_NORMAL_TEXCOORD) + { + S32 loc = TYPE_NORMAL_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_NORMAL_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL_TEXCOORD], ptr); + } + if (data_mask & MAP_METALLIC_ROUGHNESS_TEXCOORD) + { + S32 loc = TYPE_METALLIC_ROUGHNESS_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_METALLIC_ROUGHNESS_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_METALLIC_ROUGHNESS_TEXCOORD], ptr); + } + if (data_mask & MAP_EMISSIVE_TEXCOORD) + { + S32 loc = TYPE_EMISSIVE_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE_TEXCOORD], ptr); + } llglassertok(); } @@ -2472,6 +2540,30 @@ void LLVertexBuffer::setupVertexBufferFast(U32 data_mask) void* ptr = (void*)(base + mOffsets[TYPE_VERTEX]); glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_VERTEX], ptr); } + if (data_mask & MAP_BASECOLOR_TEXCOORD) + { + S32 loc = TYPE_BASECOLOR_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_BASECOLOR_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_BASECOLOR_TEXCOORD], ptr); + } + if (data_mask & MAP_NORMAL_TEXCOORD) + { + S32 loc = TYPE_NORMAL_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_NORMAL_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_NORMAL_TEXCOORD], ptr); + } + if (data_mask & MAP_METALLIC_ROUGHNESS_TEXCOORD) + { + S32 loc = TYPE_METALLIC_ROUGHNESS_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_METALLIC_ROUGHNESS_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_METALLIC_ROUGHNESS_TEXCOORD], ptr); + } + if (data_mask & MAP_EMISSIVE_TEXCOORD) + { + S32 loc = TYPE_EMISSIVE_TEXCOORD; + void* ptr = (void*)(base + mOffsets[TYPE_EMISSIVE_TEXCOORD]); + glVertexAttribPointer(loc, 2, GL_FLOAT, GL_FALSE, LLVertexBuffer::sTypeSize[TYPE_EMISSIVE_TEXCOORD], ptr); + } } LLVertexBuffer::MappedRegion::MappedRegion(S32 type, S32 index, S32 count) diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h index 233d7785f8..b54e99ca27 100644 --- a/indra/llrender/llvertexbuffer.h +++ b/indra/llrender/llvertexbuffer.h @@ -160,11 +160,12 @@ public: //WARNING -- when updating these enums you MUST // 1 - update LLVertexBuffer::sTypeSize - // 2 - add a strider accessor - // 3 - modify LLVertexBuffer::setupVertexBuffer - // 4 - modify LLVertexBuffer::setupClientArray - // 5 - modify LLViewerShaderMgr::mReservedAttribs - // 6 - update LLVertexBuffer::setupVertexArray + // 2 - update LLVertexBuffer::vb_type_name + // 3 - add a strider accessor + // 4 - modify LLVertexBuffer::setupVertexBuffer + // 5 - modify LLVertexBuffer::setupVertexBufferFast + // 6 - modify LLViewerShaderMgr::mReservedAttribs + // 7 - update LLVertexBuffer::setupVertexArray // clang-format off enum { // Shader attribute name, set in LLShaderMgr::initAttribsAndUniforms() @@ -181,6 +182,10 @@ public: TYPE_WEIGHT4, // "weight4" TYPE_CLOTHWEIGHT, // "clothing" TYPE_TEXTURE_INDEX, // "texture_index" + TYPE_BASECOLOR_TEXCOORD, // "basecolor_texcoord" (GLTF) + TYPE_NORMAL_TEXCOORD, // "normal_texcoord" (GLTF) + TYPE_METALLIC_ROUGHNESS_TEXCOORD, // "metallic_roughness_texcoord" (GLTF) + TYPE_EMISSIVE_TEXCOORD, // "emissive_texcoord" (GLTF) TYPE_MAX, // TYPE_MAX is the size/boundary marker for attributes that go in the vertex buffer TYPE_INDEX, // TYPE_INDEX is beyond _MAX because it lives in a separate (index) buffer }; @@ -195,12 +200,15 @@ public: MAP_TEXCOORD3 = (1<<TYPE_TEXCOORD3), MAP_COLOR = (1<<TYPE_COLOR), MAP_EMISSIVE = (1<<TYPE_EMISSIVE), - // These use VertexAttribPointer and should possibly be made generic MAP_TANGENT = (1<<TYPE_TANGENT), MAP_WEIGHT = (1<<TYPE_WEIGHT), MAP_WEIGHT4 = (1<<TYPE_WEIGHT4), MAP_CLOTHWEIGHT = (1<<TYPE_CLOTHWEIGHT), MAP_TEXTURE_INDEX = (1<<TYPE_TEXTURE_INDEX), + MAP_BASECOLOR_TEXCOORD = (1<<TYPE_BASECOLOR_TEXCOORD), + MAP_NORMAL_TEXCOORD = (1<<TYPE_NORMAL_TEXCOORD), + MAP_METALLIC_ROUGHNESS_TEXCOORD = (1<<TYPE_METALLIC_ROUGHNESS_TEXCOORD), + MAP_EMISSIVE_TEXCOORD = (1<<TYPE_EMISSIVE_TEXCOORD), }; protected: @@ -269,6 +277,10 @@ public: bool getWeightStrider(LLStrider<F32>& strider, S32 index=0, S32 count = -1, bool map_range = false); bool getWeight4Strider(LLStrider<LLVector4>& strider, S32 index=0, S32 count = -1, bool map_range = false); bool getClothWeightStrider(LLStrider<LLVector4>& strider, S32 index=0, S32 count = -1, bool map_range = false); + bool getBasecolorTexcoordStrider(LLStrider<LLVector2>& strider, S32 index=0, S32 count = -1, bool map_range = false); + bool getNormalTexcoordStrider(LLStrider<LLVector2>& strider, S32 index=0, S32 count = -1, bool map_range = false); + bool getMetallicRoughnessTexcoordStrider(LLStrider<LLVector2>& strider, S32 index=0, S32 count = -1, bool map_range = false); + bool getEmissiveTexcoordStrider(LLStrider<LLVector2>& strider, S32 index=0, S32 count = -1, bool map_range = false); bool useVBOs() const; 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); } diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index 23b56aa579..528675072b 100644 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -1601,6 +1601,12 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, LLMaterial* mat = tep->getMaterialParams().get(); LLGLTFMaterial* gltf_mat = tep->getGLTFRenderMaterial(); + if (gltf_mat) + { + // Transforms will be applied later + do_xform = false; + } + bool do_bump = bump_code && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1); if ((mat || gltf_mat) && !do_bump) diff --git a/indra/newview/llfetchedgltfmaterial.cpp b/indra/newview/llfetchedgltfmaterial.cpp index 22be8a03dd..a873d062bd 100644 --- a/indra/newview/llfetchedgltfmaterial.cpp +++ b/indra/newview/llfetchedgltfmaterial.cpp @@ -101,6 +101,15 @@ void LLFetchedGLTFMaterial::bind(LLGLSLShader* shader) shader->uniform1f(LLShaderMgr::ROUGHNESS_FACTOR, mRoughnessFactor); shader->uniform1f(LLShaderMgr::METALLIC_FACTOR, mMetallicFactor); shader->uniform3fv(LLShaderMgr::EMISSIVE_COLOR, 1, mEmissiveColor.mV); + + const LLMatrix3 base_color_matrix = mTextureTransform[GLTF_TEXTURE_INFO_BASE_COLOR].asMatrix(); + shader->uniformMatrix3fv(LLShaderMgr::TEXTURE_BASECOLOR_MATRIX, 1, false, (F32*)base_color_matrix.mMatrix); + const LLMatrix3 normal_matrix = mTextureTransform[GLTF_TEXTURE_INFO_NORMAL].asMatrix(); + shader->uniformMatrix3fv(LLShaderMgr::TEXTURE_NORMAL_MATRIX, 1, false, (F32*)normal_matrix.mMatrix); + const LLMatrix3 metallic_roughness_matrix = mTextureTransform[GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS].asMatrix(); + shader->uniformMatrix3fv(LLShaderMgr::TEXTURE_METALLIC_ROUGHNESS_MATRIX, 1, false, (F32*)metallic_roughness_matrix.mMatrix); + const LLMatrix3 emissive_matrix = mTextureTransform[GLTF_TEXTURE_INFO_EMISSIVE].asMatrix(); + shader->uniformMatrix3fv(LLShaderMgr::TEXTURE_EMISSIVE_MATRIX, 1, false, (F32*)emissive_matrix.mMatrix); } } |