From b349ca54ad33071d3c83581fb39a7e8a406a2944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 30 Jul 2013 15:00:28 +0200 Subject: [PATCH] Shaders: explicitly setting normal matrix in Phong shader. Currently the most used scene graph transformation implementation are dual quaternions, which don't allow any scaling. The original code normalized the rotation matrix, involving three dot products and one sqrt, even if it wasn't needed in most cases -- even if using scene graph with matrices mostly you don't scale at all and thus the shader internally renormalized already normalized vectors for _each object_ in each frame. This _will_ break things, don't forget to update the code and call `setNormalMatrix()` along with `setTransformationMatrix()`. --- src/Shaders/Phong.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Shaders/Phong.h b/src/Shaders/Phong.h index f153dc761..417611152 100644 --- a/src/Shaders/Phong.h +++ b/src/Shaders/Phong.h @@ -93,12 +93,20 @@ class MAGNUM_SHADERS_EXPORT Phong: public AbstractShaderProgram { } /** - * @brief Set transformation and normal matrix + * @brief Set transformation matrix * @return Pointer to self (for method chaining) */ Phong* setTransformationMatrix(const Matrix4& matrix) { setUniform(transformationMatrixUniform, matrix); - setUniform(normalMatrixUniform, matrix.rotation()); + return this; + } + + /** + * @brief Set normal matrix + * @return Pointer to self (for method chaining) + */ + Phong* setNormalMatrix(const Math::Matrix<3, Float>& matrix) { + setUniform(normalMatrixUniform, matrix); return this; }