From e49d602bd99f5a3b1257ba1bc7ded133eab1eb1c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 12 Sep 2022 19:48:33 -0500 Subject: SL-18095 Add tangents to mesh assets so we can calculate mikktspace tangents in the mesh's original coordinate frame. --- indra/llprimitive/llmodel.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 285c5f656b..1ce287d773 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -187,6 +187,15 @@ void LLModel::trimVolumeFacesToSize(U32 new_count, LLVolume::face_list_t* remain } } +// generate mikkt space tangents and cache optimize +void LLModel::preprocessVolumeFaces() +{ + for (auto& face : mVolumeFaces) + { + face.cacheOptimize(); + } +} + // Shrink the model to fit // on a 1x1x1 cube centered at the origin. // The positions and extents @@ -296,6 +305,7 @@ void LLModel::normalizeVolumeFaces() // the positions to fit within the unit cube. LLVector4a* pos = (LLVector4a*) face.mPositions; LLVector4a* norm = (LLVector4a*) face.mNormals; + LLVector4a* t = (LLVector4a*)face.mMikktSpaceTangents; for (U32 j = 0; j < face.mNumVertices; ++j) { @@ -306,6 +316,14 @@ void LLModel::normalizeVolumeFaces() norm[j].mul(inv_scale); norm[j].normalize3(); } + + if (t) + { + F32 w = t[j].getF32ptr()[3]; + t[j].mul(inv_scale); + t[j].normalize3(); + t[j].getF32ptr()[3] = w; + } } } @@ -726,10 +744,12 @@ LLSD LLModel::writeModel( LLSD::Binary verts(face.mNumVertices*3*2); LLSD::Binary tc(face.mNumVertices*2*2); LLSD::Binary normals(face.mNumVertices*3*2); + LLSD::Binary tangents(face.mNumVertices * 4 * 2); LLSD::Binary indices(face.mNumIndices*2); U32 vert_idx = 0; U32 norm_idx = 0; + U32 tan_idx = 0; U32 tc_idx = 0; LLVector2* ftc = (LLVector2*) face.mTexCoords; @@ -782,6 +802,22 @@ LLSD LLModel::writeModel( normals[norm_idx++] = buff[1]; } } + + if (face.mMikktSpaceTangents) + { //normals + F32* tangent = face.mMikktSpaceTangents[j].getF32ptr(); + + for (U32 k = 0; k < 4; ++k) + { //for each component + //convert to 16-bit normalized + U16 val = (U16)((tangent[k] + 1.f) * 0.5f * 65535); + U8* buff = (U8*)&val; + + //write to binary buffer + tangents[tan_idx++] = buff[0]; + tangents[tan_idx++] = buff[1]; + } + } //texcoord if (face.mTexCoords) @@ -819,6 +855,11 @@ LLSD LLModel::writeModel( mdl[model_names[idx]][i]["Normal"] = normals; } + if (face.mMikktSpaceTangents) + { + mdl[model_names[idx]][i]["Tangent"] = tangents; + } + if (face.mTexCoords) { mdl[model_names[idx]][i]["TexCoord0Domain"]["Min"] = min_tc.getValue(); -- cgit v1.2.3 From 82ab5f9765ad76c73d1d7ddd5716b22d6b92bf62 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 15 Sep 2022 17:23:34 -0500 Subject: SL-18156 WIP -- Add NormalizedScale/NormalizedTranslation to mesh assets to recover mesh's original coordinate frame when generating tangents post download. --- indra/llprimitive/llmodel.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 1ce287d773..ab507edc40 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -337,6 +337,12 @@ void LLModel::normalizeVolumeFaces() mNormalizedScale.set(normalized_scale.getF32ptr()); mNormalizedTranslation.set(trans.getF32ptr()); mNormalizedTranslation *= -1.f; + + for (auto& face : mVolumeFaces) + { + face.mNormalizedScale = mNormalizedScale; + face.mNormalizedTranslation = mNormalizedTranslation; + } } } @@ -749,7 +755,7 @@ LLSD LLModel::writeModel( U32 vert_idx = 0; U32 norm_idx = 0; - U32 tan_idx = 0; + //U32 tan_idx = 0; U32 tc_idx = 0; LLVector2* ftc = (LLVector2*) face.mTexCoords; @@ -803,6 +809,7 @@ LLSD LLModel::writeModel( } } +#if 0 if (face.mMikktSpaceTangents) { //normals F32* tangent = face.mMikktSpaceTangents[j].getF32ptr(); @@ -818,6 +825,7 @@ LLSD LLModel::writeModel( tangents[tan_idx++] = buff[1]; } } +#endif //texcoord if (face.mTexCoords) @@ -848,6 +856,9 @@ LLSD LLModel::writeModel( //write out face data mdl[model_names[idx]][i]["PositionDomain"]["Min"] = min_pos.getValue(); mdl[model_names[idx]][i]["PositionDomain"]["Max"] = max_pos.getValue(); + mdl[model_names[idx]][i]["NormalizedScale"] = face.mNormalizedScale.getValue(); + mdl[model_names[idx]][i]["NormalizedTranslation"] = face.mNormalizedTranslation.getValue(); + mdl[model_names[idx]][i]["Position"] = verts; if (face.mNormals) -- cgit v1.2.3 From 8dc59e5ef37836b15d478fb0d04e3043a9f986de Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 16 Sep 2022 16:25:26 -0500 Subject: SL-18128 Clear out much OpenGL cruft and switch to core profile on AMD --- indra/llprimitive/llmodel.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index ab507edc40..eff47d9d98 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -187,15 +187,6 @@ void LLModel::trimVolumeFacesToSize(U32 new_count, LLVolume::face_list_t* remain } } -// generate mikkt space tangents and cache optimize -void LLModel::preprocessVolumeFaces() -{ - for (auto& face : mVolumeFaces) - { - face.cacheOptimize(); - } -} - // Shrink the model to fit // on a 1x1x1 cube centered at the origin. // The positions and extents -- cgit v1.2.3 From 75de4d32768bb1359611dc7cd963c9a12f94423d Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 23 Sep 2022 12:53:24 -0500 Subject: SL-18156 Cleanup of MikktSpace integration, apply MikktSpace tangents to all meshes. --- indra/llprimitive/llmodel.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index a6492f43d4..33d52d89bd 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -53,7 +53,6 @@ const int MODEL_NAMES_LENGTH = sizeof(model_names) / sizeof(std::string); LLModel::LLModel(LLVolumeParams& params, F32 detail) : LLVolume(params, detail), mNormalizedScale(1,1,1), - mNormalizedTranslation(0,0,0), mPelvisOffset( 0.0f ), mStatus(NO_ERRORS), mSubmodelID(0) @@ -296,7 +295,7 @@ void LLModel::normalizeVolumeFaces() // the positions to fit within the unit cube. LLVector4a* pos = (LLVector4a*) face.mPositions; LLVector4a* norm = (LLVector4a*) face.mNormals; - LLVector4a* t = (LLVector4a*)face.mMikktSpaceTangents; + LLVector4a* t = (LLVector4a*)face.mTangents; for (U32 j = 0; j < face.mNumVertices; ++j) { @@ -329,10 +328,10 @@ void LLModel::normalizeVolumeFaces() mNormalizedTranslation.set(trans.getF32ptr()); mNormalizedTranslation *= -1.f; + // remember normalized scale so original dimensions can be recovered for mesh processing (i.e. tangent generation) for (auto& face : mVolumeFaces) { face.mNormalizedScale = mNormalizedScale; - face.mNormalizedTranslation = mNormalizedTranslation; } } } @@ -800,10 +799,10 @@ LLSD LLModel::writeModel( } } -#if 0 - if (face.mMikktSpaceTangents) +#if 0 // keep this code for now in case we want to support transporting tangents with mesh assets + if (face.mTangents) { //normals - F32* tangent = face.mMikktSpaceTangents[j].getF32ptr(); + F32* tangent = face.mTangents[j].getF32ptr(); for (U32 k = 0; k < 4; ++k) { //for each component @@ -848,7 +847,6 @@ LLSD LLModel::writeModel( mdl[model_names[idx]][i]["PositionDomain"]["Min"] = min_pos.getValue(); mdl[model_names[idx]][i]["PositionDomain"]["Max"] = max_pos.getValue(); mdl[model_names[idx]][i]["NormalizedScale"] = face.mNormalizedScale.getValue(); - mdl[model_names[idx]][i]["NormalizedTranslation"] = face.mNormalizedTranslation.getValue(); mdl[model_names[idx]][i]["Position"] = verts; @@ -857,10 +855,12 @@ LLSD LLModel::writeModel( mdl[model_names[idx]][i]["Normal"] = normals; } - if (face.mMikktSpaceTangents) +#if 0 // keep this code for now in case we decide to transport tangents with mesh assets + if (face.mTangents) { mdl[model_names[idx]][i]["Tangent"] = tangents; } +#endif if (face.mTexCoords) { -- cgit v1.2.3 From 473ade269628d1fb6cbc7b96a91e1c0aec1b8e59 Mon Sep 17 00:00:00 2001 From: Henri Beauchamp Date: Tue, 31 Jan 2023 17:42:51 +0100 Subject: SL-19110 Fast hashing classes for use in place of the slow LLMD5, where speed matters. (#64) This commit adds the HBXX64 and HBXX128 classes for use as a drop-in replacement for the slow LLMD5 hashing class, where speed matters and backward compatibility (with standard hashing algorithms) and/or cryptographic hashing qualities are not required. It also replaces LLMD5 with HBXX* in a few existing hot (well, ok, just "warm" for some) paths meeting the above requirements, while paving the way for future use cases, such as in the DRTVWR-559 and sibling branches where the slow LLMD5 is used (e.g. to hash materials and vertex buffer cache entries), and could be use such a (way) faster algorithm with very significant benefits and no negative impact. Here is the comment I added in indra/llcommon/hbxx.h: // HBXXH* classes are to be used where speed matters and cryptographic quality // is not required (no "one-way" guarantee, though they are likely not worst in // this respect than MD5 which got busted and is now considered too weak). The // xxHash code they are built upon is vectorized and about 50 times faster than // MD5. A 64 bits hash class is also provided for when 128 bits of entropy are // not needed. The hashes collision rate is similar to MD5's. // See https://github.com/Cyan4973/xxHash#readme for details. --- indra/llprimitive/llmodel.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'indra/llprimitive/llmodel.cpp') diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 206142fdd5..52fb8e3802 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -31,7 +31,7 @@ #include "llconvexdecomposition.h" #include "llsdserialize.h" #include "llvector4a.h" -#include "llmd5.h" +#include "hbxxh.h" #ifdef LL_USESYSTEMLIBS # include @@ -1564,7 +1564,7 @@ LLSD LLMeshSkinInfo::asLLSD(bool include_joints, bool lock_scale_if_joint_positi void LLMeshSkinInfo::updateHash() { // get hash of data relevant to render batches - LLMD5 hash; + HBXXH64 hash; //mJointNames for (auto& name : mJointNames) @@ -1573,24 +1573,19 @@ void LLMeshSkinInfo::updateHash() } //mJointNums - hash.update((U8*)&(mJointNums[0]), sizeof(S32) * mJointNums.size()); + hash.update((const void*)mJointNums.data(), sizeof(S32) * mJointNums.size()); //mInvBindMatrix F32* src = mInvBindMatrix[0].getF32ptr(); - for (int i = 0; i < mInvBindMatrix.size() * 16; ++i) + for (size_t i = 0, count = mInvBindMatrix.size() * 16; i < count; ++i) { S32 t = llround(src[i] * 10000.f); - hash.update((U8*)&t, sizeof(S32)); + hash.update((const void*)&t, sizeof(S32)); } - //hash.update((U8*)&(mInvBindMatrix[0]), sizeof(LLMatrix4a) * mInvBindMatrix.size()); + //hash.update((const void*)mInvBindMatrix.data(), sizeof(LLMatrix4a) * mInvBindMatrix.size()); - hash.finalize(); - - U64 digest[2]; - hash.raw_digest((U8*) digest); - - mHash = digest[0]; + mHash = hash.digest(); } U32 LLMeshSkinInfo::sizeBytes() const -- cgit v1.2.3