summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorCosmic Linden <cosmic@lindenlab.com>2023-10-13 09:57:24 -0700
committerCosmic Linden <cosmic@lindenlab.com>2023-10-13 09:57:24 -0700
commit49a5b79c2b1ba5f4b909d1bfab89bb7ad9c1e888 (patch)
tree8b523f42c6c778967fa01a54db186fab1df1c520 /indra
parent474923e3cb29df35e8807006ad16861eb1dc24d0 (diff)
DRTVWR-592: (WIP) Debugging, rethinking
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl3
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl7
-rw-r--r--indra/newview/lldrawpoolterrain.h1
-rw-r--r--indra/newview/llvosurfacepatch.cpp83
4 files changed, 51 insertions, 43 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
index 96903aeba8..2426199056 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainF.glsl
@@ -33,6 +33,8 @@ uniform sampler2D alpha_ramp;
in vec3 pos;
in vec3 vary_normal;
+in vec3 vary_tangent; // TODO: Decide if we want to keep this
+flat in float vary_sign; // TODO: Decide if we want to keep this
in vec4 vary_texcoord0;
in vec4 vary_texcoord1;
@@ -53,6 +55,7 @@ void main()
outColor.a = 0.0; // yes, downstream atmospherics
frag_data[0] = outColor;
+ frag_data[0] = vec4((0.5 * (1.0 + vary_sign)) * vary_tangent.xyz, 1.0); // TODO: Remove
frag_data[1] = vec4(0.0,0.0,0.0,-1.0);
vec3 nvn = normalize(vary_normal);
frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
index e8747a1f6b..fcc4448a80 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
@@ -29,15 +29,20 @@ uniform mat4 modelview_projection_matrix;
in vec3 position;
in vec3 normal;
+in vec4 tangent;
in vec4 diffuse_color;
in vec2 texcoord0;
in vec2 texcoord1;
out vec3 pos;
out vec3 vary_normal;
+out vec3 vary_tangent; // TODO: Decide if we want to keep this
+flat out float vary_sign; // TODO: Decide if we want to keep this
out vec4 vary_texcoord0;
out vec4 vary_texcoord1;
+out vec4 debug_tangent; // TODO: Remove
+
uniform vec4 object_plane_s;
uniform vec4 object_plane_t;
@@ -65,6 +70,8 @@ void main()
pos = t_pos.xyz;
vary_normal = normalize(normal_matrix * normal);
+ vary_tangent = normalize(normal_matrix * tangent.xyz); // TODO: Decide if we want to keep this
+ vary_sign = tangent.w; // TODO: Decide if we want to keep this
// Transform and pass tex coords
vary_texcoord0.xy = texgen_object(vec4(position, 1.0), vec4(texcoord0,0,1), texture_matrix0, object_plane_s, object_plane_t).xy;
diff --git a/indra/newview/lldrawpoolterrain.h b/indra/newview/lldrawpoolterrain.h
index fbf6a8d917..2a487228ed 100644
--- a/indra/newview/lldrawpoolterrain.h
+++ b/indra/newview/lldrawpoolterrain.h
@@ -37,6 +37,7 @@ public:
{
VERTEX_DATA_MASK = LLVertexBuffer::MAP_VERTEX |
LLVertexBuffer::MAP_NORMAL |
+ LLVertexBuffer::MAP_TANGENT | // Only PBR terrain uses this currently
LLVertexBuffer::MAP_TEXCOORD0 |
LLVertexBuffer::MAP_TEXCOORD1
};
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<LLVector3> &verticesp,
- LLStrider<LLVector3> &normalsp,
- LLStrider<LLVector4a> &tangentsp,
- LLStrider<LLVector2> &texCoords0p) :
- vert_offset(vert_offset),
- vert_size(vert_size),
- verticesp(verticesp),
- normalsp(normalsp),
- texCoords0p(texCoords0p)
+ MikktTerrainData(U32 vert_offset,
+ U32 vert_size,
+ LLStrider<LLVector3> &verticesp,
+ LLStrider<LLVector3> &normalsp,
+ LLStrider<LLVector4a> &tangentsp,
+ LLStrider<LLVector2> &texCoords0p) :
+ mVertOffset(vert_offset),
+ mVertSize(vert_size),
+ mVerticesp(verticesp),
+ mNormalsp(normalsp),
+ mTangentsp(tangentsp),
+ mTexCoords0p(texCoords0p)
{
}
- S32 vert_offset;
- U32 vert_size;
- LLStrider<LLVector3> verticesp;
- LLStrider<LLVector3> normalsp;
- LLStrider<LLVector4a> tangentsp;
- LLStrider<LLVector2> texCoords0p;
+ U32 mVertOffset;
+ U32 mVertSize;
+ LLStrider<LLVector3> mVerticesp;
+ LLStrider<LLVector3> mNormalsp;
+ LLStrider<LLVector4a> mTangentsp;
+ LLStrider<LLVector2> 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<LLVector3> &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<LLVector2> texcoords2;
LLStrider<U16> 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));