• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] Changing the color of lights

Tails1000

Member
I hit a hiccup in my lighting engine, as I can't figure out how to create different colored lights. I've tried several different blend modes with no luck. My goal is to create something that looks like this:



But right now I'm only able to make white light, not orange.
Here is a pic of my testing room (assets not mine obviously):



The top pic is using bm_subtract, while the bottom is using bm_add.
I'd ideally like to create an effect similar to Multiply in photoshop.
This is the code I'm working with right now:

Create:
Code:
light_surf = surface_create(room_width, room_height);
surface_set_target(light_surf);
draw_clear_alpha(c_white, 0);
surface_reset_target();
Step:
Code:
if !surface_exists(light_surf){
    light_surf = surface_create(room_width,room_height)
    surface_set_target(light_surf);
    draw_clear_alpha(c_white,0)
    surface_reset_target();
} else {
    surface_set_target(light_surf);
    
    //set the darkness
    draw_set_color(merge_color(c_black, c_navy, 0.1));    //color of the rectangle
    draw_set_alpha(0.85);                                //alpha of the rectangle
    draw_rectangle(0, 0, room_width, room_height, false);    //the rectangle
    
    //set the circles
    gpu_set_blendmode(bm_add);
    draw_set_alpha(0.1)
    
    //draw the circles
    with (obj_player4) {                                //circles for player
        draw_sprite_ext(spr_light, 0,                    //set sprite
                        x + random_range(-1, 1),
                        y + random_range(-1, 1),
                        2, 2, 0, c_white,                //size and color
                        0.8+random_range(-0.03,0.03));    //alpha
        draw_sprite_ext(spr_light, 0,
                        x + random_range(-1, 1),
                        y + random_range(-1, 1),
                        3, 3, 0, c_white,
                        .2+random_range(-0.03,0.03))   
    }
    with (obj_lamp) {
        draw_sprite_ext(spr_light, 0,
                        x + 15 +random_range(-1, 1),
                        y + 40+random_range(-1, 1),
                        1, 1, 0, c_orange,
                        0.8 +random_range(-0.1,0.1));
        draw_sprite_ext(spr_light, 0,
                        x + 15+random_range(-1, 1),
                        y + 40+random_range(-1, 1),
                        2, 2, 0, c_orange,
                        0.2+random_range(-0.05,0.05))   
                        
    }
    //reset draws
    gpu_set_blendmode(bm_normal);
    draw_set_alpha(1);
    surface_reset_target();
}
Draw:
Code:
if (!surface_exists(light_surf)){
    light_surf = surface_create(room_width,room_height);   
} else {
    if (view_current == 0) {
        draw_surface(light_surf, 0, 0)   
    }
}
I'm aware drawing a surface over the entire room isn't a good idea. Since this is just a test I'll work on correcting that later.

If anyone has any tips they would be much appreciated.
I feel like the solution is obvious, I just don't know it yet.
Of course ask me any more questions if it would help.
I am using Game Maker 2 by the way.
Thanks in advance for any help!
 

Tails1000

Member
I had seen that video before but was having difficulty making the room not pitch black. After tinkering with it more i figured it out. I'll explain it just in case someone else reading this needs help...

I modified my draw event to include:

Code:
gpu_set_blendmode_ext(bm_dest_color,bm_zero);
draw_surface(light_surf, 0, 0);
gpu_set_blendmode(bm_normal);
But that resulted in the night sky being way too dark. I wasn't able to figure out how to change the alpha, until I realized I could change my rectangle's color to gray instead of black for a similar effect. The more white the rectangle the more transparent it becomes...

Code:
draw_set_color(merge_color(merge_color(c_black,c_dkgray,0.5), c_navy, 0.1));
draw_set_alpha(0.85);
draw_rectangle(0, 0, room_width, room_height, false);
That color mix gave a nice dark sky while still being able to see. Overall I'm very happy with the effect now. It could still use some adjustments but the basic framework is there now. Thanks for the help!

 
Top