GameMaker draw half transparent overlapping sprites to surface [SOLVED]

mX273

Member
Hi guys

I spent hours on this problem without any solution. So hopefully you can help me.

I d'like that after an explosion in my game, the smoke-particles remain on a surface, which is drawn over the entire screen.
This should look like the area where the explosion was, is burned. So my smoke sprite is basically a half transparent gray circle with a smooth alpha-gradient to zero alpha.
When i draw them to the surface and they are overlapping, the outer part (fully transparent part of a smoke particle) clears a part of the previous drawn particle).

smokeToSurface.png

GML:
// Draw Event

if !surface_exists(decal_surf)
{
    decal_surf = surface_create(1920, 1080);
    surface_set_target(decal_surf);
    draw_clear_alpha(c_black, 0);
    surface_reset_target();
}
else
{
    surface_set_target(decal_surf);
    //gpu_set_blendmode_ext(bm_dest_color, bm_dest_alpha)  // i tried different blendmodes, without success
    with (obj_particle)
    {
        // the particles are fading out and then they will be destroyed.
        // only draw them for a very short time at a specific alpha value
        if (alpha > 0.3 && alpha < 0.4)
        {
            draw_sprite_ext(spr_smoke, 0, x, y, scaleX, scaleY, angle, color, alpha)    
        }
    }
    //gpu_set_blendmode(bm_normal) 
    surface_reset_target();
    draw_surface(decal_surf, 0, 0);
}
alphatest is set to:
Code:
var alphaThreshold = 1
gpu_set_alphatestenable(true)
gpu_set_alphatestref(alphaThreshold)
// I also tried different settings
any solution?

kind regards

mX273
 
Last edited:

Roldy

Member
There could be several problems that you will need to fix to get what I am guessing is your desired result.

Consider the effect of the depth buffer and your surface.

When rendering to your surface try disabling z write while leaving z read on and then think about the results.

 

mX273

Member
I dont understand exactly. What the problem with the depth?

More info about my level : I use 2 Tilemaps, one for the background (floor) at high depth and one for the walls at low depth.
On an instance-layer i place a controller-object with a depth between both tilemaps. This object then draws the surface. So the smoke will be drawn on top of the floor, but behind the walls.

[EDIT: Better explanation of the picture: The left part of the picture above shows a sandy ground (little dark points) with the smoke particles overlaying]


Which blend-modes do I have to use?
... there are so many options for
//gpu_set_blendmode_ext(bm_dest_color, bm_dest_alpha)
//gpu_set_blendmode_ext_sepalpha(bm_zero, bm_one, bm_one, bm_dest_color)
//gpu_set_blendmode_ext_sepalpha(bm_zero, bm_dest_color, bm_one, bm_dest_color)
// ... ... ...

GML:
// i tried it with zwriteenable(false).... didnt work

var alphaThreshold = 1
gpu_set_alphatestenable(true)
gpu_set_alphatestref(alphaThreshold)
gpu_set_zwriteenable(false)
I'd like to get something like this (picture edited in photoshop). No cleared area around the
smoke particles:
MyAimIsToGetSomethingLikeThis.png
 
Last edited:
Top