Skip to content

Commit

Permalink
Add a test for omni light texture matrix
Browse files Browse the repository at this point in the history
Add a new getRendererLight() method to the ILightNode interface, and use this
to retrieve and examine the texture transformation matrix of a simple omni
light.
  • Loading branch information
Matthew Mott committed Mar 10, 2021
1 parent 1db3e73 commit 622c5ca
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
11 changes: 6 additions & 5 deletions include/ilightnode.h
Expand Up @@ -5,19 +5,20 @@
#include "math/AABB.h"

/**
* LightNodes derive from this class.
* LightNodes derive from this class.
* It's mainly used to determine the selectable part
* of the light, which is usually the small "diamond" in
* of the light, which is usually the small "diamond" in
* the center.
*/
class ILightNode
{
public:
virtual ~ILightNode() {}

/**
* greebo: Get the AABB of the Light "Diamond" representation.
*/
/// Return the RendererLight instance for this light node
virtual const RendererLight& getRendererLight() const = 0;

/// Get the AABB of the Light "Diamond" representation.
virtual AABB getSelectAABB() const = 0;
};
typedef std::shared_ptr<ILightNode> ILightNodePtr;
Expand Down
3 changes: 3 additions & 0 deletions radiantcore/entity/light/LightNode.h
Expand Up @@ -58,6 +58,9 @@ class LightNode :
public:
static LightNodePtr Create(const IEntityClassPtr& eclass);

// ILightNode implementation
const RendererLight& getRendererLight() const { return _light; }

// RenderEntity implementation
virtual float getShaderParm(int parmNum) const override;

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Expand Up @@ -25,6 +25,7 @@ add_executable(drtest
PatchIterators.cpp
PatchWelding.cpp
Prefabs.cpp
Renderer.cpp
SelectionAlgorithm.cpp
Selection.cpp
VFS.cpp
Expand Down
52 changes: 52 additions & 0 deletions test/Renderer.cpp
@@ -0,0 +1,52 @@
#include "RadiantTest.h"

#include "ieclass.h"
#include "ientity.h"
#include "ilightnode.h"
#include "math/Matrix4.h"

namespace test
{

using RendererTest = RadiantTest;

IEntityNodePtr createByClassName(const std::string& className)
{
auto cls = GlobalEntityClassManager().findClass(className);
return GlobalEntityModule().createEntity(cls);
}

TEST_F(RendererTest, CreateLightNode)
{
auto light = createByClassName("light");
ILightNodePtr node = Node_getLightNode(light);
ASSERT_TRUE(node);
}

TEST_F(RendererTest, GetLightTextureTransform)
{
auto light = createByClassName("light");
Entity* lightEnt = Node_getEntity(light);
ASSERT_TRUE(lightEnt);

// Set a radius of 10 units in each dimension
lightEnt->setKeyValue("light_radius", "10 10 10");

// Get the RendererLight
ILightNodePtr node = Node_getLightNode(light);
ASSERT_TRUE(node);
const RendererLight& rLight = node->getRendererLight();

// Get the texture matrix transform
Matrix4 texMat = rLight.getLightTextureTransformation();

// Radius is symmetric around the origin, so the scale factor should be
// 1/20, with an offset to map the resulting light-space coordinates from
// [-0.5, 0.5] onto ST coordinates spanning [0, 1]
EXPECT_EQ(texMat, Matrix4::byRows(0.05, 0, 0, 0.5,
0, 0.05, 0, 0.5,
0, 0, 0.05, 0.5,
0, 0, 0, 1));
}

}

0 comments on commit 622c5ca

Please sign in to comment.