Skip to content

Commit

Permalink
Fix planar reflections' actor culling
Browse files Browse the repository at this point in the history
Thanks jwwalker for spotting these issues.

See https://forums.ogre3d.org/viewtopic.php?p=554613
  • Loading branch information
darksylinc committed May 24, 2023
1 parent 930c21e commit 8c05a5c
Showing 1 changed file with 40 additions and 47 deletions.
87 changes: 40 additions & 47 deletions Components/PlanarReflections/src/OgrePlanarReflections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,33 +522,32 @@ namespace Ogre
ArrayMaskR vertexMask = ARRAY_MASK_ZERO;
ArrayReal dotResult;

ArrayVector3 tangentDir, vertexPoint;
ArrayVector3 tangentDir, vertexPoint, xMidpoint, yMidpoint;

tangentDir = actorsPlanes->planeNormals.yAxis() * actorsPlanes->xyHalfSize[1];
xMidpoint = actorsPlanes->planeNormals.xAxis() * actorsPlanes->xyHalfSize[0];
yMidpoint = actorsPlanes->planeNormals.yAxis() * actorsPlanes->xyHalfSize[1];

tangentDir = xMidpoint + yMidpoint;
vertexPoint = actorsPlanes->center + tangentDir;
dotResult = frustums[k].normal.dotProduct( vertexPoint ) - frustums[k].negD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = frustums[k].normal.dotProduct( vertexPoint );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, frustums[k].negD ) );

vertexPoint = actorsPlanes->center - tangentDir;
dotResult = frustums[k].normal.dotProduct( vertexPoint ) - frustums[k].negD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = frustums[k].normal.dotProduct( vertexPoint );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, frustums[k].negD ) );

tangentDir = actorsPlanes->planeNormals.xAxis() * actorsPlanes->xyHalfSize[0];
tangentDir = xMidpoint - yMidpoint;
vertexPoint = actorsPlanes->center + tangentDir;
dotResult = frustums[k].normal.dotProduct( vertexPoint ) - frustums[k].negD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = frustums[k].normal.dotProduct( vertexPoint );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, frustums[k].negD ) );

vertexPoint = actorsPlanes->center - tangentDir;
dotResult = frustums[k].normal.dotProduct( vertexPoint ) - frustums[k].negD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = frustums[k].normal.dotProduct( vertexPoint );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, frustums[k].negD ) );

mask = Mathlib::And( mask, vertexMask );
}
Expand All @@ -571,10 +570,9 @@ namespace Ogre
//for( int l=0; l<8; ++l )
for( int l=0; l<4; ++l )
{
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] ) - actorPlaneNegD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, actorPlaneNegD ) );
}
mask = Mathlib::And( mask, vertexMask );

Expand All @@ -584,23 +582,21 @@ namespace Ogre
vertexMask = ARRAY_MASK_ZERO;
for( int l=0; l<8; ++l )
{
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] ) - actorPlaneNegD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, actorPlaneNegD ) );
}
mask = Mathlib::And( mask, vertexMask );

//North plane
actorPlaneNormal = actorsPlanes->planeNormals.yAxis();
// North plane
actorPlaneNormal = -actorsPlanes->planeNormals.yAxis();
actorPlaneNegD = actorsPlanes->planeNegD[1];
vertexMask = ARRAY_MASK_ZERO;
for( int l=0; l<8; ++l )
{
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] ) - actorPlaneNegD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, actorPlaneNegD ) );
}
mask = Mathlib::And( mask, vertexMask );

Expand All @@ -610,23 +606,21 @@ namespace Ogre
vertexMask = ARRAY_MASK_ZERO;
for( int l=0; l<8; ++l )
{
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] ) - actorPlaneNegD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, actorPlaneNegD ) );
}
mask = Mathlib::And( mask, vertexMask );

//East plane
actorPlaneNormal = actorsPlanes->planeNormals.xAxis();
// East plane
actorPlaneNormal = -actorsPlanes->planeNormals.xAxis();
actorPlaneNegD = actorsPlanes->planeNegD[3];
vertexMask = ARRAY_MASK_ZERO;
for( int l=0; l<8; ++l )
{
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] ) - actorPlaneNegD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, actorPlaneNegD ) );
}
mask = Mathlib::And( mask, vertexMask );

Expand All @@ -636,10 +630,9 @@ namespace Ogre
vertexMask = ARRAY_MASK_ZERO;
for( int l=0; l<8; ++l )
{
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] ) - actorPlaneNegD;
vertexMask = Mathlib::Or( vertexMask,
Mathlib::CompareGreater( dotResult,
ARRAY_REAL_ZERO ) );
dotResult = actorPlaneNormal.dotProduct( worldSpaceCorners[l] );
vertexMask =
Mathlib::Or( vertexMask, Mathlib::CompareGreater( dotResult, actorPlaneNegD ) );
}
mask = Mathlib::And( mask, vertexMask );
}
Expand Down

0 comments on commit 8c05a5c

Please sign in to comment.