HLSL loop / fetch issue

I have a piece of HLSL code that looks like this:

float4 GetIndirection(float2 TexCoord)
{
    float4 indirection = tex2D(IndirectionSampler, TexCoord);

    for (half mip = indirection.b * 255; mip > 1 && indirection.a < 128; mip--)
    {
        indirection = tex2Dlod(IndirectionSampler, float4(TexCoord, 0, mip));
    }
    return indirection;
}

      

The results I get are consistent with the loop being executed only once. I checked the shader in PIX and things got even weirder: the yellow arrow indicating that the position in the code enters the loop, goes through once and returns to the beginning, at which point the yellow arrow never moves, and the cursor moves through the code and returns result (bug in PIX, or am I just using it wrong?)

I have a suspicion that this might be a problem with reading a texture moved outside of the loop by the compiler, however I thought this did not happen with tex2Dlod as I set the LOD manually: /

So:

1) What's the problem?

2) Any suggested solutions?

+2


source to share


1 answer


The problem was resolved, it was a simple coding error, I needed to increase the mip level on each iteration, not decrease it.



float4 GetIndirection(float2 TexCoord)
{
    float4 indirection = tex2D(IndirectionSampler, TexCoord);

    for (half mip = indirection.b * 255; mip > 1 && indirection.a < 128; mip++)
    {
        indirection = tex2Dlod(IndirectionSampler, float4(TexCoord, 0, mip));
    }
    return indirection;
}

      

+2


source







All Articles