I am working along Chapter 12: Render Passes. Towards the end, when we pass the ID Texture
that is the result of rendering to a render pass with an r32Uint texture as color attachment 0, I see this fragment shader snippet that determines wether an object has been clicked by checking the ID against the .r
value encoded in the texture:
if (!is_null_texture(idTexture)) {
uint2 coord = uint2(params.touchX * 2, params.touchY * 2);
uint objectID = idTexture.read(coord).r;
if (params.objectId != 0 && objectID == params.objectId) {
material.baseColor = float3(0.9, 0.5, 0);
}
}
Can you please explain why do we need to upscale touchX
and touchY
by a factor of two? In fact, when running this in Xcode simulator on iPhone 14 Pro, these coordinates are wrong and I have to click a bit to the right of the object to actually select it:
Thanks as usual!