Hello,
I’m faily new to shader coding, so this might just be something silly haha. Somehow one of my shader properties is causing some problem with an endlessly looping for-loop.
unable to unroll loop, loop does not appear to terminate in a timely manner (994 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number
for( int i = 0; i < _TextureWidth; i += 2 ) //_TextureWidth is 8, but it causes "unable to unroll loop" somehow
{
float4 curColor = tex2D( _ColorMap, float2(i / 8.0, 0.5 ));
float4 difference = c - curColor;
if( any(difference) != 0)
{
//c = fixed4( 0, 1, 0 , 1 );
}else
{
float4 replacementColor = tex2D( _ColorMap, float2( (i+1.0) / 8.0, 0.5 ) );
mappedColor = replacementColor;
//c.rgb = mappedColor.rgb;
c = mappedColor;
c.rgb *= c.a;
return c;
}
}
(sorry for the formatting, this always happends when I copy from monodevelop
)
Here are the settings on the material;

And here is the C# script just incase;
public void BuildTexture()
{
colorMap = new Texture2D( colorSwaps.Count * 2, 1, TextureFormat.ARGB32, false);
colorMap.filterMode = FilterMode.Point;
colorMap.mipMapBias = 0;
colorMap.anisoLevel = 0;
colorMap.wrapMode = TextureWrapMode.Clamp;
for( int i = 0; i < colorSwaps.Count; i++ )
{
colorMap.SetPixel( i * 2, 0, colorSwaps[i].originalColor );
colorMap.SetPixel( (i*2) + 1,0, colorSwaps[i].replaceMentColor);
}
colorMap.Apply();
if(spriteRenderer == null ) this.spriteRenderer = GetComponent<SpriteRenderer>();
if( materialProperties == null ) materialProperties = new MaterialPropertyBlock();
spriteRenderer.GetPropertyBlock( materialProperties );
materialProperties.SetTexture( "_ColorMap", colorMap );
materialProperties.SetFloat("_TextureWidth", colorMap.width);
spriteRenderer.SetPropertyBlock( materialProperties );
Debug.Log("BuildTexture");
}
when I change _TextureWidth to 8 the error resolves, but that makes me lose a lot of flexibility.
Any idea’s?


