Hello, I am trying to implement tiled based forward shading in my engine but am having trouble understanding how the frustum is calculated for each tile. I have been reading about this topic on the internet and have found a few code samples but none explain the math behind the frustum plane calculation and I have been trying to wrap my head around it but have been unsuccessful so far. For now I was following this code here. I cant really understand how the following code calculates the plane equations
minDepth = uintBitsToFloat(minDepthInt);
maxDepth = uintBitsToFloat(maxDepthInt);
// Steps based on tile sale
vec2 negativeStep = (2.0 * vec2(tileID)) / vec2(tileNumber);
vec2 positiveStep = (2.0 * vec2(tileID + ivec2(1, 1))) / vec2(tileNumber);
// Set up starting values for planes using steps and min and max z values
frustumPlanes[0] = vec4(1.0, 0.0, 0.0, 1.0 - negativeStep.x); // Left
frustumPlanes[1] = vec4(-1.0, 0.0, 0.0, -1.0 + positiveStep.x); // Right
frustumPlanes[2] = vec4(0.0, 1.0, 0.0, 1.0 - negativeStep.y); // Bottom
frustumPlanes[3] = vec4(0.0, -1.0, 0.0, -1.0 + positiveStep.y); // Top
frustumPlanes[4] = vec4(0.0, 0.0, -1.0, -minDepth); // Near
frustumPlanes[5] = vec4(0.0, 0.0, 1.0, maxDepth); // Far
// Transform the first four planes
for (uint i = 0; i < 4; i++) {
frustumPlanes[i] *= viewProjection;
frustumPlanes[i] /= length(frustumPlanes[i].xyz);
}
// Transform the depth planes
frustumPlanes[4] *= view;
frustumPlanes[4] /= length(frustumPlanes[4].xyz);
frustumPlanes[5] *= view;
frustumPlanes[5] /= length(frustumPlanes[5].xyz);
Following the plane generation the authours multiply it by the view projection matrix which makes me think that the generation is happening in world space. Can someone help me understand the math behind this or point me to somewhere where this is explained ? Thanks !