GMS 2 An arts based lighting solution for anyone using GPU Alpha Blending.

Discussion in 'Advanced Programming Discussion' started by Robert Russell, Nov 29, 2018.

  1. Robert Russell

    Robert Russell Member

    Aug 6, 2017
    Fake lighting using GPU Alpha Blending.

    Reason for posting .. I think that this is a nice arts based technique but needs optimising +++ which is not my area of strength.

    This is something I have been meaning to post for a while .. however life gets in the way .. not least of which is that we are packing up to emigrate. So, this is just how far I've got. Unfortunately in with the many things on the go at the moment I have changed IDE so I do not really work in GM at the moment .. sorry. However I think if you do work with GM and come from an illustration background this is a nice technique for adding some nice lighting effects to your game .. it is also relatively fast to iterate through different ideas, because you are only really altering the visibility of pre-baked lighting options with a stack of masks. In short the whole lighting model (if you could call it that) fits into about 60 lines of code (incl spaces :) ), then your main challenge is to decide what to dynamically shadow and paint up some lighting options and hide/reveal masks .. once you get it, it is really fast to do.

    I have used GM quite a bit but I am a self taught coder so some of this probably needs A LOT of optimization and improvement .. I would call this a proof of concept only. The process basically takes a dark state and a lit state and reveals the lit part of the image where needed. If most of your art is flat backgrounds this allows use to select the main features you want shadowed then effectively cut them out from the background and make a reasonably effective shadow. Anyway it is easy to do things like torch direction, light through bars etc. Also it is easy with layering to control shadows correctly e.g shadows of tall objects over short ones but not the other way round

    The images below should show my light state an dark state for a little battle arena. I then drew some simple masks over areas of the background to shadow and made objects .. objects that 'collide' with the light object then add themselves to the array of objects that need their shadows dealing with. The core of the process is then to add everything cooker cutter fashion to to a GPU alpha mask that controls the reveal of the overlying lit image. I know people hate pics of code but this is the best way I could explain it.

    lightingProcess_01.jpg lightShadowsCode1.jpg
    Got to pack ..

    Regards, Rob.
    Last edited: Feb 13, 2019
    Carl Nylander likes this.
  2. RujiK

    RujiK Member

    Jun 21, 2016
    This is all very good, but are you asking a question anywhere? Are you asking for lighting method ideas? Also you mention a nice website a few times but I don't see a link anywhere. If you are just posting this to show off, why not include a demo or at least the code in text format? I doubt many people are going to copy the text from your images just to see if it works.

    Finally, your weird story/rant thing at the beginning would probably be a better fit for off topic. You will probably get more feedback if your future posts are more concise.
    Ido-f and Nocturne like 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