Potentially unintended use of a comma expression (Need help)

My shader knowledge is really limited and not having something like intellisense for shaders does make it really hard to fix stuff. I am getting the following error in a really simple “Grid” shader. Could someone with more knowledge than me point me in the right direction?

Shader Code (Warning at line 7):

    fixed4 frag (v2f i) : SV_Target
            {  
             
                fixed r = DrawGrid(i.uv , _GridSize, _GridThickness);
                fixed b = DrawGrid(i.uv, _Grid2Size, 0.005);
                fixed g = DrawGrid(i.uv, _Grid3Size, 0.002);
                fixed4 col = (_Grid1Color.r * _Grid1Color.a,_Grid1Color.g* _Grid1Color.a,_Grid1Color.b* _Grid1Color.a, (r+g+b)*_Grid1Color.a);
                clip(col.a - _Cutoff);
                return col;
                //return float4(_Grid1Color.r * _Grid1Color.a,_Grid1Color.g* _Grid1Color.a,_Grid1Color.b* _Grid1Color.a, (r+g+b)*_Grid1Color.a);
            }

I think all you need to do is to put “fixed4” immediately before the open bracket on line 7:

fixed 4 col = fixed4(_Grid1Color.r * ...);

See Operators - Win32 apps | Microsoft Learn for an explanation of the comma operator. Basically it only evaluates to the last value, which is not what you intend to do here.

1 Like

Thanks that fixed it and the explanation link really helped.