如何将数组从顶点着色器传递到片段着色器,在Metal

时间:2017-10-21 19:21:00

标签: metal

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

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]'

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

1 个答案:

答案 0 :(得分:4)

您需要“展开”数组:

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;
};
相关问题