summaryrefslogtreecommitdiff
path: root/gfx/gl
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl')
-rw-r--r--gfx/gl/sceneShader.cpp34
-rw-r--r--gfx/gl/sceneShader.h20
-rw-r--r--gfx/gl/shaders/spotLight.fs6
-rw-r--r--gfx/gl/shaders/spotLight.gs6
-rw-r--r--gfx/gl/shaders/spotLight.vs20
5 files changed, 26 insertions, 60 deletions
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<const SceneProgram *, 7> {
- &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) {
+ for (const auto & prog : std::initializer_list<const SceneProgram *> {
+ &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<const SceneProgram *, 7> {
- &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) {
+ for (const auto & prog : std::initializer_list<const SceneProgram *> {
+ &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<Position3D, Direction3D>;
- VertexArrayObject {va}.addAttribs<v3pair, &v3pair::first, &v3pair::second>(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);
-}
diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h
index 7ffaacd..7e31cb8 100644
--- a/gfx/gl/sceneShader.h
+++ b/gfx/gl/sceneShader.h
@@ -65,31 +65,13 @@ class SceneShader {
glBuffer b;
};
- class SpotLightShader : public SceneProgram {
- public:
- SpotLightShader();
-
- void add(const Position3D & position, const Direction3D & direction, const RGB & colour, const float kq,
- const float arc) const;
-
- private:
- UniformLocation directionLoc;
- UniformLocation colourLoc;
- UniformLocation kqLoc;
- UniformLocation arcLoc;
- UniformLocation viewPointLoc;
- glVertexArray va;
- glBuffer b;
- };
-
public:
SceneShader();
BasicProgram basic;
WaterProgram water;
- AbsolutePosProgram basicInst, landmass, absolute;
+ AbsolutePosProgram basicInst, landmass, absolute, spotLightInst;
PointLightShader pointLight;
- SpotLightShader spotLight;
void setViewProjection(const GlobalPosition3D & viewPoint, const glm::mat4 & viewProjection) const;
void setViewPort(const ViewPort & viewPort) const;
diff --git a/gfx/gl/shaders/spotLight.fs b/gfx/gl/shaders/spotLight.fs
index 937f922..6d5d332 100644
--- a/gfx/gl/shaders/spotLight.fs
+++ b/gfx/gl/shaders/spotLight.fs
@@ -6,8 +6,10 @@ out vec3 FragColor;
layout(binding = 0) uniform isampler2D gPosition;
layout(binding = 1) uniform sampler2D gNormal;
uniform ivec4 viewPort;
-uniform vec3 colour;
-uniform float kq;
+// uniform vec3 colour;
+// uniform float kq;
+const vec3 colour = vec3(1);
+const float kq = 0.01;
in vec4 geo_centre;
in vec4 geo_direction;
diff --git a/gfx/gl/shaders/spotLight.gs b/gfx/gl/shaders/spotLight.gs
index b58c169..a2805fe 100644
--- a/gfx/gl/shaders/spotLight.gs
+++ b/gfx/gl/shaders/spotLight.gs
@@ -11,9 +11,9 @@ const vec3[] pyramid = vec3[]( // four-sided
);
uniform mat4 viewProjection;
uniform ivec3 viewPoint;
-uniform float arc;
-
-in vec3 position[];
+// uniform float arc;
+const float arc = 1;
+in ivec3 position[];
in vec3 direction[];
in float size[];
in float cosarc[];
diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs
index ac1d1db..a2b755d 100644
--- a/gfx/gl/shaders/spotLight.vs
+++ b/gfx/gl/shaders/spotLight.vs
@@ -1,14 +1,20 @@
#version 330 core
layout(location = 0) in vec3 v_position;
+layout(location = 1) in vec3 v_direction;
+// layout(location = 2) in vec3 colour;
+// layout(location = 3) in float kq;
+// layout(location = 4) in float arc;
+layout(location = 5) in mat4 model;
+layout(location = 9) in ivec3 modelPos;
+
+const vec3 colour = vec3(1);
+const float kq = 0.01;
+const float arc = 1;
-uniform vec3 v_direction;
-uniform vec3 colour;
-uniform float kq;
-uniform float arc;
uniform ivec3 viewPoint;
-out vec3 position;
+out ivec3 position;
out vec3 direction;
out float size;
out float cosarc;
@@ -16,8 +22,8 @@ out float cosarc;
void
main()
{
- position = v_position;
- direction = normalize(v_direction);
+ position = modelPos + ivec3(v_position * mat3(model));
+ direction = normalize(v_direction * mat3(model));
size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq);
cosarc = cos(arc / 2);
gl_Position = vec4(position - viewPoint, 0);