Vulkan fragment shader if statements problem (SOLVED)

I couldn’t decide how to properly write a title for this post. Feel free to edit.

I have 3 uniforms on fragment shader for defining colors. They all set from .material and also by using go.set and colors(values) are correct(I tested them one by one).
This happens only on Vulkan, works with GL

uniform lowp vec4 color1;
uniform lowp vec4 color2;
uniform lowp vec4 color3;

When I try to assign those colors to vec3 using .rgb, values are not taken into account.

vec3 col = color1.rgb;  // <- This works
if (d_light > border.x)
{
    col = color2.rgb;                         // <- not working, no effect
    col = vec3(color2.r, color2.g color2.b); // <- not working, no effect
    col = vec3(0.9, 0.27, 0.22);              // <- This works
}
if (d_light > border.y)
{
    col = color3.rgb;                         // <- not working , no effect
    col = vec3(color3.x, color3.y, color3.z); // <- not working, no effect
    col = vec3(0.68, 0.18, 0.27);             // <- This works
}

[above code is just for giving you a info, I know last line overwrites the col. I tested them one by one]

If I use col = color2.rgb; or col = color3.rgb; then the result is always the col = color1.rgb; :

If I set the colors as vec3 like vec3(0.9, 0.27, 0.22);

Am I missing something related to Vulkan?

Not sure what’s going on to be honest.
Perhaps you can use Renderdoc to debug the uniforms, and see what’s going on?
I wonder if we for some reason doesn’t upload the uniforms correctly?

Sadly I’m on Mac. Maybe I can use xcode->instruments
I’m going to repo the case on a small project.

This is strange, I have RenderDoc 1.10 (unstable) installed on my mac, and I’ve used it before.
I just cannot find a download link for it :thinking:

Also this ugly thing is works too :hot_face:

vec3 col = color1.rgb;
vec3 col2 = color2.rgb;
vec3 col3 = color3.rgb;

if (d_light > border.x)
{
    col = col2;
}
if (d_light > border.y)
{
    col = col3; 
}

gl_FragColor = vec4(col, 1.0);

I figure that out. Looks like SPIR-V doesn’t like this terrible if condition.

if (d_light > border.x)
{
    col = color2.rgb;
}
if (d_light > border.y)
{
    col = color3.rgb; 
}

Works like this, but still a ugly solution:

if (d_light > border.x && d_light < border.y)
{
    col = color2.rgb;     
}
 if (d_light > border.y)
{
    col = color3.rgb;  
}

RenderDoc developer gave-up on MacOS

Unfortunately after doing the initial prototyping work on mac the platform proved just too unfriendly/unpleasant to develop for - especially on GL - so I dropped plans to work on it myself.
Mac Vulkan & GL support tracking issue · Issue #1272 · baldurk/renderdoc · GitHub

I change those if..else conditions to mix, if anyone has a better suggestion please share:

const lowp vec3 clear = vec3(0.0, 0.0, 0.0);
const lowp vec3 c = clear;

c += mix(clear, color3.rgb, float(d_light > border.y));
c += mix(clear, color2.rgb, float(d_light > border.x && d_light < border.y));
c += mix(clear, color1.rgb, float(d_light < border.x));

And final, thanks to @rsaienz

const lowp vec3 c = color3.rgb * float(d_light >= border.y) + color2.rgb * float(d_light >= border.x && d_light < border.y) + color1.rgb * float(d_light < border.x);