0

我试图通过获取屏幕空间坐标然后使用叉积来获取视锥平面来计算每个平截头体。然而,当我检查哪些瓷砖受到光线的影响时,它们是在相反的方向上,例如,它们在相机的相反方向上移动并且在它后面。我已经尝试更改交叉产品订单,但它似乎并没有以任何方式工作。这是生成截锥体并检查光线是否与其相交的代码:

//Start by getting the corners in screen space
uint minX = MAX_WORK_GROUP_SIZE * gl_WorkGroupID.x;
uint minY = MAX_WORK_GROUP_SIZE * gl_WorkGroupID.y;
uint maxX = MAX_WORK_GROUP_SIZE * (gl_WorkGroupID.x + 1);
uint maxY = MAX_WORK_GROUP_SIZE * (gl_WorkGroupID.y + 1);

//Convert these corners into NDC and then convert them to view space
vec4 tileCorners[4];
tileCorners[0] = unProject(vec4( (float(minX)/SCREEN_WIDTH) * 2.0f - 1.0f, (float(minY)/SCREEN_HEIGHT) * 2.0f - 1.0f, 1.0f, 1.0f));
tileCorners[1] = unProject(vec4( (float(maxX)/SCREEN_WIDTH) * 2.0f - 1.0f, (float(minY)/SCREEN_HEIGHT) * 2.0f - 1.0f, 1.0f, 1.0f));
tileCorners[2] = unProject(vec4( (float(maxX)/SCREEN_WIDTH) * 2.0f - 1.0f, (float(maxY)/SCREEN_HEIGHT) * 2.0f - 1.0f, 1.0f, 1.0f));
tileCorners[3] = unProject(vec4( (float(minX)/SCREEN_WIDTH) * 2.0f - 1.0f, (float(maxY)/SCREEN_HEIGHT) * 2.0f - 1.0f, 1.0f, 1.0f));

//Create the frustum planes by using the cross product between these points 
frustum[0] = CreatePlane(tileCorners[0], tileCorners[1]); //bot
frustum[1] = CreatePlane(tileCorners[1], tileCorners[2]); //right
frustum[2] = CreatePlane(tileCorners[2], tileCorners[3]); //top
frustum[3] = CreatePlane(tileCorners[3], tileCorners[0]); //left

和功能:

vec4 unProject(vec4 v)
{
    v = inverseProjectionMatrix * v;
    v /= v.w;
    return v;
}
vec4 CreatePlane( vec4 b, vec4 c )
{ 
    vec4 normal;
    normal.xyz = normalize(cross( b.xyz, c.xyz ));
    normal.w = 0;
    return normal;
}

float GetSignedDistanceFromPlane( vec4 p, vec4 eqn )
{
    return dot( eqn.xyz, p.xyz );
}

以及我如何检查灯光

int threadsPerTile = MAX_WORK_GROUP_SIZE*MAX_WORK_GROUP_SIZE;
for (uint i = 0; i < NUM_OF_LIGHTS; i+= threadsPerTile)
{
    uint il = gl_LocalInvocationIndex + i;


    if (il < NUM_OF_LIGHTS)
    {
        PointLight p = pointLights[il];

        vec4 viewPos = viewMatrix * vec4(p.position.xyz, 1.0f);
        float r = p.radius;

   //     if (viewPos.z + minDepthZ < r && viewPos.z - maxDepthZ < r)
 //       {

        if( ( GetSignedDistanceFromPlane( viewPos, frustum[0] ) < r ) &&
            ( GetSignedDistanceFromPlane( viewPos, frustum[1] ) < r ) &&
            ( GetSignedDistanceFromPlane( viewPos, frustum[2] ) < r ) &&
            ( GetSignedDistanceFromPlane( viewPos, frustum[3] ) < r) )

            {
                uint id = atomicAdd(pointLightCount, 1);
                pointLightIndex[id] = il;
            }
   //     }

    }
}

我已经注释掉了 z 部分只是为了调试。截锥体完全颠倒了,或者我做错了什么,在这张照片中,我在我身后向上看,所以与场景完全相反方向的瓷砖受到影响,当我移动相机时,瓷砖移动也在相反的方向

在此处输入图像描述

4

1 回答 1

1

显然平截头体的计算是正确的,但是关于 ARB 扩展的一些东西(我认为是无关的)让一切都爆炸了。我用了

#extension GL_ARB_compute_variable_group_size : enable
layout( local_size_variable ) in;

这根本不起作用,所以我只是将其更改为

layout(local_size_x = MAX_WORK_GROUP_SIZE, local_size_y = MAX_WORK_GROUP_SIZE) in;

在 CPU 上:

    glDispatchCompute((1280 / 16), (720 / 16), 1);
    //glDispatchComputeGroupSizeARB((1280 / 16), (720 / 16), 1, 16, 16, 1);

哪个工作正常,所以我想 ARB 方法有些东西没有正确初始化工作线程的数量

于 2015-11-07T12:32:53.930 回答