我正在寻找一个可以在 SceneKit 和 SCNProgram 中工作的金属着色器。
有人可以告诉我正确的方法声明/如何连接它吗?
let program = SCNProgram()
program.vertexFunctionName = "myVertex"
program.fragmentFunctionName = "myFragment"
material.program = program
然后是着色器
//MyShader.metal
vertex something myVertex(something)
{
return something;
}
fragment float4 myFragment(something)
{
return something
}
我只是在寻找最基本的例子。
我剪掉了所有“不必要”的东西,这就是它所得到的最基本的东西,几乎就是我的第一个金属着色器。
接下来,我将开始研究连接其他顶点属性(颜色、法线),并可能进行一些基本的光照计算。
#include <metal_stdlib>
using namespace metal;
#include <SceneKit/scn_metal>
struct MyNodeBuffer {
float4x4 modelTransform;
float4x4 modelViewTransform;
float4x4 normalTransform;
float4x4 modelViewProjectionTransform;
};
typedef struct {
float3 position [[ attribute(SCNVertexSemanticPosition) ]];
} MyVertexInput;
struct SimpleVertex
{
float4 position [[position]];
};
vertex SimpleVertex myVertex(MyVertexInput in [[ stage_in ]],
constant SCNSceneBuffer& scn_frame [[buffer(0)]],
constant MyNodeBuffer& scn_node [[buffer(1)]])
{
SimpleVertex vert;
vert.position = scn_node.modelViewProjectionTransform * float4(in.position, 1.0);
return vert;
}
fragment half4 myFragment(SimpleVertex in [[stage_in]])
{
half4 color;
color = half4(1.0 ,0.0 ,0.0, 1.0);
return color;
}
抱歉,有错别字,用手机编辑了一下……
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)