From 69f9e41019e424a9193164623fbc4f12407f1ca6 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Thu, 2 Mar 2023 16:22:46 -0800 Subject: SL-19293: Use Blinn-Phong texture transform as hint for texture animation direction on PBR materials --- indra/newview/llvovolume.cpp | 68 ++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp index 2eb3db6765..853c580964 100644 --- a/indra/newview/llvovolume.cpp +++ b/indra/newview/llvovolume.cpp @@ -628,6 +628,14 @@ void LLVOVolume::animateTextures() LLGLTFMaterial *gltf_mat = te->getGLTFRenderMaterial(); const bool is_pbr = gltf_mat != nullptr; + if (!facep->mTextureMatrix) + { + facep->mTextureMatrix = new LLMatrix4(); + } + + LLMatrix4& tex_mat = *facep->mTextureMatrix; + tex_mat.setIdentity(); + if (!is_pbr) { if (!(result & LLViewerTextureAnim::ROTATE)) @@ -642,32 +650,50 @@ void LLVOVolume::animateTextures() { te->getScale(&scale_s, &scale_t); } - } - if (!facep->mTextureMatrix) - { - facep->mTextureMatrix = new LLMatrix4(); - } + LLVector3 trans ; - LLMatrix4& tex_mat = *facep->mTextureMatrix; - tex_mat.setIdentity(); - - LLVector3 trans ; + trans.set(LLVector3(off_s+0.5f, off_t+0.5f, 0.f)); + tex_mat.translate(LLVector3(-0.5f, -0.5f, 0.f)); - trans.set(LLVector3(off_s+0.5f, off_t+0.5f, 0.f)); - tex_mat.translate(LLVector3(-0.5f, -0.5f, 0.f)); + LLVector3 scale(scale_s, scale_t, 1.f); + LLQuaternion quat; + quat.setQuat(rot, 0, 0, -1.f); + + tex_mat.rotate(quat); - LLVector3 scale(scale_s, scale_t, 1.f); - LLQuaternion quat; - quat.setQuat(rot, 0, 0, -1.f); - - tex_mat.rotate(quat); + LLMatrix4 mat; + mat.initAll(scale, LLQuaternion(), LLVector3()); + tex_mat *= mat; + + tex_mat.translate(trans); + } + else + { + // For PBR materials, use Blinn-Phong rotation as hint for + // translation direction. In a Blinn-Phong material, the + // translation direction would be a byproduct the texture + // transform. + F32 rot_frame; + te->getRotation(&rot_frame); + + tex_mat.translate(LLVector3(-0.5f, -0.5f, 0.f)); + + LLQuaternion quat; + quat.setQuat(rot, 0, 0, -1.f); + tex_mat.rotate(quat); + + LLMatrix4 mat; + LLVector3 scale(scale_s, scale_t, 1.f); + mat.initAll(scale, LLQuaternion(), LLVector3()); + tex_mat *= mat; + + LLVector3 off(off_s, off_t, 0.f); + off.rotVec(rot_frame, 0, 0, 1.f); + tex_mat.translate(off); - LLMatrix4 mat; - mat.initAll(scale, LLQuaternion(), LLVector3()); - tex_mat *= mat; - - tex_mat.translate(trans); + tex_mat.translate(LLVector3(0.5f, 0.5f, 0.f)); + } } } else -- cgit v1.2.3