summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-12 19:35:58 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-12 19:35:58 +0000
commit51eb25ea0f1373ca0442b02049406af38eae3b33 (patch)
tree389169a5f60d58398554168b94a0c6003302fbf6
parentFix order or multiple to address reversed rotation (diff)
downloadilt-51eb25ea0f1373ca0442b02049406af38eae3b33.tar.bz2
ilt-51eb25ea0f1373ca0442b02049406af38eae3b33.tar.xz
ilt-51eb25ea0f1373ca0442b02049406af38eae3b33.zip
Add model support for point lights
Still invokes non-instanced point light shader
-rw-r--r--game/scenary/illuminator.cpp20
-rw-r--r--game/scenary/illuminator.h17
-rw-r--r--gfx/gl/sceneShader.cpp27
-rw-r--r--gfx/gl/sceneShader.h17
-rw-r--r--test/test-assetFactory.cpp1
-rw-r--r--test/test-render.cpp30
6 files changed, 41 insertions, 71 deletions
diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp
index 6f51506..3de4e52 100644
--- a/game/scenary/illuminator.cpp
+++ b/game/scenary/illuminator.cpp
@@ -12,9 +12,16 @@ Illuminator::SpotLight::persist(Persistence::PersistenceStore & store)
}
bool
+Illuminator::PointLight::persist(Persistence::PersistenceStore & store)
+{
+ return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(colour) && STORE_MEMBER(kq);
+}
+
+bool
Illuminator::persist(Persistence::PersistenceStore & store)
{
return STORE_TYPE && STORE_HELPER(bodyMesh, Asset::MeshConstruct)
+ && STORE_HELPER(pointLight, Persistence::Appender<decltype(pointLight)>)
&& STORE_HELPER(spotLight, Persistence::Appender<decltype(spotLight)>) && Asset::persist(store);
}
@@ -32,6 +39,14 @@ Illuminator::postLoad()
std::transform(spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) {
return instancesSpotLight.acquire(*s);
});
+ VertexArrayObject {instancesPointLightVAO}
+ .addAttribs<PointLightVertex, &PointLightVertex::position, &PointLightVertex::colour,
+ &PointLightVertex::kq>(instancesPointLight.bufferName(), 0)
+ .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1);
+ std::transform(
+ pointLight.begin(), pointLight.end(), std::back_inserter(pointLightInstances), [this](const auto & s) {
+ return instancesPointLight.acquire(*s);
+ });
}
void
@@ -55,6 +70,11 @@ Illuminator::lights(const SceneShader & shader) const
glBindVertexArray(instancesSpotLightVAO);
glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(scount), static_cast<GLsizei>(count));
}
+ if (const auto pcount = instancesPointLight.size()) {
+ shader.pointLightInst.use();
+ glBindVertexArray(instancesPointLightVAO);
+ glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(pcount), static_cast<GLsizei>(count));
+ }
glBindVertexArray(0);
}
diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h
index 99b87eb..a2b287d 100644
--- a/game/scenary/illuminator.h
+++ b/game/scenary/illuminator.h
@@ -11,7 +11,7 @@ class Texture;
class Illuminator : public Asset, public Renderable, public StdTypeDefs<Illuminator> {
Mesh::Ptr bodyMesh;
std::shared_ptr<Texture> texture;
- glVertexArray instanceVAO, instancesSpotLightVAO;
+ glVertexArray instanceVAO, instancesSpotLightVAO, instancesPointLightVAO;
public:
struct SpotLightVertex {
@@ -22,16 +22,29 @@ public:
Angle arc;
};
+ struct PointLightVertex {
+ RelativePosition3D position;
+ RGB colour;
+ RelativeDistance kq;
+ };
+
struct SpotLight : Persistence::Persistable, SpotLightVertex, StdTypeDefs<SpotLight> {
private:
friend Persistence::SelectionPtrBase<std::shared_ptr<SpotLight>>;
bool persist(Persistence::PersistenceStore & store) override;
};
+ struct PointLight : Persistence::Persistable, PointLightVertex, StdTypeDefs<PointLight> {
+ private:
+ friend Persistence::SelectionPtrBase<std::shared_ptr<PointLight>>;
+ bool persist(Persistence::PersistenceStore & store) override;
+ };
+
public:
using LocationVertex = std::pair<glm::mat4, GlobalPosition3D>;
mutable InstanceVertices<LocationVertex> instances;
mutable InstanceVertices<SpotLightVertex> instancesSpotLight;
+ mutable InstanceVertices<PointLightVertex> instancesPointLight;
void render(const SceneShader &) const override;
void lights(const SceneShader &) const override;
@@ -41,5 +54,7 @@ protected:
void postLoad() override;
std::vector<SpotLight::Ptr> spotLight;
+ std::vector<PointLight::Ptr> pointLight;
std::vector<InstanceVertices<SpotLightVertex>::InstanceProxy> spotLightInstances;
+ std::vector<InstanceVertices<PointLightVertex>::InstanceProxy> pointLightInstances;
};
diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp
index cdb8d2f..64bf171 100644
--- a/gfx/gl/sceneShader.cpp
+++ b/gfx/gl/sceneShader.cpp
@@ -1,5 +1,4 @@
#include "sceneShader.h"
-#include <array>
#include <gfx/gl/shaders/fs-landmass.h>
#include <gfx/gl/shaders/fs-material.h>
#include <gfx/gl/shaders/fs-pointLight.h>
@@ -21,7 +20,8 @@
SceneShader::SceneShader() :
basicInst {dynamicPointInst_vs, material_fs}, landmass {fixedPoint_vs, landmass_fs},
- absolute {fixedPoint_vs, material_fs}, spotLightInst {spotLight_vs, spotLight_gs, spotLight_fs}
+ absolute {fixedPoint_vs, material_fs}, spotLightInst {spotLight_vs, spotLight_gs, spotLight_fs},
+ pointLightInst {pointLight_vs, pointLight_gs, pointLight_fs}
{
}
@@ -29,7 +29,7 @@ void
SceneShader::setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const
{
for (const auto & prog : std::initializer_list<const SceneProgram *> {
- &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLightInst}) {
+ &basic, &basicInst, &water, &landmass, &absolute, &pointLightInst, &spotLightInst}) {
prog->setViewProjection(viewPoint, viewProjection);
}
}
@@ -38,7 +38,7 @@ void
SceneShader::setViewPort(const ViewPort & viewPort) const
{
for (const auto & prog : std::initializer_list<const SceneProgram *> {
- &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLightInst}) {
+ &basic, &basicInst, &water, &landmass, &absolute, &pointLightInst, &spotLightInst}) {
prog->setViewPort(viewPort);
}
}
@@ -87,22 +87,3 @@ SceneShader::WaterProgram::use(float waveCycle) const
Program::use();
glUniform1f(waveLoc, waveCycle);
}
-
-SceneShader::PointLightShader::PointLightShader() :
- SceneProgram {pointLight_vs, pointLight_gs, pointLight_fs}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"},
- viewPointLoc {*this, "viewPoint"}
-{
- VertexArrayObject {va}.addAttribs<Position3D>(b);
-}
-
-void
-SceneShader::PointLightShader::add(const Position3D & position, const RGB & colour, const float kq) const
-{
- Program::use();
- glBindVertexArray(va);
- glBindBuffer(GL_ARRAY_BUFFER, b);
- glUniform3fv(colourLoc, 1, glm::value_ptr(colour));
- glUniform1f(kqLoc, kq);
- glBufferData(GL_ARRAY_BUFFER, sizeof(Position3D), glm::value_ptr(position), GL_DYNAMIC_DRAW);
- glDrawArrays(GL_POINTS, 0, 1);
-}
diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h
index 7e31cb8..813c1bf 100644
--- a/gfx/gl/sceneShader.h
+++ b/gfx/gl/sceneShader.h
@@ -51,27 +51,12 @@ class SceneShader {
RequiredUniformLocation waveLoc;
};
- class PointLightShader : public SceneProgram {
- public:
- PointLightShader();
-
- void add(const Position3D & position, const RGB & colour, const float kq) const;
-
- private:
- UniformLocation colourLoc;
- UniformLocation kqLoc;
- UniformLocation viewPointLoc;
- glVertexArray va;
- glBuffer b;
- };
-
public:
SceneShader();
BasicProgram basic;
WaterProgram water;
- AbsolutePosProgram basicInst, landmass, absolute, spotLightInst;
- PointLightShader pointLight;
+ AbsolutePosProgram basicInst, landmass, absolute, spotLightInst, pointLightInst;
void setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const;
void setViewPort(const ViewPort & viewPort) const;
diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp
index bc93729..9e278c4 100644
--- a/test/test-assetFactory.cpp
+++ b/test/test-assetFactory.cpp
@@ -48,7 +48,6 @@ public:
void
lights(const SceneShader & shader) const override
{
- shader.pointLight.add({-3, 1, 5}, {1, 1, 1}, .1F);
objects.apply(&Renderable::lights, shader);
}
diff --git a/test/test-render.cpp b/test/test-render.cpp
index 47d146c..41731dd 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -158,34 +158,4 @@ BOOST_AUTO_TEST_CASE(terrain)
Texture::save(outImage, "/tmp/terrain.tga");
}
-BOOST_AUTO_TEST_CASE(pointlight)
-{
- SceneRenderer ss {size, output};
- ss.camera.setView({-10000, -10000, 60000}, glm::normalize(glm::vec3 {1, 1, -0.5F}));
-
- class PointLightScene : public TestScene {
- public:
- void
- environment(const SceneShader &, const SceneRenderer & r) const override
- {
- r.setAmbientLight({0.2F, 0.2F, 0.2F});
- r.setDirectionalLight({0.2F, 0.2F, 0.2F}, west + down, *this);
- }
-
- void
- lights(const SceneShader & shader) const override
- {
- for (int x = 50000; x < 100000; x += 20000) {
- for (int y = 50000; y < 2000000; y += 20000) {
- shader.pointLight.add({x, y, 4000}, {1.0, 1.0, 1.0}, 0.1F);
- }
- }
- }
- };
-
- const PointLightScene scene;
- ss.render(scene);
- Texture::save(outImage, "/tmp/pointlight.tga");
-}
-
BOOST_AUTO_TEST_SUITE_END();