I'm trying to figure out how to perform tiled rendering of my 3d scene (OpenGL). The motivation is to cut the scene up into several textures, combining them into a single image for saving at a very high resolution, or for printing.
I've done some reading on this and apparently I just need to put appropriate parameters into my projection matrix for each tile in the scene. This is where I'm failing (miserably). I can't see where or what to use for it.
My perspective projection matrix is pretty standard, like this:
const T fov2 = Math::Tan(fov / 2), extent = (farPlane - nearPlane);
assert(fov2 != 0);
Matrix4x4<T> r;
r.m11 = 1 / (aspect * fov2); r.m12 = 0; r.m13 = 0; r.m14 = 0;
r.m21 = 0; r.m22 = 1 / fov2; r.m23 = 0; r.m24 = 0;
r.m31 = 0; r.m32 = 0; r.m33 = -(farPlane + nearPlane) / extent; r.m34 = -1;
r.m41 = 0; r.m42 = 0; r.m43 = -(2.f * farPlane * nearPlane) / extent; r.m44 = 0;
return r;
I tried an implementation of glFrustum (no longer available as I'm using core profile of course) as follows:
Matrix4x4<T> r(InitialiseAs::InitialiseIdentity);
r.m11 = 2.0f * nearPlane / (right - left); r.m12 = 0; r.m13 = (right + left) / (right - left); r.m14 = 0;
r.m21 = 0; r.m22 = 2.0f * nearPlane / (top - bottom); r.m23 = (top + bottom) / (top - bottom); r.m24 = 0;
r.m31 = 0; r.m32 = 0; r.m33 = -(farPlane + nearPlane) / (farPlane - nearPlane); r.m34 = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
r.m41 = 0; r.m42 = 0; r.m43 = -1; r.m44 = 0;
return r;
But, alas I'm not sure what parameters I need to use for left, top, right and bottom when iterating across the scene, viewport or screen.
Can anyone assist me?
Edit: I found this example (unfortunately D3D) of someone doing something similar. The author seems to be just multiplying _11 and _22 by the width (scale up) and then modifying _31 and _32 according to the current tile position - iterating through the whole grid.
I did try this but I got a black screen of doom.