Saturday 10 March 2012

Light System Finalization

I have continued to work on refining the light system, and have made improvements on the initial implementation.  As this is the end of this part of the development, I will re iterate over the details of the entire system.



Light Sources:
Light sources are defined in texture map.  Areas with high alpha are light sources.  The more transparent a pixel is the more light it will "emit"   This allows me to specify very detailed and unique light sources.  Light colors can also be defined in the texture.  Light sources will be saturated in the bloom process, so I define the colors in the texture map to be very desaturated, so when there is no light, the sources will be rendered gray.


Basic Method:-Draw Each model, preserving alpha values of light sources to final render
-On New Layer:  Extract pixels with alpha values less than 1 from scene
(this layer is half the size, for efficiency)
-Perform Gaussian Blur on light map

Problems:
-As the light sources of the model are drawn with transparency, you can see through parts of the model.
-Each model with light must be drawn black before the light sources are drawn, so they will not appear to be transparent.



Distance Problem: (both methods)
-As the light sources get farther away, there are less pixels for the Gaussian Filter to sample from.  The light sources appear to dissipate very quickly, especially with a render layer that is half the screen size.
-Filters with larger kernels look much better close up, but dissipate more quickly
-Filters with small kernel sizes still give a good light effect close up, and remain longer, but still dissipate too quickly.
-No filter looks bad close up, but remains over long distances.

This video shows these different cases:


To solve this problem, I use a very small kernel size (which also more efficient) and I draw the light source on the model at full resolution, and then perform the bloom process on the extracted light map.  At close distances only the bloomed light source is visible, and at the farther distances when the bloom dissipates you can still see the light source on the model.


Another goal of the light system is to allow for animations.  Each model will have a variable that will acount for the saturation and value of its light sources.  These variables can be set to be completely on or off, or for a blinking effect of the lights.



Final Process
-Draw each Model normally.  (Draw light sources more grey, this is what will be seen when the lights are off)
-If model has light, draw light pass:
  • For every pixel in texture that has alpha = 1, draw full transparency black
  • If pixel has transparency, saturate and increase brightness by alpha weight, then set final alpha value to light value.  (If light source is off, the second pass will not appear, if light value is full, second pass will be rendered over the model)
  • The alpha values of light sources still have to be less than 1 to be extracted.
-Run Light Extract pass over rendered Scene, for any pixel with any alpha, saturate to preserve color.  All other pixel are black.
-Preform Light Bloom pass on light map
-Combine bloomed light map with rendered Scene

This video shows the results of the final process.


There is still room for improvement in aesthetics with the process variables, and some of these will be able to be set in each model for diverse effects.



Light Motion Blur
-A simple feature that gives a nice effect, but may not be desirable
-Before combining Blurred Light map with final scene, save render layer as texture
-Next pass draw light map along with previous bloomed light map with partial transparency, to ensure that the previous map will dissipate.
-This effect is not very noticeable at farther distances.

No comments:

Post a Comment