Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove Light::worldOrigin()
For some reason this was a public virtual exposed on the RendererLight
interface despite not being used anywhere outside Light itself. Perhaps other
calls to this method were removed during recent renderer refactoring.
  • Loading branch information
Matthew Mott committed Feb 2, 2021
1 parent c9fba2d commit 859ed64
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 41 deletions.
23 changes: 5 additions & 18 deletions include/irender.h
Expand Up @@ -157,8 +157,7 @@ class RendererLight
virtual ~RendererLight() {}

/**
* \brief
* Return the render entity associated with this light
* \brief Return the render entity associated with this light
*
* The IRenderEntity is used to evaluate possible shader expressions in the
* shader returned by getShader(). The light object itself may be its own
Expand All @@ -170,17 +169,7 @@ class RendererLight
virtual const ShaderPtr& getShader() const = 0;

/**
* \brief Return the origin of the light volume in world space.
*
* This corresponds to the "origin" key of the light object, i.e. the center
* of the bounding box for an omni light and the tip of the pyramid for a
* projected light.
*/
virtual const Vector3& worldOrigin() const = 0;

/**
* \brief
* Return the world-space to light-texture-space transformation matrix.
* \brief Return the world-space to light-texture-space transformation matrix.
*
* The light texture space is a box, with coordinates [0..1] on each
* dimension, representing the texture (UV) coordinates of the light falloff
Expand All @@ -193,8 +182,7 @@ class RendererLight
virtual Matrix4 getLightTextureTransformation() const = 0;

/**
* \brief
* Return the AABB of the illuminated volume.
* \brief Return the AABB of the illuminated volume.
*
* This AABB represents the boundaries of the volume which are illuminated
* by this light. Anything outside of this volume does not need to be
Expand All @@ -208,8 +196,7 @@ class RendererLight
virtual AABB lightAABB() const = 0;

/**
* \brief
* Return the light origin in world space.
* \brief Return the light origin in world space.
*
* The light origin is the point from which the light rays are considered to
* be projected, i.e. the direction from which bump maps will be illuminated
Expand All @@ -227,7 +214,7 @@ typedef std::shared_ptr<RendererLight> RendererLightPtr;
/// Debug stream insertion for RendererLight
inline std::ostream& operator<< (std::ostream& os, const RendererLight& l)
{
return os << "RendererLight(origin=" << l.worldOrigin().pp()
return os << "RendererLight(origin=" << l.getLightOrigin().pp()
<< ", lightAABB=" << l.lightAABB() << ")";
}

Expand Down
33 changes: 14 additions & 19 deletions radiantcore/entity/light/Light.cpp
Expand Up @@ -161,7 +161,7 @@ void Light::updateOrigin() {

// Update the transformation matrix
_owner.localToParent() = Matrix4::getIdentity();
_owner.localToParent().translateBy(worldOrigin());
_owner.localToParent().translateBy(_originTransformed);
_owner.localToParent().multiplyBy(m_rotation.getMatrix4());

// Notify all child nodes
Expand Down Expand Up @@ -292,7 +292,7 @@ void Light::rotationChanged()

// Update the transformation matrix
_owner.localToParent() = Matrix4::getIdentity();
_owner.localToParent().translateBy(worldOrigin());
_owner.localToParent().translateBy(_originTransformed);
_owner.localToParent().multiplyBy(m_rotation.getMatrix4());

// Notify owner about this
Expand Down Expand Up @@ -449,7 +449,7 @@ Doom3LightRadius& Light::getDoom3Radius() {

void Light::renderProjectionPoints(RenderableCollector& collector,
const VolumeTest& volume,
const Matrix4& localToWorld) const
const Matrix4& localToWorld) const
{
// Add the renderable light target
collector.setHighlightFlag(RenderableCollector::Highlight::Primitives, false);
Expand All @@ -473,7 +473,7 @@ void Light::renderProjectionPoints(RenderableCollector& collector,
// Adds the light centre renderable to the given collector
void Light::renderLightCentre(RenderableCollector& collector,
const VolumeTest& volume,
const Matrix4& localToWorld) const
const Matrix4& localToWorld) const
{
collector.addRenderable(*_rCentre.getShader(), _rCentre, localToWorld);
}
Expand Down Expand Up @@ -557,7 +557,7 @@ Matrix4 Light::getLightTextureTransformation() const
// into texture coordinates that span the range [0..1] within the light volume.

// Example:
// For non-rotated point lights the world point [origin - light_radius] will be
// For non-rotated point lights the world point [origin - light_radius] will be
// transformed to [0,0,0], whereas [origin + light_radius] will be [1,1,1]

if (isProjected())
Expand Down Expand Up @@ -589,9 +589,9 @@ Matrix4 Light::getLightTextureTransformation() const
1.0f / lightBounds.extents.y(),
1.0f / lightBounds.extents.z())
));
// To get texture coordinates in the range of [0..1], we need to scale down
// To get texture coordinates in the range of [0..1], we need to scale down
// one more time. [-1..1] is 2 units wide, so scale down by factor 2.
// By this time, points within the light volume have been mapped
// By this time, points within the light volume have been mapped
// into a [-0.5..0.5] cube around the origin.
worldTolight.premultiplyBy(Matrix4::getScale(Vector3(0.5f, 0.5f, 0.5f)));

Expand Down Expand Up @@ -629,15 +629,16 @@ const Matrix4& Light::rotation() const {
* the centerTransformed variable as the lighting should be updated as soon as the light center
* is dragged.
*/
Vector3 Light::getLightOrigin() const {
Vector3 Light::getLightOrigin() const
{
if (isProjected())
{
return worldOrigin();
return _originTransformed;
}
else
{
// AABB origin + light_center, i.e. center in world space
return worldOrigin() + m_doom3Radius.m_centerTransformed;
return _originTransformed + m_doom3Radius.m_centerTransformed;
}
}

Expand Down Expand Up @@ -769,8 +770,8 @@ void Light::updateProjection() const
//{
// rMessage() << " Plane " << i << ": " << lightProject[i].normal() << ", dist: " << lightProject[i].dist() << std::endl;
//}
// greebo: Comparing this to the engine sources, all frustum planes in TDM

// greebo: Comparing this to the engine sources, all frustum planes in TDM
// appear to be negated, their normals are pointing outwards.

// we want the planes of s=0, s=q, t=0, and t=q
Expand All @@ -796,7 +797,7 @@ void Light::updateProjection() const
// Normalise all frustum planes
_frustum.normalisePlanes();

// TDM uses an array of 6 idPlanes, these relate to DarkRadiant like this:
// TDM uses an array of 6 idPlanes, these relate to DarkRadiant like this:
// 0 = left, 1 = top, 2 = right, 3 = bottom, 4 = front, 5 = back
//rMessage() << " Frustum Plane " << 0 << ": " << _frustum.left.normal() << ", dist: " << _frustum.left.dist() << std::endl;
//rMessage() << " Frustum Plane " << 1 << ": " << _frustum.top.normal() << ", dist: " << _frustum.top.dist() << std::endl;
Expand Down Expand Up @@ -873,10 +874,4 @@ const IRenderEntity& Light::getLightEntity() const
return _owner;
}

