Fields of Mistria — Vanilla GML Reference FoM v1.0.8

ShaderUtils.gml

#macro STENCIL_VALUE global.__stencil_value
STENCIL_VALUE = 0;

function gpu_reset_draw_kind() {
    gpu_set_draw_kind(DrawKind.Normal);
}

enum NodeDrawFlag {
    EMPTY = 0,
    PERFORMING_TRANSPARENCY = 1 << 0,
    PERFORMING_PREPASS = 1 << 1,
}

//
//
//
function blend_rgb32(lhs, rhs, amount) {
    var output = [0, 0, 0];

    for (var i = 0; i < 3; i++) {
        output[i] = lerp(lhs[i], rhs[i], amount);
    }

    return output;
}

//
//
//
function blend_rgba32(lhs, rhs, amount) {
    var output = [0, 0, 0, 0];

    for (var i = 0; i < 4; i++) {
        output[i] = lerp(lhs[i], rhs[i], amount);
    }

    return output;
}

function stencil_next() {
    return (STENCIL_VALUE + 1) % 256;
}

//
function stencil_increment() {
    var output = STENCIL_VALUE;
    STENCIL_VALUE += 1;

    if STENCIL_VALUE >= 256 {
        STENCIL_VALUE = 1;
        draw_clear_stencil(0);
    }

    return STENCIL_VALUE
}

//
//
//
function stencil_increment_no_clear() {
    STENCIL_VALUE = stencil_next();
    return STENCIL_VALUE;
}

//
//
//
//
function stencil_reserve_band(amount) {
    var output = STENCIL_VALUE;

    if (STENCIL_VALUE + amount) >= 255 {
        STENCIL_VALUE = 0;
        draw_clear_stencil(0);
    }

    //
    STENCIL_VALUE += amount;

    return STENCIL_VALUE
}