From 2f8d7643d03f39fa848576692264d0fe3a37ed91 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 6 Nov 2023 20:48:33 +0000 Subject: Reformat with new clang-format --- gfx/gl/camera.h | 8 ++++++++ gfx/gl/instanceVertices.h | 13 +++++++++++-- gfx/gl/program.h | 3 +++ gfx/gl/sceneProvider.cpp | 1 + gfx/gl/sceneRenderer.cpp | 1 + gfx/gl/sceneRenderer.h | 2 ++ gfx/gl/shader.h | 1 + gfx/gl/shadowMapper.cpp | 7 +++++++ gfx/gl/shadowMapper.h | 5 +++++ gfx/gl/uiShader.cpp | 2 ++ gfx/gl/vertexArrayObject.h | 5 +++++ 11 files changed, 46 insertions(+), 2 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h index 3f1c3a7..7956ec3 100644 --- a/gfx/gl/camera.h +++ b/gfx/gl/camera.h @@ -13,6 +13,7 @@ public: { return viewProjection; } + [[nodiscard]] Ray unProject(const glm::vec2 &) const; void @@ -21,11 +22,13 @@ public: position = p; updateView(); } + void setForward(const glm::vec3 & f) { setForward(f, upFromForward(f)); } + void setForward(const glm::vec3 & f, const glm::vec3 & u) { @@ -33,28 +36,33 @@ public: up = u; updateView(); } + void setView(const glm::vec3 & p, const glm::vec3 & f) { position = p; setForward(f); } + void setView(const glm::vec3 & p, const glm::vec3 & f, const glm::vec3 & u) { position = p; setView(f, u); } + void lookAt(const glm::vec3 & target) { setForward(glm::normalize(target - position)); } + [[nodiscard]] auto getForward() const { return forward; } + [[nodiscard]] auto getPosition() const { diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h index 7b0341b..a89aa78 100644 --- a/gfx/gl/instanceVertices.h +++ b/gfx/gl/instanceVertices.h @@ -13,9 +13,11 @@ public: class [[nodiscard]] InstanceProxy { public: InstanceProxy(InstanceVertices * iv, std::size_t idx) : instances {iv}, index {idx} { } + InstanceProxy(InstanceProxy && other) : instances {std::exchange(other.instances, nullptr)}, index {other.index} { } + NO_COPY(InstanceProxy); ~InstanceProxy() @@ -35,6 +37,7 @@ public: index = other.index; return *this; } + template T & operator=(U && v) @@ -42,40 +45,46 @@ public: return instances->lookup(index) = std::forward(v); } - [[nodiscard]] - operator T &() + [[nodiscard]] operator T &() { return instances->lookup(index); } + [[nodiscard]] operator const T &() const { return instances->lookup(index); } + [[nodiscard]] T * get() { return &instances->lookup(index); } + [[nodiscard]] const T * get() const { return &instances->lookup(index); } + [[nodiscard]] T * operator->() { return get(); } + [[nodiscard]] const T * operator->() const { return get(); } + [[nodiscard]] T & operator*() { return instances->lookup(index); } + [[nodiscard]] const T & operator*() const { diff --git a/gfx/gl/program.h b/gfx/gl/program.h index 76b6742..1a1c306 100644 --- a/gfx/gl/program.h +++ b/gfx/gl/program.h @@ -9,6 +9,7 @@ class Location; using ProgramRef = glRef; + class Program { public: template explicit Program(const S &... srcs) @@ -16,12 +17,14 @@ public: (glAttachShader(m_program, srcs.compile()), ...); linkAndValidate(); } + virtual ~Program() = default; DEFAULT_MOVE_NO_COPY(Program); class UniformLocation { public: UniformLocation(GLuint prog, const char * name); + // NOLINTNEXTLINE(hicpp-explicit-conversions) operator auto() const { diff --git a/gfx/gl/sceneProvider.cpp b/gfx/gl/sceneProvider.cpp index 0163b36..2e8604c 100644 --- a/gfx/gl/sceneProvider.cpp +++ b/gfx/gl/sceneProvider.cpp @@ -7,6 +7,7 @@ SceneProvider::environment(const SceneShader &, const SceneRenderer & renderer) renderer.setAmbientLight({0.5F, 0.5F, 0.5F}); renderer.setDirectionalLight({0.6F, 0.6F, 0.6F}, {-1, 1, -1}, *this); } + void SceneProvider::shadows(const ShadowMapper &) const { diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index aa9453a..5799daf 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -13,6 +13,7 @@ static constexpr const std::array displayVAOdata {{ {1, 1, 1, 1}, {1, -1, 1, 0}, }}; + SceneRenderer::SceneRenderer(glm::ivec2 s, GLuint o) : camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, ratio(s), 0.1F, 10000.0F}, size {s}, output {o}, lighting {lighting_vs, lighting_fs}, shadowMapper {{2048, 2048}} diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h index d4af665..55df84d 100644 --- a/gfx/gl/sceneRenderer.h +++ b/gfx/gl/sceneRenderer.h @@ -27,11 +27,13 @@ private: glFrameBuffer gBuffer; glTexture gPosition, gNormal, gAlbedoSpec, gIllumination; glRenderBuffer depth; + class DeferredLightProgram : public Program { public: using Program::Program; using Program::use; }; + class DirectionalLightProgram : public Program { public: DirectionalLightProgram(); diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h index 0810e6b..cff2281 100644 --- a/gfx/gl/shader.h +++ b/gfx/gl/shader.h @@ -8,6 +8,7 @@ class Shader { public: using ShaderRef = glRef; + constexpr Shader(const GLchar * text, GLint len, GLuint type) : text {text}, len {len}, type {type} { } [[nodiscard]] ShaderRef compile() const; diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 55d986c..79b39c0 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -94,11 +94,13 @@ struct DefinitionsInserter { { return out.maps++; }; + auto operator*() { return std::tie(out.projections[out.maps], out.regions[out.maps]); } + ShadowMapper::Definitions & out; }; @@ -161,12 +163,14 @@ ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir, const C } ShadowMapper::FixedPoint::FixedPoint(const Shader & vs) : Program {vs}, viewProjectionLoc {*this, "viewProjection"} { } + void ShadowMapper::FixedPoint::setViewProjection(const glm::mat4 & viewProjection) const { use(); glUniformMatrix4fv(viewProjectionLoc, 1, GL_FALSE, glm::value_ptr(viewProjection)); } + void ShadowMapper::FixedPoint::use() const { @@ -177,12 +181,14 @@ ShadowMapper::DynamicPoint::DynamicPoint() : Program {shadowDynamicPoint_vs}, viewProjectionLoc {*this, "viewProjection"}, modelLoc {*this, "model"} { } + void ShadowMapper::DynamicPoint::setViewProjection(const glm::mat4 & viewProjection) const { glUseProgram(*this); glUniformMatrix4fv(viewProjectionLoc, 1, GL_FALSE, glm::value_ptr(viewProjection)); } + void ShadowMapper::DynamicPoint::use(const Location & location) const { @@ -191,6 +197,7 @@ ShadowMapper::DynamicPoint::use(const Location & location) const const auto model = glm::translate(location.pos) * rotate_ypr(location.rot); glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); } + void ShadowMapper::DynamicPoint::setModel(const Location & location) const { diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index 36371eb..cd1b975 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -8,16 +8,19 @@ class SceneProvider; class Camera; #include + class ShadowMapper { public: explicit ShadowMapper(const glm::ivec2 & size); static constexpr std::size_t SHADOW_BANDS {4}; + struct Definitions { std::array projections {}; std::array regions {}; size_t maps {}; }; + [[nodiscard]] Definitions update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const; class FixedPoint : public Program { @@ -29,6 +32,7 @@ public: private: RequiredUniformLocation viewProjectionLoc; }; + class DynamicPoint : public Program { public: DynamicPoint(); @@ -40,6 +44,7 @@ public: RequiredUniformLocation viewProjectionLoc; RequiredUniformLocation modelLoc; }; + FixedPoint fixedPoint, dynamicPointInst; DynamicPoint dynamicPoint; diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp index 78e0064..0b47211 100644 --- a/gfx/gl/uiShader.cpp +++ b/gfx/gl/uiShader.cpp @@ -9,6 +9,7 @@ #include UIShader::IconProgram::IconProgram(const glm::mat4 & vp) : UIProgram {vp, uiShader_vs, uiShader_fs} { } + UIShader::TextProgram::TextProgram(const glm::mat4 & vp) : UIProgram {vp, uiShader_vs, uiShaderFont_fs}, colorLoc {*this, "colour"} { @@ -18,6 +19,7 @@ UIShader::UIShader(size_t width, size_t height) : UIShader {glm::ortho(0, static_cast(width), 0, static_cast(height))} { } + UIShader::UIShader(const glm::mat4 & viewProjection) : icon {viewProjection}, text {viewProjection} { } void diff --git a/gfx/gl/vertexArrayObject.h b/gfx/gl/vertexArrayObject.h index fa6baa3..57daaf3 100644 --- a/gfx/gl/vertexArrayObject.h +++ b/gfx/gl/vertexArrayObject.h @@ -11,22 +11,27 @@ public: { glBindVertexArray(arrayObject); } + ~VertexArrayObject() { glBindVertexArray(0); } + NO_MOVE(VertexArrayObject); NO_COPY(VertexArrayObject); template struct MP { constexpr MP(m T::*p) : P {p} { } + operator void *() const { return &(static_cast(nullptr)->*P); } + m T::*P; using value_type = m; }; + template MP(m T::*) -> MP; template -- cgit v1.2.3 From d6e99a696aa582b81018078b68f6600c8030d643 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Nov 2023 02:51:42 +0000 Subject: WIP typedefing all the things - headers --- gfx/gl/bufferedLocation.h | 14 +++++++------- gfx/gl/camera.cpp | 4 ++-- gfx/gl/camera.h | 25 +++++++++++++------------ gfx/gl/sceneRenderer.cpp | 2 +- gfx/gl/sceneRenderer.h | 10 +++++----- gfx/gl/sceneShader.h | 5 +++-- gfx/gl/shadowMapper.cpp | 2 +- gfx/gl/shadowMapper.h | 9 +++++---- gfx/gl/uiShader.h | 3 ++- 9 files changed, 39 insertions(+), 35 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h index 8096489..39d3139 100644 --- a/gfx/gl/bufferedLocation.h +++ b/gfx/gl/bufferedLocation.h @@ -8,7 +8,7 @@ class BufferedLocation { public: - BufferedLocation(glm::vec3 = {}, glm::vec3 = {}); + BufferedLocation(Position3D = {}, Rotation3D = {}); BufferedLocation(const Location &); virtual ~BufferedLocation() = default; @@ -16,13 +16,13 @@ public: operator const Location &() const; - glm::vec3 position() const; - glm::vec3 rotation() const; - void setPosition(glm::vec3, bool update = true); - void setRotation(glm::vec3, bool update = true); - void setLocation(glm::vec3, glm::vec3); + [[nodiscard]] Position3D position() const; + [[nodiscard]] Rotation3D rotation() const; + void setPosition(Position3D, bool update = true); + void setRotation(Rotation3D, bool update = true); + void setLocation(Position3D, Rotation3D); - glm::mat4 getTransform() const; + [[nodiscard]] glm::mat4 getTransform() const; private: virtual void updateBuffer() = 0; diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index c4c9544..80feab4 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -5,7 +5,7 @@ #include #include -Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar) : +Camera::Camera(Position3D pos, Angle fov, Angle aspect, Distance zNear, Distance zFar) : position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar}, projection {glm::perspective(fov, aspect, zNear, zFar)}, viewProjection {projection * glm::lookAt(position, position + forward, up)}, @@ -14,7 +14,7 @@ Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar) } Ray -Camera::unProject(const glm::vec2 & mouse) const +Camera::unProject(const ScreenRelCoord & mouse) const { static constexpr const glm::vec4 screen {0, 0, 1, 1}; const auto mouseProjection = glm::lookAt(::origin, forward, up); diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h index 7956ec3..469df0d 100644 --- a/gfx/gl/camera.h +++ b/gfx/gl/camera.h @@ -1,12 +1,13 @@ #pragma once +#include "config/types.h" #include #include #include class Camera { public: - Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar); + Camera(Position3D, Angle fov, Angle aspect, Distance zNear, Distance zFar); [[nodiscard]] glm::mat4 getViewProjection() const @@ -14,23 +15,23 @@ public: return viewProjection; } - [[nodiscard]] Ray unProject(const glm::vec2 &) const; + [[nodiscard]] Ray unProject(const ScreenRelCoord &) const; void - setPosition(const glm::vec3 & p) + setPosition(const Position3D & p) { position = p; updateView(); } void - setForward(const glm::vec3 & f) + setForward(const Direction3D & f) { setForward(f, upFromForward(f)); } void - setForward(const glm::vec3 & f, const glm::vec3 & u) + setForward(const Direction3D & f, const Direction3D & u) { forward = f; up = u; @@ -38,21 +39,21 @@ public: } void - setView(const glm::vec3 & p, const glm::vec3 & f) + setView(const Position3D & p, const Direction3D & f) { position = p; setForward(f); } void - setView(const glm::vec3 & p, const glm::vec3 & f, const glm::vec3 & u) + setView(const Position3D & p, const Direction3D & f, const Direction3D & u) { position = p; setView(f, u); } void - lookAt(const glm::vec3 & target) + lookAt(const Position3D & target) { setForward(glm::normalize(target - position)); } @@ -71,14 +72,14 @@ public: [[nodiscard]] std::array extentsAtDist(float) const; - [[nodiscard]] static glm::vec3 upFromForward(const glm::vec3 & forward); + [[nodiscard]] static Direction3D upFromForward(const Direction3D & forward); private: void updateView(); - glm::vec3 position; - glm::vec3 forward; - glm::vec3 up; + Position3D position; + Direction3D forward; + Direction3D up; float near, far; glm::mat4 projection; diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 5799daf..218cf6d 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -14,7 +14,7 @@ static constexpr const std::array displayVAOdata {{ {1, -1, 1, 0}, }}; -SceneRenderer::SceneRenderer(glm::ivec2 s, GLuint o) : +SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o) : camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, ratio(s), 0.1F, 10000.0F}, size {s}, output {o}, lighting {lighting_vs, lighting_fs}, shadowMapper {{2048, 2048}} { diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h index 55df84d..87f474b 100644 --- a/gfx/gl/sceneRenderer.h +++ b/gfx/gl/sceneRenderer.h @@ -11,18 +11,18 @@ class SceneRenderer { public: - explicit SceneRenderer(glm::ivec2 size, GLuint output); + explicit SceneRenderer(ScreenAbsCoord size, GLuint output); void render(const SceneProvider &) const; - void setAmbientLight(const glm::vec3 & colour) const; - void setDirectionalLight(const glm::vec3 & colour, const glm::vec3 & direction, const SceneProvider &) const; + void setAmbientLight(const RGB & colour) const; + void setDirectionalLight(const RGB & colour, const Direction3D & direction, const SceneProvider &) const; Camera camera; private: void renderQuad() const; - glm::ivec2 size; + ScreenAbsCoord size; GLuint output; glFrameBuffer gBuffer; glTexture gPosition, gNormal, gAlbedoSpec, gIllumination; @@ -39,7 +39,7 @@ private: DirectionalLightProgram(); using Program::use; - void setDirectionalLight(const glm::vec3 &, const glm::vec3 &, const std::span, + void setDirectionalLight(const RGB &, const Direction3D &, const std::span, const std::span, std::size_t maps) const; private: diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h index ead184e..d1c6ef2 100644 --- a/gfx/gl/sceneShader.h +++ b/gfx/gl/sceneShader.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include "program.h" #include @@ -52,7 +53,7 @@ class SceneShader { public: PointLightShader(); - void add(const glm::vec3 & position, const glm::vec3 & colour, const float kq) const; + void add(const Position3D & position, const RGB & colour, const float kq) const; private: UniformLocation colourLoc; @@ -65,7 +66,7 @@ class SceneShader { public: SpotLightShader(); - void add(const glm::vec3 & position, const glm::vec3 & direction, const glm::vec3 & colour, const float kq, + void add(const Position3D & position, const Direction3D & direction, const RGB & colour, const float kq, const float arc) const; private: diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 79b39c0..58f65c4 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -15,7 +15,7 @@ #include #include -ShadowMapper::ShadowMapper(const glm::ivec2 & s) : +ShadowMapper::ShadowMapper(const TextureAbsCoord & s) : fixedPoint {shadowFixedPoint_vs}, dynamicPointInst {shadowDynamicPointInst_vs}, size {s} { glBindTexture(GL_TEXTURE_2D, depthMap); diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index cd1b975..e5272a3 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include "lib/glArrays.h" #include "program.h" #include @@ -11,7 +12,7 @@ class Camera; class ShadowMapper { public: - explicit ShadowMapper(const glm::ivec2 & size); + explicit ShadowMapper(const TextureAbsCoord & size); static constexpr std::size_t SHADOW_BANDS {4}; @@ -21,7 +22,7 @@ public: size_t maps {}; }; - [[nodiscard]] Definitions update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const; + [[nodiscard]] Definitions update(const SceneProvider &, const Direction3D & direction, const Camera &) const; class FixedPoint : public Program { public: @@ -55,9 +56,9 @@ public: } private: - [[nodiscard]] static std::vector> getBandViewExtents( + [[nodiscard]] static std::vector> getBandViewExtents( const Camera &, const glm::mat4 & lightView); glFrameBuffer depthMapFBO; glTexture depthMap; - glm::ivec2 size; + TextureAbsCoord size; }; diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h index 2766af8..362e90c 100644 --- a/gfx/gl/uiShader.h +++ b/gfx/gl/uiShader.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include "program.h" #include #include @@ -33,7 +34,7 @@ private: class TextProgram : public UIProgram { public: explicit TextProgram(const glm::mat4 & vp); - void use(const glm::vec3 & colour) const; + void use(const RGB & colour) const; private: RequiredUniformLocation colorLoc; -- cgit v1.2.3 From 9c2c3f71065c94a18c02440111b6ff8ca977b90e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 00:40:40 +0000 Subject: WIP typedefing all the things - sources --- gfx/gl/bufferedLocation.cpp | 12 ++++++------ gfx/gl/camera.cpp | 11 ++++++----- gfx/gl/sceneRenderer.cpp | 7 +++---- gfx/gl/sceneShader.cpp | 14 +++++++------- gfx/gl/shadowMapper.cpp | 10 +++++----- gfx/gl/uiShader.cpp | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp index eb3dac3..62cadef 100644 --- a/gfx/gl/bufferedLocation.cpp +++ b/gfx/gl/bufferedLocation.cpp @@ -3,7 +3,7 @@ #include "maths.h" #include -BufferedLocation::BufferedLocation(glm::vec3 p, glm::vec3 r) : BufferedLocation {Location {p, r}} { } +BufferedLocation::BufferedLocation(Position3D p, Rotation3D r) : BufferedLocation {Location {p, r}} { } BufferedLocation::BufferedLocation(const Location & l) : loc {l} { } @@ -20,20 +20,20 @@ BufferedLocation::operator=(const Location & l) return *this; } -glm::vec3 +Position3D BufferedLocation::position() const { return loc.pos; } -glm::vec3 +Position3D BufferedLocation::rotation() const { return loc.rot; } void -BufferedLocation::setPosition(glm::vec3 p, bool update) +BufferedLocation::setPosition(Position3D p, bool update) { loc.pos = p; if (update) { @@ -42,7 +42,7 @@ BufferedLocation::setPosition(glm::vec3 p, bool update) } void -BufferedLocation::setRotation(glm::vec3 r, bool update) +BufferedLocation::setRotation(Position3D r, bool update) { loc.rot = r; if (update) { @@ -51,7 +51,7 @@ BufferedLocation::setRotation(glm::vec3 r, bool update) } void -BufferedLocation::setLocation(glm::vec3 p, glm::vec3 r) +BufferedLocation::setLocation(Position3D p, Rotation3D r) { loc.pos = p; loc.rot = r; diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index 80feab4..6a0359c 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -2,6 +2,7 @@ #include #include // IWYU pragma: keep #include // IWYU pragma: keep +#include #include #include @@ -28,8 +29,8 @@ Camera::updateView() inverseViewProjection = glm::inverse(viewProjection); } -glm::vec3 -Camera::upFromForward(const glm::vec3 & forward) +Direction3D +Camera::upFromForward(const Direction3D & forward) { const auto right = glm::cross(forward, ::down); return glm::cross(forward, right); @@ -38,11 +39,11 @@ Camera::upFromForward(const glm::vec3 & forward) std::array Camera::extentsAtDist(const float dist) const { - const auto clampToSeaFloor = [this, dist](const glm::vec3 & target) { + const auto clampToSeaFloor = [this, dist](const Position3D & target) { if (target.z < -1.5F) { const auto vec = glm::normalize(target - position); - constexpr glm::vec3 seafloor {0, 0, -1.5F}; - float outdist; + constexpr Position3D seafloor {0, 0, -1.5F}; + float outdist {}; if (glm::intersectRayPlane(position, vec, seafloor, ::up, outdist)) { return (vec * outdist + position) ^ outdist; } diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 218cf6d..6965175 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -97,7 +97,7 @@ SceneRenderer::render(const SceneProvider & scene) const } void -SceneRenderer::setAmbientLight(const glm::vec3 & colour) const +SceneRenderer::setAmbientLight(const RGB & colour) const { glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); glClearColor(colour.r, colour.g, colour.b, 1.0F); @@ -105,8 +105,7 @@ SceneRenderer::setAmbientLight(const glm::vec3 & colour) const } void -SceneRenderer::setDirectionalLight( - const glm::vec3 & colour, const glm::vec3 & direction, const SceneProvider & scene) const +SceneRenderer::setDirectionalLight(const RGB & colour, const Direction3D & direction, const SceneProvider & scene) const { if (colour.r > 0 || colour.g > 0 || colour.b > 0) { const auto lvp = shadowMapper.update(scene, direction, camera); @@ -135,7 +134,7 @@ SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() : } void -SceneRenderer::DirectionalLightProgram::setDirectionalLight(const glm::vec3 & c, const glm::vec3 & d, +SceneRenderer::DirectionalLightProgram::setDirectionalLight(const RGB & c, const Direction3D & d, const std::span lvp, const std::span shadowMapRegions, std::size_t maps) const { diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 1354611..04b6d9e 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -81,25 +81,25 @@ void SceneShader::WaterProgram::use(float waveCycle) const { Program::use(); - glm::vec3 waves {waveCycle, 0.F, 0.F}; + Position3D waves {waveCycle, 0.F, 0.F}; glUniform3fv(waveLoc, 1, glm::value_ptr(waves)); } SceneShader::PointLightShader::PointLightShader() : SceneProgram {pointLight_vs, pointLight_gs, pointLight_fs}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"} { - VertexArrayObject {va}.addAttribs(b); + VertexArrayObject {va}.addAttribs(b); } void -SceneShader::PointLightShader::add(const glm::vec3 & position, const glm::vec3 & colour, const float kq) const +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(glm::vec3), glm::value_ptr(position), GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(Position3D), glm::value_ptr(position), GL_DYNAMIC_DRAW); glDrawArrays(GL_POINTS, 0, 1); } @@ -107,12 +107,12 @@ SceneShader::SpotLightShader::SpotLightShader() : SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, directionLoc {*this, "v_direction"}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, arcLoc {*this, "arc"} { - using v3pair = std::pair; + using v3pair = std::pair; VertexArrayObject {va}.addAttribs(b); } void -SceneShader::SpotLightShader::add(const glm::vec3 & position, const glm::vec3 & direction, const glm::vec3 & colour, +SceneShader::SpotLightShader::add(const Position3D & position, const Direction3D & direction, const RGB & colour, const float kq, const float arc) const { Program::use(); @@ -122,6 +122,6 @@ SceneShader::SpotLightShader::add(const glm::vec3 & position, const glm::vec3 & glUniform3fv(directionLoc, 1, glm::value_ptr(direction)); glUniform1f(kqLoc, kq); glUniform1f(arcLoc, arc); - glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3), glm::value_ptr(position), GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, sizeof(Position3D), glm::value_ptr(position), GL_DYNAMIC_DRAW); glDrawArrays(GL_POINTS, 0, 1); } diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 58f65c4..aea5af3 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -104,14 +104,14 @@ struct DefinitionsInserter { ShadowMapper::Definitions & out; }; -std::vector> +std::vector> ShadowMapper::getBandViewExtents(const Camera & camera, const glm::mat4 & lightView) { - std::vector> bandViewExtents; + std::vector> bandViewExtents; for (const auto dist : shadowBands) { const auto extents = camera.extentsAtDist(dist); - bandViewExtents.emplace_back(extents * [&lightView](const auto & e) -> glm::vec3 { - return lightView * glm::vec4(glm::vec3 {e}, 1); + bandViewExtents.emplace_back(extents * [&lightView](const auto & e) -> Position3D { + return lightView * glm::vec4(Position3D {e}, 1); }); if (std::none_of(extents.begin(), extents.end(), [targetDist = dist * 0.99F](const glm::vec4 & e) { return e.w > targetDist; @@ -123,7 +123,7 @@ ShadowMapper::getBandViewExtents(const Camera & camera, const glm::mat4 & lightV } ShadowMapper::Definitions -ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir, const Camera & camera) const +ShadowMapper::update(const SceneProvider & scene, const Direction3D & dir, const Camera & camera) const { glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); glClear(GL_DEPTH_BUFFER_BIT); diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp index 0b47211..dc4f4dc 100644 --- a/gfx/gl/uiShader.cpp +++ b/gfx/gl/uiShader.cpp @@ -23,7 +23,7 @@ UIShader::UIShader(size_t width, size_t height) : UIShader::UIShader(const glm::mat4 & viewProjection) : icon {viewProjection}, text {viewProjection} { } void -UIShader::TextProgram::use(const glm::vec3 & colour) const +UIShader::TextProgram::use(const RGB & colour) const { Program::use(); glUniform3fv(colorLoc, 1, glm::value_ptr(colour)); -- cgit v1.2.3 From d771fbda2c171cfbc36cc0eb3122c1a02ffbb081 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 01:57:27 +0000 Subject: WIP typedefing just about everything else --- gfx/gl/sceneRenderer.cpp | 2 +- gfx/gl/sceneRenderer.h | 2 +- gfx/gl/sceneShader.cpp | 4 ++-- gfx/gl/sceneShader.h | 4 ++-- gfx/gl/shadowMapper.cpp | 47 ++++++++++++++++++++++++----------------------- gfx/gl/shadowMapper.h | 2 +- 6 files changed, 31 insertions(+), 30 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 6965175..4a3fec9 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -135,7 +135,7 @@ SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() : void SceneRenderer::DirectionalLightProgram::setDirectionalLight(const RGB & c, const Direction3D & d, - const std::span lvp, const std::span shadowMapRegions, + const std::span lvp, const std::span shadowMapRegions, std::size_t maps) const { glUniform3fv(colourLoc, 1, glm::value_ptr(c)); diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h index 87f474b..30fd8d3 100644 --- a/gfx/gl/sceneRenderer.h +++ b/gfx/gl/sceneRenderer.h @@ -40,7 +40,7 @@ private: using Program::use; void setDirectionalLight(const RGB &, const Direction3D &, const std::span, - const std::span, std::size_t maps) const; + const std::span, std::size_t maps) const; private: RequiredUniformLocation directionLoc, colourLoc, lightViewProjectionLoc, lightViewProjectionCountLoc, diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 04b6d9e..2dc2e70 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -35,7 +35,7 @@ SceneShader::setViewProjection(const glm::mat4 & viewProjection) const } void -SceneShader::setViewPort(const glm::ivec4 & viewPort) const +SceneShader::setViewPort(const ViewPort & viewPort) const { for (const auto & prog : std::array { &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) { @@ -51,7 +51,7 @@ SceneShader::SceneProgram::setViewProjection(const glm::mat4 & viewProjection) c } void -SceneShader::SceneProgram::setViewPort(const glm::ivec4 & viewPort) const +SceneShader::SceneProgram::setViewPort(const ViewPort & viewPort) const { if (viewPortLoc >= 0) { glUseProgram(*this); diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h index d1c6ef2..f46b842 100644 --- a/gfx/gl/sceneShader.h +++ b/gfx/gl/sceneShader.h @@ -16,7 +16,7 @@ class SceneShader { } void setViewProjection(const glm::mat4 &) const; - void setViewPort(const glm::ivec4 &) const; + void setViewPort(const ViewPort &) const; private: RequiredUniformLocation viewProjectionLoc; @@ -88,5 +88,5 @@ public: SpotLightShader spotLight; void setViewProjection(const glm::mat4 & viewProjection) const; - void setViewPort(const glm::ivec4 & viewPort) const; + void setViewPort(const ViewPort & viewPort) const; }; diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index aea5af3..94a0791 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -24,7 +24,7 @@ ShadowMapper::ShadowMapper(const TextureAbsCoord & s) : glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - static constexpr glm::vec4 border {std::numeric_limits::infinity()}; + static constexpr RGBA border {std::numeric_limits::infinity()}; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(border)); glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); @@ -37,7 +37,7 @@ ShadowMapper::ShadowMapper(const TextureAbsCoord & s) : glBindFramebuffer(GL_FRAMEBUFFER, 0); } -constexpr std::array, ShadowMapper::SHADOW_BANDS> viewports {{ +constexpr std::array, ShadowMapper::SHADOW_BANDS> viewports {{ {{ {31, 31, 0, 0}, // full }}, @@ -57,27 +57,28 @@ constexpr std::array, ShadowM {1, 1, 1, 1}, // upper right }}, }}; -constexpr std::array, ShadowMapper::SHADOW_BANDS> shadowMapRegions {{ - {{ - {0.5F, 0.5F, 0.5F, 0.5F}, // full - }}, - {{ - {0.5F, 0.25F, 0.5F, 0.25F}, // lower half - {0.5F, 0.25F, 0.5F, 0.75F}, // upper half - }}, - {{ - {0.5F, 0.25F, 0.5F, 0.25F}, // lower half - {0.25F, 0.25F, 0.25F, 0.75F}, // upper left - {0.25F, 0.25F, 0.75F, 0.75F}, // upper right - }}, - - {{ - {0.25F, 0.25F, 0.25F, 0.25F}, // lower left - {0.25F, 0.25F, 0.75F, 0.25F}, // lower right - {0.25F, 0.25F, 0.25F, 0.75F}, // upper left - {0.25F, 0.25F, 0.75F, 0.75F}, // upper right - }}, -}}; +constexpr std::array, ShadowMapper::SHADOW_BANDS> + shadowMapRegions {{ + {{ + {0.5F, 0.5F, 0.5F, 0.5F}, // full + }}, + {{ + {0.5F, 0.25F, 0.5F, 0.25F}, // lower half + {0.5F, 0.25F, 0.5F, 0.75F}, // upper half + }}, + {{ + {0.5F, 0.25F, 0.5F, 0.25F}, // lower half + {0.25F, 0.25F, 0.25F, 0.75F}, // upper left + {0.25F, 0.25F, 0.75F, 0.75F}, // upper right + }}, + + {{ + {0.25F, 0.25F, 0.25F, 0.25F}, // lower left + {0.25F, 0.25F, 0.75F, 0.25F}, // lower right + {0.25F, 0.25F, 0.25F, 0.75F}, // upper left + {0.25F, 0.25F, 0.75F, 0.75F}, // upper right + }}, + }}; constexpr std::array shadowBands { 1.F, 250.F, diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index e5272a3..d54734c 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -18,7 +18,7 @@ public: struct Definitions { std::array projections {}; - std::array regions {}; + std::array regions {}; size_t maps {}; }; -- cgit v1.2.3 From b44d10c03299953104266f01f6415b945e6520b9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 17:38:39 +0000 Subject: Fix definition of shadowMapRegions --- gfx/gl/shadowMapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gfx/gl') diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 94a0791..e4ee47a 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -57,7 +57,7 @@ constexpr std::array, S {1, 1, 1, 1}, // upper right }}, }}; -constexpr std::array, ShadowMapper::SHADOW_BANDS> +constexpr std::array, ShadowMapper::SHADOW_BANDS> shadowMapRegions {{ {{ {0.5F, 0.5F, 0.5F, 0.5F}, // full -- cgit v1.2.3 From ba4bca84808bebfc81be7df2cb536d1f73451bc6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 11 Nov 2023 17:35:07 +0000 Subject: Add BufferedLocation method for getting the rotation only transform --- gfx/gl/bufferedLocation.cpp | 6 ++++++ gfx/gl/bufferedLocation.h | 1 + 2 files changed, 7 insertions(+) (limited to 'gfx/gl') diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp index 62cadef..6ba8812 100644 --- a/gfx/gl/bufferedLocation.cpp +++ b/gfx/gl/bufferedLocation.cpp @@ -63,3 +63,9 @@ BufferedLocation::getTransform() const { return loc.getTransform(); } + +glm::mat4 +BufferedLocation::getRotationTransform() const +{ + return loc.getRotationTransform(); +} diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h index 39d3139..8302b3c 100644 --- a/gfx/gl/bufferedLocation.h +++ b/gfx/gl/bufferedLocation.h @@ -23,6 +23,7 @@ public: void setLocation(Position3D, Rotation3D); [[nodiscard]] glm::mat4 getTransform() const; + [[nodiscard]] glm::mat4 getRotationTransform() const; private: virtual void updateBuffer() = 0; -- cgit v1.2.3 From 5e25d79beef19c39537b0f15982a175fec45bb3e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 11 Nov 2023 17:37:57 +0000 Subject: Refactor BufferedLocationT to use a callback Simplifies customisation in the face of multiple fields --- gfx/gl/bufferedLocation.cpp | 7 ++++++- gfx/gl/bufferedLocation.h | 18 +++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp index 6ba8812..412e3ab 100644 --- a/gfx/gl/bufferedLocation.cpp +++ b/gfx/gl/bufferedLocation.cpp @@ -1,6 +1,5 @@ #include "bufferedLocation.h" #include "location.h" -#include "maths.h" #include BufferedLocation::BufferedLocation(Position3D p, Rotation3D r) : BufferedLocation {Location {p, r}} { } @@ -69,3 +68,9 @@ BufferedLocation::getRotationTransform() const { return loc.getRotationTransform(); } + +void +BufferedLocationUpdater::updateBuffer() const +{ + onUpdate(this); +} diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h index 8302b3c..a5cd23e 100644 --- a/gfx/gl/bufferedLocation.h +++ b/gfx/gl/bufferedLocation.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include class BufferedLocation { public: @@ -26,16 +26,16 @@ public: [[nodiscard]] glm::mat4 getRotationTransform() const; private: - virtual void updateBuffer() = 0; + virtual void updateBuffer() const = 0; Location loc; }; -template class BufferedLocationT : public BufferedLocation { +class BufferedLocationUpdater : public BufferedLocation { public: template - BufferedLocationT(Target &&... target, LocationArgs &&... t) : - BufferedLocation {std::forward(t)...}, target {std::forward(target)...} + BufferedLocationUpdater(std::function onUpdate, LocationArgs &&... t) : + BufferedLocation {std::forward(t)...}, onUpdate {std::move(onUpdate)} { updateBuffer(); } @@ -43,11 +43,7 @@ public: using BufferedLocation::operator=; private: - void - updateBuffer() override - { - std::apply(std::invoke, target) = getTransform(); - } + void updateBuffer() const override; - std::tuple target; + std::function onUpdate; }; -- cgit v1.2.3 From 356e874050e5ad5af87b04a2bb01ce34a86640bb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 13 Nov 2023 00:17:11 +0000 Subject: Send position and rotation matrix to GPU separately --- gfx/gl/camera.cpp | 9 ++++----- gfx/gl/sceneRenderer.cpp | 2 +- gfx/gl/sceneShader.cpp | 13 ++++++++----- gfx/gl/sceneShader.h | 11 +++++++---- gfx/gl/shaders/commonPoint.glsl | 2 +- gfx/gl/shaders/commonShadowPoint.glsl | 3 ++- gfx/gl/shaders/dynamicPoint.vs | 2 ++ gfx/gl/shaders/dynamicPointInst.vs | 2 ++ gfx/gl/shaders/fixedPoint.vs | 2 ++ gfx/gl/shaders/pointLight.gs | 1 + gfx/gl/shaders/pointLight.vs | 3 ++- gfx/gl/shaders/shadowDynamicPoint.vs | 2 ++ gfx/gl/shaders/shadowDynamicPointInst.vs | 2 ++ gfx/gl/shaders/shadowFixedPoint.vs | 2 ++ gfx/gl/shaders/spotLight.gs | 1 + gfx/gl/shaders/spotLight.vs | 3 ++- gfx/gl/shaders/water.vs | 7 ++++--- 17 files changed, 45 insertions(+), 22 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index 6a0359c..15f76c4 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -8,10 +8,9 @@ Camera::Camera(Position3D pos, Angle fov, Angle aspect, Distance zNear, Distance zFar) : position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar}, - projection {glm::perspective(fov, aspect, zNear, zFar)}, - viewProjection {projection * glm::lookAt(position, position + forward, up)}, - inverseViewProjection {glm::inverse(viewProjection)} + projection {glm::perspective(fov, aspect, zNear, zFar)}, viewProjection {}, inverseViewProjection {} { + updateView(); } Ray @@ -25,8 +24,8 @@ Camera::unProject(const ScreenRelCoord & mouse) const void Camera::updateView() { - viewProjection = projection * glm::lookAt(position, position + forward, up); - inverseViewProjection = glm::inverse(viewProjection); + viewProjection = projection * glm::lookAt(origin, forward, up); + inverseViewProjection = glm::inverse(projection * glm::lookAt(position, position + forward, up)); } Direction3D diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 4a3fec9..9b5510e 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -52,7 +52,7 @@ SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o) : void SceneRenderer::render(const SceneProvider & scene) const { - shader.setViewProjection(camera.getViewProjection()); + shader.setViewProjection(camera.getPosition(), camera.getViewProjection()); glViewport(0, 0, size.x, size.y); // Geometry pass diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 2dc2e70..2f391fd 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -26,11 +26,11 @@ SceneShader::SceneShader() : } void -SceneShader::setViewProjection(const glm::mat4 & viewProjection) const +SceneShader::setViewProjection(const Position3D & viewPoint, const glm::mat4 & viewProjection) const { for (const auto & prog : std::array { &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) { - prog->setViewProjection(viewProjection); + prog->setViewProjection(viewPoint, viewProjection); } } @@ -44,10 +44,11 @@ SceneShader::setViewPort(const ViewPort & viewPort) const } void -SceneShader::SceneProgram::setViewProjection(const glm::mat4 & viewProjection) const +SceneShader::SceneProgram::setViewProjection(const Position3D & viewPoint, const glm::mat4 & viewProjection) const { glUseProgram(*this); glUniformMatrix4fv(viewProjectionLoc, 1, GL_FALSE, glm::value_ptr(viewProjection)); + glUniform3fv(viewPointLoc, 1, glm::value_ptr(viewPoint)); } void @@ -86,7 +87,8 @@ SceneShader::WaterProgram::use(float waveCycle) const } SceneShader::PointLightShader::PointLightShader() : - SceneProgram {pointLight_vs, pointLight_gs, pointLight_fs}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"} + SceneProgram {pointLight_vs, pointLight_gs, pointLight_fs}, colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, + viewPointLoc {*this, "viewPoint"} { VertexArrayObject {va}.addAttribs(b); } @@ -105,7 +107,8 @@ SceneShader::PointLightShader::add(const Position3D & position, const RGB & colo SceneShader::SpotLightShader::SpotLightShader() : SceneProgram {spotLight_vs, spotLight_gs, spotLight_fs}, directionLoc {*this, "v_direction"}, - colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, arcLoc {*this, "arc"} + colourLoc {*this, "colour"}, kqLoc {*this, "kq"}, arcLoc {*this, "arc"}, viewPointLoc {*this, "viewPoint"} + { using v3pair = std::pair; VertexArrayObject {va}.addAttribs(b); diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h index f46b842..154dc17 100644 --- a/gfx/gl/sceneShader.h +++ b/gfx/gl/sceneShader.h @@ -11,15 +11,16 @@ class SceneShader { public: template inline explicit SceneProgram(const S &... srcs) : - Program {srcs...}, viewProjectionLoc {*this, "viewProjection"}, viewPortLoc {*this, "viewPort"} + Program {srcs...}, viewProjectionLoc {*this, "viewProjection"}, viewPointLoc {*this, "viewPoint"}, + viewPortLoc {*this, "viewPort"} { } - void setViewProjection(const glm::mat4 &) const; + void setViewProjection(const Position3D &, const glm::mat4 &) const; void setViewPort(const ViewPort &) const; private: - RequiredUniformLocation viewProjectionLoc; + RequiredUniformLocation viewProjectionLoc, viewPointLoc; UniformLocation viewPortLoc; }; @@ -58,6 +59,7 @@ class SceneShader { private: UniformLocation colourLoc; UniformLocation kqLoc; + UniformLocation viewPointLoc; glVertexArray va; glBuffer b; }; @@ -74,6 +76,7 @@ class SceneShader { UniformLocation colourLoc; UniformLocation kqLoc; UniformLocation arcLoc; + UniformLocation viewPointLoc; glVertexArray va; glBuffer b; }; @@ -87,6 +90,6 @@ public: PointLightShader pointLight; SpotLightShader spotLight; - void setViewProjection(const glm::mat4 & viewProjection) const; + void setViewProjection(const Position3D & viewPoint, const glm::mat4 & viewProjection) const; void setViewPort(const ViewPort & viewPort) const; }; diff --git a/gfx/gl/shaders/commonPoint.glsl b/gfx/gl/shaders/commonPoint.glsl index 35510e1..046da27 100644 --- a/gfx/gl/shaders/commonPoint.glsl +++ b/gfx/gl/shaders/commonPoint.glsl @@ -24,5 +24,5 @@ main() Colour = colour; Material = getMaterialDetail(material); - gl_Position = viewProjection * worldPos; + gl_Position = viewProjection * vec4(FragPos - viewPoint + modelPos, 1); } diff --git a/gfx/gl/shaders/commonShadowPoint.glsl b/gfx/gl/shaders/commonShadowPoint.glsl index c7cbd3e..216642e 100644 --- a/gfx/gl/shaders/commonShadowPoint.glsl +++ b/gfx/gl/shaders/commonShadowPoint.glsl @@ -1,6 +1,7 @@ void main() { - gl_Position = viewProjection * model * vec4(position, 1.0); + vec4 worldPos = model * vec4(position, 1.0); + gl_Position = viewProjection * vec4(worldPos.xyz - viewPoint + modelPos, 1); gl_Position.z = max(gl_Position.z, -1); } diff --git a/gfx/gl/shaders/dynamicPoint.vs b/gfx/gl/shaders/dynamicPoint.vs index 961535c..9dd6a47 100644 --- a/gfx/gl/shaders/dynamicPoint.vs +++ b/gfx/gl/shaders/dynamicPoint.vs @@ -5,6 +5,8 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; uniform mat4 model; +uniform vec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/dynamicPointInst.vs b/gfx/gl/shaders/dynamicPointInst.vs index 2d6cee5..4ae6813 100644 --- a/gfx/gl/shaders/dynamicPointInst.vs +++ b/gfx/gl/shaders/dynamicPointInst.vs @@ -5,6 +5,8 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; layout(location = 5) in mat4 model; +layout(location = 9) in vec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/fixedPoint.vs b/gfx/gl/shaders/fixedPoint.vs index ed78c96..0adbb02 100644 --- a/gfx/gl/shaders/fixedPoint.vs +++ b/gfx/gl/shaders/fixedPoint.vs @@ -5,6 +5,8 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; const mat4 model = mat4(1); +const vec3 modelPos = vec3(0); include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/pointLight.gs b/gfx/gl/shaders/pointLight.gs index 03d131d..ec089f5 100644 --- a/gfx/gl/shaders/pointLight.gs +++ b/gfx/gl/shaders/pointLight.gs @@ -19,6 +19,7 @@ const vec3[] cube = vec3[]( // http://www.cs.umd.edu/gvil/papers/av_ts.pdf vec3(1, 1, -1) // Back-top-right ); uniform mat4 viewProjection; +uniform vec3 viewPoint; in vec3 centre[]; in float size[]; diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs index 35682fa..b3fe7b9 100644 --- a/gfx/gl/shaders/pointLight.vs +++ b/gfx/gl/shaders/pointLight.vs @@ -4,6 +4,7 @@ layout(location = 0) in vec3 position; uniform vec3 colour; uniform float kq; +uniform vec3 viewPoint; out vec3 centre; out float size; @@ -13,5 +14,5 @@ main() { centre = position; size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); - gl_Position = vec4(centre, 0); + gl_Position = vec4(centre - viewPoint, 0); } diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs index f3ed533..eb25423 100644 --- a/gfx/gl/shaders/shadowDynamicPoint.vs +++ b/gfx/gl/shaders/shadowDynamicPoint.vs @@ -3,6 +3,8 @@ include(`meshIn.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; uniform mat4 model; +uniform vec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vs b/gfx/gl/shaders/shadowDynamicPointInst.vs index 1bf74ef..a0f51c3 100644 --- a/gfx/gl/shaders/shadowDynamicPointInst.vs +++ b/gfx/gl/shaders/shadowDynamicPointInst.vs @@ -3,6 +3,8 @@ include(`meshIn.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; layout(location = 5) in mat4 model; +layout(location = 9) in vec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs index 8921707..dfc5c42 100644 --- a/gfx/gl/shaders/shadowFixedPoint.vs +++ b/gfx/gl/shaders/shadowFixedPoint.vs @@ -3,6 +3,8 @@ include(`meshIn.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; const mat4 model = mat4(1); +const vec3 modelPos = vec3(0); include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/spotLight.gs b/gfx/gl/shaders/spotLight.gs index ad65675..0529614 100644 --- a/gfx/gl/shaders/spotLight.gs +++ b/gfx/gl/shaders/spotLight.gs @@ -10,6 +10,7 @@ const vec3[] pyramid = vec3[]( // four-sided vec3(1, -1, 1) // Front-right ); uniform mat4 viewProjection; +uniform vec3 viewPoint; uniform float arc; in vec3 position[]; diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs index dca0854..e61b641 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vs @@ -6,6 +6,7 @@ uniform vec3 v_direction; uniform vec3 colour; uniform float kq; uniform float arc; +uniform vec3 viewPoint; out vec3 position; out vec3 direction; @@ -19,5 +20,5 @@ main() direction = normalize(v_direction); size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); cosarc = cos(arc / 2); - gl_Position = vec4(position, 0); + gl_Position = vec4(position - viewPoint, 0); } diff --git a/gfx/gl/shaders/water.vs b/gfx/gl/shaders/water.vs index a21b49f..014499f 100644 --- a/gfx/gl/shaders/water.vs +++ b/gfx/gl/shaders/water.vs @@ -4,17 +4,18 @@ include(`meshIn.glsl') include(`materialInterface.glsl') uniform mat4 viewProjection; +uniform vec3 viewPoint; uniform vec3 waves; void main() { - vec4 wpos = vec4(position.x + cos(waves.x), position.y + cos(waves.x * waves.y / 2), - cos(waves.x + position.x + (position.y / 8)) * .3, 1.0); + vec3 wpos = vec3(position.x + cos(waves.x), position.y + cos(waves.x * waves.y / 2), + cos(waves.x + position.x + (position.y / 8)) * .3); FragPos = vec3(wpos.xy, position.z); TexCoords = texCoord; Normal = normal; - gl_Position = viewProjection * wpos; + gl_Position = viewProjection * vec4(wpos - viewPoint, 1.0); } -- cgit v1.2.3 From 685b33980cc7a346574b24732464f0cbe3115a1f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Nov 2023 01:29:24 +0000 Subject: Switch to millimeters for spatial units Mostly a case of changing far too many magic numbers, something else to fix I guess. I probably missed something. Also there's some hackery when loading 3D models, which are still assumed to be in metres. --- gfx/gl/sceneRenderer.cpp | 2 +- gfx/gl/shaders/landmass.fs | 6 +++--- gfx/gl/shaders/pointLight.fs | 2 +- gfx/gl/shaders/pointLight.vs | 2 +- gfx/gl/shaders/spotLight.fs | 2 +- gfx/gl/shaders/spotLight.vs | 2 +- gfx/gl/shaders/water.fs | 2 +- gfx/gl/shaders/water.vs | 4 ++-- gfx/gl/shadowMapper.cpp | 10 +++++----- 9 files changed, 16 insertions(+), 16 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 9b5510e..53178e5 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -15,7 +15,7 @@ static constexpr const std::array displayVAOdata {{ }}; SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o) : - camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, ratio(s), 0.1F, 10000.0F}, size {s}, output {o}, + camera {{-1250000.0F, -1250000.0F, 35.0F}, quarter_pi, ratio(s), 100.F, 10000000.0F}, size {s}, output {o}, lighting {lighting_vs, lighting_fs}, shadowMapper {{2048, 2048}} { shader.setViewPort({0, 0, size.x, size.y}); diff --git a/gfx/gl/shaders/landmass.fs b/gfx/gl/shaders/landmass.fs index 4dc92bb..9865d11 100644 --- a/gfx/gl/shaders/landmass.fs +++ b/gfx/gl/shaders/landmass.fs @@ -11,9 +11,9 @@ const vec3 rock = vec3(.2, .2, .1); const vec3 sand = vec3(.76, .7, .5); const vec3 snow = vec3(.97, .97, .99); -const float beachline = .5; -const float snowline_low = 28; -const float snowline_high = 30; +const float beachline = 500; +const float snowline_low = 28000; +const float snowline_high = 30000; const float slope_min = .99; const float slope_mid = .95; diff --git a/gfx/gl/shaders/pointLight.fs b/gfx/gl/shaders/pointLight.fs index bd32c05..1a68df8 100644 --- a/gfx/gl/shaders/pointLight.fs +++ b/gfx/gl/shaders/pointLight.fs @@ -26,5 +26,5 @@ main() if (normalDot < 0) { discard; } - FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist, 2))); + FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist / 1000.0, 2))); } diff --git a/gfx/gl/shaders/pointLight.vs b/gfx/gl/shaders/pointLight.vs index b3fe7b9..7694a25 100644 --- a/gfx/gl/shaders/pointLight.vs +++ b/gfx/gl/shaders/pointLight.vs @@ -13,6 +13,6 @@ void main() { centre = position; - size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); + size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); gl_Position = vec4(centre - viewPoint, 0); } diff --git a/gfx/gl/shaders/spotLight.fs b/gfx/gl/shaders/spotLight.fs index add86fd..78b8f72 100644 --- a/gfx/gl/shaders/spotLight.fs +++ b/gfx/gl/shaders/spotLight.fs @@ -30,5 +30,5 @@ main() if (normalDot < 0) { discard; } - FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist, 2))); + FragColor = (colour * normalDot) / (1 + (kq * pow(lightDist / 1000.0, 2))); } diff --git a/gfx/gl/shaders/spotLight.vs b/gfx/gl/shaders/spotLight.vs index e61b641..08197a4 100644 --- a/gfx/gl/shaders/spotLight.vs +++ b/gfx/gl/shaders/spotLight.vs @@ -18,7 +18,7 @@ main() { position = v_position; direction = normalize(v_direction); - size = (8 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); + size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); cosarc = cos(arc / 2); gl_Position = vec4(position - viewPoint, 0); } diff --git a/gfx/gl/shaders/water.fs b/gfx/gl/shaders/water.fs index 04aa94c..2ccc924 100644 --- a/gfx/gl/shaders/water.fs +++ b/gfx/gl/shaders/water.fs @@ -13,5 +13,5 @@ main() gPosition = vec4(FragPos, 1); gNormal = vec4(Normal, 1); gAlbedoSpec = texture(texture0, TexCoords); - gAlbedoSpec.a *= clamp(-FragPos.z * .7, .1, 1.0); + gAlbedoSpec.a *= clamp(-FragPos.z * .0007, .1, 1.0); } diff --git a/gfx/gl/shaders/water.vs b/gfx/gl/shaders/water.vs index 014499f..03eabb2 100644 --- a/gfx/gl/shaders/water.vs +++ b/gfx/gl/shaders/water.vs @@ -10,8 +10,8 @@ uniform vec3 waves; void main() { - vec3 wpos = vec3(position.x + cos(waves.x), position.y + cos(waves.x * waves.y / 2), - cos(waves.x + position.x + (position.y / 8)) * .3); + vec3 wpos = vec3(position.x + (cos(waves.x) * 1000.0), position.y + (cos(waves.x * waves.y / 2) * 1000.0), + cos(waves.x + (position.x / 1000.0) + (position.y * 125.0)) * 300.0); FragPos = vec3(wpos.xy, position.z); TexCoords = texCoord; diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index e4ee47a..190f20e 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -80,11 +80,11 @@ constexpr std::array, S }}, }}; constexpr std::array shadowBands { - 1.F, - 250.F, - 750.F, - 2500.F, - 10000.F, + 1000.F, + 250000.F, + 750000.F, + 2500000.F, + 10000000.F, }; static_assert(viewports.size() == shadowMapRegions.size()); static_assert(shadowBands.size() == shadowMapRegions.size() + 1); -- cgit v1.2.3 From 9bbaa4df842bf350a5d05233140bb4d631212a11 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Nov 2023 13:57:33 +0000 Subject: Send position and rotation matrix to GPU separately in basic program Missed from earlier commit --- gfx/gl/sceneShader.cpp | 9 ++++++--- gfx/gl/sceneShader.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 2f391fd..de75814 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -60,13 +60,16 @@ SceneShader::SceneProgram::setViewPort(const ViewPort & viewPort) const } } -SceneShader::BasicProgram::BasicProgram() : SceneProgram {dynamicPoint_vs, material_fs}, modelLoc {*this, "model"} { } +SceneShader::BasicProgram::BasicProgram() : + SceneProgram {dynamicPoint_vs, material_fs}, modelLoc {*this, "model"}, modelPosLoc {*this, "modelPos"} +{ +} void SceneShader::BasicProgram::setModel(Location const & location) const { - const auto model {glm::translate(location.pos) * rotate_ypr(location.rot)}; - glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); + glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(rotate_ypr(location.rot))); + glUniform3fv(modelPosLoc, 1, glm::value_ptr(location.pos)); } void diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h index 154dc17..83c234c 100644 --- a/gfx/gl/sceneShader.h +++ b/gfx/gl/sceneShader.h @@ -32,6 +32,7 @@ class SceneShader { private: RequiredUniformLocation modelLoc; + RequiredUniformLocation modelPosLoc; }; class AbsolutePosProgram : public SceneProgram { -- cgit v1.2.3 From 916fafa028b0bc8c8b0abec8c072722907d85f43 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Nov 2023 14:08:45 +0000 Subject: Send position and rotation matrix to GPU separately in shadowmapper dynamic --- gfx/gl/shadowMapper.cpp | 9 ++++----- gfx/gl/shadowMapper.h | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 190f20e..4a8d7ec 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -179,7 +179,8 @@ ShadowMapper::FixedPoint::use() const } ShadowMapper::DynamicPoint::DynamicPoint() : - Program {shadowDynamicPoint_vs}, viewProjectionLoc {*this, "viewProjection"}, modelLoc {*this, "model"} + Program {shadowDynamicPoint_vs}, viewProjectionLoc {*this, "viewProjection"}, modelLoc {*this, "model"}, + modelPosLoc {*this, "modelPos"} { } @@ -195,13 +196,11 @@ ShadowMapper::DynamicPoint::use(const Location & location) const { glUseProgram(*this); setModel(location); - const auto model = glm::translate(location.pos) * rotate_ypr(location.rot); - glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); } void ShadowMapper::DynamicPoint::setModel(const Location & location) const { - const auto model = glm::translate(location.pos) * rotate_ypr(location.rot); - glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); + glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(rotate_ypr(location.rot))); + glUniform3fv(modelPosLoc, 1, glm::value_ptr(location.pos)); } diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index d54734c..b53a7f1 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -44,6 +44,7 @@ public: private: RequiredUniformLocation viewProjectionLoc; RequiredUniformLocation modelLoc; + RequiredUniformLocation modelPosLoc; }; FixedPoint fixedPoint, dynamicPointInst; -- cgit v1.2.3 From 3200eb41d60595813dca751fe15193ba0b44dddf Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Nov 2023 14:32:56 +0000 Subject: Remove getTransform --- gfx/gl/bufferedLocation.cpp | 6 ------ gfx/gl/bufferedLocation.h | 1 - 2 files changed, 7 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp index 412e3ab..2a2e723 100644 --- a/gfx/gl/bufferedLocation.cpp +++ b/gfx/gl/bufferedLocation.cpp @@ -57,12 +57,6 @@ BufferedLocation::setLocation(Position3D p, Rotation3D r) updateBuffer(); } -glm::mat4 -BufferedLocation::getTransform() const -{ - return loc.getTransform(); -} - glm::mat4 BufferedLocation::getRotationTransform() const { diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h index a5cd23e..30967e3 100644 --- a/gfx/gl/bufferedLocation.h +++ b/gfx/gl/bufferedLocation.h @@ -22,7 +22,6 @@ public: void setRotation(Rotation3D, bool update = true); void setLocation(Position3D, Rotation3D); - [[nodiscard]] glm::mat4 getTransform() const; [[nodiscard]] glm::mat4 getRotationTransform() const; private: -- cgit v1.2.3 From 0aa665c3648d788755b00c9e431c872d57fddbb8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 25 Nov 2023 16:28:39 +0000 Subject: Model positions as integers Introduces test failure in arcs due to rounding, but I don't want to create a complicated fix as link positions are still floats and hopefully that'll go away... somehow --- gfx/gl/bufferedLocation.cpp | 8 ++++---- gfx/gl/bufferedLocation.h | 8 ++++---- gfx/gl/sceneShader.cpp | 2 +- gfx/gl/shaders/dynamicPoint.vs | 2 +- gfx/gl/shaders/dynamicPointInst.vs | 2 +- gfx/gl/shaders/fixedPoint.vs | 2 +- gfx/gl/shaders/shadowDynamicPoint.vs | 2 +- gfx/gl/shaders/shadowDynamicPointInst.vs | 2 +- gfx/gl/shaders/shadowFixedPoint.vs | 2 +- gfx/gl/shadowMapper.cpp | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) (limited to 'gfx/gl') diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp index 2a2e723..d6a63b9 100644 --- a/gfx/gl/bufferedLocation.cpp +++ b/gfx/gl/bufferedLocation.cpp @@ -2,7 +2,7 @@ #include "location.h" #include -BufferedLocation::BufferedLocation(Position3D p, Rotation3D r) : BufferedLocation {Location {p, r}} { } +BufferedLocation::BufferedLocation(GlobalPosition3D p, Rotation3D r) : BufferedLocation {Location {p, r}} { } BufferedLocation::BufferedLocation(const Location & l) : loc {l} { } @@ -19,7 +19,7 @@ BufferedLocation::operator=(const Location & l) return *this; } -Position3D +GlobalPosition3D BufferedLocation::position() const { return loc.pos; @@ -32,7 +32,7 @@ BufferedLocation::rotation() const } void -BufferedLocation::setPosition(Position3D p, bool update) +BufferedLocation::setPosition(GlobalPosition3D p, bool update) { loc.pos = p; if (update) { @@ -50,7 +50,7 @@ BufferedLocation::setRotation(Position3D r, bool update) } void -BufferedLocation::setLocation(Position3D p, Rotation3D r) +BufferedLocation::setLocation(GlobalPosition3D p, Rotation3D r) { loc.pos = p; loc.rot = r; diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h index 30967e3..87b957f 100644 --- a/gfx/gl/bufferedLocation.h +++ b/gfx/gl/bufferedLocation.h @@ -8,7 +8,7 @@ class BufferedLocation { public: - BufferedLocation(Position3D = {}, Rotation3D = {}); + BufferedLocation(GlobalPosition3D = {}, Rotation3D = {}); BufferedLocation(const Location &); virtual ~BufferedLocation() = default; @@ -16,11 +16,11 @@ public: operator const Location &() const; - [[nodiscard]] Position3D position() const; + [[nodiscard]] GlobalPosition3D position() const; [[nodiscard]] Rotation3D rotation() const; - void setPosition(Position3D, bool update = true); + void setPosition(GlobalPosition3D, bool update = true); void setRotation(Rotation3D, bool update = true); - void setLocation(Position3D, Rotation3D); + void setLocation(GlobalPosition3D, Rotation3D); [[nodiscard]] glm::mat4 getRotationTransform() const; diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index de75814..59a9748 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -69,7 +69,7 @@ void SceneShader::BasicProgram::setModel(Location const & location) const { glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(rotate_ypr(location.rot))); - glUniform3fv(modelPosLoc, 1, glm::value_ptr(location.pos)); + glUniform3iv(modelPosLoc, 1, glm::value_ptr(location.pos)); } void diff --git a/gfx/gl/shaders/dynamicPoint.vs b/gfx/gl/shaders/dynamicPoint.vs index 9dd6a47..667f247 100644 --- a/gfx/gl/shaders/dynamicPoint.vs +++ b/gfx/gl/shaders/dynamicPoint.vs @@ -7,6 +7,6 @@ include(`materialInterface.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; uniform mat4 model; -uniform vec3 modelPos; +uniform ivec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/dynamicPointInst.vs b/gfx/gl/shaders/dynamicPointInst.vs index 4ae6813..adf39bd 100644 --- a/gfx/gl/shaders/dynamicPointInst.vs +++ b/gfx/gl/shaders/dynamicPointInst.vs @@ -7,6 +7,6 @@ include(`materialInterface.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; layout(location = 5) in mat4 model; -layout(location = 9) in vec3 modelPos; +layout(location = 9) in ivec3 modelPos; include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/fixedPoint.vs b/gfx/gl/shaders/fixedPoint.vs index 0adbb02..6e1ab49 100644 --- a/gfx/gl/shaders/fixedPoint.vs +++ b/gfx/gl/shaders/fixedPoint.vs @@ -7,6 +7,6 @@ include(`materialInterface.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; const mat4 model = mat4(1); -const vec3 modelPos = vec3(0); +const vec3 modelPos = ivec3(0); include(`commonPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPoint.vs b/gfx/gl/shaders/shadowDynamicPoint.vs index eb25423..e20d31a 100644 --- a/gfx/gl/shaders/shadowDynamicPoint.vs +++ b/gfx/gl/shaders/shadowDynamicPoint.vs @@ -5,6 +5,6 @@ include(`meshIn.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; uniform mat4 model; -uniform vec3 modelPos; +uniform ivec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowDynamicPointInst.vs b/gfx/gl/shaders/shadowDynamicPointInst.vs index a0f51c3..ab3e976 100644 --- a/gfx/gl/shaders/shadowDynamicPointInst.vs +++ b/gfx/gl/shaders/shadowDynamicPointInst.vs @@ -5,6 +5,6 @@ include(`meshIn.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; layout(location = 5) in mat4 model; -layout(location = 9) in vec3 modelPos; +layout(location = 9) in ivec3 modelPos; include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shaders/shadowFixedPoint.vs b/gfx/gl/shaders/shadowFixedPoint.vs index dfc5c42..a9fb4a3 100644 --- a/gfx/gl/shaders/shadowFixedPoint.vs +++ b/gfx/gl/shaders/shadowFixedPoint.vs @@ -5,6 +5,6 @@ include(`meshIn.glsl') uniform mat4 viewProjection; uniform vec3 viewPoint; const mat4 model = mat4(1); -const vec3 modelPos = vec3(0); +const ivec3 modelPos = ivec3(0); include(`commonShadowPoint.glsl') diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 4a8d7ec..07db6a1 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -202,5 +202,5 @@ void ShadowMapper::DynamicPoint::setModel(const Location & location) const { glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(rotate_ypr(location.rot))); - glUniform3fv(modelPosLoc, 1, glm::value_ptr(location.pos)); + glUniform3iv(modelPosLoc, 1, glm::value_ptr(location.pos)); } -- cgit v1.2.3