const Vector3& Light::worldOrigin() const
{
// return the absolute world origin
return _originTransformed;
}

} // namespace entity
5 changes: 2 additions & 3 deletions radiantcore/entity/light/Light.h
Expand Up @@ -140,11 +140,11 @@ class Light: public RendererLight
KeyObserverDelegate _lightEndObserver;
KeyObserverDelegate _lightTextureObserver;

private:

void construct();
void destroy();

private:

// Ensure the start and end points are set to sensible values
void checkStartEnd();

Expand Down Expand Up @@ -246,7 +246,6 @@ class Light: public RendererLight

// RendererLight implementation
const IRenderEntity& getLightEntity() const override;
const Vector3& worldOrigin() const override;
Matrix4 getLightTextureTransformation() const override;
Vector3 getLightOrigin() const override;
const ShaderPtr& getShader() const override;
Expand Down
2 changes: 1 addition & 1 deletion test/Entity.cpp
Expand Up @@ -371,7 +371,7 @@ TEST_F(EntityTest, RenderLightAsLightSource)
ASSERT_EQ(renderF.collector.lightPtrs.size(), 1);
const RendererLight* rLight = renderF.collector.lightPtrs.front();
ASSERT_TRUE(rLight);
EXPECT_EQ(rLight->worldOrigin(), ORIGIN);
EXPECT_EQ(rLight->getLightOrigin(), ORIGIN);
EXPECT_EQ(rLight->lightAABB().origin, ORIGIN);

// Default light properties from the entitydef
Expand Down

0 comments on commit 859ed64

Please sign in to comment.