Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass an array from the vertex shader to the fragment shader, in Metal

Tags:

metal

In GLSL, I would simply use out vec3 array[10];, to pass an array from the vertex shader to the fragment shader. In Metal, however, I thought to do it this way:

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

This produces the following error:

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

How can I solve this issue? I need to do certain calculations with per-vertex data that the fragment shader will use.

like image 737
Andreas detests censorship Avatar asked Mar 08 '23 18:03

Andreas detests censorship


1 Answers

You need to "unroll" the array:

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;
};
like image 67
Ken Thomases Avatar answered Apr 28 '23 21:04

Ken Thomases