From 8c0163bcb48df56112a625550d411741c20c5846 Mon Sep 17 00:00:00 2001 From: Dave Houlton Date: Wed, 13 Apr 2022 12:32:58 -0600 Subject: SL-17214 initial loader class skeleton --- indra/llmath/v4color.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'indra/llmath') diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h index 175edf1471..f2863be531 100644 --- a/indra/llmath/v4color.h +++ b/indra/llmath/v4color.h @@ -88,7 +88,8 @@ class LLColor4 const LLColor4& set(const LLColor3 &vec); // Sets LLColor4 to LLColor3 vec (no change in alpha) const LLColor4& set(const LLColor3 &vec, F32 a); // Sets LLColor4 to LLColor3 vec, with alpha specified const LLColor4& set(const F32 *vec); // Sets LLColor4 to vec - const LLColor4& set(const LLColor4U& color4u); // Sets LLColor4 to color4u, rescaled. + const LLColor4& set(const F64 *vec); // Sets LLColor4 to (double)vec + const LLColor4& set(const LLColor4U& color4u); // Sets LLColor4 to color4u, rescaled. const LLColor4& setAlpha(F32 a); @@ -334,6 +335,15 @@ inline const LLColor4& LLColor4::set(const F32 *vec) return (*this); } +inline const LLColor4& LLColor4::set(const F64 *vec) +{ + mV[VX] = static_cast(vec[VX]); + mV[VY] = static_cast(vec[VY]); + mV[VZ] = static_cast(vec[VZ]); + mV[VW] = static_cast(vec[VW]); + return (*this); +} + // deprecated inline const LLColor4& LLColor4::setVec(F32 x, F32 y, F32 z) { -- cgit v1.2.3 From 8ad7240a3bb626ebaabcc81fb8155a8cbb5adf39 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 8 Sep 2022 10:06:53 -0500 Subject: SL-18095 WIP -- Add Mikktspace tangent generation for PBR materials and switch to per-pixel binormal generation. Still bugged with some test content. --- indra/llmath/llvolume.cpp | 272 ++++++++++++++++++++++++++++++++++++++++------ indra/llmath/llvolume.h | 7 +- 2 files changed, 244 insertions(+), 35 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 4a069b0f63..539db9d0e1 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -32,6 +32,7 @@ #include #endif #include +#include #include "llerror.h" @@ -52,6 +53,9 @@ #include "llmeshoptimizer.h" #include "lltimer.h" +#include "mikktspace/mikktspace.h" +#include "mikktspace/mikktspace.c" // insert mikktspace implementation into llvolume object file + #define DEBUG_SILHOUETTE_BINORMALS 0 #define DEBUG_SILHOUETTE_NORMALS 0 // TomY: Use this to display normals using the silhouette #define DEBUG_SILHOUETTE_EDGE_MAP 0 // DaveP: Use this to display edge map using the silhouette @@ -2096,9 +2100,9 @@ void LLVolume::regen() createVolumeFaces(); } -void LLVolume::genTangents(S32 face) +void LLVolume::genTangents(S32 face, bool mikktspace) { - mVolumeFaces[face].createTangents(); + mVolumeFaces[face].createTangents(mikktspace); } LLVolume::~LLVolume() @@ -4797,6 +4801,17 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src) mTangents = NULL; } + if (src.mMikktSpaceTangents) + { + allocateTangents(src.mNumVertices, true); + LLVector4a::memcpyNonAliased16((F32*)mMikktSpaceTangents, (F32*)src.mMikktSpaceTangents, vert_size); + } + else + { + ll_aligned_free_16(mMikktSpaceTangents); + mMikktSpaceTangents = nullptr; + } + if (src.mWeights) { llassert(!mWeights); // don't orphan an old alloc here accidentally @@ -4867,6 +4882,8 @@ void LLVolumeFace::freeData() mIndices = NULL; ll_aligned_free_16(mTangents); mTangents = NULL; + ll_aligned_free_16(mMikktSpaceTangents); + mMikktSpaceTangents = nullptr; ll_aligned_free_16(mWeights); mWeights = NULL; @@ -4988,6 +5005,9 @@ void LLVolumeFace::remap() ll_aligned_free_16(mTangents); mTangents = NULL; + ll_aligned_free_16(mMikktSpaceTangents); + mMikktSpaceTangents = nullptr; + // Assign new values mIndices = remap_indices; mPositions = remap_positions; @@ -5514,6 +5534,12 @@ bool LLVolumeFace::cacheOptimize() } } + llassert(mTangents == nullptr); // cache optimize called too late, tangents already generated + llassert(mMikktSpaceTangents == nullptr); + + // ===================================================================================== + // DEPRECATED -- cacheOptimize should always be called before tangents are generated + // ===================================================================================== LLVector4a* binorm = NULL; if (mTangents) { @@ -5526,11 +5552,11 @@ bool LLVolumeFace::cacheOptimize() return false; } } + // ===================================================================================== - //allocate mapping of old indices to new indices + //allocate mapping of old indices to new indices std::vector new_idx; - - try + try { new_idx.resize(mNumVertices, -1); } @@ -5673,6 +5699,7 @@ void LLVolumeFace::swapData(LLVolumeFace& rhs) llswap(rhs.mPositions, mPositions); llswap(rhs.mNormals, mNormals); llswap(rhs.mTangents, mTangents); + llswap(rhs.mMikktSpaceTangents, mMikktSpaceTangents); llswap(rhs.mTexCoords, mTexCoords); llswap(rhs.mIndices,mIndices); llswap(rhs.mNumVertices, mNumVertices); @@ -6380,37 +6407,217 @@ BOOL LLVolumeFace::createCap(LLVolume* volume, BOOL partial_build) void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal, const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent); -void LLVolumeFace::createTangents() + +// data structures for tangent generation + +// key for summing tangents +// We will blend tangents wherever a common position and normal is found +struct MikktKey { - LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME + // Position + LLVector3 p; + // Normal + LLVector3 n; - if (!mTangents) - { - allocateTangents(mNumVertices); + bool operator==(const MikktKey& rhs) const { return p == rhs.p && n == rhs.n; } +}; - //generate tangents - //LLVector4a* pos = mPositions; - //LLVector2* tc = (LLVector2*) mTexCoords; - LLVector4a* binorm = (LLVector4a*) mTangents; +// sum of tangents and list of signs and index array indices for a given position and normal combination +// sign must be kept separate from summed tangent because a single position and normal may have a different +// tangent facing where UV seams exist +struct MikktTangent +{ + // tangent vector + LLVector3 t; + // signs + std::vector s; + // indices (in index array) + std::vector i; +}; - LLVector4a* end = mTangents+mNumVertices; - while (binorm < end) - { - (*binorm++).clear(); - } +// hash function for MikktTangent +namespace boost +{ + template <> + struct hash + { + std::size_t operator()(LLVector3 const& k) const + { + size_t seed = 0; + boost::hash_combine(seed, k.mV[0]); + boost::hash_combine(seed, k.mV[1]); + boost::hash_combine(seed, k.mV[2]); + return seed; + } + }; + + template <> + struct hash + { + std::size_t operator()(MikktKey const& k) const + { + size_t seed = 0; + boost::hash_combine(seed, k.p); + boost::hash_combine(seed, k.n); + return seed; + } + }; +} + +// boost adapter +namespace std +{ + template<> + struct hash + { + std::size_t operator()(MikktKey const& k) const + { + return boost::hash()(k); + } + }; +} + +struct MikktData +{ + LLVolumeFace* face; + std::unordered_map tangents; +}; - binorm = mTangents; - CalculateTangentArray(mNumVertices, mPositions, mNormals, mTexCoords, mNumIndices/3, mIndices, mTangents); +void LLVolumeFace::createTangents(bool mikktspace) +{ + LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME; - //normalize tangents - for (U32 i = 0; i < mNumVertices; i++) - { - //binorm[i].normalize3fast(); - //bump map/planar projection code requires normals to be normalized - mNormals[i].normalize3fast(); - } - } + auto& tangents = mikktspace ? mMikktSpaceTangents : mTangents; + + if (!tangents) + { + allocateTangents(mNumVertices, mikktspace); + + if (mikktspace) + { + LL_PROFILE_ZONE_NAMED_CATEGORY_VOLUME("mikktspace"); + SMikkTSpaceInterface ms; + + ms.m_getNumFaces = [](const SMikkTSpaceContext* pContext) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + return face->mNumIndices / 3; + }; + + ms.m_getNumVerticesOfFace = [](const SMikkTSpaceContext* pContext, const int iFace) + { + return 3; + }; + + ms.m_getPosition = [](const SMikkTSpaceContext* pContext, float fvPosOut[], const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 idx = face->mIndices[iFace * 3 + iVert]; + auto& vert = face->mPositions[idx]; + F32* v = vert.getF32ptr(); + fvPosOut[0] = v[0]; + fvPosOut[1] = v[1]; + fvPosOut[2] = v[2]; + }; + + ms.m_getNormal = [](const SMikkTSpaceContext* pContext, float fvNormOut[], const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 idx = face->mIndices[iFace * 3 + iVert]; + auto& norm = face->mNormals[idx]; + F32* n = norm.getF32ptr(); + fvNormOut[0] = n[0]; + fvNormOut[1] = n[1]; + fvNormOut[2] = n[2]; + }; + + ms.m_getTexCoord = [](const SMikkTSpaceContext* pContext, float fvTexcOut[], const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 idx = face->mIndices[iFace * 3 + iVert]; + auto& tc = face->mTexCoords[idx]; + fvTexcOut[0] = tc.mV[0]; + fvTexcOut[1] = tc.mV[1]; + }; + + ms.m_setTSpaceBasic = [](const SMikkTSpaceContext* pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 i = iFace * 3 + iVert; + S32 idx = face->mIndices[i]; + + LLVector3 p(face->mPositions[idx].getF32ptr()); + LLVector3 n(face->mNormals[idx].getF32ptr()); + LLVector3 t(fvTangent); + + MikktKey key = { p, n }; + + MikktTangent& mt = data->tangents[key]; + mt.t += t; + mt.s.push_back(fSign); + mt.i.push_back(i); + }; + + ms.m_setTSpace = nullptr; + + MikktData data; + data.face = this; + + SMikkTSpaceContext ctx = { &ms, &data }; + + genTangSpaceDefault(&ctx); + + for (U32 i = 0; i < mNumVertices; ++i) + { + MikktKey key = { LLVector3(mPositions[i].getF32ptr()), LLVector3(mNormals[i].getF32ptr()) }; + MikktTangent& t = data.tangents[key]; + + //set tangent + mMikktSpaceTangents[i].load3(t.t.mV); + mMikktSpaceTangents[i].normalize3fast(); + + //set sign + F32 sign = 0.f; + for (int j = 0; j < t.i.size(); ++j) + { + if (mIndices[t.i[j]] == i) + { + sign = t.s[j]; + break; + } + } + + llassert(sign != 0.f); + mMikktSpaceTangents[i].getF32ptr()[3] = sign; + } + } + else + { + //generate tangents + LLVector4a* ptr = (LLVector4a*)tangents; + + LLVector4a* end = mTangents + mNumVertices; + while (ptr < end) + { + (*ptr++).clear(); + } + + CalculateTangentArray(mNumVertices, mPositions, mNormals, mTexCoords, mNumIndices / 3, mIndices, tangents); + } + + //normalize normals + for (U32 i = 0; i < mNumVertices; i++) + { + //bump map/planar projection code requires normals to be normalized + mNormals[i].normalize3fast(); + } + } } void LLVolumeFace::resizeVertices(S32 num_verts) @@ -6511,10 +6718,11 @@ void LLVolumeFace::pushVertex(const LLVector4a& pos, const LLVector4a& norm, con mNumVertices++; } -void LLVolumeFace::allocateTangents(S32 num_verts) +void LLVolumeFace::allocateTangents(S32 num_verts, bool mikktspace) { - ll_aligned_free_16(mTangents); - mTangents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); + auto& buff = mikktspace ? mMikktSpaceTangents : mTangents; + ll_aligned_free_16(buff); + buff = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); } void LLVolumeFace::allocateWeights(S32 num_verts) diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h index 9697952f5b..8c604c5d1a 100644 --- a/indra/llmath/llvolume.h +++ b/indra/llmath/llvolume.h @@ -870,10 +870,10 @@ private: public: BOOL create(LLVolume* volume, BOOL partial_build = FALSE); - void createTangents(); + void createTangents(bool mikktspace = false); void resizeVertices(S32 num_verts); - void allocateTangents(S32 num_verts); + void allocateTangents(S32 num_verts, bool mikktspace = false); void allocateWeights(S32 num_verts); void allocateJointIndices(S32 num_verts); void resizeIndices(S32 num_indices); @@ -947,6 +947,7 @@ public: LLVector4a* mPositions; // Contains vertices, nortmals and texcoords LLVector4a* mNormals; // pointer into mPositions LLVector4a* mTangents; + LLVector4a* mMikktSpaceTangents = nullptr; // for GLTF rendering, use mikkt space tangents LLVector2* mTexCoords; // pointer into mPositions // mIndices contains mNumIndices amount of elements. @@ -1028,7 +1029,7 @@ public: void setDirty() { mPathp->setDirty(); mProfilep->setDirty(); } void regen(); - void genTangents(S32 face); + void genTangents(S32 face, bool mikktspace = false); BOOL isConvex() const; BOOL isCap(S32 face); -- cgit v1.2.3 From c822da9fe644e4a420caabb30a25b487ce75c099 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 9 Sep 2022 20:56:22 -0500 Subject: SL-18095 WIP -- Allow mikktspace generator to add more vertices (skip re-welding step for now). --- indra/llmath/llvolume.cpp | 551 ++++++++++++---------------------------------- indra/llmath/llvolume.h | 2 +- 2 files changed, 139 insertions(+), 414 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 539db9d0e1..0ce1577d00 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -2102,7 +2102,12 @@ void LLVolume::regen() void LLVolume::genTangents(S32 face, bool mikktspace) { - mVolumeFaces[face].createTangents(mikktspace); + // generate legacy tangents for the specified face + // if mikktspace is true, only generate tangents if mikktspace tangents are not present (handles the case for non-mesh prims) + if (!mikktspace || mVolumeFaces[face].mMikktSpaceTangents == nullptr) + { + mVolumeFaces[face].createTangents(); + } } LLVolume::~LLVolume() @@ -5373,252 +5378,155 @@ public: } }; +// data structures for tangent generation -bool LLVolumeFace::cacheOptimize() -{ //optimize for vertex cache according to Forsyth method: - // http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html - - llassert(!mOptimized); - mOptimized = TRUE; - - LLVCacheLRU cache; - - if (mNumVertices < 3 || mNumIndices < 3) - { //nothing to do - return true; - } +struct MikktData +{ + LLVolumeFace* face; + std::vector p; + std::vector n; + std::vector tc; + std::vector w; + std::vector t; + + MikktData(LLVolumeFace* f) + : face(f) + { + U32 count = face->mNumIndices; - //mapping of vertices to triangles and indices - std::vector vertex_data; + p.resize(count); + n.resize(count); + tc.resize(count); + t.resize(count); - //mapping of triangles do vertices - std::vector triangle_data; + if (face->mWeights) + { + w.resize(count); + } - try - { - triangle_data.resize(mNumIndices / 3); - vertex_data.resize(mNumVertices); + for (int i = 0; i < face->mNumIndices; ++i) + { + U32 idx = face->mIndices[i]; - for (U32 i = 0; i < mNumIndices; i++) - { //populate vertex data and triangle data arrays - U16 idx = mIndices[i]; - U32 tri_idx = i / 3; + p[i].set(face->mPositions[idx].getF32ptr()); + n[i].set(face->mNormals[idx].getF32ptr()); + tc[i].set(face->mTexCoords[idx]); - vertex_data[idx].mTriangles.push_back(&(triangle_data[tri_idx])); - vertex_data[idx].mIdx = idx; - triangle_data[tri_idx].mVertex[i % 3] = &(vertex_data[idx]); + if (face->mWeights) + { + w[i].set(face->mWeights[idx].getF32ptr()); + } } } - catch (std::bad_alloc&) - { - // resize or push_back failed - LL_WARNS("LLVOLUME") << "Resize for " << mNumVertices << " vertices failed" << LL_ENDL; - return false; - } - - /*F32 pre_acmr = 1.f; - //measure cache misses from before rebuild - { - LLVCacheFIFO test_cache; - for (U32 i = 0; i < mNumIndices; ++i) - { - test_cache.addVertex(&vertex_data[mIndices[i]]); - } - - for (U32 i = 0; i < mNumVertices; i++) - { - vertex_data[i].mCacheTag = -1; - } - - pre_acmr = (F32) test_cache.mMisses/(mNumIndices/3); - }*/ - - for (U32 i = 0; i < mNumVertices; i++) - { //initialize score values (no cache -- might try a fifo cache here) - LLVCacheVertexData& data = vertex_data[i]; - - data.mScore = find_vertex_score(data); - data.mActiveTriangles = data.mTriangles.size(); +}; - for (U32 j = 0; j < data.mActiveTriangles; ++j) - { - data.mTriangles[j]->mScore += data.mScore; - } - } - //sort triangle data by score - std::sort(triangle_data.begin(), triangle_data.end()); +bool LLVolumeFace::cacheOptimize() +{ //optimize for vertex cache according to Forsyth method: + LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME; + llassert(!mOptimized); + mOptimized = TRUE; - std::vector new_indices; + allocateTangents(mNumVertices, true); - LLVCacheTriangleData* tri; + SMikkTSpaceInterface ms; - //prime pump by adding first triangle to cache; - tri = &(triangle_data[0]); - cache.addTriangle(tri); - new_indices.push_back(tri->mVertex[0]->mIdx); - new_indices.push_back(tri->mVertex[1]->mIdx); - new_indices.push_back(tri->mVertex[2]->mIdx); - tri->complete(); + ms.m_getNumFaces = [](const SMikkTSpaceContext* pContext) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + return face->mNumIndices / 3; + }; - U32 breaks = 0; - for (U32 i = 1; i < mNumIndices/3; ++i) - { - cache.updateScores(); - tri = cache.mBestTriangle; - if (!tri) - { - breaks++; - for (U32 j = 0; j < triangle_data.size(); ++j) - { - if (triangle_data[j].mActive) - { - tri = &(triangle_data[j]); - break; - } - } - } - - cache.addTriangle(tri); - new_indices.push_back(tri->mVertex[0]->mIdx); - new_indices.push_back(tri->mVertex[1]->mIdx); - new_indices.push_back(tri->mVertex[2]->mIdx); - tri->complete(); - } + ms.m_getNumVerticesOfFace = [](const SMikkTSpaceContext* pContext, const int iFace) + { + return 3; + }; - for (U32 i = 0; i < mNumIndices; ++i) - { - mIndices[i] = new_indices[i]; - } + ms.m_getPosition = [](const SMikkTSpaceContext* pContext, float fvPosOut[], const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 idx = face->mIndices[iFace * 3 + iVert]; + auto& vert = face->mPositions[idx]; + F32* v = vert.getF32ptr(); + fvPosOut[0] = v[0]; + fvPosOut[1] = v[1]; + fvPosOut[2] = v[2]; + }; - /*F32 post_acmr = 1.f; - //measure cache misses from after rebuild - { - LLVCacheFIFO test_cache; - for (U32 i = 0; i < mNumVertices; i++) - { - vertex_data[i].mCacheTag = -1; - } + ms.m_getNormal = [](const SMikkTSpaceContext* pContext, float fvNormOut[], const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 idx = face->mIndices[iFace * 3 + iVert]; + auto& norm = face->mNormals[idx]; + F32* n = norm.getF32ptr(); + fvNormOut[0] = n[0]; + fvNormOut[1] = n[1]; + fvNormOut[2] = n[2]; + }; - for (U32 i = 0; i < mNumIndices; ++i) - { - test_cache.addVertex(&vertex_data[mIndices[i]]); - } - - post_acmr = (F32) test_cache.mMisses/(mNumIndices/3); - }*/ + ms.m_getTexCoord = [](const SMikkTSpaceContext* pContext, float fvTexcOut[], const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 idx = face->mIndices[iFace * 3 + iVert]; + auto& tc = face->mTexCoords[idx]; + fvTexcOut[0] = tc.mV[0]; + fvTexcOut[1] = tc.mV[1]; + }; - //optimize for pre-TnL cache - - //allocate space for new buffer - S32 num_verts = mNumVertices; - S32 size = ((num_verts*sizeof(LLVector2)) + 0xF) & ~0xF; - LLVector4a* pos = (LLVector4a*) ll_aligned_malloc<64>(sizeof(LLVector4a)*2*num_verts+size); - if (pos == NULL) - { - LL_WARNS("LLVOLUME") << "Allocation of positions vector[" << sizeof(LLVector4a) * 2 * num_verts + size << "] failed. " << LL_ENDL; - return false; - } - LLVector4a* norm = pos + num_verts; - LLVector2* tc = (LLVector2*) (norm + num_verts); + ms.m_setTSpaceBasic = [](const SMikkTSpaceContext* pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 i = iFace * 3 + iVert; + S32 idx = face->mIndices[i]; - LLVector4a* wght = NULL; - if (mWeights) - { - wght = (LLVector4a*)ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); - if (wght == NULL) - { - ll_aligned_free<64>(pos); - LL_WARNS("LLVOLUME") << "Allocation of weights[" << sizeof(LLVector4a) * num_verts << "] failed" << LL_ENDL; - return false; - } - } + LLVector3 p(face->mPositions[idx].getF32ptr()); + LLVector3 n(face->mNormals[idx].getF32ptr()); + LLVector3 t(fvTangent); - llassert(mTangents == nullptr); // cache optimize called too late, tangents already generated - llassert(mMikktSpaceTangents == nullptr); + data->t[i].set(fvTangent); + data->t[i].mV[3] = fSign; + }; - // ===================================================================================== - // DEPRECATED -- cacheOptimize should always be called before tangents are generated - // ===================================================================================== - LLVector4a* binorm = NULL; - if (mTangents) - { - binorm = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); - if (binorm == NULL) - { - ll_aligned_free<64>(pos); - ll_aligned_free_16(wght); - LL_WARNS("LLVOLUME") << "Allocation of binormals[" << sizeof(LLVector4a)*num_verts << "] failed" << LL_ENDL; - return false; - } - } - // ===================================================================================== + ms.m_setTSpace = nullptr; - //allocate mapping of old indices to new indices - std::vector new_idx; - try - { - new_idx.resize(mNumVertices, -1); - } - catch (std::bad_alloc&) - { - ll_aligned_free<64>(pos); - ll_aligned_free_16(wght); - ll_aligned_free_16(binorm); - LL_WARNS("LLVOLUME") << "Resize failed: " << mNumVertices << LL_ENDL; - return false; - } + MikktData data(this); - S32 cur_idx = 0; - for (U32 i = 0; i < mNumIndices; ++i) - { - U16 idx = mIndices[i]; - if (new_idx[idx] == -1) - { //this vertex hasn't been added yet - new_idx[idx] = cur_idx; + SMikkTSpaceContext ctx = { &ms, &data }; - //copy vertex data - pos[cur_idx] = mPositions[idx]; - norm[cur_idx] = mNormals[idx]; - tc[cur_idx] = mTexCoords[idx]; - if (mWeights) - { - wght[cur_idx] = mWeights[idx]; - } - if (mTangents) - { - binorm[cur_idx] = mTangents[idx]; - } + genTangSpaceDefault(&ctx); + + resizeVertices(data.p.size()); + resizeIndices(data.p.size()); + + if (!data.w.empty()) + { + allocateWeights(data.w.size()); + } - cur_idx++; - } - } + allocateTangents(mNumVertices, true); - for (U32 i = 0; i < mNumIndices; ++i) - { - mIndices[i] = new_idx[mIndices[i]]; - } - - ll_aligned_free<64>(mPositions); - // DO NOT free mNormals and mTexCoords as they are part of mPositions buffer - ll_aligned_free_16(mWeights); - ll_aligned_free_16(mTangents); -#if USE_SEPARATE_JOINT_INDICES_AND_WEIGHTS - ll_aligned_free_16(mJointIndices); - ll_aligned_free_16(mJustWeights); - mJustWeights = NULL; - mJointIndices = NULL; // filled in later as necessary by skinning code for acceleration -#endif + for (int i = 0; i < mNumIndices; ++i) + { + mIndices[i] = i; - mPositions = pos; - mNormals = norm; - mTexCoords = tc; - mWeights = wght; - mTangents = binorm; + mPositions[i].load3(data.p[i].mV); + mNormals[i].load3(data.n[i].mV); + mTexCoords[i] = data.tc[i]; + + mMikktSpaceTangents[i].loadua(data.t[i].mV); - //std::string result = llformat("ACMR pre/post: %.3f/%.3f -- %d triangles %d breaks", pre_acmr, post_acmr, mNumIndices/3, breaks); - //LL_INFOS() << result << LL_ENDL; + if (mWeights) + { + mWeights[i].loadua(data.w[i].mV); + } + } + return true; } @@ -6407,209 +6315,25 @@ BOOL LLVolumeFace::createCap(LLVolume* volume, BOOL partial_build) void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal, const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent); - -// data structures for tangent generation - -// key for summing tangents -// We will blend tangents wherever a common position and normal is found -struct MikktKey -{ - // Position - LLVector3 p; - // Normal - LLVector3 n; - - bool operator==(const MikktKey& rhs) const { return p == rhs.p && n == rhs.n; } -}; - -// sum of tangents and list of signs and index array indices for a given position and normal combination -// sign must be kept separate from summed tangent because a single position and normal may have a different -// tangent facing where UV seams exist -struct MikktTangent -{ - // tangent vector - LLVector3 t; - // signs - std::vector s; - // indices (in index array) - std::vector i; -}; - -// hash function for MikktTangent -namespace boost -{ - template <> - struct hash - { - std::size_t operator()(LLVector3 const& k) const - { - size_t seed = 0; - boost::hash_combine(seed, k.mV[0]); - boost::hash_combine(seed, k.mV[1]); - boost::hash_combine(seed, k.mV[2]); - return seed; - } - }; - - template <> - struct hash - { - std::size_t operator()(MikktKey const& k) const - { - size_t seed = 0; - boost::hash_combine(seed, k.p); - boost::hash_combine(seed, k.n); - return seed; - } - }; -} - -// boost adapter -namespace std -{ - template<> - struct hash - { - std::size_t operator()(MikktKey const& k) const - { - return boost::hash()(k); - } - }; -} - -struct MikktData -{ - LLVolumeFace* face; - std::unordered_map tangents; -}; - - -void LLVolumeFace::createTangents(bool mikktspace) +void LLVolumeFace::createTangents() { LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME; - auto& tangents = mikktspace ? mMikktSpaceTangents : mTangents; - - if (!tangents) + + if (!mTangents) { - allocateTangents(mNumVertices, mikktspace); + allocateTangents(mNumVertices); + + //generate tangents + LLVector4a* ptr = (LLVector4a*)mTangents; - if (mikktspace) + LLVector4a* end = mTangents + mNumVertices; + while (ptr < end) { - LL_PROFILE_ZONE_NAMED_CATEGORY_VOLUME("mikktspace"); - SMikkTSpaceInterface ms; - - ms.m_getNumFaces = [](const SMikkTSpaceContext* pContext) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - return face->mNumIndices / 3; - }; - - ms.m_getNumVerticesOfFace = [](const SMikkTSpaceContext* pContext, const int iFace) - { - return 3; - }; - - ms.m_getPosition = [](const SMikkTSpaceContext* pContext, float fvPosOut[], const int iFace, const int iVert) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 idx = face->mIndices[iFace * 3 + iVert]; - auto& vert = face->mPositions[idx]; - F32* v = vert.getF32ptr(); - fvPosOut[0] = v[0]; - fvPosOut[1] = v[1]; - fvPosOut[2] = v[2]; - }; - - ms.m_getNormal = [](const SMikkTSpaceContext* pContext, float fvNormOut[], const int iFace, const int iVert) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 idx = face->mIndices[iFace * 3 + iVert]; - auto& norm = face->mNormals[idx]; - F32* n = norm.getF32ptr(); - fvNormOut[0] = n[0]; - fvNormOut[1] = n[1]; - fvNormOut[2] = n[2]; - }; - - ms.m_getTexCoord = [](const SMikkTSpaceContext* pContext, float fvTexcOut[], const int iFace, const int iVert) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 idx = face->mIndices[iFace * 3 + iVert]; - auto& tc = face->mTexCoords[idx]; - fvTexcOut[0] = tc.mV[0]; - fvTexcOut[1] = tc.mV[1]; - }; - - ms.m_setTSpaceBasic = [](const SMikkTSpaceContext* pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 i = iFace * 3 + iVert; - S32 idx = face->mIndices[i]; - - LLVector3 p(face->mPositions[idx].getF32ptr()); - LLVector3 n(face->mNormals[idx].getF32ptr()); - LLVector3 t(fvTangent); - - MikktKey key = { p, n }; - - MikktTangent& mt = data->tangents[key]; - mt.t += t; - mt.s.push_back(fSign); - mt.i.push_back(i); - }; - - ms.m_setTSpace = nullptr; - - MikktData data; - data.face = this; - - SMikkTSpaceContext ctx = { &ms, &data }; - - genTangSpaceDefault(&ctx); - - for (U32 i = 0; i < mNumVertices; ++i) - { - MikktKey key = { LLVector3(mPositions[i].getF32ptr()), LLVector3(mNormals[i].getF32ptr()) }; - MikktTangent& t = data.tangents[key]; - - //set tangent - mMikktSpaceTangents[i].load3(t.t.mV); - mMikktSpaceTangents[i].normalize3fast(); - - //set sign - F32 sign = 0.f; - for (int j = 0; j < t.i.size(); ++j) - { - if (mIndices[t.i[j]] == i) - { - sign = t.s[j]; - break; - } - } - - llassert(sign != 0.f); - mMikktSpaceTangents[i].getF32ptr()[3] = sign; - } + (*ptr++).clear(); } - else - { - //generate tangents - LLVector4a* ptr = (LLVector4a*)tangents; - - LLVector4a* end = mTangents + mNumVertices; - while (ptr < end) - { - (*ptr++).clear(); - } - CalculateTangentArray(mNumVertices, mPositions, mNormals, mTexCoords, mNumIndices / 3, mIndices, tangents); - } + CalculateTangentArray(mNumVertices, mPositions, mNormals, mTexCoords, mNumIndices / 3, mIndices, mTangents); //normalize normals for (U32 i = 0; i < mNumVertices; i++) @@ -6618,6 +6342,7 @@ void LLVolumeFace::createTangents(bool mikktspace) mNormals[i].normalize3fast(); } } + } void LLVolumeFace::resizeVertices(S32 num_verts) diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h index 8c604c5d1a..f1feaade58 100644 --- a/indra/llmath/llvolume.h +++ b/indra/llmath/llvolume.h @@ -870,7 +870,7 @@ private: public: BOOL create(LLVolume* volume, BOOL partial_build = FALSE); - void createTangents(bool mikktspace = false); + void createTangents(); void resizeVertices(S32 num_verts); void allocateTangents(S32 num_verts, bool mikktspace = false); -- cgit v1.2.3 From d7c77e5c64ddfef44b3e47f4c7ae6943ff0e860a Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 12 Sep 2022 11:48:16 -0500 Subject: SL-18095 WIP -- Use meshoptimizer to re-weld and cache optimize after generating tangents --- indra/llmath/llvolume.cpp | 56 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 0ce1577d00..fca9471f14 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -56,6 +56,8 @@ #include "mikktspace/mikktspace.h" #include "mikktspace/mikktspace.c" // insert mikktspace implementation into llvolume object file +#include "meshoptimizer/meshoptimizer.h" + #define DEBUG_SILHOUETTE_BINORMALS 0 #define DEBUG_SILHOUETTE_NORMALS 0 // TomY: Use this to display normals using the silhouette #define DEBUG_SILHOUETTE_EDGE_MAP 0 // DaveP: Use this to display edge map using the silhouette @@ -5499,34 +5501,66 @@ bool LLVolumeFace::cacheOptimize() SMikkTSpaceContext ctx = { &ms, &data }; genTangSpaceDefault(&ctx); - - resizeVertices(data.p.size()); - resizeIndices(data.p.size()); - + + //re-weld + meshopt_Stream mos[] = + { + { &data.p[0], sizeof(LLVector3), sizeof(LLVector3) }, + { &data.n[0], sizeof(LLVector3), sizeof(LLVector3) }, + { &data.t[0], sizeof(LLVector4), sizeof(LLVector4) }, + { &data.tc[0], sizeof(LLVector2), sizeof(LLVector2) }, + { data.w.empty() ? nullptr : &data.w[0], sizeof(LLVector4), sizeof(LLVector4) } + }; + + std::vector remap; + remap.resize(data.p.size()); + + U32 stream_count = data.w.empty() ? 4 : 5; + + U32 vert_count = meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count); + + std::vector indices; + indices.resize(mNumIndices); + + //copy results back into volume + resizeVertices(vert_count); + if (!data.w.empty()) { - allocateWeights(data.w.size()); + allocateWeights(vert_count); } allocateTangents(mNumVertices, true); for (int i = 0; i < mNumIndices; ++i) { - mIndices[i] = i; + U32 src_idx = i; + U32 dst_idx = remap[i]; + mIndices[i] = dst_idx; - mPositions[i].load3(data.p[i].mV); - mNormals[i].load3(data.n[i].mV); - mTexCoords[i] = data.tc[i]; + mPositions[dst_idx].load3(data.p[src_idx].mV); + mNormals[dst_idx].load3(data.n[src_idx].mV); + mTexCoords[dst_idx] = data.tc[src_idx]; - mMikktSpaceTangents[i].loadua(data.t[i].mV); + mMikktSpaceTangents[dst_idx].loadua(data.t[src_idx].mV); if (mWeights) { - mWeights[i].loadua(data.w[i].mV); + mWeights[dst_idx].loadua(data.w[src_idx].mV); } } + // cache optimize index buffer + + // meshopt needs scratch space, do some pointer shuffling to avoid an extra index buffer copy + U16* src_indices = mIndices; + mIndices = nullptr; + resizeIndices(mNumIndices); + + meshopt_optimizeVertexCache(mIndices, src_indices, mNumIndices, mNumVertices); + ll_aligned_free_16(src_indices); + return true; } -- cgit v1.2.3 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/llmath/llvolume.cpp | 233 +++++++++++++++++++++++++++------------------- 1 file changed, 135 insertions(+), 98 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index fca9471f14..563a325f03 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -2431,11 +2431,10 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) LLSD::Binary pos = mdl[i]["Position"]; LLSD::Binary norm = mdl[i]["Normal"]; + LLSD::Binary tangent = mdl[i]["Tangent"]; LLSD::Binary tc = mdl[i]["TexCoord0"]; LLSD::Binary idx = mdl[i]["TriangleList"]; - - //copy out indices S32 num_indices = idx.size() / 2; face.resizeIndices(num_indices); @@ -2534,6 +2533,33 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) } } + { + if (!tangent.empty()) + { + face.allocateTangents(face.mNumVertices, true); + U16* t = (U16*)&(tangent[0]); + + // store incoming tangents in mMikktSpaceTangents + // NOTE: tangents coming from the asset may not be mikkt space, but they should always be used by the CLTF shaders to + // maintain compliance with the GLTF spec + LLVector4a* t_out = face.mMikktSpaceTangents; + + for (U32 j = 0; j < num_verts; ++j) + { + t_out->set((F32)t[0], (F32)t[1], (F32)t[2], (F32) t[3]); + t_out->div(65535.f); + t_out->mul(2.f); + t_out->sub(1.f); + + F32* tp = t_out->getF32ptr(); + tp[3] = tp[3] < 0.f ? -1.f : 1.f; + + t_out++; + t += 4; + } + } + } + { if (!tc.empty()) { @@ -5429,124 +5455,135 @@ bool LLVolumeFace::cacheOptimize() llassert(!mOptimized); mOptimized = TRUE; - allocateTangents(mNumVertices, true); + if (!mNormals || !mTexCoords) + { // can't perform this operation without normals and texture coordinates + return false; + } - SMikkTSpaceInterface ms; + if (mMikktSpaceTangents == nullptr) + { // make sure to generate mikkt space tangents for cache optimizing since the index buffer may change + allocateTangents(mNumVertices, true); - ms.m_getNumFaces = [](const SMikkTSpaceContext* pContext) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - return face->mNumIndices / 3; - }; + SMikkTSpaceInterface ms; - ms.m_getNumVerticesOfFace = [](const SMikkTSpaceContext* pContext, const int iFace) - { - return 3; - }; + ms.m_getNumFaces = [](const SMikkTSpaceContext* pContext) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + return face->mNumIndices / 3; + }; - ms.m_getPosition = [](const SMikkTSpaceContext* pContext, float fvPosOut[], const int iFace, const int iVert) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 idx = face->mIndices[iFace * 3 + iVert]; - auto& vert = face->mPositions[idx]; - F32* v = vert.getF32ptr(); - fvPosOut[0] = v[0]; - fvPosOut[1] = v[1]; - fvPosOut[2] = v[2]; - }; - - ms.m_getNormal = [](const SMikkTSpaceContext* pContext, float fvNormOut[], const int iFace, const int iVert) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 idx = face->mIndices[iFace * 3 + iVert]; - auto& norm = face->mNormals[idx]; - F32* n = norm.getF32ptr(); - fvNormOut[0] = n[0]; - fvNormOut[1] = n[1]; - fvNormOut[2] = n[2]; - }; - - ms.m_getTexCoord = [](const SMikkTSpaceContext* pContext, float fvTexcOut[], const int iFace, const int iVert) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 idx = face->mIndices[iFace * 3 + iVert]; - auto& tc = face->mTexCoords[idx]; - fvTexcOut[0] = tc.mV[0]; - fvTexcOut[1] = tc.mV[1]; - }; - - ms.m_setTSpaceBasic = [](const SMikkTSpaceContext* pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert) - { - MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 i = iFace * 3 + iVert; - S32 idx = face->mIndices[i]; + ms.m_getNumVerticesOfFace = [](const SMikkTSpaceContext* pContext, const int iFace) + { + return 3; + }; - LLVector3 p(face->mPositions[idx].getF32ptr()); - LLVector3 n(face->mNormals[idx].getF32ptr()); - LLVector3 t(fvTangent); + ms.m_getPosition = [](const SMikkTSpaceContext* pContext, float fvPosOut[], const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 idx = face->mIndices[iFace * 3 + iVert]; + auto& vert = face->mPositions[idx]; + F32* v = vert.getF32ptr(); + fvPosOut[0] = v[0]; + fvPosOut[1] = v[1]; + fvPosOut[2] = v[2]; + }; + + ms.m_getNormal = [](const SMikkTSpaceContext* pContext, float fvNormOut[], const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 idx = face->mIndices[iFace * 3 + iVert]; + auto& norm = face->mNormals[idx]; + F32* n = norm.getF32ptr(); + fvNormOut[0] = n[0]; + fvNormOut[1] = n[1]; + fvNormOut[2] = n[2]; + }; + + ms.m_getTexCoord = [](const SMikkTSpaceContext* pContext, float fvTexcOut[], const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 idx = face->mIndices[iFace * 3 + iVert]; + auto& tc = face->mTexCoords[idx]; + fvTexcOut[0] = tc.mV[0]; + fvTexcOut[1] = tc.mV[1]; + }; + + ms.m_setTSpaceBasic = [](const SMikkTSpaceContext* pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert) + { + MikktData* data = (MikktData*)pContext->m_pUserData; + LLVolumeFace* face = data->face; + S32 i = iFace * 3 + iVert; + S32 idx = face->mIndices[i]; - data->t[i].set(fvTangent); - data->t[i].mV[3] = fSign; - }; + LLVector3 p(face->mPositions[idx].getF32ptr()); + LLVector3 n(face->mNormals[idx].getF32ptr()); + LLVector3 t(fvTangent); - ms.m_setTSpace = nullptr; + // assert that this tangent hasn't already been set + llassert(data->t[i].magVec() < 0.1f); - MikktData data(this); + data->t[i].set(fvTangent); + data->t[i].mV[3] = fSign; + }; - SMikkTSpaceContext ctx = { &ms, &data }; + ms.m_setTSpace = nullptr; - genTangSpaceDefault(&ctx); + MikktData data(this); - //re-weld - meshopt_Stream mos[] = - { - { &data.p[0], sizeof(LLVector3), sizeof(LLVector3) }, - { &data.n[0], sizeof(LLVector3), sizeof(LLVector3) }, - { &data.t[0], sizeof(LLVector4), sizeof(LLVector4) }, - { &data.tc[0], sizeof(LLVector2), sizeof(LLVector2) }, - { data.w.empty() ? nullptr : &data.w[0], sizeof(LLVector4), sizeof(LLVector4) } - }; + SMikkTSpaceContext ctx = { &ms, &data }; - std::vector remap; - remap.resize(data.p.size()); + genTangSpaceDefault(&ctx); - U32 stream_count = data.w.empty() ? 4 : 5; + //re-weld + meshopt_Stream mos[] = + { + { &data.p[0], sizeof(LLVector3), sizeof(LLVector3) }, + { &data.n[0], sizeof(LLVector3), sizeof(LLVector3) }, + { &data.t[0], sizeof(LLVector4), sizeof(LLVector4) }, + { &data.tc[0], sizeof(LLVector2), sizeof(LLVector2) }, + { data.w.empty() ? nullptr : &data.w[0], sizeof(LLVector4), sizeof(LLVector4) } + }; - U32 vert_count = meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count); + std::vector remap; + remap.resize(data.p.size()); - std::vector indices; - indices.resize(mNumIndices); + U32 stream_count = data.w.empty() ? 4 : 5; - //copy results back into volume - resizeVertices(vert_count); + U32 vert_count = meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count); - if (!data.w.empty()) - { - allocateWeights(vert_count); - } + std::vector indices; + indices.resize(mNumIndices); - allocateTangents(mNumVertices, true); + //copy results back into volume + resizeVertices(vert_count); - for (int i = 0; i < mNumIndices; ++i) - { - U32 src_idx = i; - U32 dst_idx = remap[i]; - mIndices[i] = dst_idx; + if (!data.w.empty()) + { + allocateWeights(vert_count); + } - mPositions[dst_idx].load3(data.p[src_idx].mV); - mNormals[dst_idx].load3(data.n[src_idx].mV); - mTexCoords[dst_idx] = data.tc[src_idx]; - - mMikktSpaceTangents[dst_idx].loadua(data.t[src_idx].mV); + allocateTangents(mNumVertices, true); - if (mWeights) + for (int i = 0; i < mNumIndices; ++i) { - mWeights[dst_idx].loadua(data.w[src_idx].mV); + U32 src_idx = i; + U32 dst_idx = remap[i]; + mIndices[i] = dst_idx; + + mPositions[dst_idx].load3(data.p[src_idx].mV); + mNormals[dst_idx].load3(data.n[src_idx].mV); + mTexCoords[dst_idx] = data.tc[src_idx]; + + mMikktSpaceTangents[dst_idx].loadua(data.t[src_idx].mV); + + if (mWeights) + { + mWeights[dst_idx].loadua(data.w[src_idx].mV); + } } } -- 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/llmath/llvolume.cpp | 78 ++++++++++++++++++++++++++++++++--------------- indra/llmath/llvolume.h | 6 ++++ 2 files changed, 60 insertions(+), 24 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 563a325f03..ae753fc0f3 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -2483,6 +2483,24 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) min_tc.setValue(mdl[i]["TexCoord0Domain"]["Min"]); max_tc.setValue(mdl[i]["TexCoord0Domain"]["Max"]); + //unpack normalized scale/translation + if (mdl[i].has("NormalizedScale")) + { + face.mNormalizedScale.setValue(mdl[i]["NormalizedScale"]); + } + else + { + face.mNormalizedScale.set(1, 1, 1); + } + if (mdl[i].has("NormalizedTranslation")) + { + face.mNormalizedTranslation.setValue(mdl[i]["NormalizedTranslation"]); + } + else + { + face.mNormalizedTranslation.set(1, 1, 1); + } + LLVector4a pos_range; pos_range.setSub(max_pos, min_pos); LLVector2 tc_range2 = max_tc - min_tc; @@ -2533,6 +2551,7 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) } } +#if 0 { if (!tangent.empty()) { @@ -2559,6 +2578,7 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) } } } +#endif { if (!tc.empty()) @@ -4888,7 +4908,9 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src) } mOptimized = src.mOptimized; - + mNormalizedScale = src.mNormalizedScale; + mNormalizedTranslation = src.mNormalizedTranslation; + //delete return *this; } @@ -5432,12 +5454,19 @@ struct MikktData w.resize(count); } + + LLVector3 inv_scale(1.f / face->mNormalizedScale.mV[0], 1.f / face->mNormalizedScale.mV[1], 1.f / face->mNormalizedScale.mV[2]); + + for (int i = 0; i < face->mNumIndices; ++i) { U32 idx = face->mIndices[i]; p[i].set(face->mPositions[idx].getF32ptr()); + p[i].scaleVec(face->mNormalizedScale); //put mesh in original coordinate frame when reconstructing tangents n[i].set(face->mNormals[idx].getF32ptr()); + n[i].scaleVec(inv_scale); + n[i].normalize(); tc[i].set(face->mTexCoords[idx]); if (face->mWeights) @@ -5481,10 +5510,7 @@ bool LLVolumeFace::cacheOptimize() ms.m_getPosition = [](const SMikkTSpaceContext* pContext, float fvPosOut[], const int iFace, const int iVert) { MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 idx = face->mIndices[iFace * 3 + iVert]; - auto& vert = face->mPositions[idx]; - F32* v = vert.getF32ptr(); + F32* v = data->p[iFace * 3 + iVert].mV; fvPosOut[0] = v[0]; fvPosOut[1] = v[1]; fvPosOut[2] = v[2]; @@ -5493,10 +5519,7 @@ bool LLVolumeFace::cacheOptimize() ms.m_getNormal = [](const SMikkTSpaceContext* pContext, float fvNormOut[], const int iFace, const int iVert) { MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 idx = face->mIndices[iFace * 3 + iVert]; - auto& norm = face->mNormals[idx]; - F32* n = norm.getF32ptr(); + F32* n = data->n[iFace * 3 + iVert].mV; fvNormOut[0] = n[0]; fvNormOut[1] = n[1]; fvNormOut[2] = n[2]; @@ -5505,27 +5528,16 @@ bool LLVolumeFace::cacheOptimize() ms.m_getTexCoord = [](const SMikkTSpaceContext* pContext, float fvTexcOut[], const int iFace, const int iVert) { MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; - S32 idx = face->mIndices[iFace * 3 + iVert]; - auto& tc = face->mTexCoords[idx]; - fvTexcOut[0] = tc.mV[0]; - fvTexcOut[1] = tc.mV[1]; + F32* tc = data->tc[iFace * 3 + iVert].mV; + fvTexcOut[0] = tc[0]; + fvTexcOut[1] = tc[1]; }; ms.m_setTSpaceBasic = [](const SMikkTSpaceContext* pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert) { MikktData* data = (MikktData*)pContext->m_pUserData; - LLVolumeFace* face = data->face; S32 i = iFace * 3 + iVert; - S32 idx = face->mIndices[i]; - - LLVector3 p(face->mPositions[idx].getF32ptr()); - LLVector3 n(face->mNormals[idx].getF32ptr()); - LLVector3 t(fvTangent); - - // assert that this tangent hasn't already been set - llassert(data->t[i].magVec() < 0.1f); - + data->t[i].set(fvTangent); data->t[i].mV[3] = fSign; }; @@ -5585,6 +5597,24 @@ bool LLVolumeFace::cacheOptimize() mWeights[dst_idx].loadua(data.w[src_idx].mV); } } + + + // put back in normalized coordinate frame + LLVector4a inv_scale(1.f/mNormalizedScale.mV[0], 1.f / mNormalizedScale.mV[1], 1.f / mNormalizedScale.mV[2]); + LLVector4a scale; + scale.load3(mNormalizedScale.mV); + scale.getF32ptr()[3] = 1.f; + + for (int i = 0; i < mNumVertices; ++i) + { + mPositions[i].mul(inv_scale); + mNormals[i].mul(scale); + mNormals[i].normalize3(); + F32 w = mMikktSpaceTangents[i].getF32ptr()[3]; + mMikktSpaceTangents[i].mul(scale); + mMikktSpaceTangents[i].normalize3(); + mMikktSpaceTangents[i].getF32ptr()[3] = w; + } } // cache optimize index buffer diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h index f1feaade58..e373d0175d 100644 --- a/indra/llmath/llvolume.h +++ b/indra/llmath/llvolume.h @@ -984,6 +984,12 @@ public: //whether or not face has been cache optimized BOOL mOptimized; + // if this is a mesh asset, scale and translation that were applied + // when encoding the source mesh into a unit cube + // used for regenerating tangents + LLVector3 mNormalizedScale = LLVector3(1,1,1); + LLVector3 mNormalizedTranslation; + private: BOOL createUnCutCubeCap(LLVolume* volume, BOOL partial_build = FALSE); BOOL createCap(LLVolume* volume, BOOL partial_build = FALSE); -- 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/llmath/llvolume.cpp | 15 +++++---------- indra/llmath/llvolume.h | 11 +++++------ 2 files changed, 10 insertions(+), 16 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index ae753fc0f3..559d790d77 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -2783,7 +2783,7 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) } } - if (!cacheOptimize()) + if (!cacheOptimize(true)) { // Out of memory? LL_WARNS() << "Failed to optimize!" << LL_ENDL; @@ -2824,11 +2824,11 @@ void LLVolume::copyVolumeFaces(const LLVolume* volume) mSculptLevel = 0; } -bool LLVolume::cacheOptimize() +bool LLVolume::cacheOptimize(bool gen_tangents) { for (S32 i = 0; i < mVolumeFaces.size(); ++i) { - if (!mVolumeFaces[i].cacheOptimize()) + if (!mVolumeFaces[i].cacheOptimize(gen_tangents)) { return false; } @@ -5478,18 +5478,13 @@ struct MikktData }; -bool LLVolumeFace::cacheOptimize() +bool LLVolumeFace::cacheOptimize(bool gen_tangents) { //optimize for vertex cache according to Forsyth method: LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME; llassert(!mOptimized); mOptimized = TRUE; - if (!mNormals || !mTexCoords) - { // can't perform this operation without normals and texture coordinates - return false; - } - - if (mMikktSpaceTangents == nullptr) + if (mMikktSpaceTangents == nullptr && gen_tangents && mNormals && mTexCoords) { // make sure to generate mikkt space tangents for cache optimizing since the index buffer may change allocateTangents(mNumVertices, true); diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h index e373d0175d..6ea12c6920 100644 --- a/indra/llmath/llvolume.h +++ b/indra/llmath/llvolume.h @@ -907,7 +907,7 @@ public: void remap(); void optimize(F32 angle_cutoff = 2.f); - bool cacheOptimize(); + bool cacheOptimize(bool gen_tangents = false); void createOctree(F32 scaler = 0.25f, const LLVector4a& center = LLVector4a(0,0,0), const LLVector4a& size = LLVector4a(0.5f,0.5f,0.5f)); @@ -957,10 +957,6 @@ public: // indexes for mPositions/mNormals/mTexCoords U16* mIndices; - // vertex buffer filled in by LLFace to cache this volume face geometry in vram - // (declared as a LLPointer to LLRefCount to avoid dependency on LLVertexBuffer) - mutable LLPointer mVertexBuffer; - std::vector mEdge; //list of skin weights for rigged volumes @@ -1089,7 +1085,10 @@ public: void copyVolumeFaces(const LLVolume* volume); void copyFacesTo(std::vector &faces) const; void copyFacesFrom(const std::vector &faces); - bool cacheOptimize(); + + // use meshoptimizer to optimize index buffer for vertex shader cache + // gen_tangents - if true, generate MikkTSpace tangents if needed before optimizing index buffer + bool cacheOptimize(bool gen_tangents = false); private: void sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type); -- 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/llmath/llvolume.cpp | 77 +++++++++++++++++------------------------------ indra/llmath/llvolume.h | 6 ++-- 2 files changed, 30 insertions(+), 53 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 454969b912..21df7f2b2d 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -2102,14 +2102,11 @@ void LLVolume::regen() createVolumeFaces(); } -void LLVolume::genTangents(S32 face, bool mikktspace) +void LLVolume::genTangents(S32 face) { // generate legacy tangents for the specified face - // if mikktspace is true, only generate tangents if mikktspace tangents are not present (handles the case for non-mesh prims) - if (!mikktspace || mVolumeFaces[face].mMikktSpaceTangents == nullptr) - { - mVolumeFaces[face].createTangents(); - } + llassert(!isMeshAssetLoaded() || mVolumeFaces[face].mTangents != nullptr); // if this is a complete mesh asset, we should already have tangents + mVolumeFaces[face].createTangents(); } LLVolume::~LLVolume() @@ -2492,15 +2489,7 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) { face.mNormalizedScale.set(1, 1, 1); } - if (mdl[i].has("NormalizedTranslation")) - { - face.mNormalizedTranslation.setValue(mdl[i]["NormalizedTranslation"]); - } - else - { - face.mNormalizedTranslation.set(1, 1, 1); - } - + LLVector4a pos_range; pos_range.setSub(max_pos, min_pos); LLVector2 tc_range2 = max_tc - min_tc; @@ -2551,17 +2540,16 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) } } -#if 0 +#if 0 // keep this code for now in case we decide to add support for on-the-wire tangents { if (!tangent.empty()) { - face.allocateTangents(face.mNumVertices, true); + face.allocateTangents(face.mNumVertices); U16* t = (U16*)&(tangent[0]); - // store incoming tangents in mMikktSpaceTangents - // NOTE: tangents coming from the asset may not be mikkt space, but they should always be used by the CLTF shaders to + // NOTE: tangents coming from the asset may not be mikkt space, but they should always be used by the GLTF shaders to // maintain compliance with the GLTF spec - LLVector4a* t_out = face.mMikktSpaceTangents; + LLVector4a* t_out = face.mTangents; for (U32 j = 0; j < num_verts; ++j) { @@ -4111,7 +4099,7 @@ S32 LLVolume::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& en { if (tangent_out != NULL) // if the caller wants tangents, we may need to generate them { - genTangents(i); + genTangents(i); } if (isUnique()) @@ -4854,15 +4842,15 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src) mTangents = NULL; } - if (src.mMikktSpaceTangents) + if (src.mTangents) { - allocateTangents(src.mNumVertices, true); - LLVector4a::memcpyNonAliased16((F32*)mMikktSpaceTangents, (F32*)src.mMikktSpaceTangents, vert_size); + allocateTangents(src.mNumVertices); + LLVector4a::memcpyNonAliased16((F32*)mTangents, (F32*)src.mTangents, vert_size); } else { - ll_aligned_free_16(mMikktSpaceTangents); - mMikktSpaceTangents = nullptr; + ll_aligned_free_16(mTangents); + mTangents = nullptr; } if (src.mWeights) @@ -4909,8 +4897,7 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src) mOptimized = src.mOptimized; mNormalizedScale = src.mNormalizedScale; - mNormalizedTranslation = src.mNormalizedTranslation; - + //delete return *this; } @@ -4937,8 +4924,6 @@ void LLVolumeFace::freeData() mIndices = NULL; ll_aligned_free_16(mTangents); mTangents = NULL; - ll_aligned_free_16(mMikktSpaceTangents); - mMikktSpaceTangents = nullptr; ll_aligned_free_16(mWeights); mWeights = NULL; @@ -5060,9 +5045,6 @@ void LLVolumeFace::remap() ll_aligned_free_16(mTangents); mTangents = NULL; - ll_aligned_free_16(mMikktSpaceTangents); - mMikktSpaceTangents = nullptr; - // Assign new values mIndices = remap_indices; mPositions = remap_positions; @@ -5484,10 +5466,10 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents) llassert(!mOptimized); mOptimized = TRUE; - if (mMikktSpaceTangents == nullptr && gen_tangents && mNormals && mTexCoords) - { // make sure to generate mikkt space tangents for cache optimizing since the index buffer may change - allocateTangents(mNumVertices, true); - + if (gen_tangents && mNormals && mTexCoords) + { // generate mikkt space tangents before cache optimizing since the index buffer may change + // a bit of a hack to do this here, but this function gets called exactly once for the lifetime of a mesh + // and is executed on a background thread SMikkTSpaceInterface ms; ms.m_getNumFaces = [](const SMikkTSpaceContext* pContext) @@ -5573,7 +5555,7 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents) allocateWeights(vert_count); } - allocateTangents(mNumVertices, true); + allocateTangents(mNumVertices); for (int i = 0; i < mNumIndices; ++i) { @@ -5585,7 +5567,7 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents) mNormals[dst_idx].load3(data.n[src_idx].mV); mTexCoords[dst_idx] = data.tc[src_idx]; - mMikktSpaceTangents[dst_idx].loadua(data.t[src_idx].mV); + mTangents[dst_idx].loadua(data.t[src_idx].mV); if (mWeights) { @@ -5605,10 +5587,10 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents) mPositions[i].mul(inv_scale); mNormals[i].mul(scale); mNormals[i].normalize3(); - F32 w = mMikktSpaceTangents[i].getF32ptr()[3]; - mMikktSpaceTangents[i].mul(scale); - mMikktSpaceTangents[i].normalize3(); - mMikktSpaceTangents[i].getF32ptr()[3] = w; + F32 w = mTangents[i].getF32ptr()[3]; + mTangents[i].mul(scale); + mTangents[i].normalize3(); + mTangents[i].getF32ptr()[3] = w; } } @@ -5703,7 +5685,6 @@ void LLVolumeFace::swapData(LLVolumeFace& rhs) llswap(rhs.mPositions, mPositions); llswap(rhs.mNormals, mNormals); llswap(rhs.mTangents, mTangents); - llswap(rhs.mMikktSpaceTangents, mMikktSpaceTangents); llswap(rhs.mTexCoords, mTexCoords); llswap(rhs.mIndices,mIndices); llswap(rhs.mNumVertices, mNumVertices); @@ -6415,7 +6396,6 @@ void LLVolumeFace::createTangents() { LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME; - if (!mTangents) { allocateTangents(mNumVertices); @@ -6539,11 +6519,10 @@ void LLVolumeFace::pushVertex(const LLVector4a& pos, const LLVector4a& norm, con mNumVertices++; } -void LLVolumeFace::allocateTangents(S32 num_verts, bool mikktspace) +void LLVolumeFace::allocateTangents(S32 num_verts) { - auto& buff = mikktspace ? mMikktSpaceTangents : mTangents; - ll_aligned_free_16(buff); - buff = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); + ll_aligned_free_16(mTangents); + mTangents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts); } void LLVolumeFace::allocateWeights(S32 num_verts) diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h index 6ea12c6920..3aa7034357 100644 --- a/indra/llmath/llvolume.h +++ b/indra/llmath/llvolume.h @@ -873,7 +873,7 @@ public: void createTangents(); void resizeVertices(S32 num_verts); - void allocateTangents(S32 num_verts, bool mikktspace = false); + void allocateTangents(S32 num_verts); void allocateWeights(S32 num_verts); void allocateJointIndices(S32 num_verts); void resizeIndices(S32 num_indices); @@ -947,7 +947,6 @@ public: LLVector4a* mPositions; // Contains vertices, nortmals and texcoords LLVector4a* mNormals; // pointer into mPositions LLVector4a* mTangents; - LLVector4a* mMikktSpaceTangents = nullptr; // for GLTF rendering, use mikkt space tangents LLVector2* mTexCoords; // pointer into mPositions // mIndices contains mNumIndices amount of elements. @@ -984,7 +983,6 @@ public: // when encoding the source mesh into a unit cube // used for regenerating tangents LLVector3 mNormalizedScale = LLVector3(1,1,1); - LLVector3 mNormalizedTranslation; private: BOOL createUnCutCubeCap(LLVolume* volume, BOOL partial_build = FALSE); @@ -1031,7 +1029,7 @@ public: void setDirty() { mPathp->setDirty(); mProfilep->setDirty(); } void regen(); - void genTangents(S32 face, bool mikktspace = false); + void genTangents(S32 face); BOOL isConvex() const; BOOL isCap(S32 face); -- cgit v1.2.3 From 2e499bcc40871b6a68700203cc83fe7d81c79c24 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 28 Sep 2022 19:14:00 -0500 Subject: SL-18190 Prune srgb_to_linear from atmosphericsFuncs.glsl --- indra/llmath/v3color.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h index 43a632408c..c3c6ae2242 100644 --- a/indra/llmath/v3color.h +++ b/indra/llmath/v3color.h @@ -484,13 +484,23 @@ inline const LLColor3 srgbColor3(const LLColor3 &a) { return srgbColor; } -inline const LLColor3 linearColor3(const LLColor3 &a) { +inline const LLColor3 linearColor3(const F32* v) { LLColor3 linearColor; - linearColor.mV[0] = sRGBtoLinear(a.mV[0]); - linearColor.mV[1] = sRGBtoLinear(a.mV[1]); - linearColor.mV[2] = sRGBtoLinear(a.mV[2]); + linearColor.mV[0] = sRGBtoLinear(v[0]); + linearColor.mV[1] = sRGBtoLinear(v[1]); + linearColor.mV[2] = sRGBtoLinear(v[2]); return linearColor; } +template +inline const LLColor3 linearColor3(const T& a) { + return linearColor3(a.mV); +} + +template +inline const LLVector3 linearColor3v(const T& a) { + return LLVector3(linearColor3(a.mV).mV); +} + #endif -- cgit v1.2.3 From 5c83ac76b5439a72db0d1b7ac3a747b19d8e048a Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Thu, 29 Sep 2022 13:23:11 -0700 Subject: fix for mac build breakage DRTVWR-559 --- indra/llmath/v3color.h | 5 ----- indra/llmath/v3math.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h index c3c6ae2242..7d825b2b94 100644 --- a/indra/llmath/v3color.h +++ b/indra/llmath/v3color.h @@ -498,9 +498,4 @@ inline const LLColor3 linearColor3(const T& a) { return linearColor3(a.mV); } -template -inline const LLVector3 linearColor3v(const T& a) { - return LLVector3(linearColor3(a.mV).mV); -} - #endif diff --git a/indra/llmath/v3math.h b/indra/llmath/v3math.h index 068f489020..48c5c21863 100644 --- a/indra/llmath/v3math.h +++ b/indra/llmath/v3math.h @@ -609,4 +609,9 @@ inline std::ostream& operator<<(std::ostream& s, const LLVector3 &a) return s; } +template +inline const LLVector3 linearColor3v(const T& a) { + return LLVector3(linearColor3(a.mV).mV); +} + #endif -- cgit v1.2.3 From f2867c71dba95b21771dc1f6edacaed6755ab6da Mon Sep 17 00:00:00 2001 From: Brad Kittenbrink Date: Thu, 29 Sep 2022 13:58:05 -0700 Subject: Better fix for DRTVWR-559 mac build breakage --- indra/llmath/v3color.h | 6 ++++++ indra/llmath/v3math.h | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h index 7d825b2b94..60353bea6e 100644 --- a/indra/llmath/v3color.h +++ b/indra/llmath/v3color.h @@ -33,6 +33,7 @@ class LLVector4; #include "llerror.h" #include "llmath.h" #include "llsd.h" +#include "v3math.h" // needed for linearColor3v implemtation below #include // LLColor3 = |r g b| @@ -498,4 +499,9 @@ inline const LLColor3 linearColor3(const T& a) { return linearColor3(a.mV); } +template +inline const LLVector3 linearColor3v(const T& a) { + return LLVector3(linearColor3(a.mV).mV); +} + #endif diff --git a/indra/llmath/v3math.h b/indra/llmath/v3math.h index 48c5c21863..068f489020 100644 --- a/indra/llmath/v3math.h +++ b/indra/llmath/v3math.h @@ -609,9 +609,4 @@ inline std::ostream& operator<<(std::ostream& s, const LLVector3 &a) return s; } -template -inline const LLVector3 linearColor3v(const T& a) { - return LLVector3(linearColor3(a.mV).mV); -} - #endif -- cgit v1.2.3 From 598c953d540090caa8a9a12581a4ab8ae52615dd Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 12 Oct 2022 18:49:18 -0500 Subject: SL-18190 Fix for assert on 360 snapshot and ? fix for mac build ? --- indra/llmath/v3color.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h index 60353bea6e..0b3b4ea3e1 100644 --- a/indra/llmath/v3color.h +++ b/indra/llmath/v3color.h @@ -485,7 +485,7 @@ inline const LLColor3 srgbColor3(const LLColor3 &a) { return srgbColor; } -inline const LLColor3 linearColor3(const F32* v) { +inline const LLColor3 linearColor3p(const F32* v) { LLColor3 linearColor; linearColor.mV[0] = sRGBtoLinear(v[0]); linearColor.mV[1] = sRGBtoLinear(v[1]); @@ -496,12 +496,12 @@ inline const LLColor3 linearColor3(const F32* v) { template inline const LLColor3 linearColor3(const T& a) { - return linearColor3(a.mV); + return linearColor3p(a.mV); } template inline const LLVector3 linearColor3v(const T& a) { - return LLVector3(linearColor3(a.mV).mV); + return LLVector3(linearColor3p(a.mV).mV); } #endif -- cgit v1.2.3 From f6762c3de57434730a2cbf6d0241bf1db5c9346c Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 14 Oct 2022 17:35:48 -0500 Subject: SL-18105 Add to/from json capability to LLGLTFMaterial --- indra/llmath/v3color.h | 32 ++++++++++++++++++++++++++++++++ indra/llmath/v4color.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) (limited to 'indra/llmath') diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h index 0b3b4ea3e1..d925f56e97 100644 --- a/indra/llmath/v3color.h +++ b/indra/llmath/v3color.h @@ -88,6 +88,16 @@ public: const LLColor3& set(F32 x, F32 y, F32 z); // Sets LLColor3 to (x, y, z) const LLColor3& set(const LLColor3 &vec); // Sets LLColor3 to vec const LLColor3& set(const F32 *vec); // Sets LLColor3 to vec + + // set from a vector of unknown type and size + // may leave some data unmodified + template + const LLColor3& set(const std::vector& v); + + // write to a vector of unknown type and size + // maye leave some data unmodified + template + void write(std::vector& v) const; F32 magVec() const; // deprecated F32 magVecSquared() const; // deprecated @@ -504,4 +514,26 @@ inline const LLVector3 linearColor3v(const T& a) { return LLVector3(linearColor3p(a.mV).mV); } +template +const LLColor3& LLColor3::set(const std::vector& v) +{ + for (S32 i = 0; i < llmin((S32)v.size(), 3); ++i) + { + mV[i] = v[i]; + } + + return *this; +} + +// write to a vector of unknown type and size +// maye leave some data unmodified +template +void LLColor3::write(std::vector& v) const +{ + for (int i = 0; i < llmin((S32)v.size(), 3); ++i) + { + v[i] = mV[i]; + } +} + #endif diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h index f2863be531..daa61594fb 100644 --- a/indra/llmath/v4color.h +++ b/indra/llmath/v4color.h @@ -91,6 +91,15 @@ class LLColor4 const LLColor4& set(const F64 *vec); // Sets LLColor4 to (double)vec const LLColor4& set(const LLColor4U& color4u); // Sets LLColor4 to color4u, rescaled. + // set from a vector of unknown type and size + // may leave some data unmodified + template + const LLColor4& set(const std::vector& v); + + // write to a vector of unknown type and size + // maye leave some data unmodified + template + void write(std::vector& v) const; const LLColor4& setAlpha(F32 a); @@ -690,5 +699,25 @@ inline const LLColor4 linearColor4(const LLColor4 &a) return linearColor; } +template +const LLColor4& LLColor4::set(const std::vector& v) +{ + for (S32 i = 0; i < llmin((S32)v.size(), 4); ++i) + { + mV[i] = v[i]; + } + + return *this; +} + +template +void LLColor4::write(std::vector& v) const +{ + for (int i = 0; i < llmin((S32)v.size(), 4); ++i) + { + v[i] = mV[i]; + } +} + #endif -- cgit v1.2.3 From 3377b19de43dfe0922174240a7844ba8f82eba23 Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Mon, 6 Mar 2023 10:15:38 -0500 Subject: Fix double copy of tangents array (#107) --- indra/llmath/llvolume.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 9919af5368..7a694ab10c 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -4863,17 +4863,6 @@ LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src) mTangents = NULL; } - if (src.mTangents) - { - allocateTangents(src.mNumVertices); - LLVector4a::memcpyNonAliased16((F32*)mTangents, (F32*)src.mTangents, vert_size); - } - else - { - ll_aligned_free_16(mTangents); - mTangents = nullptr; - } - if (src.mWeights) { llassert(!mWeights); // don't orphan an old alloc here accidentally -- cgit v1.2.3 From 5882215a6d53f5a20779be78805392f4e38c3669 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 24 Mar 2023 14:33:41 -0500 Subject: SL-19321 Optimization pass -- Remove another shadow split from probe render, incidental decruft. --- indra/llmath/llcamera.cpp | 222 ---------------------------------------------- indra/llmath/llcamera.h | 9 -- 2 files changed, 231 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llcamera.cpp b/indra/llmath/llcamera.cpp index 9034182072..18d704dd0f 100644 --- a/indra/llmath/llcamera.cpp +++ b/indra/llmath/llcamera.cpp @@ -311,104 +311,6 @@ int LLCamera::sphereInFrustumQuick(const LLVector3 &sphere_center, const F32 rad return 0; } -// HACK: This version is still around because the version below doesn't work -// unless the agent planes are initialized. -// Return 1 if sphere is in frustum, 2 if fully in frustum, otherwise 0. -// NOTE: 'center' is in absolute frame. -int LLCamera::sphereInFrustumOld(const LLVector3 &sphere_center, const F32 radius) const -{ - // Returns 1 if sphere is in frustum, 0 if not. - // modified so that default view frust is along X with Z vertical - F32 x, y, z, rightDist, leftDist, topDist, bottomDist; - - // Subtract the view position - //LLVector3 relative_center; - //relative_center = sphere_center - getOrigin(); - LLVector3 rel_center(sphere_center); - rel_center -= mOrigin; - - bool all_in = TRUE; - - // Transform relative_center.x to camera frame - x = mXAxis * rel_center; - if (x < MIN_NEAR_PLANE - radius) - { - return 0; - } - else if (x < MIN_NEAR_PLANE + radius) - { - all_in = FALSE; - } - - if (x > mFarPlane + radius) - { - return 0; - } - else if (x > mFarPlane - radius) - { - all_in = FALSE; - } - - // Transform relative_center.y to camera frame - y = mYAxis * rel_center; - - // distance to plane is the dot product of (x, y, 0) * plane_normal - rightDist = x * mLocalPlanes[PLANE_RIGHT][VX] + y * mLocalPlanes[PLANE_RIGHT][VY]; - if (rightDist < -radius) - { - return 0; - } - else if (rightDist < radius) - { - all_in = FALSE; - } - - leftDist = x * mLocalPlanes[PLANE_LEFT][VX] + y * mLocalPlanes[PLANE_LEFT][VY]; - if (leftDist < -radius) - { - return 0; - } - else if (leftDist < radius) - { - all_in = FALSE; - } - - // Transform relative_center.y to camera frame - z = mZAxis * rel_center; - - topDist = x * mLocalPlanes[PLANE_TOP][VX] + z * mLocalPlanes[PLANE_TOP][VZ]; - if (topDist < -radius) - { - return 0; - } - else if (topDist < radius) - { - all_in = FALSE; - } - - bottomDist = x * mLocalPlanes[PLANE_BOTTOM][VX] + z * mLocalPlanes[PLANE_BOTTOM][VZ]; - if (bottomDist < -radius) - { - return 0; - } - else if (bottomDist < radius) - { - all_in = FALSE; - } - - if (all_in) - { - return 2; - } - - return 1; -} - - -// HACK: This (presumably faster) version only currently works if you set up the -// frustum planes using GL. At some point we should get those planes through another -// mechanism, and then we can get rid of the "old" version above. - // Return 1 if sphere is in frustum, 2 if fully in frustum, otherwise 0. // NOTE: 'center' is in absolute frame. int LLCamera::sphereInFrustum(const LLVector3 &sphere_center, const F32 radius) const @@ -463,65 +365,6 @@ F32 LLCamera::heightInPixels(const LLVector3 ¢er, F32 radius ) const } } -// If pos is visible, return the distance from pos to the camera. -// Use fudge distance to scale rad against top/bot/left/right planes -// Otherwise, return -distance -F32 LLCamera::visibleDistance(const LLVector3 &pos, F32 rad, F32 fudgedist, U32 planemask) const -{ - if (mFixedDistance > 0) - { - return mFixedDistance; - } - LLVector3 dvec = pos - mOrigin; - // Check visibility - F32 dist = dvec.magVec(); - if (dist > rad) - { - F32 dp,tdist; - dp = dvec * mXAxis; - if (dp < -rad) - return -dist; - - rad *= fudgedist; - LLVector3 tvec(pos); - for (int p=0; p rad) - return -dist; - } - } - return dist; -} - -// Like visibleDistance, except uses mHorizPlanes[], which are left and right -// planes perpindicular to (0,0,1) in world space -F32 LLCamera::visibleHorizDistance(const LLVector3 &pos, F32 rad, F32 fudgedist, U32 planemask) const -{ - if (mFixedDistance > 0) - { - return mFixedDistance; - } - LLVector3 dvec = pos - mOrigin; - // Check visibility - F32 dist = dvec.magVec(); - if (dist > rad) - { - rad *= fudgedist; - LLVector3 tvec(pos); - for (int p=0; p rad) - return -dist; - } - } - return dist; -} // ---------------- friends and operators ---------------- @@ -536,18 +379,6 @@ std::ostream& operator<<(std::ostream &s, const LLCamera &C) s << " Aspect = " << C.getAspect() << "\n"; s << " NearPlane = " << C.mNearPlane << "\n"; s << " FarPlane = " << C.mFarPlane << "\n"; - s << " TopPlane = " << C.mLocalPlanes[LLCamera::PLANE_TOP][VX] << " " - << C.mLocalPlanes[LLCamera::PLANE_TOP][VY] << " " - << C.mLocalPlanes[LLCamera::PLANE_TOP][VZ] << "\n"; - s << " BottomPlane = " << C.mLocalPlanes[LLCamera::PLANE_BOTTOM][VX] << " " - << C.mLocalPlanes[LLCamera::PLANE_BOTTOM][VY] << " " - << C.mLocalPlanes[LLCamera::PLANE_BOTTOM][VZ] << "\n"; - s << " LeftPlane = " << C.mLocalPlanes[LLCamera::PLANE_LEFT][VX] << " " - << C.mLocalPlanes[LLCamera::PLANE_LEFT][VY] << " " - << C.mLocalPlanes[LLCamera::PLANE_LEFT][VZ] << "\n"; - s << " RightPlane = " << C.mLocalPlanes[LLCamera::PLANE_RIGHT][VX] << " " - << C.mLocalPlanes[LLCamera::PLANE_RIGHT][VY] << " " - << C.mLocalPlanes[LLCamera::PLANE_RIGHT][VZ] << "\n"; s << "}"; return s; } @@ -675,26 +506,6 @@ void LLCamera::calcRegionFrustumPlanes(const LLVector3& shift, F32 far_clip_dist void LLCamera::calculateFrustumPlanes(F32 left, F32 right, F32 top, F32 bottom) { - LLVector3 a, b, c; - - // For each plane we need to define 3 points (LLVector3's) in camera view space. - // The order in which we pass the points to planeFromPoints() matters, because the - // plane normal has a degeneracy of 2; we want it pointing _into_ the frustum. - - a.setVec(0.0f, 0.0f, 0.0f); - b.setVec(mFarPlane, right, top); - c.setVec(mFarPlane, right, bottom); - mLocalPlanes[PLANE_RIGHT].setVec(a, b, c); - - c.setVec(mFarPlane, left, top); - mLocalPlanes[PLANE_TOP].setVec(a, c, b); - - b.setVec(mFarPlane, left, bottom); - mLocalPlanes[PLANE_LEFT].setVec(a, b, c); - - c.setVec(mFarPlane, right, bottom); - mLocalPlanes[PLANE_BOTTOM].setVec( a, c, b); - //calculate center and radius squared of frustum in world absolute coordinates static LLVector3 const X_AXIS(1.f, 0.f, 0.f); mFrustCenter = X_AXIS*mFarPlane*0.5f; @@ -718,39 +529,6 @@ void LLCamera::calculateFrustumPlanesFromWindow(F32 x1, F32 y1, F32 x2, F32 y2) calculateFrustumPlanes(left, right, top, bottom); } -void LLCamera::calculateWorldFrustumPlanes() -{ - F32 d; - LLVector3 center = mOrigin - mXAxis*mNearPlane; - mWorldPlanePos = center; - LLVector3 pnorm; - for (int p = 0; p < PLANE_NUM; p++) - { - mLocalPlanes[p].getVector3(pnorm); - LLVector3 norm = rotateToAbsolute(pnorm); - norm.normVec(); - d = -(center * norm); - mWorldPlanes[p] = LLPlane(norm, d); - } - // horizontal planes, perpindicular to (0,0,1); - LLVector3 zaxis(0, 0, 1.0f); - F32 yaw = getYaw(); - { - LLVector3 tnorm; - mLocalPlanes[PLANE_LEFT].getVector3(tnorm); - tnorm.rotVec(yaw, zaxis); - d = -(mOrigin * tnorm); - mHorizPlanes[HORIZ_PLANE_LEFT] = LLPlane(tnorm, d); - } - { - LLVector3 tnorm; - mLocalPlanes[PLANE_RIGHT].getVector3(tnorm); - tnorm.rotVec(yaw, zaxis); - d = -(mOrigin * tnorm); - mHorizPlanes[HORIZ_PLANE_RIGHT] = LLPlane(tnorm, d); - } -} - // NOTE: this is the OpenGL matrix that will transform the default OpenGL view // (-Z=at, Y=up) to the default view of the LLCamera class (X=at, Z=up): // diff --git a/indra/llmath/llcamera.h b/indra/llmath/llcamera.h index d0afa0e88f..27eaa614c9 100644 --- a/indra/llmath/llcamera.h +++ b/indra/llmath/llcamera.h @@ -131,14 +131,10 @@ private: S32 mViewHeightInPixels; // for ViewHeightInPixels() only F32 mNearPlane; F32 mFarPlane; - LL_ALIGN_16(LLPlane mLocalPlanes[PLANE_NUM]); F32 mFixedDistance; // Always return this distance, unless < 0 LLVector3 mFrustCenter; // center of frustum and radius squared for ultra-quick exclusion test F32 mFrustRadiusSquared; - LL_ALIGN_16(LLPlane mWorldPlanes[PLANE_NUM]); - LL_ALIGN_16(LLPlane mHorizPlanes[HORIZ_PLANE_NUM]); - U32 mPlaneCount; //defaults to 6, if setUserClipPlane is called, uses user supplied clip plane in LLVector3 mWorldPlanePos; // Position of World Planes (may be offset from camera) @@ -184,7 +180,6 @@ public: return atan2f(mXAxis[VZ], xylen); } - const LLPlane& getWorldPlane(S32 index) const { return mWorldPlanes[index]; } const LLVector3& getWorldPlanePos() const { return mWorldPlanePos; } // Copy mView, mAspect, mNearPlane, and mFarPlane to buffer. @@ -200,7 +195,6 @@ public: // Returns 1 if partly in, 2 if fully in. // NOTE: 'center' is in absolute frame. - S32 sphereInFrustumOld(const LLVector3 ¢er, const F32 radius) const; S32 sphereInFrustum(const LLVector3 ¢er, const F32 radius) const; S32 pointInFrustum(const LLVector3 &point) const { return sphereInFrustum(point, 0.0f); } S32 sphereInFrustumFull(const LLVector3 ¢er, const F32 radius) const { return sphereInFrustum(center, radius); } @@ -217,8 +211,6 @@ public: F32 heightInPixels(const LLVector3 ¢er, F32 radius ) const; // return the distance from pos to camera if visible (-distance if not visible) - F32 visibleDistance(const LLVector3 &pos, F32 rad, F32 fudgescale = 1.0f, U32 planemask = PLANE_ALL_MASK) const; - F32 visibleHorizDistance(const LLVector3 &pos, F32 rad, F32 fudgescale = 1.0f, U32 planemask = HORIZ_PLANE_ALL_MASK) const; void setFixedDistance(F32 distance) { mFixedDistance = distance; } friend std::ostream& operator<<(std::ostream &s, const LLCamera &C); @@ -227,7 +219,6 @@ protected: void calculateFrustumPlanes(); void calculateFrustumPlanes(F32 left, F32 right, F32 top, F32 bottom); void calculateFrustumPlanesFromWindow(F32 x1, F32 y1, F32 x2, F32 y2); - void calculateWorldFrustumPlanes(); } LL_ALIGN_POSTFIX(16); -- cgit v1.2.3 From 6c5b9076704865e96adb5b4a25a518633da1174e Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Thu, 13 Apr 2023 19:41:11 -0500 Subject: SL-19358 Fix for explody meshes. --- indra/llmath/llvolume.cpp | 51 +++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 7a694ab10c..2a906c8d41 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -5574,37 +5574,44 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents) U32 vert_count = meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count); - std::vector indices; - indices.resize(mNumIndices); + if (vert_count < 65535) + { + std::vector indices; + indices.resize(mNumIndices); - //copy results back into volume - resizeVertices(vert_count); + //copy results back into volume + resizeVertices(vert_count); - if (!data.w.empty()) - { - allocateWeights(vert_count); - } + if (!data.w.empty()) + { + allocateWeights(vert_count); + } - allocateTangents(mNumVertices); + allocateTangents(mNumVertices); - for (int i = 0; i < mNumIndices; ++i) - { - U32 src_idx = i; - U32 dst_idx = remap[i]; - mIndices[i] = dst_idx; + for (int i = 0; i < mNumIndices; ++i) + { + U32 src_idx = i; + U32 dst_idx = remap[i]; + mIndices[i] = dst_idx; - mPositions[dst_idx].load3(data.p[src_idx].mV); - mNormals[dst_idx].load3(data.n[src_idx].mV); - mTexCoords[dst_idx] = data.tc[src_idx]; + mPositions[dst_idx].load3(data.p[src_idx].mV); + mNormals[dst_idx].load3(data.n[src_idx].mV); + mTexCoords[dst_idx] = data.tc[src_idx]; - mTangents[dst_idx].loadua(data.t[src_idx].mV); + mTangents[dst_idx].loadua(data.t[src_idx].mV); - if (mWeights) - { - mWeights[dst_idx].loadua(data.w[src_idx].mV); + if (mWeights) + { + mWeights[dst_idx].loadua(data.w[src_idx].mV); + } } } - + else + { + // blew past the max vertex size limit, use legacy tangent generation which never adds verts + createTangents(); + } // put back in normalized coordinate frame LLVector4a inv_scale(1.f/mNormalizedScale.mV[0], 1.f / mNormalizedScale.mV[1], 1.f / mNormalizedScale.mV[2]); -- cgit v1.2.3 From 1cadfd44fe5ddafaf3ba3560bd8ec8e1351b347d Mon Sep 17 00:00:00 2001 From: RunitaiLinden Date: Wed, 3 May 2023 17:30:02 -0500 Subject: DRTVWR-559 WIP - optimize ARC calculation et al. --- indra/llmath/llvolume.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 2a906c8d41..b6cdcb2736 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -3351,12 +3351,12 @@ BOOL LLVolume::isFlat(S32 face) bool LLVolumeParams::isSculpt() const { - return mSculptID.notNull(); + return (mSculptType & LL_SCULPT_TYPE_MASK) != LL_SCULPT_TYPE_NONE; } bool LLVolumeParams::isMeshSculpt() const { - return isSculpt() && ((mSculptType & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH); + return (mSculptType & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH; } bool LLVolumeParams::operator==(const LLVolumeParams ¶ms) const @@ -3771,6 +3771,7 @@ bool LLVolumeParams::validate(U8 prof_curve, F32 prof_begin, F32 prof_end, F32 h void LLVolume::getLoDTriangleCounts(const LLVolumeParams& params, S32* counts) { //attempt to approximate the number of triangles that will result from generating a volume LoD set for the //supplied LLVolumeParams -- inaccurate, but a close enough approximation for determining streaming cost + LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME; F32 detail[] = {1.f, 1.5f, 2.5f, 4.f}; for (S32 i = 0; i < 4; i++) { -- cgit v1.2.3 From ca84e0e0c0b4b2844f478a549cb2cb1fbb52c898 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 22 Jun 2023 22:09:42 +0300 Subject: SL-5161 Avatars should stay hidden longer if they are waiting for meshes or skin data --- indra/llmath/llvolume.cpp | 25 ++++++++++++++++++++++--- indra/llmath/llvolume.h | 9 ++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 91e463cc32..0e3792fda3 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -2056,7 +2056,8 @@ LLVolume::LLVolume(const LLVolumeParams ¶ms, const F32 detail, const BOOL ge mDetail = detail; mSculptLevel = -2; mSurfaceArea = 1.f; //only calculated for sculpts, defaults to 1 for all other prims - mIsMeshAssetLoaded = FALSE; + mIsMeshAssetLoaded = false; + mIsMeshAssetUnavaliable = false; mLODScaleBias.setVec(1,1,1); mHullPoints = NULL; mHullIndices = NULL; @@ -2804,14 +2805,32 @@ bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl) } -BOOL LLVolume::isMeshAssetLoaded() +bool LLVolume::isMeshAssetLoaded() { return mIsMeshAssetLoaded; } -void LLVolume::setMeshAssetLoaded(BOOL loaded) +void LLVolume::setMeshAssetLoaded(bool loaded) { mIsMeshAssetLoaded = loaded; + if (loaded) + { + mIsMeshAssetUnavaliable = false; + } +} + +void LLVolume::setMeshAssetUnavaliable(bool unavaliable) +{ + // Don't set it if at least one lod loaded + if (!mIsMeshAssetLoaded) + { + mIsMeshAssetUnavaliable = unavaliable; + } +} + +bool LLVolume::isMeshAssetUnavaliable() +{ + return mIsMeshAssetUnavaliable; } void LLVolume::copyFacesTo(std::vector &faces) const diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h index ad6a669531..afed98ff36 100644 --- a/indra/llmath/llvolume.h +++ b/indra/llmath/llvolume.h @@ -1111,15 +1111,18 @@ private: bool unpackVolumeFacesInternal(const LLSD& mdl); public: - virtual void setMeshAssetLoaded(BOOL loaded); - virtual BOOL isMeshAssetLoaded(); + virtual void setMeshAssetLoaded(bool loaded); + virtual bool isMeshAssetLoaded(); + virtual void setMeshAssetUnavaliable(bool unavaliable); + virtual bool isMeshAssetUnavaliable(); protected: BOOL mUnique; F32 mDetail; S32 mSculptLevel; F32 mSurfaceArea; //unscaled surface area - BOOL mIsMeshAssetLoaded; + bool mIsMeshAssetLoaded; + bool mIsMeshAssetUnavaliable; const LLVolumeParams mParams; LLPath *mPathp; -- cgit v1.2.3 From 59a626c2a22aa7cbccf87ce435012583d7610cd4 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Tue, 11 Jul 2023 16:08:03 -0700 Subject: SL-19992: Fix assert in LLVolumeLODGroup::refLOD when LLMeshRepository::notifyMeshUnavailable is called on the highest LOD --- indra/llmath/llvolumemgr.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolumemgr.cpp b/indra/llmath/llvolumemgr.cpp index 89cdb1c6b9..9399504529 100644 --- a/indra/llmath/llvolumemgr.cpp +++ b/indra/llmath/llvolumemgr.cpp @@ -89,7 +89,7 @@ BOOL LLVolumeMgr::cleanup() // Note however that LLVolumeLODGroup that contains the volume // also holds a LLPointer so the volume will only go away after // anything holding the volume and the LODGroup are destroyed -LLVolume* LLVolumeMgr::refVolume(const LLVolumeParams &volume_params, const S32 detail) +LLVolume* LLVolumeMgr::refVolume(const LLVolumeParams &volume_params, const S32 lod) { LLVolumeLODGroup* volgroupp; if (mDataMutex) @@ -109,7 +109,7 @@ LLVolume* LLVolumeMgr::refVolume(const LLVolumeParams &volume_params, const S32 { mDataMutex->unlock(); } - return volgroupp->refLOD(detail); + return volgroupp->refLOD(lod); } // virtual @@ -287,18 +287,18 @@ bool LLVolumeLODGroup::cleanupRefs() return res; } -LLVolume* LLVolumeLODGroup::refLOD(const S32 detail) +LLVolume* LLVolumeLODGroup::refLOD(const S32 lod) { - llassert(detail >=0 && detail < NUM_LODS); - mAccessCount[detail]++; + llassert(lod >=0 && lod < NUM_LODS); + mAccessCount[lod]++; mRefs++; - if (mVolumeLODs[detail].isNull()) + if (mVolumeLODs[lod].isNull()) { - mVolumeLODs[detail] = new LLVolume(mVolumeParams, mDetailScales[detail]); + mVolumeLODs[lod] = new LLVolume(mVolumeParams, mDetailScales[lod]); } - mLODRefs[detail]++; - return mVolumeLODs[detail]; + mLODRefs[lod]++; + return mVolumeLODs[lod]; } BOOL LLVolumeLODGroup::derefLOD(LLVolume *volumep) -- cgit v1.2.3 From a280bacfea5453df3453322223b677adc2780511 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Mon, 11 Sep 2023 17:11:03 -0700 Subject: SL-20157: Fix scale of avatar mesh parts when mikktspace tangent generation fails --- indra/llmath/llvolume.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 0e3792fda3..6d36daa92a 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -5626,29 +5626,29 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents) mWeights[dst_idx].loadua(data.w[src_idx].mV); } } + + // put back in normalized coordinate frame + LLVector4a inv_scale(1.f/mNormalizedScale.mV[0], 1.f / mNormalizedScale.mV[1], 1.f / mNormalizedScale.mV[2]); + LLVector4a scale; + scale.load3(mNormalizedScale.mV); + scale.getF32ptr()[3] = 1.f; + + for (int i = 0; i < mNumVertices; ++i) + { + mPositions[i].mul(inv_scale); + mNormals[i].mul(scale); + mNormals[i].normalize3(); + F32 w = mTangents[i].getF32ptr()[3]; + mTangents[i].mul(scale); + mTangents[i].normalize3(); + mTangents[i].getF32ptr()[3] = w; + } } else { // blew past the max vertex size limit, use legacy tangent generation which never adds verts createTangents(); } - - // put back in normalized coordinate frame - LLVector4a inv_scale(1.f/mNormalizedScale.mV[0], 1.f / mNormalizedScale.mV[1], 1.f / mNormalizedScale.mV[2]); - LLVector4a scale; - scale.load3(mNormalizedScale.mV); - scale.getF32ptr()[3] = 1.f; - - for (int i = 0; i < mNumVertices; ++i) - { - mPositions[i].mul(inv_scale); - mNormals[i].mul(scale); - mNormals[i].normalize3(); - F32 w = mTangents[i].getF32ptr()[3]; - mTangents[i].mul(scale); - mTangents[i].normalize3(); - mTangents[i].getF32ptr()[3] = w; - } } // cache optimize index buffer -- cgit v1.2.3 From 07a830a4cef1ccc600f8c4dc5e4fcdba83df839b Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Thu, 12 Oct 2023 13:02:23 -0700 Subject: SL-20062: Fix near clip on reflection probes being clamped to at or below 10 --- indra/llmath/llcamera.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llcamera.h b/indra/llmath/llcamera.h index 27eaa614c9..c4d04f5d02 100644 --- a/indra/llmath/llcamera.h +++ b/indra/llmath/llcamera.h @@ -39,7 +39,7 @@ const F32 DEFAULT_NEAR_PLANE = 0.25f; const F32 DEFAULT_FAR_PLANE = 64.f; // far reaches across two horizontal, not diagonal, regions const F32 MAX_ASPECT_RATIO = 50.0f; -const F32 MAX_NEAR_PLANE = 10.f; +const F32 MAX_NEAR_PLANE = 1023.9f; // Clamp the near plane just before the skybox ends const F32 MAX_FAR_PLANE = 100000.0f; //1000000.0f; // Max allowed. Not good Z precision though. const F32 MAX_FAR_CLIP = 512.0f; -- cgit v1.2.3