From ae292a88bd752822e0c0f6ed6fd6029e3fc64d0e Mon Sep 17 00:00:00 2001 From: Rhys Mainwaring Date: Wed, 1 Dec 2021 22:02:44 +0000 Subject: [PATCH] [Metal] update depth camera and selection buffer shaders to match #446 (#498) - Add new param colorTexResolution to the selection buffer shader - Implement the Metal equivalent of texelFetch in the shaders Signed-off-by: Rhys Mainwaring --- .../materials/programs/Metal/depth_camera_final_fs.metal | 7 ++++--- .../materials/programs/Metal/selection_buffer_fs.metal | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ogre2/src/media/materials/programs/Metal/depth_camera_final_fs.metal b/ogre2/src/media/materials/programs/Metal/depth_camera_final_fs.metal index 90454a833..8133f0872 100644 --- a/ogre2/src/media/materials/programs/Metal/depth_camera_final_fs.metal +++ b/ogre2/src/media/materials/programs/Metal/depth_camera_final_fs.metal @@ -49,9 +49,10 @@ fragment float4 main_metal // values close to 0 get rounded to 0) // // See https://github.com/ignitionrobotics/ign-rendering/issues/332 - // float4 p = texelFetch(inputTexture, int2(inPs.uv0 * params.texResolution.xy), 0); - // TODO - establish Metal equivalent - use standard sampler as interim approx. - float4 p = inputTexture.sample(inputSampler, inPs.uv0); + // Either: Metal equivalent of texelFetch + float4 p = inputTexture.read(uint2(inPs.uv0 * params.texResolution.xy), 0); + // Or: Use standard sampler + // float4 p = inputTexture.sample(inputSampler, inPs.uv0); float3 point = p.xyz; diff --git a/ogre2/src/media/materials/programs/Metal/selection_buffer_fs.metal b/ogre2/src/media/materials/programs/Metal/selection_buffer_fs.metal index 5620d1c12..28ce70f4b 100644 --- a/ogre2/src/media/materials/programs/Metal/selection_buffer_fs.metal +++ b/ogre2/src/media/materials/programs/Metal/selection_buffer_fs.metal @@ -29,6 +29,7 @@ struct Params float2 projectionParams; float far; float inf; + float4 colorTexResolution; }; float packFloat(float4 color) @@ -66,7 +67,11 @@ fragment float4 main_metal point = float3(p.inf); // color - float4 color = colorTexture.sample(colorSampler, inPs.uv0); + // Either: Metal equivalent of texelFetch + float4 color = colorTexture.read( + uint2(inPs.uv0 * p.colorTexResolution.xy), 0); + // Or: Use standard sampler + // float4 color = colorTexture.sample(colorSampler, inPs.uv0); float rgba = packFloat(color);