Advertisement Jump to content
Sign in to follow this  
Niruz

OpenGL Tiled Deferred Frustum Culling issues

This topic is 1772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Edited by Ashaman73

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

This topic is 1772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!