From b8401062e1d3f5e6554ab7fd9b983ea63cfb05c5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 10 Jan 2024 19:04:30 +0000 Subject: Initial commit with working light instancing --- gfx/gl/sceneShader.cpp | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'gfx/gl/sceneShader.cpp') diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index ccc1a1d..cdb8d2f 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -21,15 +21,15 @@ SceneShader::SceneShader() : basicInst {dynamicPointInst_vs, material_fs}, landmass {fixedPoint_vs, landmass_fs}, - absolute {fixedPoint_vs, material_fs} + absolute {fixedPoint_vs, material_fs}, spotLightInst {spotLight_vs, spotLight_gs, spotLight_fs} { } void SceneShader::setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const { - for (const auto & prog : std::array { - &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) { + for (const auto & prog : std::initializer_list { + &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLightInst}) { prog->setViewProjection(viewPoint, viewProjection); } } @@ -37,8 +37,8 @@ SceneShader::setViewProjection(const GlobalPosition3D & viewPoint, const glm::ma void SceneShader::setViewPort(const ViewPort & viewPort) const { - for (const auto & prog : std::array { - &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) { + for (const auto & prog : std::initializer_list { + &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLightInst}) { prog->setViewPort(viewPort); } } @@ -106,27 +106,3 @@ SceneShader::PointLightShader::add(const Position3D & position, const RGB & colo glBufferData(GL_ARRAY_BUFFER, sizeof(Position3D), glm::value_ptr(position), GL_DYNAMIC_DRAW); glDrawArrays(GL_POINTS, 0, 1); } - -SceneShader::SpotLightShader::SpotLightShader() : - SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, directionLoc {*this, "v_direction"}, - colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, arcLoc {*this, "arc"}, viewPointLoc {*this, "viewPoint"} - -{ - using v3pair = std::pair; - VertexArrayObject {va}.addAttribs(b); -} - -void -SceneShader::SpotLightShader::add(const Position3D & position, const Direction3D & direction, const RGB & colour, - const float kq, const float arc) const -{ - Program::use(); - glBindVertexArray(va); - glBindBuffer(GL_ARRAY_BUFFER, b); - glUniform3fv(colourLoc, 1, glm::value_ptr(colour)); - glUniform3fv(directionLoc, 1, glm::value_ptr(direction)); - glUniform1f(kqLoc, kq); - glUniform1f(arcLoc, arc); - glBufferData(GL_ARRAY_BUFFER, sizeof(Position3D), glm::value_ptr(position), GL_DYNAMIC_DRAW); - glDrawArrays(GL_POINTS, 0, 1); -} -- cgit v1.2.3 From 51eb25ea0f1373ca0442b02049406af38eae3b33 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 12 Jan 2024 19:35:58 +0000 Subject: Add model support for point lights Still invokes non-instanced point light shader --- gfx/gl/sceneShader.cpp | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'gfx/gl/sceneShader.cpp') 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 #include #include #include @@ -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 { - &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 { - &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(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); -} -- cgit v1.2.3