[[ stage_in ]] for Fragment Function

Hello Caroline, you told me what meaning is [[ stage_in ]] in Vertex Function. But In chapter 5, I can not find anything to need to match with VertexOut in fragment_main function. So would you please tell me information about [[ stage_in ]] in Fragment function table list?

Section 5.2.4 Input Assembly Attribute of Apple’s Metal Shading Language specification talks about the stage_in attribute.

In Chapter 5 Shaders.metal, you are sending each vertex from the vertex function through the rasterizer. This will make up triangles and work out which fragments to render and send them to the fragment function.

By using the stage_in attribute, the fragment shader can take in interpolated vertex information from each vertex.

So for example if you have a triangle vertex 0 with a color green property and vertex 1 as color red and vertex 2 as color blue, all fragments rendered in the triangle will have their colors interpolated between each of the vertices.

In our case, we’re not using colors, but we are using normals, so the world normals have to be interpolated between vertices for each fragment.