I was playing with applying dithering to a simple colored quad, and found a strange issue. I have a fragment shader which should calculate dithering at some uv
and return a dithered color. This works fine on a textured quad, but strangely enough, when I access color data from my inVertex
, the uv
coordinates change to some bizarre values, and y
value seems to be mapped to x
axis. I'll try to illustrate what happens when I change stuff around the fragment shader code.
fragment float4 fragment_colored_dithered(ColoredVertex inVertex [[stage_in]],
float2 uv[[point_coord]]) {
float4 color = inVertex.color;
uv = (uv/2) + 0.5;
if (uv.y < 0.67) {
return float4(uv.y, 0, 0, 1);
}
else {
return color;
}
}
Produces the following result:
Where the left side of the image shows my gradient quad, notice that if (uv.y < 0.67)
maps to x values in the image ????.
If I change this fragment shader and nothing else in the code, like so, where I return float4(0, 0, 1, 0)
instead of inVertex.color
, the uv
coordinates are mapped correctly.
fragment float4 fragment_colored_dithered(ColoredVertex inVertex [[stage_in]],
float2 uv[[point_coord]]) {
float4 color = inVertex.color;
uv = (uv/2) + 0.5;
if (uv.y < 0.67) {
return float4(uv.y, 0, 0, 1);
}
else {
return float4(0, 0, 1, 0); //return color;
}
}
Produces this (correct) result:
I think I can hack around this problem by applying a 1x1 texture to the gradient and using texture coordinates, but I'd really like to know what is happening here, is this a bug or a feature that I don't understand?