Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove RendererLight::intersectsAABB()
Now that RendererLight exposes a lightAABB() method to return the actual AABB
of the illuminated area, we can just do a simple intersection test between
lightAABB and worldAABB for each lit object, instead of calling the complex and
slow Light::intersectsAABB() method.
  • Loading branch information
Matthew Mott committed Dec 15, 2020
1 parent a8a19be commit e649657
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 54 deletions.
3 changes: 0 additions & 3 deletions include/irender.h
Expand Up @@ -194,9 +194,6 @@ class RendererLight
*/
virtual Matrix4 getLightTextureTransformation() const = 0;

/// Return true if this light intersects the given AABB
virtual bool intersectsAABB(const AABB& aabb) const = 0;

/**
* \brief
* Return the AABB of the illuminated volume.
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/brush/BrushNode.cpp
Expand Up @@ -296,7 +296,7 @@ void BrushNode::DEBUG_verify() {
}

bool BrushNode::intersectsLight(const RendererLight& light) const {
return light.intersectsAABB(worldAABB());
return light.lightAABB().intersects(worldAABB());
}

void BrushNode::renderComponents(RenderableCollector& collector, const VolumeTest& volume) const
Expand Down
50 changes: 4 additions & 46 deletions radiantcore/entity/light/Light.cpp
Expand Up @@ -730,60 +730,18 @@ Matrix4 Light::getLightTextureTransformation() const
// outside the volume), used for drag manipulator and render culling.
AABB Light::lightAABB() const
{
if (isProjected())
// Return Frustum AABB in *world* space
return _frustum.getTransformedBy(_owner.localToParent()).getAABB();
else
return AABB(_originTransformed, m_doom3Radius.m_radiusTransformed);
}

bool Light::intersectsAABB(const AABB& other) const
{
bool returnVal;

if (isProjected())
{
// Update the projection, including the Frustum (we don't care about the
// projection matrix itself).
// Make sure our frustum is up to date
updateProjection();

// Construct a transformation with the rotation and translation of the
// frustum
Matrix4 transRot = Matrix4::getIdentity();
transRot.translateBy(worldOrigin());
transRot.multiplyBy(rotation());

// Transform the frustum with the rotate/translate matrix and test its
// intersection with the AABB
Frustum frustumTrans = _frustum.getTransformedBy(transRot);

VolumeIntersectionValue intersects = frustumTrans.testIntersection(other);

returnVal = intersects != VOLUME_OUTSIDE;
// Return Frustum AABB in *world* space
return _frustum.getTransformedBy(_owner.localToParent()).getAABB();
}
else
{
// test against an AABB which contains the rotated bounds of this light.
AABB bounds = localAABB();
bounds.origin += worldOrigin();

returnVal = other.intersects(AABB(
bounds.origin,
Vector3(
static_cast<float>(fabs(m_rotation[0] * bounds.extents[0])
+ fabs(m_rotation[3] * bounds.extents[1])
+ fabs(m_rotation[6] * bounds.extents[2])),
static_cast<float>(fabs(m_rotation[1] * bounds.extents[0])
+ fabs(m_rotation[4] * bounds.extents[1])
+ fabs(m_rotation[7] * bounds.extents[2])),
static_cast<float>(fabs(m_rotation[2] * bounds.extents[0])
+ fabs(m_rotation[5] * bounds.extents[1])
+ fabs(m_rotation[8] * bounds.extents[2]))
)
));
return AABB(_originTransformed, m_doom3Radius.m_radiusTransformed);
}

return returnVal;
}

const Matrix4& Light::rotation() const {
Expand Down
1 change: 0 additions & 1 deletion radiantcore/entity/light/Light.h
Expand Up @@ -262,7 +262,6 @@ class Light :
const IRenderEntity& getLightEntity() const override;
const Vector3& worldOrigin() const override;
Matrix4 getLightTextureTransformation() const override;
bool intersectsAABB(const AABB& other) const override;
Vector3 getLightOrigin() const override;
const ShaderPtr& getShader() const override;

Expand Down
2 changes: 1 addition & 1 deletion radiantcore/model/md5/MD5ModelNode.cpp
Expand Up @@ -69,7 +69,7 @@ bool MD5ModelNode::getIntersection(const Ray& ray, Vector3& intersection)

bool MD5ModelNode::intersectsLight(const RendererLight& light) const
{
return light.intersectsAABB(worldAABB());
return light.lightAABB().intersects(worldAABB());
}

void MD5ModelNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/model/picomodel/StaticModelNode.cpp
Expand Up @@ -87,7 +87,7 @@ void StaticModelNode::setModel(const StaticModelPtr& model) {
// LitObject test function
bool StaticModelNode::intersectsLight(const RendererLight& light) const
{
return light.intersectsAABB(worldAABB());
return light.lightAABB().intersects(worldAABB());
}

void StaticModelNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/patch/PatchNode.cpp
Expand Up @@ -262,7 +262,7 @@ bool PatchNode::getIntersection(const Ray& ray, Vector3& intersection)
}

bool PatchNode::intersectsLight(const RendererLight& light) const {
return light.intersectsAABB(worldAABB());
return light.lightAABB().intersects(worldAABB());
}

void PatchNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
Expand Down

0 comments on commit e649657

Please sign in to comment.