R
Robert Russell
Guest
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.
Got to pack ..
Regards, Rob.
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.
Got to pack ..
Regards, Rob.
Last edited by a moderator: