GMS 2 Why is my additive lighting creating darker areas?

Discussion in 'Programming' started by mattmls00, Oct 11, 2019.

  1. mattmls00

    mattmls00 Member

    Joined:
    Oct 6, 2019
    Posts:
    13
    So I am working on an additive lighting system similar to many of the online tutorials. I am having one major issue. Where the lights overlap, I am actually getting areas that appear to be darker, not lighter. After reading the YoYo Games blog post about blend modes, I thought bm_add could only make things lighter.

    I am creating a lighting surface, clearing it to black, and then drawing a light circle using circle_draw_color with a gradient from orange to black. Then I draw this surface over the application surface using a multiply blend mode. Here is an example of the issue:
    lights.png

    Just to list some of the things I have tried:
    -Using sprites instead of draw-circle-color
    -Using different colors and trying extended blend modes
    -Not using a gradient color, but this produces really hard lines that I don't like


    I am thinking maybe I need a shader but have no idea what I would do with it. I am hoping someone can help me as I have been beating my head against the wall with this for a few days and even tried the dev discord, but no solutions so far.

    Thanks guys.
     
  2. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    11
    "Then I draw this surface over the application surface using a multiply blend mode"

    If your creating a multiply blend mode, then that is the issue, you want to use additive.

    *edit, but thinking about that mode it's probably not what you want either. Regardless, multiplying the surface is your problem. It's hard to know what is going exactly from that screen, but I am assuming that it has something to do with how you are drawing the circles. How many are in your screen? 3? When you draw the circles are you blending them, or just drawing them? You should draw the main light surface without any blend mode first to get the circles on the surface how you want. Keep in mind anything not 100% white will come through as darker in multiply blend.
     
    Last edited: Oct 11, 2019
  3. mattmls00

    mattmls00 Member

    Joined:
    Oct 6, 2019
    Posts:
    13
    I may not have been clear with my writing, but I am drawing the lights with bm_add, to the light surface and then drawing the entire surface with multiply so you can see through that surface.

    If you were meaning that I need to draw my lighting surface to the application surface with an additive blend as well, that makes it so my entire level is covered in opaque colors.

    But if you think either option may not work, then I am back to square one.
     
  4. mattmls00

    mattmls00 Member

    Joined:
    Oct 6, 2019
    Posts:
    13
    I guess I am mainly confused because if all the bm_add blend mode does is add RGB values then even a very dark color blended with another very dark color should get lighter.

    For example a dark orange: RGB(80, 40, 0) + RGB(80, 40, 0) = RGB(160, 80, 0)

    It makes me wonder if there is an issue with the color blending. It seems to work as expected with brighter colors in the gradient, which is even more odd.

    I am just not sure what it could be doing at this point.
     
  5. mattmls00

    mattmls00 Member

    Joined:
    Oct 6, 2019
    Posts:
    13
    Okay so I finally figured out something that works. Maybe this is part of what you are trying to explain. But this is what I did.

    Draw all my lights onto a surface with NO blend mode. The lights are now sprites with a gradient from any given color to transparent. So I let their transparency handle the blending in a sense.

    Then I draw that onto another surface with bm_add. And then finally draw this combined surface with a multiply blend mode. Hopefully that makes sense.

    I am just glad to finally have a better solution after days of toying with this.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice