mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:27:35 +00:00
LibSoftGPU+LibGfx: Transform and normalize normals before lighting
We were transforming the vertices' normals twice (bug 1) and normalizing them after lighting (bug 2). In the lighting code, we were then diverting from the spec to deal with the normal situation, which is now no longer needed. This fixes the lighting of Tux in Tux Racer.
This commit is contained in:
parent
23476dac64
commit
bc5e5afc7b
2 changed files with 17 additions and 29 deletions
|
@ -27,6 +27,8 @@ constexpr static Vector4<T> operator*(const Matrix4x4<T>& m, const Vector4<T>& v
|
|||
v.x() * elements[3][0] + v.y() * elements[3][1] + v.z() * elements[3][2] + v.w() * elements[3][3]);
|
||||
}
|
||||
|
||||
// FIXME: this is a specific Matrix4x4 * Vector3 interaction that implies W=1; maybe move this out of LibGfx
|
||||
// or replace a Matrix4x4 * Vector4 operation?
|
||||
template<typename T>
|
||||
constexpr static Vector3<T> transform_point(const Matrix4x4<T>& m, const Vector3<T>& p)
|
||||
{
|
||||
|
@ -37,16 +39,6 @@ constexpr static Vector3<T> transform_point(const Matrix4x4<T>& m, const Vector3
|
|||
p.x() * elements[2][0] + p.y() * elements[2][1] + p.z() * elements[2][2] + elements[2][3]);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr static Vector3<T> transform_direction(const Matrix4x4<T>& m, const Vector3<T>& d)
|
||||
{
|
||||
auto const& elements = m.elements();
|
||||
return Vector3<T>(
|
||||
d.x() * elements[0][0] + d.y() * elements[0][1] + d.z() * elements[0][2],
|
||||
d.x() * elements[1][0] + d.y() * elements[1][1] + d.z() * elements[1][2],
|
||||
d.x() * elements[2][0] + d.y() * elements[2][1] + d.z() * elements[2][2]);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr static Matrix4x4<T> translation_matrix(const Vector3<T>& p)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue