【发布时间】: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