Completely red screen in Chapter 2 after changing to .point

The starter code for chapter 2 works totally fine, but if I change .triangle to .point where instructed, I get some variation of this screen when I’m supposed to get a sphere that’s made of points:

I also tried this with my code from Chapter 1, and got the same result. I’m using Xcode 13 on macOS Monterey.

I have no idea how to fix this kind of bug this early in the book. What’s happening here?

Hi @makoren and welcome to the forum!

Unfortunately Apple changed the default size of a “point”.

In Chapter 2 playground, you can change the shader code to this:

let shader = """
#include <metal_stdlib>
using namespace metal;
struct VertexIn {
float4 position [[ attribute(0) ]];
};
struct VertexOut {
float4 position [[position]];
float pointSize [[point_size]];
};
vertex VertexOut vertex_main(const VertexIn vertex_in [[ stage_in ]]) {
VertexOut out {
.position = vertex_in.position,
.pointSize = 5
};
return out;
}
fragment float4 fragment_main() {
return float4(1, 0, 0, 1);
}
"""

Here, instead of just returning the vertex position from the vertex shader, you’re creating a structure VertexOut which holds both the position and the specified point size.

You’ll be creating structures very shortly to return from shaders. This is more common than just returning a float4 position.

At the beginning of learning Metal, you’ll probably get the feeling that you need to know something before you tackle something else, and you haven’t learned that something yet. There is a lot to get your head around in the beginning, but if you stick with it, you’ll find after a few chapters of repeating creating shaders and passing around vertices, that it all falls into place.

3 Likes

Thanks for pointing the solution, I hit the same issue.

1 Like