1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
7 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
9 \*---------------------------------------------------------------------------*/
10 /*---------------------------------------------------------------------------*\
13 * This library is free software; you can redistribute it and/or modify it *
14 * under the terms of the GNU Library General Public License as published *
15 * by the Free Software Foundation, version 2. *
17 * This library is distributed in the hope that it will be useful, but *
18 * WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
20 * Library General Public License for more details. *
22 * You should have received a copy of the GNU Library General Public *
23 * License along with this library; if not, write to the Free Software *
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
26 \*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*\
35 \*---------------------------------------------------------------------------*/
37 //---------------------------------------------------------------------------
39 //---------------------------------------------------------------------------
43 /*--------------------- Plane and Frustums Test --------------------------*/
46 // Check to see if a point is fully behind (inside the negative halfspace of) a plane.
48 inline bool ClusterShadingStage::PointInsidePlane(
52 Real32 val = plane.getNormal().dot(p) - plane.getDistanceFromOrigin();
57 // Check to see if a sphere is fully behind (inside the negative halfspace of) a plane.
59 inline bool ClusterShadingStage::SphereInsidePlane(
63 Real32 val = plane.getNormal().dot(sphere.c) - plane.getDistanceFromOrigin();
64 return val < -sphere.r;
68 // Check to see if a cone if fully behind (inside the negative halfspace of) a plane.
70 inline bool ClusterShadingStage::ConeInsidePlane(
74 // Compute the farthest point on the end of the cone to the positive space of the plane.
75 Vec3f m = plane.getNormal().cross(cone.d).cross(cone.d);
76 Pnt3f Q = cone.T + cone.d * cone.h - m * cone.r;
78 // The cone is in the negative halfspace of the plane if both
79 // the tip of the cone and the farthest point on the end of the cone to the
80 // positive halfspace of the plane are both inside the negative halfspace
82 return PointInsidePlane(cone.T, plane) && PointInsidePlane(Q, plane);
86 // Check to see of a point light is partially contained within the frustum.
88 inline bool ClusterShadingStage::SphereInsideFrustum(
90 const Frustum& frustum,
96 if (sphere.c.z() - sphere.r > zNear || zFar > sphere.c.z() + sphere.r)
101 for (int i = 0; i < 4 && result; i++)
103 if (SphereInsidePlane(sphere, frustum.planes[i]))
112 inline bool ClusterShadingStage::ConeInsideFrustum(
114 const Frustum& frustum,
120 Plane nearPlane(Vec3f(0, 0,-1),-zNear);
121 Plane farPlane (Vec3f(0, 0, 1), zFar );
123 if (ConeInsidePlane(cone, nearPlane) || ConeInsidePlane(cone, farPlane))
128 for (int i = 0; i < 4 && result; i++)
130 if (ConeInsidePlane(cone, frustum.planes[i]))