-
Notifications
You must be signed in to change notification settings - Fork 2
Home
hxDynaLight is a geometry based lighting engine.
I guess that's a fancy way of saying that you have to define a polygon or a circle, and it will cast shadows from that object rather than being based on Sprites or Movieclips.
The main class in this kerfuffle is the LightEngine. You can add Light and ILightOccluder objects to the light engine, and then lightEngine.render( myBitmapData) all the pretty lights.
Super quick example:
var engine:LightEngine = new LightEngine();
var light:Light = new Light( LightTool.radialLightMap( 400, 400, 0.9));
var circle:ShadowCircle = new ShadowCircle( 20);
//Random positions
light.x = light.y = 100;
circle.x = 50;
circle.y = 180;
var canvas:BitmapData = new BitmapData( 500, 500, true, 0x00000000);
engine.addLight( light);
engine.addOccluder( circle);
engine.render( canvas);
// Add the canvas BitmapData to the stage to see the result! And make sure to import all necessary classes.
Currently lights all have to be of the same colour. This is something I have been thinking of, and can't seem to find an efficient, optimized solution, though if I ever dig into Starling, or start using drawTriangles(), then this should in fact be easy. To change the colour of all the lights rendered:
var engine:LightEngine = new LightEngine();
/*
Set a green lighted colour palette.
The first element of the colour array will be the colour of the brightest point of lights,
the last is the darkest colour. If you want pitch black to be the darkest colour, just change
the EE to FF in the last colour.
The second array is an array of ratios that corresponds to the colours provided.
(Only necessary when more than 2 colours are provided,
otherwise assumed as an array [ 0, 256])
*/
engine.paletteMap = LightTool.paletteMap( [ 0x0000FF00, 0xAA005500, 0xEE000000], [ 0, 180, 256]);
All renderings will be rendered with green lights now!
com.pdev.tools.LightTool holds 2 static functions. 1 for creating radial gradients as light maps for lights, and another for creating a paletteMap that will translate lightmap values to actual colour values.
I suggest checking out Main.hx to see an example of how to set things up. The same code should apply to as3 users too.
Polygonal Data structures. If you are using the .swc for as3, then you don't need to worry about this, the required classes should all be included in the .swc
If you are using haxe, just run the following command from commandline:
haxelib install polygonal-ds
You can post a comment on my "blog": http://psvilans.wrongbananas.net/dynalight-dynamic-lighting-engine/ I'll definitely see it, and try to answer asap!