GML Any idea how this kind of lighting is made?

M

maratae

Guest
So how the heck did these guys make this kind of lighting?
Is this shaders? Or is this color subtraction? Something else?
I can manage something like this on a image editing program with indexed colours and subtracting layers, but can't get my head arround how something like this would be written.
In my head it goes something like having 4 layers and each one is subtracting colors from the ones bellow, but I've been thinking about this for a while now and I still have no concrete idea on how to do something like this ingame.
Any thoughts?
 

Jaqueta

Member
Maybe this can be achieved a simple lighting system, combined with a shader that "rounds" the "lighting" values of the pixels.

EDIT: The word for that is called Posterization.
 
Last edited:

Neptune

Member
I do something similar and a bit more complex using shaders in my current project -- however this can be done using 1 surface, and a "light" object.
if !surface_exists(dark_surface)
{
var width = surface_get_width(application_surface);
var height = surface_get_height(application_surface);
dark_surface = surface_create(width,height);
}

surface_set_target(dark_surface);
draw_clear(c_black);

//Torch
with(o_torch)
{
gpu_set_blendmode(bm_src_color);
draw_sprite_ext(s_torch_glow,torch_index,x-camera_get_view_x(view_camera[0]),y-camera_get_view_y(view_camera[0]),glow_size,glow_size,0,c_white,1);
gpu_set_blendmode(bm_normal);
}

surface_reset_target();
draw_surface_ext(dark_surface,camera_get_view_x(view_camera[0]),camera_get_view_y(view_camera[0]),1,1,0,c_white,alpha);

Essentially that code just plasters a surface that is flushed black over the visible screen (you can set the surface's alpha for varying darkness), and then the torch objects just reverse the darkness based on their alpha (you'll need a simple light sprite, like a circle with feathered edges).

NOTE: If you're not using GMS2, the terminology is probably slightly different for setting the blend mode.

And lastly, this effect is super dope for the amount of code it takes :D
Hope that helps!
 
Last edited:
M

maratae

Guest
I do something similar and a bit more complex using shaders in my current project -- however this can be done using 1 surface, and a "light" object.
if !surface_exists(dark_surface)
{
var width = surface_get_width(application_surface);
var height = surface_get_height(application_surface);
dark_surface = surface_create(width,height);
}

surface_set_target(dark_surface);
draw_clear(c_black);

//Torch
with(o_torch)
{
gpu_set_blendmode(bm_src_color);
draw_sprite_ext(s_torch_glow,torch_index,x-camera_get_view_x(view_camera[0]),y-camera_get_view_y(view_camera[0]),glow_size,glow_size,0,c_white,1);
gpu_set_blendmode(bm_normal);
}

surface_reset_target();
draw_surface_ext(dark_surface,camera_get_view_x(view_camera[0]),camera_get_view_y(view_camera[0]),1,1,0,c_white,alpha);

Essentially that code just plasters a surface that is flushed black over the visible screen (you can set the surface's alpha for varying darkness), and then the torch objects just reverse the darkness based on their alpha (you'll need a simple light sprite, like a circle with feathered edges).

NOTE: If you're not using GMS2, the terminology is probably slightly different for setting the blend mode.

And lastly, this effect is super dope for the amount of code it takes :D
Hope that helps!
I am aware of this system, and I thank you for you suggestion.
However the exemples I shown above simulate a lighting system that seem to go up and down values on a limited colour palette, depending on the brightness.


Maybe this can be achieved a simple lighting system, combined with a shader that "rounds" the "lighting" values of the pixels.

EDIT: The word for that is called Posterization.
I will investigate this Posterization thing. Cheers

Thanks

Also, this kind of light system was used by games with very limited colour palettes as a workarround - notice how both exemples only use 4 colours ever?
Could this be part of the solution?
 

CMAllen

Member
Yup. You'd have to take over control of drawing the application surface, activating and deactivating a posterization shader when you do. Essentially, when you're drawing the application surface, you'd look at each pixel of the surface, and convert the variable rgb ranges to your clamped palette values. Go look up the free shader package on the GM market place by xygthop3. There's a posterization shader as part of the package, though I don't think it clamps to an exact palette (like what you'd get with old 8-bit games). Still, it'll give you a jumping off point to do that yourself.
 

Neptune

Member
Aw, I see. Looked like a slab of blackness over green sprites to me.
I think the way I'm doing lighting now is capable of this (essentially feeding a texture to the shader).
Here is an example:

If this picture is similar to want you're wanting, I can post code or we can talk more, otherwise idk and goodluck!
 

Niels

Member
Aw, I see. Looked like a slab of blackness over green sprites to me.
I think the way I'm doing lighting now is capable of this (essentially feeding a texture to the shader).
Here is an example:

If this picture is similar to want you're wanting, I can post code or we can talk more, otherwise idk and goodluck!
I'm quite interested in the colored lighting :) If you want to share the code you will make me happy
 
M

maratae

Guest
Yup. You'd have to take over control of drawing the application surface, activating and deactivating a posterization shader when you do. Essentially, when you're drawing the application surface, you'd look at each pixel of the surface, and convert the variable rgb ranges to your clamped palette values. Go look up the free shader package on the GM market place by xygthop3. There's a posterization shader as part of the package, though I don't think it clamps to an exact palette (like what you'd get with old 8-bit games). Still, it'll give you a jumping off point to do that yourself.
I'm already on it. I'll let you guys know how it goes :)
 

Neptune

Member
I'm quite interested in the colored lighting :) If you want to share the code you will make me happy
Here is the drawing of the application surface:
Code:
shader_set(shader_cycle);

    shader_set_uniform_f(o_weather.shader_b_out, o_weather.b_add);
    shader_set_uniform_f(o_weather.shader_r_out, o_weather.r_add);
    shader_set_uniform_f(o_weather.shader_g_out, o_weather.g_add);
    shader_set_uniform_f(o_weather.shader_darkness, o_weather.night_alpha);
    texture_counter = surface_get_texture(o_weather.light_surface);
    sampler_counter = shader_get_sampler_index(shader_cycle,"lightSurface");
    texture_set_stage(sampler_counter,texture_counter);
draw_surface(application_surface,global.offset_x,global.offset_y);
shader_reset();
The "light surface" is a surface that has light sprites drawn to it -- it is never actually drawn, and it is just sent to the shader as a texture.
In the shader you can then reference the texture's .a or alpha value, and say things like, "If the alpha is > 0, skip shading this pixel." (Or create a nice gradient of colored lighting).
Otherwise it is just a matter of drawing your lights in different ways / changing your shader's RBG floats!
 

jobjorgos

Member
This is what I used for my game without any knowledge of shaders and surfaces.
I just littarly copied the steps in the video.
In your case you could do the same, but set the alpha to 1 if you always want it to be dark outside of the lightnings for example.
 
M

maratae

Guest
So, to be a bit more clear on what problem I am trying to find a solution for:

1. We draw stuff in our image (or game), using 4 colors, in the style of a game boy or other 4 color screen / console.
2. Using the same 4 colors, we make our light, a color for each intensity of light. This could be done as a surface and some blend mode I guess?
3. In an image editing program (Aseprite), I put [2] over [1] as a 'Darken' layer, and the magic happens.
- My question is: How the heck can we achieve this in Game Maker.

 
M

maratae

Guest
Top