Deltarune (Chapter 3) script viewer

← back to main script listing

gml_GlobalScript_scr_chromakey

(view raw script w/o annotations or w/e)
1
global.__shd_chromakey_u_key_color = shader_get_uniform(shd_chromakey, "key_color");
2
global.__shd_chromakey_u_similarity = shader_get_uniform(shd_chromakey, "similarity");
3
global.__chromakey_surface = -1;
4
global.__chromakey_mask_surface = -1;
5
6
function surface_check(arg0, arg1, arg2)
7
{
8
    if (!surface_exists(arg0))
9
    {
10
        return surface_create(arg1, arg2);
11
    }
12
    else if (surface_get_width(arg0) != arg1 || surface_get_height(arg0) != arg2)
13
    {
14
        surface_resize(arg0, arg1, arg2);
15
        return arg0;
16
    }
17
    return arg0;
18
}
19
20
function chromakey_mask_begin(arg0, arg1 = 0)
21
{
22
    global.__chromakey_mask_surface = surface_check(global.__chromakey_mask_surface, room_width, room_height);
23
    surface_set_target(global.__chromakey_mask_surface);
24
    draw_clear_alpha(c_black, 0);
25
    gpu_set_blendmode_ext_sepalpha(bm_src_alpha, bm_inv_src_alpha, bm_one, bm_inv_src_alpha);
26
    shader_set(shd_chromakey);
27
    shader_set_uniform_f(global.__shd_chromakey_u_key_color, color_get_red(arg0) / 255, color_get_green(arg0) / 255, color_get_blue(arg0) / 255);
28
    shader_set_uniform_f(global.__shd_chromakey_u_similarity, arg1);
29
}
30
31
function chromakey_mask_end()
32
{
33
    shader_reset();
34
    surface_reset_target();
35
}
36
37
function chromakey_on()
38
{
39
    global.__chromakey_surface = surface_check(global.__chromakey_surface, room_width, room_height);
40
    surface_set_target(global.__chromakey_surface);
41
    draw_clear_alpha(c_black, 0);
42
    gpu_set_blendmode_ext_sepalpha(bm_src_alpha, bm_inv_src_alpha, bm_one, bm_inv_src_alpha);
43
}
44
45
function chromakey_off()
46
{
47
    gpu_set_blendenable(false);
48
    gpu_set_colorwriteenable(0, 0, 0, 1);
49
    draw_surface(global.__chromakey_mask_surface, 0, 0);
50
    gpu_set_blendenable(true);
51
    gpu_set_colorwriteenable(1, 1, 1, 1);
52
    surface_reset_target();
53
    gpu_set_blendmode(bm_normal);
54
    draw_surface(global.__chromakey_surface, 0, 0);
55
}