GMS 2 How to draw particles not affected by the surfaces above them?


I know its possible to just draw particle system above the lighting surfaces, but I really need to preserve depth order. Here's a screenshot of current situation:1.png
Particles on hand and sword are too dim, but the depth is ok.

And here's how they look when being drawn above everything:2.png
Bright and clear, except that the depth now is not ok.

So how do I preserve both luminosity and depth? Any help with solving this problem is greatly appreciated.


So... after three days of pathetic attempts of fixing this issue I've settled down on using bm_subtract to cut holes in lighting surface, and although it is the closest I can get it to being perfect there are still some imperfections such as visible holes and pixelated particles, as seen here:3.png

And it's still not looking any better than previous variants, so I dunno...

var cam = view_get_camera(0);
var cx = camera_get_view_x(cam);
var cy = camera_get_view_y(cam);

//Cutting holes from final lighting surface
//Shader for transforming all colors to black without affecting alpha

if !surface_exists(_pl_final) _pl_final = surface_create(1440,900);

//Drawing application surface without lightmap, so we can
//Drawing lightmap with blendmode
gpu_set_blendmode_ext(bm_dest_color, bm_src_color);
draw_surface_ext(_pl_lightmap, 0, 0, 4, 4, 0, c_white, 1);

//Drawing final surface (for some reason it's huge, so I scaled it down)

Any suggestions? C:

I'm exhausted fighting with this thing.
Last edited:

Phil Strahl

I am by no means an expert, but theoretically, could you fake some of depth buffer, e.g. draw all the sprites in solid colors on a separate view and then sample those pixels when drawing particles? Should be halfway decent with shaders, I presume, but hacky af. Someone in here who knows how to do this?
If I understand you correctly, your issue is thst the lighting surface is darkening the particles. You solution would be to mask the particles and draw them atop.

Heres another solution, not perfect but probably fast: why not draw lights to the light surface where the particles are? Of course the light wont be masked but it might look good enough.
One solution could be to use multiple rendering targets. That would allow you to easily mask all the particles on your lighting surface.

But I think there are easier solutions. One is to not include the darkening portion of your ambient lighting in the actual light surface. If you moved that to a shader or to blending colors, then you can easily select not to have it affect your particles. In which case you can change your lighting surface to only have an additive effect.