Better env_probe interpolation when triangles form a line

This commit is contained in:
Robert Beckebans 2024-10-15 20:38:09 +02:00
parent 9a99185fe9
commit 590cc61c24
6 changed files with 38 additions and 7 deletions

View file

@ -4,8 +4,8 @@ bind "N" "noclip"
//bind "M" "spawn moveable_macbethchart"
bind "M" "maskShot"
bind "O" "toggle r_useMaskedOcclusionCulling"
bind "P" "toggle r_showPortals"
// bind "P" "toggle r_showViewEnvprobes 1 2 0"
//bind "P" "toggle r_showPortals"
bind "P" "toggle r_showViewEnvprobes 1 2 3 0"
bind "F1" "editLights"
bind "F2" "toggle r_showTris 1 2 0"

View file

@ -1178,8 +1178,12 @@ void idRenderBackend::DBG_ShowViewEnvprobes()
float denom = idWinding::TriangleArea( verts[0], verts[1], verts[2] );
if( denom == 0 )
{
// all points at same location
barycentricWeights.Set( 1, 0, 0 );
// triangle is line
float t;
R_ClosestPointOnLineSegment( testOrigin, verts[0], verts[1], t );
barycentricWeights.Set( 1.0f - t, t, 0 );
}
else
{

View file

@ -1675,6 +1675,7 @@ void R_CreateStaticBuffersForTri( srfTriangles_t& tri, nvrhi::ICommandList* c
// RB
idVec3 R_ClosestPointPointTriangle( const idVec3& point, const idVec3& vertex1, const idVec3& vertex2, const idVec3& vertex3 );
idVec3 R_ClosestPointOnLineSegment( const idVec3& point, const idVec3& lineStart, const idVec3& lineEnd, float& t );
// deformable meshes precalculate as much as possible from a base frame, then generate
// complete srfTriangles_t from just a new set of vertexes

View file

@ -313,7 +313,7 @@ idCVar r_renderMode( "r_renderMode", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_IN
idCVar r_psxVertexJitter( "r_psxVertexJitter", "0.5", CVAR_RENDERER | CVAR_FLOAT | CVAR_NEW, "", 0.0f, 0.75f );
idCVar r_psxAffineTextures( "r_psxAffineTextures", "1", CVAR_RENDERER | CVAR_FLOAT | CVAR_NEW, "" );
idCVar r_useMaskedOcclusionCulling( "r_useMaskedOcclusionCulling", "1", CVAR_RENDERER | CVAR_BOOL | CVAR_NEW, "SIMD optimized software culling by Intel" );
idCVar r_useMaskedOcclusionCulling( "r_useMaskedOcclusionCulling", "1", CVAR_RENDERER | CVAR_BOOL | CVAR_NOCHEAT | CVAR_NEW, "SIMD optimized software culling by Intel" );
// RB end
const char* fileExten[4] = { "tga", "png", "jpg", "exr" };

View file

@ -558,8 +558,12 @@ static void R_FindClosestEnvironmentProbes()
float denom = idWinding::TriangleArea( verts[0], verts[1], verts[2] );
if( denom == 0 )
{
// all points at same location
bary.Set( 1, 0, 0 );
// triangle is line
float t;
R_ClosestPointOnLineSegment( testOrigin, verts[0], verts[1], t );
bary.Set( 1.0f - t, t, 0 );
}
else
{

View file

@ -2242,6 +2242,28 @@ idVec3 R_ClosestPointPointTriangle( const idVec3& point, const idVec3& vertex1,
return result;
}
idVec3 R_ClosestPointOnLineSegment( const idVec3& point, const idVec3& lineStart, const idVec3& lineEnd, float& t )
{
idVec3 lineDirection = lineEnd - lineStart;
float lineLengthSquared = lineDirection.LengthSqr();
if( lineLengthSquared == 0.0f )
{
// the line segment is actually a point
t = 0.0f;
return lineStart;
}
// calculate the projection of the point onto the line
t = ( ( point - lineStart ) * lineDirection ) / lineLengthSquared;
// clamp t to the range [0, 1] to ensure the closest point is on the line segment
t = idMath::ClampFloat( 0, 1, t );
// calculate the closest point on the line segment
return lineStart + t * lineDirection;
}
void R_CreateMaskedOcclusionCullingTris( srfTriangles_t* tri )
{
//assert( tri->mocVerts == NULL );