【问题标题】:no matching function for call to 'dot' and 'reflect'调用 'dot' 和 'reflect' 没有匹配的函数
【发布时间】:2019-01-28 18:10:33
【问题描述】:

我正在尝试运行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行的“no matching function for call to 'reflect'”

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。如果有人能解决我的问题,我将不胜感激。

谢谢

【问题讨论】:

  • 请逐字显示整个着色器编译器输出。您可能需要从构建日志中复制它。
  • @KenThomases 我更新了我的问题,谢谢

标签: ios swift shader arkit metal


【解决方案1】:

我认为出现此问题是因为 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);

并在每次调用中使用它,而不是直接传递结构成员。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 2021-09-21
    • 2016-11-23
    • 2016-08-08
    • 2014-03-12
    • 2015-03-17
    • 2018-08-04
    相关资源
    最近更新 更多