Dev Test - Multiple Layouts - Blender Game Engine
306 views · Published 11 September 2012 · 2:15 · Indexed 21 October 2026
Channel: Dalai Felinto · 2012 · Education
Test for a patch I'm building for BGE for *internal* use.
The idea is to split the screen in 2 or 3 pieces, each one receiving a unique shader uniform (bge_layout). This way the objects using custom shaders can render differently in each layout.
This works for both fragment shader (see the different colors of the monkey) and for vertex shader (see the size change during the video).
Each layout has a viewport taking the correspond part of the screen (e.g., a third of it) and have a ProjectionMatrix shifted accordingly.
I like the code so much that I will post here :)
It takes a valid projection matrix (for the whole canvas) and does the shift.
MT_Matrix4x4 RAS_OpenGLRasterizer::GetLayoutProjectionMatrix(
MT_Matrix4x4 projmat,
float near,
int layout,
int layouts
) {
MT_Matrix4x4 retmat = projmat;
float side = near / retmat.getElement(0, 0);
float offset = 2.f * side / layouts;
float left = -side + (layout * offset);
float right = left + offset;
/* recalculate glFrustrum matrices */
projmat[0][0] = (2 * near) / (right - left);
projmat[0][2] = (right + left) / (right - left);
return projmat;
}