From 474923e3cb29df35e8807006ad16861eb1dc24d0 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:57:17 -0700 Subject: DRTVWR-592: (WIP) Add code for generating terrain tangents (not yet used) --- indra/newview/llvosurfacepatch.cpp | 169 +++++++++++++++++++++++++++++-------- 1 file changed, 136 insertions(+), 33 deletions(-) (limited to 'indra/newview/llvosurfacepatch.cpp') diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp index 3f5f56d378..bfa622b6c1 100644 --- a/indra/newview/llvosurfacepatch.cpp +++ b/indra/newview/llvosurfacepatch.cpp @@ -43,6 +43,9 @@ #include "pipeline.h" #include "llspatialpartition.h" +#include "mikktspace/mikktspace.h" +// mikktspace implementation already included in llvovolume object file + F32 LLVOSurfacePatch::sLODFactor = 1.f; LLVOSurfacePatch::LLVOSurfacePatch(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) @@ -241,39 +244,53 @@ BOOL LLVOSurfacePatch::updateLOD() return TRUE; } -void LLVOSurfacePatch::getGeometry(LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp) +void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &tangentsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp) { LLFace* facep = mDrawable->getFace(0); - if (facep) - { - U32 index_offset = facep->getGeomIndex(); - - updateMainGeometry(facep, - verticesp, - normalsp, - texCoords0p, - texCoords1p, - indicesp, - index_offset); - updateNorthGeometry(facep, - verticesp, - normalsp, - texCoords0p, - texCoords1p, - indicesp, - index_offset); - updateEastGeometry(facep, - verticesp, - normalsp, - texCoords0p, - texCoords1p, - indicesp, - index_offset); - } + if (!facep) + { + return; + } + + U32 index_offset = facep->getGeomIndex(); + + updateMainGeometry(facep, + verticesp, + normalsp, + texCoords0p, + texCoords1p, + indicesp, + index_offset); + updateNorthGeometry(facep, + verticesp, + normalsp, + texCoords0p, + texCoords1p, + indicesp, + index_offset); + updateEastGeometry(facep, + verticesp, + normalsp, + texCoords0p, + texCoords1p, + indicesp, + index_offset); + + const bool has_tangents = tangentsp.get() != nullptr; + if (has_tangents) + { + // Last but not least, calculate tangents for the updated terrain vertices + genTerrainTangents(facep, + verticesp, + normalsp, + tangentsp, + texCoords0p); + } } void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, @@ -759,6 +776,88 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, index_offset += num_vertices; } +struct MikktData +{ + MikktData(S32 vert_offet, + S32 vert_size, + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &tangentsp, + LLStrider &texCoords0p) : + vert_offset(vert_offset), + vert_size(vert_size), + verticesp(verticesp), + normalsp(normalsp), + texCoords0p(texCoords0p) + { + } + S32 vert_offset; + U32 vert_size; + LLStrider verticesp; + LLStrider normalsp; + LLStrider tangentsp; + LLStrider texCoords0p; +}; + + +void LLVOSurfacePatch::genTerrainTangents(LLFace *facep, + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &tangentsp, + LLStrider &texCoords0p) +{ + SMikkTSpaceInterface ms; + + ms.m_getNumFaces = [](const SMikkTSpaceContext *pContext) + { + MikktData *data = (MikktData *) pContext->m_pUserData; + return S32(data->vert_size / 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; + fvPosOut[0] = data->verticesp[data->vert_offset + iVert].mV[0]; + fvPosOut[1] = data->verticesp[data->vert_offset + iVert].mV[1]; + fvPosOut[2] = data->verticesp[data->vert_offset + iVert].mV[2]; + }; + + ms.m_getNormal = [](const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert) + { + MikktData *data = (MikktData *) pContext->m_pUserData; + fvNormOut[0] = data->normalsp[data->vert_offset + iVert].mV[0]; + fvNormOut[1] = data->normalsp[data->vert_offset + iVert].mV[1]; + fvNormOut[2] = data->normalsp[data->vert_offset + iVert].mV[2]; + }; + + ms.m_getTexCoord = [](const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert) + { + MikktData *data = (MikktData *) pContext->m_pUserData; + fvTexcOut[0] = data->texCoords0p[data->vert_offset + iVert].mV[0]; + fvTexcOut[1] = data->texCoords0p[data->vert_offset + iVert].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; + data->tangentsp[data->vert_offset + iVert] = LLVector4a(fvTangent[0], fvTangent[1], fvTangent[2], fSign); + }; + + ms.m_setTSpace = nullptr; + + MikktData data(facep->getGeomIndex(), + facep->getGeomCount(), + verticesp, + normalsp, + tangentsp, + texCoords0p); + SMikkTSpaceContext ctx = { &ms, &data }; + genTangSpaceDefault(&ctx); +} + void LLVOSurfacePatch::setPatch(LLSurfacePatch *patchp) { mPatchp = patchp; @@ -998,12 +1097,16 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) //get vertex buffer striders LLStrider vertices; LLStrider normals; - LLStrider texcoords2; + LLStrider tangents; LLStrider texcoords; + LLStrider texcoords2; LLStrider indices; + const bool has_tangents = buffer->hasDataType(LLVertexBuffer::TYPE_TANGENT); + llassert_always(buffer->getVertexStrider(vertices)); llassert_always(buffer->getNormalStrider(normals)); + llassert_always(has_tangents ? buffer->getTangentStrider(tangents) : true); llassert_always(buffer->getTexCoord0Strider(texcoords)); llassert_always(buffer->getTexCoord1Strider(texcoords2)); llassert_always(buffer->getIndexStrider(indices)); @@ -1020,7 +1123,7 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) facep->setVertexBuffer(buffer); LLVOSurfacePatch* patchp = (LLVOSurfacePatch*) facep->getViewerObject(); - patchp->getGeometry(vertices, normals, texcoords, texcoords2, indices); + patchp->getTerrainGeometry(vertices, normals, tangents, texcoords, texcoords2, indices); indices_index += facep->getIndicesCount(); index_offset += facep->getGeomCount(); -- cgit v1.2.3 From 49a5b79c2b1ba5f4b909d1bfab89bb7ad9c1e888 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:57:24 -0700 Subject: DRTVWR-592: (WIP) Debugging, rethinking --- indra/newview/llvosurfacepatch.cpp | 83 ++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 43 deletions(-) (limited to 'indra/newview/llvosurfacepatch.cpp') diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp index bfa622b6c1..edb07ffd9b 100644 --- a/indra/newview/llvosurfacepatch.cpp +++ b/indra/newview/llvosurfacepatch.cpp @@ -776,29 +776,33 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, index_offset += num_vertices; } -struct MikktData +struct MikktTerrainData { - MikktData(S32 vert_offet, - S32 vert_size, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &tangentsp, - LLStrider &texCoords0p) : - vert_offset(vert_offset), - vert_size(vert_size), - verticesp(verticesp), - normalsp(normalsp), - texCoords0p(texCoords0p) + MikktTerrainData(U32 vert_offset, + U32 vert_size, + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &tangentsp, + LLStrider &texCoords0p) : + mVertOffset(vert_offset), + mVertSize(vert_size), + mVerticesp(verticesp), + mNormalsp(normalsp), + mTangentsp(tangentsp), + mTexCoords0p(texCoords0p) { } - S32 vert_offset; - U32 vert_size; - LLStrider verticesp; - LLStrider normalsp; - LLStrider tangentsp; - LLStrider texCoords0p; + U32 mVertOffset; + U32 mVertSize; + LLStrider mVerticesp; + LLStrider mNormalsp; + LLStrider mTangentsp; + LLStrider mTexCoords0p; }; +// TODO: mikktspace? lol no, use this instead +// void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal, +// const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent) void LLVOSurfacePatch::genTerrainTangents(LLFace *facep, LLStrider &verticesp, @@ -810,51 +814,46 @@ void LLVOSurfacePatch::genTerrainTangents(LLFace *facep, ms.m_getNumFaces = [](const SMikkTSpaceContext *pContext) { - MikktData *data = (MikktData *) pContext->m_pUserData; - return S32(data->vert_size / 3); + MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; + return S32(data->mVertSize / 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; - fvPosOut[0] = data->verticesp[data->vert_offset + iVert].mV[0]; - fvPosOut[1] = data->verticesp[data->vert_offset + iVert].mV[1]; - fvPosOut[2] = data->verticesp[data->vert_offset + iVert].mV[2]; + MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; + fvPosOut[0] = data->mVerticesp[data->mVertOffset + iVert].mV[0]; + fvPosOut[1] = data->mVerticesp[data->mVertOffset + iVert].mV[1]; + fvPosOut[2] = data->mVerticesp[data->mVertOffset + iVert].mV[2]; }; ms.m_getNormal = [](const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert) { - MikktData *data = (MikktData *) pContext->m_pUserData; - fvNormOut[0] = data->normalsp[data->vert_offset + iVert].mV[0]; - fvNormOut[1] = data->normalsp[data->vert_offset + iVert].mV[1]; - fvNormOut[2] = data->normalsp[data->vert_offset + iVert].mV[2]; + MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; + fvNormOut[0] = data->mNormalsp[data->mVertOffset + iVert].mV[0]; + fvNormOut[1] = data->mNormalsp[data->mVertOffset + iVert].mV[1]; + fvNormOut[2] = data->mNormalsp[data->mVertOffset + iVert].mV[2]; }; ms.m_getTexCoord = [](const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert) { - MikktData *data = (MikktData *) pContext->m_pUserData; - fvTexcOut[0] = data->texCoords0p[data->vert_offset + iVert].mV[0]; - fvTexcOut[1] = data->texCoords0p[data->vert_offset + iVert].mV[1]; + MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; + fvTexcOut[0] = data->mTexCoords0p[data->mVertOffset + iVert].mV[0]; + fvTexcOut[1] = data->mTexCoords0p[data->mVertOffset + iVert].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; - data->tangentsp[data->vert_offset + iVert] = LLVector4a(fvTangent[0], fvTangent[1], fvTangent[2], fSign); + MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; + data->mTangentsp[data->mVertOffset + iVert] = LLVector4a(fvTangent[0], fvTangent[1], fvTangent[2], fSign); }; ms.m_setTSpace = nullptr; - MikktData data(facep->getGeomIndex(), - facep->getGeomCount(), - verticesp, - normalsp, - tangentsp, - texCoords0p); - SMikkTSpaceContext ctx = { &ms, &data }; + MikktTerrainData data((U32) (facep->getGeomIndex()), (U32) (facep->getGeomCount()), verticesp, normalsp, tangentsp, texCoords0p); + SMikkTSpaceContext ctx = {&ms, &data}; genTangSpaceDefault(&ctx); } @@ -1102,11 +1101,9 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) LLStrider texcoords2; LLStrider indices; - const bool has_tangents = buffer->hasDataType(LLVertexBuffer::TYPE_TANGENT); - llassert_always(buffer->getVertexStrider(vertices)); llassert_always(buffer->getNormalStrider(normals)); - llassert_always(has_tangents ? buffer->getTangentStrider(tangents) : true); + llassert_always(buffer->getTangentStrider(tangents)); llassert_always(buffer->getTexCoord0Strider(texcoords)); llassert_always(buffer->getTexCoord1Strider(texcoords2)); llassert_always(buffer->getIndexStrider(indices)); -- cgit v1.2.3 From 763a9b5249640ef71d532ff3c9c28418bd90fb68 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:57:32 -0700 Subject: DRTVWR-592: Working tangent calculation, not yet used --- indra/newview/llvosurfacepatch.cpp | 214 ++++++++++++++++--------------------- 1 file changed, 90 insertions(+), 124 deletions(-) (limited to 'indra/newview/llvosurfacepatch.cpp') diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp index edb07ffd9b..839eb2b737 100644 --- a/indra/newview/llvosurfacepatch.cpp +++ b/indra/newview/llvosurfacepatch.cpp @@ -39,13 +39,11 @@ #include "llviewerobjectlist.h" #include "llviewerregion.h" #include "llvlcomposition.h" +#include "llvolume.h" #include "llvovolume.h" #include "pipeline.h" #include "llspatialpartition.h" -#include "mikktspace/mikktspace.h" -// mikktspace implementation already included in llvovolume object file - F32 LLVOSurfacePatch::sLODFactor = 1.f; LLVOSurfacePatch::LLVOSurfacePatch(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) @@ -246,7 +244,6 @@ BOOL LLVOSurfacePatch::updateLOD() void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, LLStrider &normalsp, - LLStrider &tangentsp, LLStrider &texCoords0p, LLStrider &texCoords1p, LLStrider &indicesp) @@ -280,17 +277,6 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, texCoords1p, indicesp, index_offset); - - const bool has_tangents = tangentsp.get() != nullptr; - if (has_tangents) - { - // Last but not least, calculate tangents for the updated terrain vertices - genTerrainTangents(facep, - verticesp, - normalsp, - tangentsp, - texCoords0p); - } } void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, @@ -776,87 +762,6 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, index_offset += num_vertices; } -struct MikktTerrainData -{ - MikktTerrainData(U32 vert_offset, - U32 vert_size, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &tangentsp, - LLStrider &texCoords0p) : - mVertOffset(vert_offset), - mVertSize(vert_size), - mVerticesp(verticesp), - mNormalsp(normalsp), - mTangentsp(tangentsp), - mTexCoords0p(texCoords0p) - { - } - U32 mVertOffset; - U32 mVertSize; - LLStrider mVerticesp; - LLStrider mNormalsp; - LLStrider mTangentsp; - LLStrider mTexCoords0p; -}; - -// TODO: mikktspace? lol no, use this instead -// void CalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal, -// const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent) - -void LLVOSurfacePatch::genTerrainTangents(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &tangentsp, - LLStrider &texCoords0p) -{ - SMikkTSpaceInterface ms; - - ms.m_getNumFaces = [](const SMikkTSpaceContext *pContext) - { - MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; - return S32(data->mVertSize / 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) - { - MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; - fvPosOut[0] = data->mVerticesp[data->mVertOffset + iVert].mV[0]; - fvPosOut[1] = data->mVerticesp[data->mVertOffset + iVert].mV[1]; - fvPosOut[2] = data->mVerticesp[data->mVertOffset + iVert].mV[2]; - }; - - ms.m_getNormal = [](const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert) - { - MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; - fvNormOut[0] = data->mNormalsp[data->mVertOffset + iVert].mV[0]; - fvNormOut[1] = data->mNormalsp[data->mVertOffset + iVert].mV[1]; - fvNormOut[2] = data->mNormalsp[data->mVertOffset + iVert].mV[2]; - }; - - ms.m_getTexCoord = [](const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert) - { - MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; - fvTexcOut[0] = data->mTexCoords0p[data->mVertOffset + iVert].mV[0]; - fvTexcOut[1] = data->mTexCoords0p[data->mVertOffset + iVert].mV[1]; - }; - - ms.m_setTSpaceBasic = - [](const SMikkTSpaceContext *pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert) - { - MikktTerrainData *data = (MikktTerrainData *) pContext->m_pUserData; - data->mTangentsp[data->mVertOffset + iVert] = LLVector4a(fvTangent[0], fvTangent[1], fvTangent[2], fSign); - }; - - ms.m_setTSpace = nullptr; - - MikktTerrainData data((U32) (facep->getGeomIndex()), (U32) (facep->getGeomCount()), verticesp, normalsp, tangentsp, texCoords0p); - SMikkTSpaceContext ctx = {&ms, &data}; - genTangSpaceDefault(&ctx); -} - void LLVOSurfacePatch::setPatch(LLSurfacePatch *patchp) { mPatchp = patchp; @@ -1087,6 +992,47 @@ LLTerrainPartition::LLTerrainPartition(LLViewerRegion* regionp) mPartitionType = LLViewerRegion::PARTITION_TERRAIN; } +// Do not add vertices; honor strict vertex count specified by strider_vertex_count +void gen_terrain_tangents(U16 strider_vertex_count, + U32 strider_index_count, + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &tangentsp, + LLStrider &texCoords0p, + LLStrider &indicesp) +{ + LLVector4a *vertices = new LLVector4a[strider_vertex_count]; + LLVector4a *normals = new LLVector4a[strider_vertex_count]; + LLVector4a *tangents = new LLVector4a[strider_vertex_count]; + std::vector texcoords(strider_vertex_count); + std::vector indices(strider_index_count); + + for (U16 v = 0; v < strider_vertex_count; ++v) + { + F32 *vert = verticesp[v].mV; + vertices[v] = LLVector4a(vert[0], vert[1], vert[2], 1.f); + F32 *n = normalsp[v].mV; + normals[v] = LLVector4a(n[0], n[1], n[2], 1.f); + tangents[v] = tangentsp[v]; + texcoords[v] = texCoords0p[v]; + } + for (U32 i = 0; i < strider_index_count; ++i) + { + indices[i] = indicesp[i]; + } + + LLCalculateTangentArray(strider_vertex_count, vertices, normals, texcoords.data(), strider_index_count / 3, indices.data(), tangents); + + for (U16 v = 0; v < strider_vertex_count; ++v) + { + tangentsp[v] = tangents[v]; + } + + delete[] vertices; + delete[] normals; + delete[] tangents; +} + void LLTerrainPartition::getGeometry(LLSpatialGroup* group) { LL_PROFILE_ZONE_SCOPED; @@ -1094,37 +1040,57 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) LLVertexBuffer* buffer = group->mVertexBuffer; //get vertex buffer striders - LLStrider vertices; - LLStrider normals; - LLStrider tangents; - LLStrider texcoords; - LLStrider texcoords2; - LLStrider indices; - - llassert_always(buffer->getVertexStrider(vertices)); - llassert_always(buffer->getNormalStrider(normals)); - llassert_always(buffer->getTangentStrider(tangents)); - llassert_always(buffer->getTexCoord0Strider(texcoords)); - llassert_always(buffer->getTexCoord1Strider(texcoords2)); - llassert_always(buffer->getIndexStrider(indices)); - - U32 indices_index = 0; - U32 index_offset = 0; - - for (std::vector::iterator i = mFaceList.begin(); i != mFaceList.end(); ++i) - { - LLFace* facep = *i; + LLStrider vertices_start; + LLStrider normals_start; + LLStrider tangents_start; + LLStrider texcoords_start; + LLStrider texcoords2_start; + LLStrider indices_start; + + llassert_always(buffer->getVertexStrider(vertices_start)); + llassert_always(buffer->getNormalStrider(normals_start)); + llassert_always(buffer->getTangentStrider(tangents_start)); + llassert_always(buffer->getTexCoord0Strider(texcoords_start)); + llassert_always(buffer->getTexCoord1Strider(texcoords2_start)); + llassert_always(buffer->getIndexStrider(indices_start)); + + U32 indices_index = 0; + U32 index_offset = 0; - facep->setIndicesIndex(indices_index); - facep->setGeomIndex(index_offset); - facep->setVertexBuffer(buffer); + { + LLStrider vertices = vertices_start; + LLStrider normals = normals_start; + LLStrider texcoords = texcoords_start; + LLStrider texcoords2 = texcoords2_start; + LLStrider indices = indices_start; + + for (std::vector::iterator i = mFaceList.begin(); i != mFaceList.end(); ++i) + { + LLFace* facep = *i; + + facep->setIndicesIndex(indices_index); + facep->setGeomIndex(index_offset); + facep->setVertexBuffer(buffer); + + LLVOSurfacePatch* patchp = (LLVOSurfacePatch*) facep->getViewerObject(); + patchp->getTerrainGeometry(vertices, normals, texcoords, texcoords2, indices); + + indices_index += facep->getIndicesCount(); + index_offset += facep->getGeomCount(); + } + } - LLVOSurfacePatch* patchp = (LLVOSurfacePatch*) facep->getViewerObject(); - patchp->getTerrainGeometry(vertices, normals, tangents, texcoords, texcoords2, indices); + const bool has_tangents = tangents_start.get() != nullptr; + if (has_tangents) + { + LLStrider vertices = vertices_start; + LLStrider normals = normals_start; + LLStrider tangents = tangents_start; + LLStrider texcoords = texcoords_start; + LLStrider indices = indices_start; - indices_index += facep->getIndicesCount(); - index_offset += facep->getGeomCount(); - } + gen_terrain_tangents(index_offset, indices_index, vertices, normals, tangents, texcoords, indices); + } buffer->unmapBuffer(); mFaceList.clear(); -- cgit v1.2.3 From de9184479cfc179ba6e9d6ff388aff7da7f0b4ab Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 09:58:50 -0700 Subject: DRTVWR-592: (WIP) Fix tiling only in the PBR case. Begin hooking up code for PBR-specific terrain geometry updates. Unfortunately, this version has a bug which can cause rebuilds to be skipped. Needs more work/testing --- indra/newview/llvosurfacepatch.cpp | 84 ++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 35 deletions(-) (limited to 'indra/newview/llvosurfacepatch.cpp') diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp index 839eb2b737..69b721c899 100644 --- a/indra/newview/llvosurfacepatch.cpp +++ b/indra/newview/llvosurfacepatch.cpp @@ -246,7 +246,8 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, LLStrider &normalsp, LLStrider &texCoords0p, LLStrider &texCoords1p, - LLStrider &indicesp) + LLStrider &indicesp, + bool pbr) { LLFace* facep = mDrawable->getFace(0); if (!facep) @@ -262,30 +263,34 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, texCoords0p, texCoords1p, indicesp, - index_offset); + index_offset, + pbr); updateNorthGeometry(facep, verticesp, normalsp, texCoords0p, texCoords1p, indicesp, - index_offset); + index_offset, + pbr); updateEastGeometry(facep, verticesp, normalsp, texCoords0p, texCoords1p, indicesp, - index_offset); + index_offset, + pbr); } void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp, - U32 &index_offset) + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp, + U32 &index_offset, + bool pbr) { S32 i, j, x, y; @@ -321,7 +326,7 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, { x = i * render_stride; y = j * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -384,12 +389,13 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp, - U32 &index_offset) + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp, + U32 &index_offset, + bool pbr) { S32 vertex_count = 0; S32 i, x, y; @@ -421,7 +427,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -434,7 +440,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, { x = i * render_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -471,7 +477,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -485,7 +491,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -529,7 +535,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * north_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -543,7 +549,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * north_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -581,12 +587,13 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, } void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp, - U32 &index_offset) + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp, + U32 &index_offset, + bool pbr) { S32 i, x, y; @@ -612,7 +619,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -624,7 +631,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, { x = 16; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -660,7 +667,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -672,7 +679,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -714,7 +721,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * east_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -726,7 +733,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16; y = i * east_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -1037,6 +1044,13 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) { LL_PROFILE_ZONE_SCOPED; + const LLFace* region_facep = *mFaceList.begin(); + const LLViewerObject* region_patchp = region_facep->getViewerObject(); + LLVLComposition* composition = region_patchp->mRegionp->getComposition(); + // TODO: This is not good; it will result in wrong texture repeats in cases where the assets have not loaded. Need to rebuild terrain on asset load event if it changes the composition type. Probably best to have a flag to bookkeep that, to know if the composition type has actually changed. Make sure the draw pool is boosting the textures so they load in a timely fashion. + composition->updateMaterialType(); + const bool pbr = composition->getMaterialType() == LLTerrainMaterial::Type::PBR; + LLVertexBuffer* buffer = group->mVertexBuffer; //get vertex buffer striders -- cgit v1.2.3 From 2318d657660320b921e1566b54d3833c0401a34c Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Mon, 22 May 2023 10:10:14 -0700 Subject: Revert "DRTVWR-592: (WIP) Fix tiling only in the PBR case. Begin hooking up code for PBR-specific terrain geometry updates. Unfortunately, this version has a bug which can cause rebuilds to be skipped. Needs more work/testing" This reverts commit de9184479cfc179ba6e9d6ff388aff7da7f0b4ab. --- indra/newview/llvosurfacepatch.cpp | 84 ++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 49 deletions(-) (limited to 'indra/newview/llvosurfacepatch.cpp') diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp index 69b721c899..839eb2b737 100644 --- a/indra/newview/llvosurfacepatch.cpp +++ b/indra/newview/llvosurfacepatch.cpp @@ -246,8 +246,7 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, LLStrider &normalsp, LLStrider &texCoords0p, LLStrider &texCoords1p, - LLStrider &indicesp, - bool pbr) + LLStrider &indicesp) { LLFace* facep = mDrawable->getFace(0); if (!facep) @@ -263,34 +262,30 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, texCoords0p, texCoords1p, indicesp, - index_offset, - pbr); + index_offset); updateNorthGeometry(facep, verticesp, normalsp, texCoords0p, texCoords1p, indicesp, - index_offset, - pbr); + index_offset); updateEastGeometry(facep, verticesp, normalsp, texCoords0p, texCoords1p, indicesp, - index_offset, - pbr); + index_offset); } void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp, - U32 &index_offset, - bool pbr) + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp, + U32 &index_offset) { S32 i, j, x, y; @@ -326,7 +321,7 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, { x = i * render_stride; y = j * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -389,13 +384,12 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp, - U32 &index_offset, - bool pbr) + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp, + U32 &index_offset) { S32 vertex_count = 0; S32 i, x, y; @@ -427,7 +421,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -440,7 +434,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, { x = i * render_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -477,7 +471,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -491,7 +485,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -535,7 +529,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * north_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -549,7 +543,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * north_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -587,13 +581,12 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, } void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp, - U32 &index_offset, - bool pbr) + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp, + U32 &index_offset) { S32 i, x, y; @@ -619,7 +612,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -631,7 +624,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, { x = 16; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -667,7 +660,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -679,7 +672,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -721,7 +714,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * east_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -733,7 +726,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16; y = i * east_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -1044,13 +1037,6 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) { LL_PROFILE_ZONE_SCOPED; - const LLFace* region_facep = *mFaceList.begin(); - const LLViewerObject* region_patchp = region_facep->getViewerObject(); - LLVLComposition* composition = region_patchp->mRegionp->getComposition(); - // TODO: This is not good; it will result in wrong texture repeats in cases where the assets have not loaded. Need to rebuild terrain on asset load event if it changes the composition type. Probably best to have a flag to bookkeep that, to know if the composition type has actually changed. Make sure the draw pool is boosting the textures so they load in a timely fashion. - composition->updateMaterialType(); - const bool pbr = composition->getMaterialType() == LLTerrainMaterial::Type::PBR; - LLVertexBuffer* buffer = group->mVertexBuffer; //get vertex buffer striders -- cgit v1.2.3 From 57433341abffba9382e6899b164af40200f5d6d3 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:35:02 -0700 Subject: Revert "Revert "DRTVWR-592: (WIP) Fix tiling only in the PBR case. Begin hooking up code for PBR-specific terrain geometry updates. Unfortunately, this version has a bug which can cause rebuilds to be skipped. Needs more work/testing"" This reverts commit 2318d657660320b921e1566b54d3833c0401a34c. --- indra/newview/llvosurfacepatch.cpp | 84 ++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 35 deletions(-) (limited to 'indra/newview/llvosurfacepatch.cpp') diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp index 839eb2b737..69b721c899 100644 --- a/indra/newview/llvosurfacepatch.cpp +++ b/indra/newview/llvosurfacepatch.cpp @@ -246,7 +246,8 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, LLStrider &normalsp, LLStrider &texCoords0p, LLStrider &texCoords1p, - LLStrider &indicesp) + LLStrider &indicesp, + bool pbr) { LLFace* facep = mDrawable->getFace(0); if (!facep) @@ -262,30 +263,34 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, texCoords0p, texCoords1p, indicesp, - index_offset); + index_offset, + pbr); updateNorthGeometry(facep, verticesp, normalsp, texCoords0p, texCoords1p, indicesp, - index_offset); + index_offset, + pbr); updateEastGeometry(facep, verticesp, normalsp, texCoords0p, texCoords1p, indicesp, - index_offset); + index_offset, + pbr); } void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp, - U32 &index_offset) + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp, + U32 &index_offset, + bool pbr) { S32 i, j, x, y; @@ -321,7 +326,7 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, { x = i * render_stride; y = j * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -384,12 +389,13 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp, - U32 &index_offset) + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp, + U32 &index_offset, + bool pbr) { S32 vertex_count = 0; S32 i, x, y; @@ -421,7 +427,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -434,7 +440,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, { x = i * render_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -471,7 +477,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -485,7 +491,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -529,7 +535,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * north_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -543,7 +549,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * north_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -581,12 +587,13 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, } void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, - LLStrider &verticesp, - LLStrider &normalsp, - LLStrider &texCoords0p, - LLStrider &texCoords1p, - LLStrider &indicesp, - U32 &index_offset) + LLStrider &verticesp, + LLStrider &normalsp, + LLStrider &texCoords0p, + LLStrider &texCoords1p, + LLStrider &indicesp, + U32 &index_offset, + bool pbr) { S32 i, x, y; @@ -612,7 +619,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -624,7 +631,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, { x = 16; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -660,7 +667,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -672,7 +679,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -714,7 +721,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * east_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -726,7 +733,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16; y = i * east_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); verticesp++; normalsp++; texCoords0p++; @@ -1037,6 +1044,13 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) { LL_PROFILE_ZONE_SCOPED; + const LLFace* region_facep = *mFaceList.begin(); + const LLViewerObject* region_patchp = region_facep->getViewerObject(); + LLVLComposition* composition = region_patchp->mRegionp->getComposition(); + // TODO: This is not good; it will result in wrong texture repeats in cases where the assets have not loaded. Need to rebuild terrain on asset load event if it changes the composition type. Probably best to have a flag to bookkeep that, to know if the composition type has actually changed. Make sure the draw pool is boosting the textures so they load in a timely fashion. + composition->updateMaterialType(); + const bool pbr = composition->getMaterialType() == LLTerrainMaterial::Type::PBR; + LLVertexBuffer* buffer = group->mVertexBuffer; //get vertex buffer striders -- cgit v1.2.3 From b9ba57fd0004751dfbcbea90264a6e16c5849e5e Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:38:42 -0700 Subject: DRTVWR-592: (WIP) Fix terrain PBR texture repeat seam. Legacy terrain texture repeats currently broken --- indra/newview/llvosurfacepatch.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/newview/llvosurfacepatch.cpp') diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp index 69b721c899..a672777914 100644 --- a/indra/newview/llvosurfacepatch.cpp +++ b/indra/newview/llvosurfacepatch.cpp @@ -1046,10 +1046,10 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) const LLFace* region_facep = *mFaceList.begin(); const LLViewerObject* region_patchp = region_facep->getViewerObject(); - LLVLComposition* composition = region_patchp->mRegionp->getComposition(); + LLVLComposition* composition = region_patchp->getRegion()->getComposition(); // TODO: This is not good; it will result in wrong texture repeats in cases where the assets have not loaded. Need to rebuild terrain on asset load event if it changes the composition type. Probably best to have a flag to bookkeep that, to know if the composition type has actually changed. Make sure the draw pool is boosting the textures so they load in a timely fashion. composition->updateMaterialType(); - const bool pbr = composition->getMaterialType() == LLTerrainMaterial::Type::PBR; + const bool pbr = composition->getMaterialType() == LLTerrainMaterials::Type::PBR; LLVertexBuffer* buffer = group->mVertexBuffer; @@ -1087,7 +1087,7 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) facep->setVertexBuffer(buffer); LLVOSurfacePatch* patchp = (LLVOSurfacePatch*) facep->getViewerObject(); - patchp->getTerrainGeometry(vertices, normals, texcoords, texcoords2, indices); + patchp->getTerrainGeometry(vertices, normals, texcoords, texcoords2, indices, pbr); indices_index += facep->getIndicesCount(); index_offset += facep->getGeomCount(); -- cgit v1.2.3 From d6aced7abf0c54ec94033534124025c87fb9aeb2 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:38:54 -0700 Subject: DRTVWR-592: Remove WIP separate code path for terrain geometry rebuilds for PBR as that is not needed at the moment --- indra/newview/llvosurfacepatch.cpp | 56 ++++++++++++++------------------------ 1 file changed, 21 insertions(+), 35 deletions(-) (limited to 'indra/newview/llvosurfacepatch.cpp') diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp index a672777914..6318361d8d 100644 --- a/indra/newview/llvosurfacepatch.cpp +++ b/indra/newview/llvosurfacepatch.cpp @@ -246,8 +246,7 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, LLStrider &normalsp, LLStrider &texCoords0p, LLStrider &texCoords1p, - LLStrider &indicesp, - bool pbr) + LLStrider &indicesp) { LLFace* facep = mDrawable->getFace(0); if (!facep) @@ -263,24 +262,21 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider &verticesp, texCoords0p, texCoords1p, indicesp, - index_offset, - pbr); + index_offset); updateNorthGeometry(facep, verticesp, normalsp, texCoords0p, texCoords1p, indicesp, - index_offset, - pbr); + index_offset); updateEastGeometry(facep, verticesp, normalsp, texCoords0p, texCoords1p, indicesp, - index_offset, - pbr); + index_offset); } void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, @@ -289,8 +285,7 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, LLStrider &texCoords0p, LLStrider &texCoords1p, LLStrider &indicesp, - U32 &index_offset, - bool pbr) + U32 &index_offset) { S32 i, j, x, y; @@ -326,7 +321,7 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep, { x = i * render_stride; y = j * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -394,8 +389,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, LLStrider &texCoords0p, LLStrider &texCoords1p, LLStrider &indicesp, - U32 &index_offset, - bool pbr) + U32 &index_offset) { S32 vertex_count = 0; S32 i, x, y; @@ -427,7 +421,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -440,7 +434,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, { x = i * render_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -477,7 +471,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -491,7 +485,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * render_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -535,7 +529,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * north_stride; y = 16 - render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -549,7 +543,7 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep, x = i * north_stride; y = 16; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -592,8 +586,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, LLStrider &texCoords0p, LLStrider &texCoords1p, LLStrider &indicesp, - U32 &index_offset, - bool pbr) + U32 &index_offset) { S32 i, x, y; @@ -619,7 +612,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -631,7 +624,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, { x = 16; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -667,7 +660,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -679,7 +672,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16; y = i * render_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -721,7 +714,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16 - render_stride; y = i * east_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -733,7 +726,7 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep, x = 16; y = i * east_stride; - mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get(), pbr); + mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get()); verticesp++; normalsp++; texCoords0p++; @@ -1044,13 +1037,6 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) { LL_PROFILE_ZONE_SCOPED; - const LLFace* region_facep = *mFaceList.begin(); - const LLViewerObject* region_patchp = region_facep->getViewerObject(); - LLVLComposition* composition = region_patchp->getRegion()->getComposition(); - // TODO: This is not good; it will result in wrong texture repeats in cases where the assets have not loaded. Need to rebuild terrain on asset load event if it changes the composition type. Probably best to have a flag to bookkeep that, to know if the composition type has actually changed. Make sure the draw pool is boosting the textures so they load in a timely fashion. - composition->updateMaterialType(); - const bool pbr = composition->getMaterialType() == LLTerrainMaterials::Type::PBR; - LLVertexBuffer* buffer = group->mVertexBuffer; //get vertex buffer striders @@ -1087,7 +1073,7 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group) facep->setVertexBuffer(buffer); LLVOSurfacePatch* patchp = (LLVOSurfacePatch*) facep->getViewerObject(); - patchp->getTerrainGeometry(vertices, normals, texcoords, texcoords2, indices, pbr); + patchp->getTerrainGeometry(vertices, normals, texcoords, texcoords2, indices); indices_index += facep->getIndicesCount(); index_offset += facep->getGeomCount(); -- cgit v1.2.3 From 7f7431891661668b898e03345c8023b4bbd0d9d9 Mon Sep 17 00:00:00 2001 From: Cosmic Linden Date: Fri, 13 Oct 2023 10:38:59 -0700 Subject: DRTVWR-592: Add tracy block to gen_terrain_tangents (not profiled) --- indra/newview/llvosurfacepatch.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/llvosurfacepatch.cpp') diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp index 6318361d8d..feb1e26d57 100644 --- a/indra/newview/llvosurfacepatch.cpp +++ b/indra/newview/llvosurfacepatch.cpp @@ -1001,6 +1001,8 @@ void gen_terrain_tangents(U16 strider_vertex_count, LLStrider &texCoords0p, LLStrider &indicesp) { + LL_PROFILE_ZONE_SCOPED + LLVector4a *vertices = new LLVector4a[strider_vertex_count]; LLVector4a *normals = new LLVector4a[strider_vertex_count]; LLVector4a *tangents = new LLVector4a[strider_vertex_count]; -- cgit v1.2.3