Packageorg.zozuar.volumetrics
Classpublic class EffectContainer
InheritanceEffectContainer Inheritance flash.display.Sprite
Subclasses VolumetricPointLight

The EffectContainer class creates a volumetric light effect (also known as crepuscular or "god" rays). This is done in 2D with some bitmap processing of an emission object, and optionally an occlusion object.



Public Properties
 PropertyDefined By
  blur : Boolean = false
When true a blur filter is applied to the final effect bitmap (can help when colorIntegrity == true).
EffectContainer
  colorIntegrity : Boolean = false
Selects rendering method; when set to true colors won't be distorted and performance will be a little worse.
EffectContainer
  intensity : Number = 4
Light intensity.
EffectContainer
  passes : uint = 6
Number of passes applied to buffer.
EffectContainer
  rasterQuality : String = null
Set this to one of the StageQuality constants to use this quality level when drawing bitmaps, or to null to use the current stage quality.
EffectContainer
  scale : Number = 2
Final scale of emission.
EffectContainer
  smoothing : Boolean = true
Smooth scaling of the effect's final output bitmap.
EffectContainer
  srcX : Number
Light source x.
EffectContainer
  srcY : Number
Light source y.
EffectContainer
Protected Properties
 PropertyDefined By
  _baseBmd : BitmapData
EffectContainer
  _blurFilter : BlurFilter
EffectContainer
  _bufferBmd : BitmapData
EffectContainer
  _bufferRect : Rectangle
EffectContainer
  _bufferSize : uint = 0x8000
EffectContainer
  _ct : ColorTransform
EffectContainer
  _emission : DisplayObject
EffectContainer
  _halve : ColorTransform
EffectContainer
  _lightBmp : Bitmap
EffectContainer
  _mtx : Matrix
EffectContainer
  _occlusion : DisplayObject
EffectContainer
  _occlusionLoResBmd : BitmapData
EffectContainer
  _occlusionLoResBmp : Bitmap
EffectContainer
  _viewportHeight : uint
EffectContainer
  _viewportWidth : uint
EffectContainer
  _zero : Point
EffectContainer
Public Methods
 MethodDefined By
  
EffectContainer(width:uint, height:uint, emission:DisplayObject, occlusion:DisplayObject = null)
Creates a new effect container.
EffectContainer
  
dispose():void
Dispose of all intermediate buffers.
EffectContainer
  
render(e:Event = null):void
Render a single frame.
EffectContainer
  
setBufferSize(size:uint):void
Sets the approximate size (in pixels) of the effect's internal buffers.
EffectContainer
  
setViewportSize(width:uint, height:uint):void
Sets the container's size.
EffectContainer
  
Render the effect on every frame until stopRendering is called.
EffectContainer
  
Stop rendering on every frame.
EffectContainer
Protected Methods
 MethodDefined By
  
_applyEffect(bmd:BitmapData, rect:Rectangle, buffer:BitmapData, mtx:Matrix, passes:uint):void
Low-level workhorse, applies the lighting effect to a bitmap.
EffectContainer
  
_copyMatrix(src:Matrix, dst:Matrix):void
EffectContainer
  
Draws a scaled-down emission on _baseBmd.
EffectContainer
  
Draws a scaled-down occlusion on _occlusionLoResBmd and erases it from _baseBmd.
EffectContainer
  
EffectContainer
Property Detail
_baseBmdproperty
protected var _baseBmd:BitmapData

_blurFilterproperty 
protected var _blurFilter:BlurFilter

_bufferBmdproperty 
protected var _bufferBmd:BitmapData

_bufferRectproperty 
protected var _bufferRect:Rectangle

_bufferSizeproperty 
protected var _bufferSize:uint = 0x8000

_ctproperty 
protected var _ct:ColorTransform

_emissionproperty 
protected var _emission:DisplayObject

_halveproperty 
protected var _halve:ColorTransform

_lightBmpproperty 
protected var _lightBmp:Bitmap

_mtxproperty 
protected var _mtx:Matrix

_occlusionproperty 
protected var _occlusion:DisplayObject

_occlusionLoResBmdproperty 
protected var _occlusionLoResBmd:BitmapData

_occlusionLoResBmpproperty 
protected var _occlusionLoResBmp:Bitmap

_viewportHeightproperty 
protected var _viewportHeight:uint

_viewportWidthproperty 
protected var _viewportWidth:uint

_zeroproperty 
protected var _zero:Point

blurproperty 
public var blur:Boolean = false

When true a blur filter is applied to the final effect bitmap (can help when colorIntegrity == true).

colorIntegrityproperty 
public var colorIntegrity:Boolean = false

Selects rendering method; when set to true colors won't be distorted and performance will be a little worse. Also, this might make the final output appear grainier.

intensityproperty 
public var intensity:Number = 4

Light intensity.

passesproperty 
public var passes:uint = 6

Number of passes applied to buffer. Lower numbers mean lower quality but better performance, anything above 8 is probably overkill.

rasterQualityproperty 
public var rasterQuality:String = null

Set this to one of the StageQuality constants to use this quality level when drawing bitmaps, or to null to use the current stage quality. Mileage may vary on different platforms and player versions. I think it should only be used when stage.quality is LOW (set this to BEST to get reasonable results).

scaleproperty 
public var scale:Number = 2

Final scale of emission. Should always be more than 1.

smoothingproperty 
public var smoothing:Boolean = true

Smooth scaling of the effect's final output bitmap.

srcXproperty 
public var srcX:Number

Light source x.

The default value is viewport center (set in constructor)..

srcYproperty 
public var srcY:Number

Light source y.

The default value is viewport center (set in constructor)..

Constructor Detail
EffectContainer()Constructor
public function EffectContainer(width:uint, height:uint, emission:DisplayObject, occlusion:DisplayObject = null)

Creates a new effect container.

Parameters
width:uint — Viewport width in pixels.
 
height:uint — Viewport height in pixels.
 
emission:DisplayObject — A DisplayObject to which the effect will be applied. This object will be added as a child of the container. When applying the effect the object's filters and color transform are ignored, if you want to use filters or a color transform put your content in another object and addChild it to this one instead.
 
occlusion:DisplayObject (default = null) — An optional occlusion object, handled the same way as the emission object.
Method Detail
_applyEffect()method
protected function _applyEffect(bmd:BitmapData, rect:Rectangle, buffer:BitmapData, mtx:Matrix, passes:uint):void

Low-level workhorse, applies the lighting effect to a bitmap. This function modifies the bmd and buffer bitmaps and its mtx argument.

Parameters

bmd:BitmapData — The BitmapData to apply the effect on.
 
rect:Rectangle — BitmapData rectangle.
 
buffer:BitmapData — Another BitmapData object for temporary storage. Must be the same size as bmd.
 
mtx:Matrix — Effect matrix.
 
passes:uint — Number of passes to make.

_copyMatrix()method 
protected function _copyMatrix(src:Matrix, dst:Matrix):void

Parameters

src:Matrix
 
dst:Matrix

_drawLoResEmission()method 
protected function _drawLoResEmission():void

Draws a scaled-down emission on _baseBmd.

_eraseLoResOcclusion()method 
protected function _eraseLoResOcclusion():void

Draws a scaled-down occlusion on _occlusionLoResBmd and erases it from _baseBmd.

_updateBuffers()method 
protected function _updateBuffers():void

dispose()method 
public function dispose():void

Dispose of all intermediate buffers. After calling this the EffectContainer object will be unusable.

render()method 
public function render(e:Event = null):void

Render a single frame.

Parameters

e:Event (default = null) — In case you want to make this an event listener.

setBufferSize()method 
public function setBufferSize(size:uint):void

Sets the approximate size (in pixels) of the effect's internal buffers. Smaller number means lower quality and better performance. This method recreates internal buffers (slow), do not call this on every frame.

Parameters

size:uint — Buffer size in pixels

setViewportSize()method 
public function setViewportSize(width:uint, height:uint):void

Sets the container's size. This method recreates internal buffers (slow), do not call this on every frame.

Parameters

width:uint — Viewport width in pixels
 
height:uint — Viewport height in pixels

startRendering()method 
public function startRendering():void

Render the effect on every frame until stopRendering is called.

stopRendering()method 
public function stopRendering():void

Stop rendering on every frame.