Tiled Deferred Frustum Culling issues

Started by
1 comment, last by Niruz 10 years, 1 month ago

I'm having some issues getting culling to work for the near/far plane per tile when doing tiled deferred shading. The way to do it in DirectX based on http://malegebi.wordpress.com/2012/01/30/a-new-era-of-forward-shading-is-coming/ is to do it like this.


// Work out scale/bias from [0, 1]
float2 tileScale = float2(DisplaySize.xy) * rcp(2.0f * float2(LightTileSize, LightTileSize));
float2 tileBias = tileScale - float2(GroupID.xy);

// Now work out composite projection matrix
// Relevant matrix columns for this tile frusta
float4 c1 = float4(Projection._11 * tileScale.x, 0.0f, tileBias.x, 0.0f);
float4 c2 = float4(0.0f, -Projection._22 * tileScale.y, tileBias.y, 0.0f);
float4 c4 = float4(0.0f, 0.0f, 1.0f, 0.0f);

// Derive frustum planes
float4 frustumPlanes[6];

// Sides
frustumPlanes[0] = c4 - c1;
frustumPlanes[1] = c4 + c1;
frustumPlanes[2] = c4 - c2;
frustumPlanes[3] = c4 + c2;

// Near/far
frustumPlanes[4] = float4(0.0f, 0.0f, 1.0f, -minTileZ);
frustumPlanes[5] = float4(0.0f, 0.0f, -1.0f, maxTileZ);

I've tried just doing an opengl version of that but it doesn't seem to work, here's what I have so far, notice that near/far aren't correct:


vec4 frustumPlanes[6];

    vec2 tileScale = vec2(SCREEN_WIDTH,SCREEN_HEIGHT) * (1.0f / float( 2 * MAX_WORK_GROUP_SIZE));

    vec2 tileBias = tileScale - vec2(gl_WorkGroupID.xy);

    vec4 col1 = vec4(-projectionMatrix[0][0] * tileScale.x, projectionMatrix[0][1], tileBias.x, projectionMatrix[0][3]);

vec4 col2 = vec4(projectionMatrix[1][0], -projectionMatrix[1][1] * tileScale.y, tileBias.y, projectionMatrix[1][3]);

vec4 col4 = vec4(projectionMatrix[3][0], projectionMatrix[3][1], -1.0f, projectionMatrix[3][3]);

    //Left plane
frustumPlanes[0] = col4 + col1;

//right plane
frustumPlanes[1] = col4 - col1;

//top plane
frustumPlanes[2] = col4 - col2;

//bottom plane
frustumPlanes[3] = col4 + col2;

//near
frustumPlanes[4] = vec4(0.0f, 0.0f, -1.0f, -minDepthZ);

//far
frustumPlanes[5] = vec4(0.0f, 0.0f, -1.0f, maxDepthZ);

    for(int i = 0; i < 4; i++)
{
frustumPlanes[i] *= 1.0f / length(frustumPlanes[i].xyz);
}

I want to do near = vec4(0.0f, 0,0f, -1,0f, -minDepthZ) and for the far I want to do vec4(0.0f,0.0f,1.0f,maxDepthZ) which is like the directX version only reversed, I've been basing things on this link too http://www.lighthouse3d.com/tutorials/view-frustum-culling/clip-space-approach-extracting-the-planes/

But I cannot seem to get it to work, does anyone have any idea on how to correctly implement the near and far plane for the frustum?

Advertisement

Pls, don't double post. You have posted this question already yesterday (here) and people will answer if they think, that they can help you.

I'm sorry, it was my meaning to delete the old thread as I thought it would fit more in here, however I can't seem to do it

This topic is closed to new replies.

Advertisement