From 8c05a5c260272b35bbcf1073a051735bf27b25c9 Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Tue, 23 May 2023 23:22:17 -0300 Subject: [PATCH] Fix planar reflections' actor culling Thanks jwwalker for spotting these issues. See https://forums.ogre3d.org/viewtopic.php?p=554613 --- .../src/OgrePlanarReflections.cpp | 87 +++++++++---------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/Components/PlanarReflections/src/OgrePlanarReflections.cpp b/Components/PlanarReflections/src/OgrePlanarReflections.cpp index aeb8039d637..e60f16157a7 100644 --- a/Components/PlanarReflections/src/OgrePlanarReflections.cpp +++ b/Components/PlanarReflections/src/OgrePlanarReflections.cpp @@ -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 ); } @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 ); }