Correct for non uniform scale in lighting
This commit is contained in:
@@ -53,6 +53,10 @@ void Shader::UpdateProjection(Matrix projection) {
|
||||
glUniformMatrix4fv(glGetUniformLocation(id, "PROJECTION"), 1, GL_FALSE, glm::value_ptr(projection));
|
||||
}
|
||||
|
||||
void Shader::UpdateNormal(glm::mat3 normal) {
|
||||
glUniformMatrix3fv(glGetUniformLocation(id, "NORMAL"), 1, GL_FALSE, glm::value_ptr(normal));
|
||||
}
|
||||
|
||||
void Shader::UpdateMaterial(Material material) {
|
||||
glUniform1i(glGetUniformLocation(id, "material.usesTex"), (int) material.usesTex);
|
||||
if (material.usesTex) {
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
void UpdateView(Matrix view);
|
||||
void UpdateModel(Matrix model);
|
||||
void UpdateProjection(Matrix projection);
|
||||
void UpdateNormal(glm::mat3 normal);
|
||||
|
||||
void UpdateMaterial(Material material);
|
||||
|
||||
|
||||
@@ -74,6 +74,9 @@ Skybox *Skybox::FromFiles(const char *right, const char* left, const char* top,
|
||||
const char* files[] = {right, left, top, bottom, front, back};
|
||||
for (int i = 0; i < 6; i++) {
|
||||
data = stbi_load(files[i], &width, &height, &nrChannels, 3);
|
||||
if (!data) {
|
||||
Util::Die("Could not load skybox image ", files[i]);
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
|
||||
0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
stbi_image_free(data);
|
||||
|
||||
@@ -46,6 +46,7 @@ void render(Node *curr, Shader *shader, Matrix model) {
|
||||
model = glm::translate(model, spatial->transform.position);
|
||||
model = glm::scale(model, spatial->transform.scale);
|
||||
shader->UpdateModel(model);
|
||||
shader->UpdateNormal(glm::mat3(glm::transpose(glm::inverse(model))));
|
||||
}
|
||||
Mesh *mesh = dynamic_cast<Mesh*>(curr);
|
||||
mesh->Draw(shader);
|
||||
|
||||
Reference in New Issue
Block a user