0

我有以下用于计算景深的计算着色器代码。但是,非常不寻常的是,即使 g_rayCount 为 10,循环也只执行一次。请查看 for 循环所在的主函数 raycastercs。

//--------------------------------------------------------------------------------------
// Compute Shader
//-------------------------------------------------------------------------------------

SamplerState SSLinear
{
    Filter = Min_Mag_Linear_Mip_Point;
    AddressU = Border;
    AddressV = Border;
    AddressW = Border;
};

float3 CalculateDoF(uint seedIndex, uint2 fragPos)
{
    ;
}

[numthreads(RAYCASTER_THREAD_BLOCK_SIZE, RAYCASTER_THREAD_BLOCK_SIZE, 1)]
void RaycasterCS(in uint3 threadID: SV_GroupThreadID, in uint3 groupID: SV_GroupID, in uint3 dispatchThreadID :SV_DispatchThreadID)
{
    uint2 fragPos   = groupID.xy * RAYCASTER_THREAD_BLOCK_SIZE + threadID.xy;
    float4 dstColor = g_texFinal[fragPos];
    uint seedIndex  = dispatchThreadID.x * dispatchThreadID.y;


    float3 final = float3(0, 0, 0);
    float color = 0;

    [loop][allow_uav_condition]
    for (int i = 0; i < g_rayCount; ++i);
    {
        float3 dof = CalculateDoF(seedIndex, fragPos);
        final += dof;
    }

    final *= 1.0f / ((float) g_rayCount);
    g_texFinalRW[fragPos] = float4(final, 1);
}


//--------------------------------------------------------------------------------------


technique10 Raycaster
{
    pass RaycastDefault
    {
        SetVertexShader(NULL);
        SetGeometryShader(NULL);
        SetPixelShader(NULL);
        SetComputeShader(CompileShader(cs_5_0, RaycasterCS()));
    }
}
4

1 回答 1

4

去掉 for 语句末尾的分号

for (int i = 0; i < g_rayCount; ++i)  // removed semicolon
{
    float3 dof = CalculateDoF(seedIndex, fragPos);
    final += dof;
}

我猜你知道,分号只是运行一个空for循环,然后大括号中的代码只执行一次。

于 2013-09-23T08:44:43.923 回答