GMS 2 Lighting

Azenris

Member
Hi I am having problems with my lighting ( still ;_; ) I kinda thought It was working ok, but looking
closer I can see problems.

This link shows the surface_light

https://imgur.com/a/7i020P0

However as you can see. There are these weird black lines that intrude on the light.
Ignore the little white stuff inside the light :)

My lighting is
Code:
shader_set( light_overlay_shader );
   {
       surface_set_target( surface_light );
       {
           blend_push( bm_src_alpha, bm_one );
           {
               draw_all_light_objects( _light_flicker_enabled );
           }
           blend_pop();
       }
       surface_reset_target();
   }
   shader_reset();
Code:
// draw_all_light_objects.gml
var _lf = global.time * argument0; // light flickers more the later it is

draw_primitive_begin( pr_trianglelist );

with ( obj_light )
{
   if ( active )
   {
       var _x = x + bulb_spr_xoffset, _y = y + bulb_spr_yoffset;
       var _radius = light_radius + irandom( light_flicker * _lf );
       var _l = _x - _radius, _t = _y - _radius, _r = _x + _radius, _b = _y + _radius;

       draw_light( _l, _t, _r, _b, light_colour, 1 );
   }
}

draw_primitive_end();
Code:
//draw_light.gml
draw_vertex_texture_colour( argument0, argument1, 0, 0, argument4, argument5 );
draw_vertex_texture_colour( argument0, argument3, 0, 1, argument4, argument5 );
draw_vertex_texture_colour( argument2, argument1, 1, 0, argument4, argument5 );

draw_vertex_texture_colour( argument2, argument1, 1, 0, argument4, argument5 );
draw_vertex_texture_colour( argument0, argument3, 0, 1, argument4, argument5 );
draw_vertex_texture_colour( argument2, argument3, 1, 1, argument4, argument5 );
My lighting shader for the surface ( of the pic you saw )
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec2 v_vRange;

void main()
{
   float dist = abs( length( v_vTexcoord - 0.5 ) );

   vec4 colour = v_vColour;

   // cut corners
   colour.a = mix( colour.a, 0.0, step( 0.5, dist ) );

   // fade towards edge
   colour.a = min( colour.a, ( 0.5 - dist ) * 2.0 );

   gl_FragColor = colour;
}
// -------------------------------------------------------------------

I cannot understand the blackness intruding in on the connecting lights.
I thought with the blend mode
src = bm_src_alpha
dst = bm_one
the lowest the colour could go is of the destination, because the destination is 1 always, so, its atleast that.
So I was hoping someone could explain what is happening :(

// -------------------------------------------------------------------

As I was writing this I think I have realised some of the problem.
It's because the blend is done first, then it goes to the shader, which darkens it towrds the edge.
I need that darken to not go darker than the current destination pixel, but I cant read the surface while writing to it.

I removed the line from the shader
// fade towards edge
colour.a = min( colour.a, ( 0.5 - dist ) * 2.0 );

https://imgur.com/a/6hifqPQ

Is it possible to take that screen/state into a similar way as before but without the black lines?

// -------------------------------------------------------------------

Or am I thinking about this all wrong? Not sure I'm going to post this post.

I want to get

https://imgur.com/a/MZ5uxo4

with some smooth lighting.

// -------------------------------------------------------------------

I'm not sure what to call the lighting to search for it, I've tried some youtube tutorials, but they usually use textures of faded circle but they wont scale up because its a sprite.

Maybe making a more complex vertex shape, like a triangle fan with alpha1 in centre and alpha0 at the edge with the second shader would work. But then all my lights have gone from 6 verticies, to a bunch per light, and each requiring calculations of those positions within a circle.

// -------------------------------------------------------------------

Does anyone have some tutorials maybe I havv't seen? :D
 

Azenris

Member
No i was wrong, ofc the blend is done after... with the resulting output of the shader.

Maybe it's just an illusion of the two circles...

So maybe nothing is 'wrong' i Just dont like this lighting technique, will have to research some other way of doing things.

I dont like how the lights interact. I want a more fluid/smooth in how they come together.
 
Top