From e4414150da485a8aacdd221e23cad801f8d532c6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 17 Apr 2023 17:04:32 +0100 Subject: Fix up the way spotlight shader works Was mostly through lack of understanding and coincidences. Position is now the only vertex data, direction is moved to a uniform. Instancing will address this by making everything instance data. --- gfx/gl/sceneShader.cpp | 10 +++++----- gfx/gl/sceneShader.h | 1 + gfx/gl/shaders/spotLight.vs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'gfx') diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 54f5737..37eacbd 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -20,8 +20,8 @@ #include SceneShader::SceneShader() : - basicInst {dynamicPointInst_vs, material_fs}, landmass {fixedPoint_vs, landmass_fs}, absolute {fixedPoint_vs, - material_fs} + basicInst {dynamicPointInst_vs, material_fs}, landmass {fixedPoint_vs, landmass_fs}, + absolute {fixedPoint_vs, material_fs} { } @@ -104,8 +104,8 @@ SceneShader::PointLightShader::add(const glm::vec3 & position, const glm::vec3 & } SceneShader::SpotLightShader::SpotLightShader() : - SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, - arcLoc {*this, "arc"} + SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, directionLoc {*this, "v_direction"}, + colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, arcLoc {*this, "arc"} { using v3pair = std::pair; VertexArrayObject::configure<&v3pair::first, &v3pair::second>(va, b); @@ -119,9 +119,9 @@ SceneShader::SpotLightShader::add(const glm::vec3 & position, const glm::vec3 & 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); 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); } diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h index 0ccf152..c135050 100644 --- a/gfx/gl/sceneShader.h +++ b/gfx/gl/sceneShader.h @@ -69,6 +69,7 @@ class SceneShader { const float arc) const; private: + UniformLocation directionLoc; UniformLocation colourLoc; UniformLocation kqLoc; UniformLocation arcLoc; diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs index e648553..dca0854 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vs @@ -1,8 +1,8 @@ #version 330 core layout(location = 0) in vec3 v_position; -layout(location = 1) in vec3 v_direction; +uniform vec3 v_direction; uniform vec3 colour; uniform float kq; uniform float arc; -- cgit v1.2.3