【问题标题】:Did Apple break texture projection again?苹果又打破纹理投影了吗?
【发布时间】:2015-12-21 10:17:24
【问题描述】:

在 iOS 8 中,Metal 中的浮动分割存在问题,无法正确投影纹理,which I solved

今天发现iOS 9上的纹理投影又坏了,虽然不知道是什么原因。

在 CPU(使用 OpenCV)和 GPU 上扭曲纹理的结果不一样。如果您从 iOS 9 运行 this example app(已经包含 iOS 8 的修复程序),您可以在 iPhone 上看到。

预期的 CPU 扭曲是红色的,而由 Metal 完成的 GPU 扭曲是绿色的,所以它们重叠的地方是黄色的。理想情况下,您不应看到绿色或红色,而只能看到黄色阴影。

你能:

  • 确认您的问题存在;
  • 对任何可能出错的地方提供任何建议?

着色器代码为:

struct VertexInOut
{
  float4 position [[ position ]];
  float3 warpedTexCoords;
  float3 originalTexCoords;
};

vertex VertexInOut warpVertex(uint vid [[ vertex_id ]],
                              device float4 *positions [[ buffer(0) ]],
                              device float3 *texCoords [[ buffer(1) ]])
{
  VertexInOut v;
  v.position = positions[vid];

  // example homography
  simd::float3x3 h = {
    {1.03140473, 0.0778113901, 0.000169219566},
    {0.0342947133, 1.06025684, 0.000459250761},
    {-0.0364957005, -38.3375587, 0.818259298}
  };

  v.warpedTexCoords = h * texCoords[vid];
  v.originalTexCoords = texCoords[vid];

  return v;
}

fragment half4 warpFragment(VertexInOut inFrag [[ stage_in ]],
                            texture2d<half, access::sample> original [[ texture(0) ]],
                            texture2d<half, access::sample> cpuWarped [[ texture(1) ]])
{
  constexpr sampler s(coord::pixel, filter::linear, address::clamp_to_zero);
  half4 gpuWarpedPixel = half4(original.sample(s, inFrag.warpedTexCoords.xy * (1.0 / inFrag.warpedTexCoords.z)).r, 0, 0, 255);
  half4 cpuWarpedPixel = half4(0, cpuWarped.sample(s, inFrag.originalTexCoords.xy).r, 0, 255);

  return (gpuWarpedPixel + cpuWarpedPixel) * 0.5;
}

【问题讨论】:

    标签: ios 3d texture-mapping metal


    【解决方案1】:

    不要问我为什么,但是如果我将扭曲的坐标乘以1.00005 或任何接近1.0 的数字,它就会被修复(除了非常微小的细节)。请参阅示例应用程序仓库中的最后一次提交。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-19
      • 2017-12-21
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2016-01-04
      • 2019-11-23
      • 1970-01-01
      相关资源
      最近更新 更多