如何将数组从顶点着色器传递给片段着色器,在Metal中
问题描述:
在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]'
我怎样才能解决这个问题呢?我需要对片段着色器将使用的每个顶点数据进行一定的计算。
答
你需要 “展开” 阵列:
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;
};