I am writing a 3D app using Metal. For rendering in 3D I need to control each pixel. In normal screens this seems to be working ok with the [[position]] variable passed to the shader. But in Retina display, where there is a scaling factor, each screen-coordinate represent 2x2 (or 3x3) pixels.
Let me elaborate with iPhone 6 screen as example: screen-coordinates is 375x667 and pixel-coordinates is 750x1334. Here is my (test) shader code:
fragment half4 myFragShader(vtxOut in [[stage_in]],
float4 pcoord [[position]])
{
if(pcoord.x >187.5) //187.5=375/2
return half4(1.0 , 0.0 , 0.0, 1.0); // return red
else return half4(0.0 , 0.0 , 1.0, 1.0); // return blue
}
With the above test code, I am getting (exactly) left half of the screen as blue and right half as red. This means the pcoord is coming in the coordinates system 375x667, not in 750x1334.
Questions:
Will the fragment shader be called for every pixel-coordinate? Or only for every screen-coordinate?
If it gets called for every pixel-coordinate, how do I access each pixel inside the fragment shader?
I tried the same with the pcoord.y (in my code above) with similar result.