【问题标题】:Pass MTLTexture to SCNProgram with metal vertex and fragment shaders使用金属顶点和片段着色器将 MTLTexture 传递给 SCNProgram
【发布时间】:2016-11-13 17:23:21
【问题描述】:

我有一组图像,我必须根据顶点随机选择一个图像,使用金属我可以实现这个 MTLTexture2DArray。

但我使用的是 SceneKit 和自定义 SCNProgram,问题是我无法将 MTLTexture 传递给 Metal 片段函数。

如果我将图像设置为 SCNMaterial 它可以工作,如果我设置金属纹理它会抛出异常。

let material = SCNMaterial()
material.program = program
material.setValue(metalTexture, forKey: "customTexture")

问题和这个问题完全一样 Passing Metal texture2d_array to SceneKit shader modifier

但它使用着色器修改器,这里我使用自定义着色器。

是否可以将金属的 texture2d 数组传递给自定义 SCNProgram,或者是否有另一种方法可以将图像数组传递给 SCNProgram 中的着色器函数?

【问题讨论】:

    标签: ios swift scenekit metal


    【解决方案1】:

    将金属纹理包裹在SCNMaterialProperty 对象中会起作用。

    let imageProperty = SCNMaterialProperty(contents: metalTexture)
    material.setValue(imageProperty, forKey: "customTexture")
    

    【讨论】:

    • 非常有用,也适用于立方体贴图纹理
    猜你喜欢
    • 2014-11-02
    • 2015-11-20
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多