简体   繁体   English

ARKit,用于ARSCNView的金属着色器

[英]ARKit, metal shader for ARSCNView

Trying to figure out how to solve my issue of applying shaders to my ARSCNView. 试图弄清楚如何解决我的着色器应用到我的ARSCNView的问题。 Previously, when using a standard SCNView, i have successfully been able to apply a distortion shader the following way: 以前,当使用标准SCNView时,我已成功地通过以下方式应用失真着色器:

if let path = Bundle.main.path(forResource: "art.scnassets/distortion", ofType: "plist") {
    if let dict = NSDictionary(contentsOfFile: path)  {
        let technique = SCNTechnique(dictionary: dict as! [String : AnyObject])

        scnView.technique = technique
    }
}

Replacing SCNView with ARSCNView gives me the following error(s): 用ARSCNView替换SCNView会给我以下错误:

"Error: Metal renderer does not support nil vertex function name" “错误:金属渲染器不支持nil顶点函数名称”

"Error: _executeProgram - no pipeline state" “错误:_executeProgram - 没有管道状态”

I was thinking it's because that ARSCNView uses a different renderer than SCNView. 我在想它是因为ARSCNView使用与SCNView不同的渲染器。 But logging ARSCNView.renderingAPI tells me nothing about the renderer, and i can't seem to choose one when i construct my ARSCNView instance. 但是记录ARSCNView.renderingAPI告诉我关于渲染器的任何信息,当我构建我的ARSCNView实例时,我似乎无法选择一个。 I must be missing something obvious, because i can't seem to find a single resource when scouring for references online. 我必须遗漏一些明显的东西,因为我在网上搜索参考资料时似乎无法找到单一资源。

My initial idea was instead use a SCNProgram to apply the shaders. 我最初的想法是使用SCNProgram来应用着色器。 But i can't find any resources of how to apply it to an ARSCNView, or if it's even a correct/possible solution, SCNProgram seems to be reserved for materials. 但我找不到任何有关如何将其应用于ARSCNView的资源,或者如果它甚至是正确/可能的解决方案,SCNProgram似乎是为材料保留的。

Anyone able to give me any useful pointers of how to solve vertex+fragment shaders for ARSCNView? 有谁能给我任何有用的指针,如何解决ARSCNView的顶点+片段着色器?

SCNTechnique for ARSCNView does not work with GLSL shaders, instead Metal functions need to be provided in the technique's plist file under the keys metalVertexShader and metalFragmentShader . SCNTechniqueARSCNView不GLSL着色器的工作,而是需要在技术的plist文件键下方设置金属功能metalVertexShadermetalFragmentShader

To the contrary, documentation says any combination of shader should work: 相反, 文档说明着色器的任何组合应该工作:

You must specify both fragment and vertex shaders, and you must specify either a GLSL shader program, a pair of Metal functions, or both. 您必须同时指定片段和顶点着色器,并且必须指定GLSL着色器程序,一对Metal函数或两者。 If both are specified, SceneKit uses whichever shader is appropriate for the current renderer. 如果同时指定了两者,则SceneKit将使用适合当前渲染器的任何着色器。

So it might be a mistake, but I guess the documentation is outdated. 所以这可能是一个错误,但我想文档已经过时了。 Since all ARKit running devices also run Metal, GLSL support has not been added to ARSCNViews. 由于所有ARKit运行设备也运行Metal,因此尚未向ARSCNViews添加GLSL支持。 As iOS12 deprecates OpenGL this looks like planned. 由于iOS12对OpenGL不赞成,这看起来像是计划好的。

I had this issue in ARKit iOS11.4 and 12 and it came down to a series of miss-spelt shaders. 我在ARKit iOS11.4和12中遇到过这个问题,它归结为一系列拼错的着色器。 I hope this might help someone. 我希望这可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM