package necro
{
	import flash.display.*;

	public class AmbientShader extends AbstractShader
	{
		use namespace RemusM;
		public var color:uint;
		public function AmbientShader(init:Object = null)
		{
			super(init);
		}
		public override function updateMaterial(source:Object3D, view:View3D):void
        	{
			clearLightingShapeDictionary();
		}
		protected override function clearFaceDictionary(source:Object3D, view:View3D):void
		{
			for each (_faceVO in _faceDictionary) {
				if (source == _faceVO.source) {
					if (!_faceVO.cleared) {
						_faceVO.clear();
					}
					_faceVO.invalidated = true;
				}
			}
		}
		public override function renderLayer(tri:DrawTriangle, layer:Sprite, level:int):void
		{
			super.renderLayer(tri, layer, level);
			for each (ambient in tri.source.session.lightarray.ambients)
			{
        			if (_lights.numLights > 1) {
					_shape = getLightingShape(layer, ambient);
		        		_shape.blendMode = blendMode;
		        		_graphics = _shape.graphics;
				} else {
					_graphics = layer.graphics;
				}
			_source.session.renderTriangleBitmap(ambient.ambientBitmap, _mapping, tri.v0, tri.v1, tri.v2, smooth, false, _graphics);
        		}
			if (debug) {
				tri.source.session.renderTriangleLine(0, 0x0000FF, 1, tri.v0, tri.v1, tri.v2);
			}
        	}
        	protected override function renderShader(face:Face):void
        	{
			for each (ambient in _source.session.lightarray.ambients) {
				_faceVO.bitmap.draw(ambient.ambientBitmap, null, null, blendMode);
	    		}
	    		for each (directional in _source.session.lightarray.directionals) {
				_faceVO.bitmap.draw(directional.ambientBitmap, null, null, blendMode);
	    		}
		}
	}
}