
uniform sampler2D u_placement_map;

in vec3 v_position;
in vec2 v_lookup;
in vec3 v_fragpos;

layout (location = 0) out vec3 frag_color;
layout (location = 1) out vec3 g_normal;
layout (location = 2) out vec3 g_position;

void main() {
    vec3 col = SELECTION_VALID;
    if (texture(u_placement_map, v_lookup).r > 0.5) {
        col = SELECTION_INVALID;
    }
    vec2 grid = abs(mod(v_position.xz, 0.25) - 0.125) / 0.125;
    if (grid.x > 0.85 || grid.y > 0.85) {
        if (v_lookup.x > -0.5) {
            col *= 0.5;
        } else {
            col = vec3(0.18, 0.447, 0.255);
        }
    } else if (v_lookup.x < -0.5) {
        discard;
    }
    frag_color = col;
    g_normal = vec3(0.0, 1.0, 0.0) * 0.5 + 0.5;
    g_position = v_fragpos;
}
