我试图通过获取屏幕空间坐标然后使用叉积来获得视锥体平面来计算每个平截头体。然而,当我检查哪些瓷砖受到光线的影响时,它们是相反的方向,如同在中,它们在相机的相反方向上移动并且在其后面。我尝试过更改产品订单,但它似乎无论如何都无法正常工作。这里是生成截头锥体并检查光线是否与其相交的代码:
//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部分仅用于调试。截头锥体是完全颠倒过来的,或者我做了一些非常错误的事情,在这张照片中,我正在向后看着我,因此瓷砖会受到影响,它们与场景完全相反,当我移动时相机瓷砖也向相反的方向移动
答案 0 :(得分: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方法没有正确初始化工作线程的数量