苹果又打破纹理投影了吗?
Did Apple break texture projection again?
在 iOS 8 中,Metal 中的浮点数划分存在问题,阻止了正确的纹理投影,。
今天发现iOS9的贴图投影又坏了,不知道是什么原因。
在 CPU(使用 OpenCV)和 GPU 上扭曲纹理的结果是不一样的。如果您 运行 this example app(已经包含 iOS 8 的修复),您可以在 iPhone 上看到 iOS 9.
预期 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;
}
不要问我为什么,但如果我将扭曲坐标乘以 1.00005
或任何接近 1.0
的数字,它就是固定的(除了非常小的细节)。请参阅示例应用程序存储库中的最后一次提交。
在 iOS 8 中,Metal 中的浮点数划分存在问题,阻止了正确的纹理投影,
今天发现iOS9的贴图投影又坏了,不知道是什么原因。
在 CPU(使用 OpenCV)和 GPU 上扭曲纹理的结果是不一样的。如果您 运行 this example app(已经包含 iOS 8 的修复),您可以在 iPhone 上看到 iOS 9.
预期 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;
}
不要问我为什么,但如果我将扭曲坐标乘以 1.00005
或任何接近 1.0
的数字,它就是固定的(除了非常小的细节)。请参阅示例应用程序存储库中的最后一次提交。