diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-01-05 19:45:36 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-01-05 19:45:36 +0000 |
commit | 7c1e9b25fa4062a69ea00c20cdbcc745d1b82659 (patch) | |
tree | 03a200a82211016a70420930ee88d2afd01f60a5 /gfx/gl/sceneShader.cpp | |
parent | Include uniform name in required uniform does not exist error message (diff) | |
download | ilt-7c1e9b25fa4062a69ea00c20cdbcc745d1b82659.tar.bz2 ilt-7c1e9b25fa4062a69ea00c20cdbcc745d1b82659.tar.xz ilt-7c1e9b25fa4062a69ea00c20cdbcc745d1b82659.zip |
Add rendering support for spot lights
Diffstat (limited to 'gfx/gl/sceneShader.cpp')
-rw-r--r-- | gfx/gl/sceneShader.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index d0b26c8..981e7df 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -3,11 +3,14 @@ #include <gfx/gl/shaders/fs-basicShader.h> #include <gfx/gl/shaders/fs-landmassShader.h> #include <gfx/gl/shaders/fs-pointLight.h> +#include <gfx/gl/shaders/fs-spotLight.h> #include <gfx/gl/shaders/fs-waterShader.h> #include <gfx/gl/shaders/gs-pointLight.h> +#include <gfx/gl/shaders/gs-spotLight.h> #include <gfx/gl/shaders/vs-basicShader.h> #include <gfx/gl/shaders/vs-landmassShader.h> #include <gfx/gl/shaders/vs-pointLight.h> +#include <gfx/gl/shaders/vs-spotLight.h> #include <gfx/gl/shaders/vs-waterShader.h> #include <gfx/gl/vertexArrayObject.hpp> #include <glm/gtc/type_ptr.hpp> @@ -23,7 +26,8 @@ SceneShader::SceneShader() : void SceneShader::setViewProjection(const glm::mat4 & viewProjection) const { - for (const auto & prog : std::array<const SceneProgram *, 5> {&basic, &water, &landmass, &absolute, &pointLight}) { + for (const auto & prog : + std::array<const SceneProgram *, 6> {&basic, &water, &landmass, &absolute, &pointLight, &spotLight}) { prog->setViewProjection(viewProjection); } } @@ -31,7 +35,8 @@ SceneShader::setViewProjection(const glm::mat4 & viewProjection) const void SceneShader::setViewPort(const glm::ivec4 & viewPort) const { - for (const auto & prog : std::array<const SceneProgram *, 5> {&basic, &water, &landmass, &absolute, &pointLight}) { + for (const auto & prog : + std::array<const SceneProgram *, 6> {&basic, &water, &landmass, &absolute, &pointLight, &spotLight}) { prog->setViewPort(viewPort); } } @@ -95,3 +100,26 @@ SceneShader::PointLightShader::add(const glm::vec3 & position, const glm::vec3 & glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(glm::vec3), glm::value_ptr(position)); glDrawArrays(GL_POINTS, 0, 1); } + +SceneShader::SpotLightShader::SpotLightShader() : + SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, + arcLoc {*this, "arc"} +{ + using v3pair = std::pair<glm::vec3, glm::vec3>; + VertexArrayObject<v3pair>::configure<&v3pair::first, &v3pair::second>(va, b); +} + +void +SceneShader::SpotLightShader::add(const glm::vec3 & position, const glm::vec3 & direction, const glm::vec3 & colour, + const float kq, const float arc) const +{ + Program::use(); + glBindVertexArray(va); + glBindBuffer(GL_ARRAY_BUFFER, b); + glUniform3fv(colourLoc, 1, glm::value_ptr(colour)); + glUniform1f(kqLoc, kq); + glUniform1f(arcLoc, arc); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(glm::vec3), glm::value_ptr(position)); + glBufferSubData(GL_ARRAY_BUFFER, sizeof(glm::vec3), sizeof(glm::vec3), glm::value_ptr(direction)); + glDrawArrays(GL_POINTS, 0, 1); +} |