我想在 SCNView 上的 Swift Playgrounds 中使用带有金属着色器的 SCNTechnique。因此,我尝试使用以下代码编译我的着色器:
guard let metalDevice = sceneView.device else {
return
}
if let path = Bundle.main.path(forResource: "distortTechnique", ofType: "metal") {
do {
let contents = try String(contentsOf: URL(fileURLWithPath: path))
do {
try metalDevice.makeLibrary(source: contents, options: nil)
} catch { error
print(error)
}
} catch {
// contents could not be loaded
}
}
Run Code Online (Sandbox Code Playgroud)
该文件已加载,但出现以下编译器错误:
Error Domain=MTLLibraryErrorDomain Code=3 "Compilation failed:
program_source:11:10: fatal error: 'SceneKit/scn_metal' file not found
#include <SceneKit/scn_metal>
^
" UserInfo={NSLocalizedDescription=Compilation failed:
program_source:11:10: fatal error: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在AR SceneKit演示的后处理步骤中进行深度测试。为此,我需要渲染器ARSCNView的深度图。使用SCNTechnique似乎无法获得它。
尝试将DRAW_SCENE传递的深度用作SCNTechnique的DRAW_QUAD传递的输入时,我一直保持空白(充满1.0-s)深度缓冲区。我遵循了SCNTechnique上的指南,并命名了深度目标。这是SCNTechnique实施中的错误,还是我在配置中缺少某些内容?
颜色缓冲区已正确链接,并且https://github.com/lachlanhurst/SCNTechniqueTest/tree/pixelate中的示例适用。
这是技术列表:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>passes</key>
<dict>
<key>pixelate_scene</key>
<dict>
<key>draw</key>
<string>DRAW_SCENE</string>
<key>inputs</key>
<dict/>
<key>outputs</key>
<dict>
<key>color</key>
<string>color_scene</string>
<key>depth</key>
<string>depth_scene</string>
</dict>
<key>colorStates</key>
<dict>
<key>clear</key>
<true/>
<key>clearColor</key>
<string>sceneBackground</string>
</dict>
</dict>
<key>resample_pixelation</key>
<dict>
<key>draw</key>
<string>DRAW_QUAD</string>
<key>program</key>
<string>doesntexist</string>
<key>metalVertexShader</key>
<string>pixelate_pass_through_vertex</string>
<key>metalFragmentShader</key>
<string>pixelate_pass_through_fragment</string>
<key>inputs</key>
<dict>
<key>colorSampler</key>
<string>color_scene</string>
<key>depthSampler</key>
<string>depth_scene</string>
</dict>
<key>outputs</key>
<dict>
<key>color</key>
<string>COLOR</string>
</dict>
</dict>
</dict>
<key>sequence</key>
<array>
<string>pixelate_scene</string>
<string>resample_pixelation</string>
</array>
<key>targets</key>
<dict>
<key>color_scene</key>
<dict>
<key>type</key> …
Run Code Online (Sandbox Code Playgroud) 基本上,我想在一个立方体周围渲染一个轮廓。为此,我想我可以使用SCNTechnique
具有以下渲染通道的 :
问题是,模板中的文档SCNTechnique
非常稀少,我无法确切地知道如何使用它。
我已经通过首先在禁用深度测试的情况下绘制较大的“轮廓立方体”然后再绘制普通立方体来成功绘制轮廓,这效果很好,但是由于这种方法的其他复杂性,我想改用模板。
在尝试使用模板缓冲区使其工作时,我的第一遍stencilStates
看起来像(以及我认为我需要这些属性的原因):
clear = YES // To clear the buffer from last
enable = YES // To write to the buffer
behavior:
writeMask = 1 // Use bit 1
function = always // Always write to stencil regardless?
Run Code Online (Sandbox Code Playgroud)
第二遍的stencilStates
样子:
clear = NO // Keep the buffer from last step
enable = NO // Don't write to the buffer (only read?)
behavior:
readMask = 1 // Use bit …
Run Code Online (Sandbox Code Playgroud) 在 iOS 13(iOS 11 和 12)之前,SCNTechnique 应用于具有多通道设置的 ARSCNView,该设置首先应该将整个场景绘制到纹理中(通过 DRAW_SCENE)也会影响 ARKit 场景背景(相机源)。\n现在在 iOS 13 中,情况似乎不再如此。应用于生成的纹理的片段着色器不会更改相机输入\xe2\x80\x93,仅更改SceneKit 内容(例如节点)。当使用自定义场景背景(例如图像)时,一切都会按预期运行。仅使用 SCNView 时会得到相同的结果。
\n\n在 colorStates 中将clearColor 设置为 sceneBackground 没有帮助。\n我还尝试禁用环境纹理和人物遮挡。
\n\n有谁知道这个问题的解决方法?我希望过滤整个渲染的 ARKit 场景,以改变我的 AR 体验氛围。\n随附的是我的技术 plist 的屏幕截图。
\n\n谢谢你!
\n\n\n