Search Unity

Blur Build error

Discussion in 'Shaders' started by GustavNinja, Sep 26, 2016.

  1. GustavNinja

    GustavNinja

    Joined:
    Jun 13, 2016
    Posts:
    96
    Hi, I have a shader error that might sometimes leave the game in a white screen. I have tried to fix it but I only seem to create more errors.

    The error occurs on the for loop for me.

    Shader error in 'DSS/UI/Blur': unable to unroll loop, loop does not appear to terminate in a timely manner (721 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number at line 131 (on d3d9)
    Shader error in 'DSS/UI/Blur': unable to unroll loop, loop does not appear to terminate in a timely manner (45 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number at line 131 (on d3d11_9x)

    Code (CSharp):
    1.  
    2. float2 pix = float2( 1 / _TexWidth, 1 / _TexHeight );
    3.  
    4. color = ((tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color) / _Fineness;
    5. //    #if SHADER_API_D3D9 || SHADER_API_D3D11_9X
    6. //    [unroll(45)]
    7. //    #endif
    8. for ( int i = 0; i < _Fineness; ++i )
    9. {
    10.      half4 fcol = float4(0, 0, 0, 0);
    11.      col += ((tex2D(_MainTex, IN.texcoord + float2(pix.x * i, 0)) + _TextureSampleAdd) * IN.color) * 0.125;
    12.      fcol += ((tex2D(_MainTex, IN.texcoord + float2(pix.x * -i, 0)) + _TextureSampleAdd) * IN.color) * 0.125;
    13.      fcol += ((tex2D(_MainTex, IN.texcoord + float2(0, pix.y * i)) + _TextureSampleAdd) * IN.color) * 0.125;
    14.      col += ((tex2D(_MainTex, IN.texcoord + float2(0, pix.y * -i)) + _TextureSampleAdd) * IN.color) * 0.125;
    15.      fcol += ((tex2D(_MainTex, IN.texcoord + float2(pix.x * i, pix.y * i)) + _TextureSampleAdd) * IN.color) * 0.125;
    16.      fcol += ((tex2D(_MainTex, IN.texcoord + float2(pix.x * -i, pix.y * i)) + _TextureSampleAdd) * IN.color) * 0.125;
    17.      fcol += ((tex2D(_MainTex, IN.texcoord + float2(pix.x * i, pix.y * -i)) + _TextureSampleAdd) * IN.color) * 0.125;
    18.      fcol += ((tex2D(_MainTex, IN.texcoord + float2(pix.x * -i, pix.y * -i)) + _TextureSampleAdd) * IN.color) * 0.125;
    19.      color += fcol / _Fineness;[/INDENT]
    20. }
    21.              
    22. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
    23.  
    I tried adding the unroll but that seemed to create other problems. Hopefully someone have had a similar problem and can help me out. Cheers all.