Change normal matrix from 4x4 to 3x3
This commit is contained in:
@@ -47,7 +47,7 @@ void Mesh::render(const glm::mat4 &model_matrix, const glm::mat4 &normal_matrix)
|
||||
{
|
||||
this->shaderprog->use();
|
||||
this->shaderprog->setUniformMat4("model_matrix", model_matrix);
|
||||
this->shaderprog->setUniformMat4("normal_matrix", normal_matrix);
|
||||
this->shaderprog->setUniformMat3("normal_matrix", normal_matrix);
|
||||
this->shaderprog->setUniformMat4("projection_view_matrix", GlobalCanvasSettings::getPVMatrix());
|
||||
this->shaderprog->setUniformVec3("camera_position", GlobalCanvasSettings::getCameraPosition());
|
||||
|
||||
|
@@ -1,7 +1,5 @@
|
||||
#include <opengl-playground/openglgraphics.hpp>
|
||||
|
||||
|
||||
|
||||
OpenGlGraphics::OpenGlGraphics(std::shared_ptr<OpenGlShaderProgram>shader_prog)
|
||||
{
|
||||
this->shaderprog = shader_prog;
|
||||
@@ -16,15 +14,15 @@ OpenGlGraphics::~OpenGlGraphics()
|
||||
void OpenGlGraphics::setModelMatrix(const glm::mat4 &model_matrix)
|
||||
{
|
||||
this->model_matrix = model_matrix;
|
||||
this->normal_matrix = glm::transpose(glm::inverse(model_matrix));
|
||||
this->normal_matrix = glm::mat3(glm::transpose(glm::inverse(model_matrix)));
|
||||
}
|
||||
|
||||
glm::mat4 OpenGlGraphics::getModelMatrix()
|
||||
const glm::mat4 &OpenGlGraphics::getModelMatrix()
|
||||
{
|
||||
return this->model_matrix;
|
||||
}
|
||||
|
||||
glm::mat4 OpenGlGraphics::getNormalMatrix()
|
||||
const glm::mat3 &OpenGlGraphics::getNormalMatrix()
|
||||
{
|
||||
return this->normal_matrix;
|
||||
}
|
||||
|
@@ -200,6 +200,14 @@ void OpenGlShaderProgram::setUniformMat4(const std::string &uniform, const glm::
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGlShaderProgram::setUniformMat3(const std::string &uniform, const glm::mat3 &matrix)
|
||||
{
|
||||
int loc = this->getUniformLoc(uniform);
|
||||
if (loc >= 0) {
|
||||
glUniformMatrix3fv(loc, 1, GL_FALSE, &matrix[0][0]);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGlShaderProgram::setUniformVec4(const std::string &uniform, const glm::vec4 &vector)
|
||||
{
|
||||
int loc = this->getUniformLoc(uniform);
|
||||
|
Reference in New Issue
Block a user