What is the difference between screen space and canvas space?

Godot Version

V4.2

Question

There’s a few transformation matrices available in canvas item shaders. I’m trying to get my head around the different coordinate systems to make sure i’m comfortable with the foundational aspects of shaders.

I was wanting to see if I could figure out how to write a shader that would take a position (given in screen space) and convert it to world coordinates. The three matrices available are:

 * MODEL_MATRIX: Local space to world space transform. World space is the coordinates you normally use in the editor.
 * CANVAS_MATRIX: World space to canvas space transform. In canvas space the origin is the upper-left corner of the screen and coordinates ranging from (0, 0) to viewport size.
 * SCREEN_MATRIX: Canvas space to clip space. In clip space coordinates ranging from (-1, -1) to (1, 1).

I think I got it working using the inverse of the CANVAS_MATRIX, however that would be mapping from canvas space to world space, whereas the coordinate I was given (the LIGHT_POSITION builtin) was in screen space.

It appears to work, so my tentative conclusion is that screen space and canvas space are the same thing here, but this reasoning is really not all that solid.

Essential elements of the shader are replicated here:

shader_type canvas_item;

uniform vec4 sprite_position = vec4(0.0, 0.0, 0.0, 1.0); // specified in global (world) coordinates
varying mat4 canvas_matrix;

void vertex() {
    canvas_matrix = CANVAS_MATRIX; // World space to canvas space transform.
}

// Called for every pixel for every light affecting the CanvasItem.
void light() {
    // this is how I calculate the global (worldspace) position of the lightsource
    vec4 light_y_pos = inverse(canvas_matrix) * vec4(LIGHT_POSITION, 1.0);
    if (sprite_position.y > light_y_pos.y) {
        LIGHT = LIGHT_COLOR * LIGHT_ENERGY / clamp(abs(sprite_position.y - light_y_pos.y), 1.0, 3.0);
    } else {
        LIGHT = LIGHT_COLOR * LIGHT_ENERGY ;
    }
}