带有SceneKit SCNProgram的金属着色器 [英] Metal Shader with SceneKit SCNProgram

查看:94
本文介绍了带有SceneKit SCNProgram的金属着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在寻找可以在带有SCNProgram的SceneKit中工作的Metal着色器.

I'm looking for just a working Metal shader that works in SceneKit with SCNProgram.

有人可以告诉我正确的方法声明/如何进行连接吗?

Can someone show me the correct method declarations/how to hook this up?

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
}

我只是在寻找最基本的示例.

I'm just looking for the most basic example please.

推荐答案

我裁剪了所有不必要的"内容,这与它的基本知识和我的第一个Metal着色器差不多.

I clipped out all the 'unnecessary' stuff, this is about as basic as it gets and pretty much what my first Metal shader was.

接下来,我将开始研究连接其他顶点属性(颜色,法线),并可能进行一些基本的光照计算.

Next I'd start looking into wiring up the other vertex attributes (colour, normals), and maybe do some basic lighting calculations.

#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;
}

对任何错别字表示歉意,已在我的手机上对其进行了编辑...

Apologies for any typos, edited it down on my phone...

这篇关于带有SceneKit SCNProgram的金属着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