【问题标题】:How to pass an array from the vertex shader to the fragment shader, in Metal如何在Metal中将数组从顶点着色器传递到片段着色器
【发布时间】:2018-04-02 16:31:55
【问题描述】:

在 GLSL 中,我会简单地使用 out vec3 array[10];,将数组从顶点着色器传递到片段着色器。然而,在 Metal 中,我想这样做:

struct FragmentIn {
    float4 position [[position]];
    float3 array[10];
};

这会产生以下错误:

Type 'FragmentIn' is not valid for attribute 'stage_in' because field 'array' has invalid type 'float3 [10]'

我该如何解决这个问题?我需要对片段着色器将使用的每个顶点数据进行某些计算。

【问题讨论】:

    标签: metal


    【解决方案1】:

    您需要“展开”数组:

    struct FragmentIn {
        float4 position [[position]];
        float3 thing0;
        float3 thing1;
        float3 thing2;
        float3 thing3;
        float3 thing4;
        float3 thing5;
        float3 thing6;
        float3 thing7;
        float3 thing8;
        float3 thing9;
    };
    

    【讨论】:

    • 没有别的办法了吗?
    猜你喜欢
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多