我正在尝试运行 this GitHub repository 中可用的 ARBrush iOS ARKit 应用程序.这是一个非常酷的 3D 绘图应用程序!不幸的是,我收到 2 个错误。我不知道为什么会出现这些错误以及如何解决这些错误。 第一个错误是 shaders.metal 中第 104 行的“no matching function for call to 'dot'”:
float diffuseFactor = max(0.0,dot(interpolated.normal, light.direction)); // 1
第二个是同一文件 (shaders.metal) 的第 109 行中的“没有匹配函数调用‘反射’”
float3 reflection = reflect(light.direction, interpolated.normal); // 2
下面是我完整的错误报告
CompileMetalFile /Users/Myname/Documents/Xcode/ARBrush/ARBrush/Shaders.metal (in target: ARBrush)
cd /Users/Myname/Documents/Xcode/ARBrush
export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/metal -arch air64 -emit-llvm -c -gline-tables-only -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk -ffast-math -serialize-diagnostics /Users/Myname/Library/Developer/Xcode/DerivedData/ARBrush-amgfmkvulxeadccjphanytgyilwe/Build/Intermediates.noindex/ARBrush.build/Debug-iphoneos/ARBrush.build/Metal/Shaders.dia -o /Users/Myname/Library/Developer/Xcode/DerivedData/ARBrush-amgfmkvulxeadccjphanytgyilwe/Build/Intermediates.noindex/ARBrush.build/Debug-iphoneos/ARBrush.build/Metal/Shaders.air -mios-version-min=11.0 "" -MMD -MT dependencies -MF /Users/Myname/Library/Developer/Xcode/DerivedData/ARBrush-amgfmkvulxeadccjphanytgyilwe/Build/Intermediates.noindex/ARBrush.build/Debug-iphoneos/ARBrush.build/Metal/Shaders.dat /Users/Myname/Documents/Xcode/ARBrush/ARBrush/Shaders.metal
/Users/Myname/Documents/Xcode/ARBrush/ARBrush/Shaders.metal:104:35: error: no matching function for call to 'dot'
float diffuseFactor = max(0.0,dot(interpolated.normal, light.direction)); // 1
^~~
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/lib/clang/902.1/include/metal/metal_geometric:171:30: note: candidate template ignored: requirement '_geometric_binary_func_enable<float __attribute__((ext_vector_type(3))), float __attribute__((packed_vector_type(3)))>::value' was not satisfied [with T = float __attribute__((ext_vector_type(3))), U = float __attribute__((packed_vector_type(3)))]
METAL_FUNC make_scalar_t<_O> dot(T x, U y)
^
/Users/Myname/Documents/Xcode/ARBrush/ARBrush/Shaders.metal:109:25: error: no matching function for call to 'reflect'
float3 reflection = reflect(light.direction, interpolated.normal); // 2
^~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/lib/clang/902.1/include/metal/metal_geometric:354:15: note: candidate template ignored: requirement '_geometric_binary_func_enable<float __attribute__((packed_vector_type(3))), float __attribute__((ext_vector_type(3)))>::value' was not satisfied [with T = float __attribute__((packed_vector_type(3))), U = float __attribute__((ext_vector_type(3)))]
METAL_FUNC _O reflect(T i, U n)
^
2 errors generated.
我在 Xcode 10.1 上使用 swift 4 运行这个应用程序,我的开发目标是 iOS 11。如果有人能解决我的问题,我将非常感激。
谢谢
最佳答案
我认为出现此问题是因为 Metal 标准库中的函数不接受打包 向量类型。您应该能够在调用站点通过内联类型转换来解决此问题:
float diffuseFactor = max(0.0,dot(interpolated.normal, float3(light.direction))); // 1
float3 reflection = reflect(float3(light.direction), interpolated.normal); // 2
或者简单地创建一个非压缩类型的局部变量
float3 lightDir(light.direction);
并在每次调用中使用它而不是直接传递结构成员。
关于ios - 没有匹配函数调用 'dot' 和 'reflect',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54407927/