So, I said that I would update the lights. The latest post a made was some little picture of a light with a simple rectangle. Hours have past, yet no update. Well, here it is. People wanted it, and it's added.
The New Lighting System
http://www.youtube.com/watch?v=NFxENq0xiWU
Features:
- Ray Casted Lights
Per Boxel Lighting (Will be Explained)
Shadows
Optimization (Yet Still in the works)
Optimization Techniques:
Per Boxel Lighting - Ever heard of per pixel things? Things like per pixel lighting, per pixel collision. Well, in case you didn't know, that can be quite a CPU hog. But it's because it very precise. When colliding, it's to the very pixel (hence, "per pixel"), when lighting, it's down to the very pixel. So what is per boxel? Per Boxel is just some clever name I made up. Here's how it works:
It shoots rays of lights (ray casting) in the angle of the lighting. This is very accurate. But when looking for Blocks (things that block the light and casts a shadow), it doesn't cast a shadow down to the exact pixel. Instead, it stops based off the Block's Bounding Box. This allows the lights to reflect correctly, yet still maintaining a reasonable frame rate. The only downfall is that it's not 100% correct, meaning there may be some things that will cast a noticeable box shadow, when the block is a completely different shape.
Light Spacing - The way that lights get the roundness and the width of it's light is stored in it's class called "AngleSpacing". Yet the Light System itself it what takes advantage of it. The light system holds a variable that can be changed to set the spacing. What this does, is it determines how much spacing between the light rays until it reaches it's full light. The higher the spacing, the less light rays, yet the better the performance. Examples of changing the value are:
Spacing at 5.
Spacing at 2. You can see more light rays, and can easily make out the outline of the flashlight.
Spacing at 1. (Default for quality + performance.)
Spacing at .3 . (Default for quality)
My goal is to be able to run many lights + blocks at .3 spacing with little to no performance impact. I'm not too sure if I can, but believe me, I'm working on it. :P
On the video, you can see it running pretty smooth. Yet on the area where I'm shining lights through holes in the wall. I can feel a frame rate decrease. And that's not good obviously. :P
Thanks for reading. : )