Hi, something strange is happening that I don't understand. This is the code for my shader that does a guassian blur:
void main( in PS_Input i, out PS_Output o )
{
float4 TotalColour = 0;
float texelSize = float( 1.0f / TexWidth );
TotalColour += tex2D( Tex0, float2( i.TexCoord0.x, i.TexCoord0.y ) ) * ( KernelSize+1.0f ) / (100.0f/KernelSize);
int limit = KernelSize;
// Loop as many times as there are kernels
for( int p=1; p <= KernelSize; p++ )
{
TotalColour += tex2D( Tex0, float2( i.TexCoord0.x - ( p*texelSize ), i.TexCoord0.y) ) * (KernelSize+1 -p) / (100.0f/KernelSize);
TotalColour += tex2D( Tex0, float2( i.TexCoord0.x + ( p*texelSize ), i.TexCoord0.y) ) * (KernelSize+1 -p) / (100.0f/KernelSize);
}
o.Colour.rgba = TotalColour;
o.Colour.a = 0.3f;
}
When I try to compile I am getting an error and subsequent warning:
warning X3553: Can't use gradient instructions in loops with break, forcing loop to unroll
error X3511: Unable to unroll loop, loop does not appear to terminate in a timely manner (1024 iterations)
However, if I change the loop parameter to an integer rather than the KernelSize constant it runs and works perfectly. This is the code with that one change:
void main( in PS_Input i, out PS_Output o )
{
float4 TotalColour = 0;
float texelSize = float( 1.0f / TexWidth );
TotalColour += tex2D( Tex0, float2( i.TexCoord0.x, i.TexCoord0.y ) ) * ( KernelSize+1.0f ) / (100.0f/KernelSize);
int limit = KernelSize;
// Loop as many times as there are kernels
for( int p=1; p <= 5; p++ )
{
TotalColour += tex2D( Tex0, float2( i.TexCoord0.x - ( p*texelSize ), i.TexCoord0.y) ) * (KernelSize+1 -p) / (100.0f/KernelSize);
TotalColour += tex2D( Tex0, float2( i.TexCoord0.x + ( p*texelSize ), i.TexCoord0.y) ) * (KernelSize+1 -p) / (100.0f/KernelSize);
}
o.Colour.rgba = TotalColour;
o.Colour.a = 0.3f;
}
That is the only thing that is stopping the shader from working correctly, and without that, I can't have any sort of flexibility with the shader.
Anybody any ideas why this is happening?