[Solved] How do you draw overlapping shapes at <1 alpha without the alpha value stacking?

Goldoche

Member
I'm drawing a bunch of triangles on a surface at 0.7 alpha. Right now, if the triangles overlap it will create a darker value on the screen. However, I want all the shadows to be uniform in value on the screen. How would you do that?

Screenshot:


Code:
if (surface_exists(other.surface))
{
    surface_set_target(other.surface);
    other.surface.depth = -10000;
    draw_clear_alpha(c_white, 0);
    draw_set_colour(c_black);
    draw_set_alpha(1);
  
    var indexValide1 = 0;
    var indexValide2 = 0;
    for (var index = 0; index < 4; index++)
    {
        if (coins[index] == true)
        {
            if (indexValide1 == 0)
            {
                indexValide1 = index;
            }
            else
            {
                indexValide2 = index;
            }
        }
    }
    draw_triangle(parX[indexValide1], parY[indexValide1], primeX[indexValide1], primeY[indexValide1], parX[indexValide2], parY[indexValide2], false);
    draw_triangle(parX[indexValide2], parY[indexValide2], primeX[indexValide2], primeY[indexValide2], primeX[indexValide1], primeY[indexValide1], false);
    surface_reset_target();
    draw_surface_ext(other.surface, 0, 0, 1, 1, 0, c_black, 0.7);

  
    draw_set_alpha(1);
}
else
{
    other.surface = surface_create(room_width, room_height);
    surface_reset_target();
}
 

sp202

Member
Draw the shadows onto the surface with an alpha of 1 and then draw the surface with a lower alpha.
 

Perseus

Not Medusa
Forum Staff
Moderator
Draw onto the surface with full opacity, then draw the surface at a lower alpha value.
 

Goldoche

Member
Draw the shadows onto the surface with an alpha of 1 and then draw the surface with a lower alpha.
Isn't this what I'm already doing? "draw_set_alpha();" is always set to 1, I set the alpha at 0.7 only when drawing the surface. It doesn't work. I've tried the other way too.
 

sp202

Member
Oh, sorry, I'll admit I didn't read the code. Are you perhaps stacking surfaces? I can only see two triangles being drawn each step.
 

Goldoche

Member
Oh, sorry, I'll admit I didn't read the code. Are you perhaps stacking surfaces? I can only see two triangles being drawn each step.
I don't think so. Even if I were, I don't think it would cause this issue. The problem is that I'm stacking triangles with <1 alpha.
 

Perseus

Not Medusa
Forum Staff
Moderator
That's because you're drawing multiple surfaces and their alpha values are adding up. Instead of using a new surface for every instance, keep a single surface that has dimensions of the view. For all the instances present inside the view, draw the shadows at their respective positions onto the surface at full opacity, then draw the whole surface at the view position at lower alpha value.
 

Goldoche

Member
That's because you're drawing multiple surfaces and their alpha values are adding up. Instead of using a new surface for every instance, keep a single surface that has dimensions of the view. For all the instances present inside the view, draw the shadows at their respective positions onto the surface at full opacity, then draw the whole surface at the view position at lower alpha value.
Oh, sorry, I'll admit I didn't read the code. Are you perhaps stacking surfaces? I can only see two triangles being drawn each step.

Oh nevermind, I see what you guys mean. Thanks for the help!
 
Top