Completely red screen in Chapter 2 after changing to .point

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