Don't Forget Point Size cover image

Don't Forget Point Size

David Kanenwisher • November 17, 2022

swift

I ran into some trouble when I didn't specify the point_size in the output from the vertex function.

a white screen with a red point flickering across it

It took me quite a bit of head scratching to figure out what was going on. It lead me to the Metal Shading Language Specification where I found that all of the possible values are predefined.

After seeing position in there it makes the interpolation in the fragment function make more sense. I had been trying to figure out how the fragment function knows which attribute of the input is the value to interpolate. Clearly, with position being part of the specification it simply knows.

After updating the shader with the point it works as expected.

VertexOut vertex_out {
    .position = transform * float4(v.position, 1),
    .point_size = 20.0
};

a white screen with a red point in the middle

Fascinating!