Browse Source

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()`.
pull/277/head
Vladimír Vondruš 13 years ago
parent
commit
b349ca54ad
  1. 12
      src/Shaders/Phong.h

12
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;
}

Loading…
Cancel
Save