diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index 7235847ce..387c398ec 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -371,7 +371,7 @@ void HWDrawInfo::AddLine (seg_t *seg, bool portalclip, FRenderState& state) backsector = hw_FakeFlat(drawctx, seg->backsector, in_area, true); - if (hw_CheckClip(seg->sidedef, currentsector, backsector)) + if (hw_CheckClip(seg->sidedef, currentsector, backsector, &ClipFrustum)) { if(!Viewpoint.IsAllowedOoB() && !(seg->sidedef->Flags & WALLF_DITHERTRANS_MID)) clipper.SafeAddClipRange(startAngle, endAngle); @@ -1048,6 +1048,10 @@ void HWDrawInfo::RenderBSP(void *node, bool drawpsprites, FRenderState& state) viewy = FLOAT2FIXED(Viewpoint.OffPos.Y); } + VSMatrix m = VPUniforms.mProjectionMatrix; + m.multMatrix(VPUniforms.mViewMatrix); + ClipFrustum.Set(m, Viewpoint.Pos); + validcount++; // used for processing sidedefs only once by the renderer. multithread = gl_multithread; diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.h b/src/rendering/hwrenderer/scene/hw_drawinfo.h index 7e9c4c53c..33d88ccef 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.h +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.h @@ -96,6 +96,50 @@ enum DrawListType GLDL_TYPES, }; +struct CameraFrustum +{ + void Set(const VSMatrix& worldToProjection, const DVector3& viewpoint); + + bool IsSphereVisible(const DVector3& point, double radius) const + { + for (int i = 0; i < 6; i++) + { + if ((Planes[i].XYZ() | point) < -radius) + return false; + } + return true; + } + + bool IsAABBVisible(const DVector3& aabbMin, const DVector3& aabbMax) const + { + DVector3 aabbCenter = (aabbMin + aabbMax) * 0.5; + DVector3 aabbExtents = (aabbMax - aabbMin) * 0.5; + for (int i = 0; i < 6; i++) + { + double distance = Planes[i] | DVector4(aabbCenter, 1.0); + double radius = AbsPlaneNormals[i] | aabbExtents; + bool outside = distance < -radius; + //bool inside = distance > radius; + //bool intersect = distance > -radius && distance < radius; + if (outside) + return false; + } + return true; + } + +private: + static DVector4 LeftFrustum(const VSMatrix& matrix); + static DVector4 RightFrustum(const VSMatrix& matrix); + static DVector4 TopFrustum(const VSMatrix& matrix); + static DVector4 BottomFrustum(const VSMatrix& matrix); + static DVector4 NearFrustum(const VSMatrix& matrix); + static DVector4 FarFrustum(const VSMatrix& matrix); + static DVector4 Normalize(DVector4 v); + + DVector3 AbsPlaneNormals[6]; + DVector4 Planes[6]; +}; + struct HWDrawInfo { struct wallseg @@ -149,6 +193,7 @@ struct HWDrawInfo Clipper *mClipper; Clipper *vClipper; // Vertical clipper Clipper *rClipper; // Radar clipper + CameraFrustum ClipFrustum; FRenderViewpoint Viewpoint; HWViewpointUniforms VPUniforms; // per-viewpoint uniform state VSMatrix ProjectionMatrix2; diff --git a/src/rendering/hwrenderer/scene/hw_visibleset.h b/src/rendering/hwrenderer/scene/hw_visibleset.h index 919a75321..d31b557c4 100644 --- a/src/rendering/hwrenderer/scene/hw_visibleset.h +++ b/src/rendering/hwrenderer/scene/hw_visibleset.h @@ -4,6 +4,7 @@ #include "r_utility.h" #include "hw_fakeflat.h" #include "hw_drawcontext.h" +#include "hw_drawinfo.h" #include #include #include @@ -13,50 +14,6 @@ class Clipper; class HWPortal; struct HWDrawInfo; -struct CameraFrustum -{ - void Set(const VSMatrix& worldToProjection, const DVector3& viewpoint); - - bool IsSphereVisible(const DVector3& point, double radius) const - { - for (int i = 0; i < 6; i++) - { - if ((Planes[i].XYZ() | point) < -radius) - return false; - } - return true; - } - - bool IsAABBVisible(const DVector3& aabbMin, const DVector3& aabbMax) const - { - DVector3 aabbCenter = (aabbMin + aabbMax) * 0.5; - DVector3 aabbExtents = (aabbMax - aabbMin) * 0.5; - for (int i = 0; i < 6; i++) - { - double distance = Planes[i] | DVector4(aabbCenter, 1.0); - double radius = AbsPlaneNormals[i] | aabbExtents; - bool outside = distance < -radius; - //bool inside = distance > radius; - //bool intersect = distance > -radius && distance < radius; - if (outside) - return false; - } - return true; - } - -private: - static DVector4 LeftFrustum(const VSMatrix& matrix); - static DVector4 RightFrustum(const VSMatrix& matrix); - static DVector4 TopFrustum(const VSMatrix& matrix); - static DVector4 BottomFrustum(const VSMatrix& matrix); - static DVector4 NearFrustum(const VSMatrix& matrix); - static DVector4 FarFrustum(const VSMatrix& matrix); - static DVector4 Normalize(DVector4 v); - - DVector3 AbsPlaneNormals[6]; - DVector4 Planes[6]; -}; - class HWVisibleSet { public: