sHTiF
October 19th, 2010, 06:44 PM
Hi there, recently i've been inspired to work on my Genome2D engine again and since reading the topic by justkevin and his Darkness game I focused on dynamic lightning and shadows in 2D game.
Who doesn't know what Genome2D is don't panic its my 2D game engine which i neglected for around a year due to other work so its time to work on it once more. The 15 month old Genome2D demo can be found here http://www.flash-core.com/examples/g2d/270609/ (W/S/A/D/Mouse Click)
Its kind of obsolete since i ported parts of Genome2D to Alchemy and haXe however i had no time to post a new demo yet.
Anyway as mentioned i focused on lights and shadow casting in this new non-interactive demo to show that it can be done quite easily and at decent speed. Latest shadow demo can be found here: http://www.flash-core.com/examples/shadows/
It runs at my Q6600 2.4GHz at 55-60FPS where 60 is the well known new flash player fps cap.
It has 6 dynamic lights with various speeds and 104 shadow casting objects which rerender each frame if needed. I was kind of surprised that justkevin in his post said that the lightning render was a bottleneck with just one shadow casting light.
The shadow casting technique is quite straight forward, each light consists of 2 layers, first layer is the light itself and second layer drawn on top of it is the shadow layer. Each shadow casting object is represented by a polygon (rectangles in this demo but work with any polygons) so light firstly checks if the polygon is in range of the light since there is no need to cast shadows of polygons which are outside of the radiance. Once the polygon is in range it renders it shadow by iterating edges and checking if the edge is a back edge from current light position if yes then draw an edge shadow if not skip the edge since front edges should not cast shadows.
Pretty simple, there is some optimalizations used since the layers are managed using bitmap data copypixels and drawing within a bounding rectangle so the really long shadows outside of light radiance will be cropped within.
There is no scenario specific optimization so as it is it can be used with any kind of objects and those objects may have dynamic nature (moving, scaling, rotating) the shadows will render correctly without any performance loss. And ofcourse the object can have various "height" defined as well as can be seen in the old Genome2D demo crates cast smaller shadow than pillars.
I will probably post more demos just for the fun of it. The two optimalizations that come to mind is quad tree for casting precheck and silhouette drawing using one pass instead of per edge pass. But both of these optimalizations based on my earlier experience will not increase the performance in any significant way, i will give them a try thou ;)
If there are any questions, feel free to ask, if there are any suggestions or ideas for upcoming demos i would be very pleased to read them and maybe implement them.
Thanks.
Who doesn't know what Genome2D is don't panic its my 2D game engine which i neglected for around a year due to other work so its time to work on it once more. The 15 month old Genome2D demo can be found here http://www.flash-core.com/examples/g2d/270609/ (W/S/A/D/Mouse Click)
Its kind of obsolete since i ported parts of Genome2D to Alchemy and haXe however i had no time to post a new demo yet.
Anyway as mentioned i focused on lights and shadow casting in this new non-interactive demo to show that it can be done quite easily and at decent speed. Latest shadow demo can be found here: http://www.flash-core.com/examples/shadows/
It runs at my Q6600 2.4GHz at 55-60FPS where 60 is the well known new flash player fps cap.
It has 6 dynamic lights with various speeds and 104 shadow casting objects which rerender each frame if needed. I was kind of surprised that justkevin in his post said that the lightning render was a bottleneck with just one shadow casting light.
The shadow casting technique is quite straight forward, each light consists of 2 layers, first layer is the light itself and second layer drawn on top of it is the shadow layer. Each shadow casting object is represented by a polygon (rectangles in this demo but work with any polygons) so light firstly checks if the polygon is in range of the light since there is no need to cast shadows of polygons which are outside of the radiance. Once the polygon is in range it renders it shadow by iterating edges and checking if the edge is a back edge from current light position if yes then draw an edge shadow if not skip the edge since front edges should not cast shadows.
Pretty simple, there is some optimalizations used since the layers are managed using bitmap data copypixels and drawing within a bounding rectangle so the really long shadows outside of light radiance will be cropped within.
There is no scenario specific optimization so as it is it can be used with any kind of objects and those objects may have dynamic nature (moving, scaling, rotating) the shadows will render correctly without any performance loss. And ofcourse the object can have various "height" defined as well as can be seen in the old Genome2D demo crates cast smaller shadow than pillars.
I will probably post more demos just for the fun of it. The two optimalizations that come to mind is quad tree for casting precheck and silhouette drawing using one pass instead of per edge pass. But both of these optimalizations based on my earlier experience will not increase the performance in any significant way, i will give them a try thou ;)
If there are any questions, feel free to ask, if there are any suggestions or ideas for upcoming demos i would be very pleased to read them and maybe implement them.
Thanks.