我可以将sampler2D类型的自定义参数传递给SCNTechnique的Metal fragment function,并且我有第二次工作:
PList:
<key>inputs</key>
<dict>
<key>imageFromPass1</key>
<string>COLOR</string>
<key>myCustomImage</key>
<string>myCustomImage_sym</string>
</dict>..。
<key>symbols</key>
<dict>
<key>myCustomImage_sym</key>
<dict>
<key>type</key>
<string>sampler2D</string>
</dict>
</dict>相关的Obj-C代码:
[technique setValue: UIImagePNGRepresentation(myCustomTexture) forKey:@"myCustomImage_sym"];金属功能参数:
fragment half4 myFS(out_vertex_t vert [[stage_in]],
texture2d<float, access::sample> imageFromPass1 [[texture(0)]],
texture2d<float, access::sample> myCustomImage [[texture(1)]],
constant SCNSceneBuffer& scn_frame [[buffer(0)]]) { ...我在着色器函数中访问和使用所有这些输入。它起作用了!
到目前一切尚好!
但是,当我添加另一个类型为float的自定义参数时.
<key>blob_pos</key>
<string>blob_pos_sym</string>..。
<key>blob_pos_sym</key>
<dict>
<key>type</key>
<string>float</string>
</dict>[_sceneView.technique setValue:[NSNumber numberWithFloat:0.5f] forKey:@"blob_pos_sym"]; constant float& blob_pos [[buffer(2)]]..。传递的值永远不会到达着色函数。
我试过了
..。但都失败了。
然后我看着handleBindingOfSymbol:usingBlock: ..。但它只是GLSL。
我发现是金属对口,handleBindingOfBufferNamed:frequency:usingBlock: .这在SCNTechnique中是不可用的。
我搜索了SCNTechnique金属 ..。并实现了所有的项目只使用sampler2D参数。
最后,我了解到这不是新的,而是多年来的bug开发人员。
在我去编码这个浮动在一个纹理,让我知道丢失的位,使它的工作方式。
发布于 2018-08-09 07:50:23
您必须使用结构来包装输入符号,并确保使用[SCNTechnique setObject:forKeyedSubscript:]将符号值传递给您的技术。setObject:forKeyedSubscript:的文档提到了金属,但是它没有解释如何在金属函数中接收值,这是不幸的。
使用您的例子:
技术定义:
"inputs": [
"imageFromPass1": "COLOR",
"myCustomImage": "myCustomImage_sym",
"blob_pos": "blob_pos_sym",
],
...
"symbols": [
"myCustomImage_sym": ["type": "sampler2D"],
"blob_pos_sym": ["type": "float"]
]Obj-C:
[_sceneView.technique setObject:[NSNumber numberWithFloat:0.5f] forKeyedSubscript:@"blob_pos_sym"];金属:
typedef struct {
float blob_pos; // Must be spelled exactly the same as in inputs dictionary.
} Inputs;
fragment half4 myFS(out_vertex_t vert [[stage_in]],
texture2d<float, access::sample> imageFromPass1 [[texture(0)]],
texture2d<float, access::sample> myCustomImage [[texture(1)]],
constant Inputs& myInputs [[buffer(0)]]) {
float blob_pos = myInputs.blob_pos;
...https://stackoverflow.com/questions/50990241
复制相似问题