From 622c5ca05d48f543f4387a69cad4c84c9d3d310c Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Tue, 9 Mar 2021 20:54:26 +0000 Subject: [PATCH] Add a test for omni light texture matrix 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. --- include/ilightnode.h | 11 +++--- radiantcore/entity/light/LightNode.h | 3 ++ test/CMakeLists.txt | 1 + test/Renderer.cpp | 52 ++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 test/Renderer.cpp diff --git a/include/ilightnode.h b/include/ilightnode.h index 17853aa209..892c1448c3 100644 --- a/include/ilightnode.h +++ b/include/ilightnode.h @@ -5,9 +5,9 @@ #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 @@ -15,9 +15,10 @@ 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 ILightNodePtr; diff --git a/radiantcore/entity/light/LightNode.h b/radiantcore/entity/light/LightNode.h index d4d2f6d37f..e234ecd82e 100644 --- a/radiantcore/entity/light/LightNode.h +++ b/radiantcore/entity/light/LightNode.h @@ -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; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8fb7d04ca6..035cb98cbb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,6 +25,7 @@ add_executable(drtest PatchIterators.cpp PatchWelding.cpp Prefabs.cpp + Renderer.cpp SelectionAlgorithm.cpp Selection.cpp VFS.cpp diff --git a/test/Renderer.cpp b/test/Renderer.cpp new file mode 100644 index 0000000000..0e5b1eb19e --- /dev/null +++ b/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)); +} + +} \ No newline at end of file