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/sceneShader.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'gfx/gl/sceneShader.cpp') 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); -- cgit v1.2.3