GML 2 Color Lighting System - Surfaces & bm_max Issue

RyanC

Member
Hi All,

I'm wondering if anyone can suggest a better way of doing this:

My lighting system uses 2 separate surfaces, 1 for all the background sprites and 1 for the foreground with the player and floor blocks etc.

I am trying to achieve a system that will render these surfaces in the GUI_Begin event, with a different lighting color on the background then on the foreground.

The system draws the current background sprites to the background surface in Draw_Begin, and then switches to the foreground surface in Draw_Main and draws everything normally to the second surface. It then draws the surfaces to the application_surface, with a shader for each surface to create the lighting colors.

The issue is that things drawn on the foreground surface that use bm_max have no background to apply the additional alpha values to because the background is now on a different surface. So the final result gives transparent sprites that have been added to c_black and do not glow.

It's worth noting that if I draw_clear_alpha(1) on the foreground surface, I get a better result then draw_clear_alpha(0) but then I have to detect unchanged pixels within the shader so it does not draw the background of the surface, which then looks terrible, like when removing a background color from a faded sprite.

I can't just draw the foreground surface all with bm_max in the gui either because then everything is to bright.

Any suggestions appreciated to fix or replace this system.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
The issue is that things drawn on the foreground surface that use bm_max have no background to apply the additional alpha values to because the background is now on a different surface. So the final result gives transparent sprites that have been added to c_black and do not glow.
I'm having difficulty visualising the effect you are creating and the issues you are having... could you maybe add in some screenshots to better illustrate what you have, what you want and the issues you are having? Would be a big help!
I can't just draw the foreground surface all with bm_max in the gui either because then everything is to bright.
Do you WANT a bright effect at all? I'm asking because maybe using a multiply blend mode would be better than using bm_max when used in this way? It would mitigate having to look for more complex solutions... For multiply use:
gpu_set_blendmode_ext(bm_dest_colour, bm_zero)
 

RyanC

Member
In the first screenshot on the left, we can see the flame has been drawn with bm_max to create a glow effect, but the background surface was not present at the time, as it was drawn to a separate surface, so the blocks look fine but the flame was drawn with bm_max on a blank surface that was cleared with draw_clear_alpha(c_black,0),

I would like somehow that the flame (drawn with bm_max) in the 1st screenshot was added to the color of the blue background where it is relevant.

In the second image to the right we can see what the flame should look like, as the blocks are part of the foreground surface too, so the additional values have been multiplied onto the blocks to create that glow effect.

I am also not keen on using the complex blend modes, as the game is for Android & iOS, and I read somewhere these are not all supported, so I use shaders for the lighting colors.


Screenshot1.png 1 Screenshot2.png 2


Here's the fragment shader I'm using for the lighting. It just creates a circle shape colored area in the center for each surface:

C#:
// Simple passthrough fragment shader
//
// Color Overlay Fragment Shader
varying vec2 v_vTexcoord;

// u_colour is and array of global.light_color [r, g, b, a]
uniform vec4 u_colour;

void main()
{
    vec4 texColor = texture2D(gm_BaseTexture, v_vTexcoord); 
     
    vec2 coordinates;
 
    coordinates = vec2(v_vTexcoord.x, v_vTexcoord.y);
 
    float c;

    c = min(1.-length(coordinates-.5)*2.,0.65);
             
    vec4 texColor2 = texColor +(u_colour*c);
    gl_FragColor = vec4(texColor2.rgb, texColor.a);
}
 
Last edited:
Top