summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-17 17:04:32 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-17 17:04:32 +0100
commite4414150da485a8aacdd221e23cad801f8d532c6 (patch)
treed93c48015e50501477bb97d067eca16c746a36f5
parentAssets moved to global game state (diff)
downloadilt-e4414150da485a8aacdd221e23cad801f8d532c6.tar.bz2
ilt-e4414150da485a8aacdd221e23cad801f8d532c6.tar.xz
ilt-e4414150da485a8aacdd221e23cad801f8d532c6.zip
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.
-rw-r--r--gfx/gl/sceneShader.cpp10
-rw-r--r--gfx/gl/sceneShader.h1
-rw-r--r--gfx/gl/shaders/spotLight.vs2
3 files changed, 7 insertions, 6 deletions
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 <maths.h>
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<glm::vec3, glm::vec3>;
VertexArrayObject<v3pair>::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;