1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:37:34 +00:00

LibGL+LibSoftGPU+LibGfx: Reimplement normal transformation

We now support generating top-left submatrices from a `Gfx::Matrix`
and we move the normal transformation calculation into
`SoftGPU::Device`. No functional changes.
This commit is contained in:
Jelle Raaijmakers 2022-03-23 14:07:27 +01:00 committed by Brian Gianforcaro
parent 74de8e4224
commit 8a3242cb83
4 changed files with 22 additions and 14 deletions

View file

@ -639,9 +639,8 @@ static void generate_texture_coordinates(Vertex& vertex, RasterizerOptions const
}
}
void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& model_view_transform, FloatMatrix3x3 const& normal_transform,
FloatMatrix4x4 const& projection_transform, FloatMatrix4x4 const& texture_transform, Vector<Vertex> const& vertices,
Vector<size_t> const& enabled_texture_units)
void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const& model_view_transform, FloatMatrix4x4 const& projection_transform,
FloatMatrix4x4 const& texture_transform, Vector<Vertex> const& vertices, Vector<size_t> const& enabled_texture_units)
{
// At this point, the user has effectively specified that they are done with defining the geometry
// of what they want to draw. We now need to do a few things (https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview):
@ -716,6 +715,10 @@ void Device::draw_primitives(PrimitiveType primitive_type, FloatMatrix4x4 const&
}
}
// Set up normals transform by taking the upper left 3x3 elements from the model view matrix
// See section 2.11.3 of the OpenGL 1.5 spec
auto normal_transform = model_view_transform.submatrix_from_topleft<3>().transpose().inverse();
// Now let's transform each triangle and send that to the GPU
auto const viewport = m_options.viewport;
auto const viewport_half_width = viewport.width() / 2.0f;