Anyway to achieve this without performance issue.

396 views
Skip to first unread message

Niko

unread,
Aug 11, 2015, 4:24:38 PM8/11/15
to HaxeFlixel
Hi,
Just saw a cool but fake 2d lighting which looks great, can be achieved with minimal effort. Its also very performance friendly, as the author stated. The full post is here,

http://techblog.orangepixel.net/2015/07/shine-a-light-on-it/



Achieved result:





There is a sprite.stamp function in flixel but its very very slow, unusable in this kinda scenario.

SruloArt

unread,
Aug 11, 2015, 5:24:19 PM8/11/15
to haxef...@googlegroups.com
* If you search in the forum for a 2d lighting (or something similar, I forget) you would get a much better system with shadows and the whole shebang. I think there are actually several systems that work.

* I don't want to get into the details, but:
 - you can't easily manipulate non-blitting targets,
 - nor should you, as you have an in-game blending for FlxSprites/Tiles that works everywhere.
 - Of course, then your performance would suffer because blending in openfl-legacy is done by software,
 - and HaxeFlixel doesn't have an OpenGL renderer.
 - But people do O.K with what they have.

Niko

unread,
Aug 12, 2015, 12:58:13 PM8/12/15
to haxef...@googlegroups.com
I am not sure what are non-blitting targets, but my main concern is native target (PC and mobiles). I am aware of box2d lighting, there is even a demo included in flixel-demos. But that system is good for shadows and fog of war.

Are you suggesting haxeflixel still uses openfl-legacy which has software blending? Afaik, latest openfl has hardware blendmode support. If openfl internally uses opengl (latest release), so if these functions are available in openfl then they should also work with haxeflixel, though I have no idea about haxeflixel's render methods.

SruloArt

unread,
Aug 12, 2015, 3:17:54 PM8/12/15
to haxef...@googlegroups.com
* I've really meant for you to search this forum, you're not the first guy to try adding lights with blending :)

* There are methods other than dynamic shadows (and for that we usually use Nape and not box2d btw).

* This is what I was referring to: http://haxeflixel.com/forum/?place=msg%2Fhaxeflixel%2F8IX0tTHifsQ%2Fk8A3QD6wWiYJ

* If the method above isn't for you (though it has a very similar light sprite) then read on.

* HaxeFlixel uses OpenFL-Legacy because OpenFL-Next is a work in progress. You can try OpenFL-Next by adding this to your project.xml file before you add the flixel library:
<set name="next"/>

*This will allow you to use a few Hardware supported blend modes anywhere but Flash. This is how you set it up:
yourSprite.blend = BlendMode.NAME

* GPU-supported
blend modes: ADD, DIFFERENCE, INVERT, MULTIPLY, NORMAL, SCREEN, SUBTRACT

* Software based blend modes: ALPHA, DARKEN, ERASE, HARDLIGHT, LAYER, LIGHTEN, OVERLAY

* Anyhow, this is where you would go and check out the code here: http://haxeflixel.com/forum/?place=msg%2Fhaxeflixel%2FbRcmtU-nmJ8%2F49176o0nJ2YJ.

* Now, I really want to avoid trying to explain to you how to hack your way through the HaxeFlixel rendering system because this is a really long and tedious subject (you can catch a little glimpse of it here: http://haxeflixel.com/blog/01-HaxeFlixel-rendering/) and I can barely grasp it. Same goes to using OpenGL from within HaxeFlixel.

* In the far future when we can use OpenFL-Next and shaders then we can start thinking about a real lighting system that uses normal maps.

* And draw forces software mode.

Niko

unread,
Aug 12, 2015, 4:25:16 PM8/12/15
to HaxeFlixel
Thanks for your descriptive answer, will surely look into those posts.


On Thursday, August 13, 2015 at 1:17:54 AM UTC+6, SruloArt wrote:
* I've really meant for you to search this forum, you're not the first guy to try adding lights with blending :)

* There are methods other than dynamic shadows (and for that we usually use Nape and not box2d btw).

* This is what I was referring to: http://haxeflixel.com/forum/?place=msg%2Fhaxeflixel%2F8IX0tTHifsQ%2Fk8A3QD6wWiYJ

* If the method above isn't for you (though it has a very similar light sprite) then read on.

* HaxeFlixel uses OpenFL-Legacy because OpenFL-Next is a work in progress. You can try OpenFL-Next by adding this to your project.xml file before you add the flixel library:
<set name="next"/>

*This will allow you to use a few Hardware supported filters anywhere but Flash. This is how you set it up:
yourSprite.blend = BlendMode.NAME

* GPU-supported filters: ADD, DIFFERENCE, INVERT, MULTIPLY, NORMAL, SCREEN, SUBTRACT

* Software based filters: ALPHA, DARKEN, ERASE, HARDLIGHT, LAYER, LIGHTEN, OVERLAY

Ali Hassan

unread,
Aug 13, 2015, 3:48:08 AM8/13/15
to HaxeFlixel
i used the demo that @SruloArt mentioned in a gamejam a week ago ..
it was missing a function to convert tile maps to the visibility  class .. because all values were added manually .
so if you are interested in that demo i can post it here .

you can check the game here .. http://alihassan.itch.io/the-floor-master

SruloArt

unread,
Aug 13, 2015, 6:18:51 AM8/13/15
to HaxeFlixel
Nice!

I never read the instructions so I was running for my life for not being able to shoot at anything.

I really like the enemies.

When a light hits a tile and creates a lighted end (with a light line) then it should stop updating because the flickering is pretty bad.

If you can upload a fixed demo that would be great!

Ali Hassan

unread,
Aug 13, 2015, 5:51:18 PM8/13/15
to HaxeFlixel
so  here is the demo .. you can test it online from here http://www.newgrounds.com/dump/item/e4d9d6f0938b71a8f90636fa04f592ec
press "esc" to generate a new level

the procedurally generated rooms are taken from here : http://gamedevelopment.tutsplus.com/tutorials/how-to-use-bsp-trees-to-generate-game-maps--gamedev-12268



On Tuesday, August 11, 2015 at 10:24:38 PM UTC+2, Niko wrote:
lighting demo.zip

SruloArt

unread,
Aug 13, 2015, 6:03:03 PM8/13/15
to HaxeFlixel
Cool! we do have a bsp demo over the flixel-demo dev branch you know ;) but it's basically the same algorithm (not the first time I'm reading this article). 

Niko

unread,
Aug 14, 2015, 4:44:32 AM8/14/15
to HaxeFlixel
The demo is really cool, I will look into it later. But I see only single light source, can there be multiple such lights with different color, overlapping each other?

Ali Hassan

unread,
Aug 15, 2015, 12:24:03 PM8/15/15
to HaxeFlixel
sure .. just add extra raylights  .. but performance on neko may be a problem then

On Tuesday, August 11, 2015 at 10:24:38 PM UTC+2, Niko wrote:
Reply all
Reply to author
Forward
0 new messages