- Home /
Question by
Andy-Xiaohuo · Aug 12, 2016 at 09:42 AM ·
shadershader programmingcg
why can a array that must be declared by 'static' be read correctly
Hi guys! I'm writing a blur shader for my game. like this
float samples[6] = { -0.05, -0.03, -0.01, 0.01, 0.03, 0.05, };
half4 frag (v2f i) : SV_Target
{
float2 dir = float2(0.5, 0.5) - i.texcoord;
float2 texcoord = i.texcoord;
float dist = length(dir);
dir = normalize(dir);
float4 color = tex2D(_MainTex, texcoord);
float4 sum= color;
for (int i = 0; i < 6; ++i)
{
sum+= tex2D(_MainTex, texcoord+dir * samples[i] * _fSampleDist);
}
sum/= 7.0;
float t = saturate(dist * _fSampleStrength);
return lerp(color, sum, t);
}
but I found it didn't work,which took me around a whole day to find the problem.
at the end. I found the array 'samples' in my shader file cound't be read correctly.
once I declare it with 'static', it works well.
I don't know why.
so genius, could you tell me why I must declare that array with 'static'?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612090655im_/https://answers.unity.com/themes/thub/images/avi.jpg)