Показать сообщение отдельно
Старый 01.12.2012, 14:29
i.o. вне форума Посмотреть профиль Отправить личное сообщение для i.o. Найти все сообщения от i.o.
  № 8  
Ответить с цитированием
i.o.
 
Аватар для i.o.

Регистрация: Apr 2010
Адрес: Earth
Сообщений: 1,897
Помогло выставление всех компонентов цвета в ноль:
Код AS3:
_context3D.clear(0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Context3DClearMask.ALL);
Результат в 11.4.402.287:
Нажмите на изображение для увеличения
Название: Untitled-1.png
Просмотров: 202
Размер:	114.2 Кб
ID:	28761

Полный код примера:
Код AS3:
/*!*****************************************************************
 *																	
 *  File created: '30.11.2012 6:10 PM'								
 *																	
 *  Copyright (c) 2012  iodev (i.o.developer@gmail.com)	
 *  All Rights Reserved.											
 *																	
 *  NOTICE: using this code allowed after author approving only.	
 *																	
 **/
 
package 
{
	import com.adobe.utils.*;
	import flash.display.*;
	import flash.display3D.*;
	import flash.display3D.textures.*;
	import flash.events.*;
	import flash.utils.*;
 
	/**														
	 *  @author  iodev (i.o.developer[at]gmail.com)	
	 */
	public class Main extends Sprite
	{
		[Embed(source="flash_logo_alpha.png")]
		private static const alphaTextureCl : Class;
 
 
		public function Main()
		{
			_init();
		}
 
 
		private var _stage3D : Stage3D;
		private var _context3D : Context3D;
 
		private var _vbufA : VertexBuffer3D;
		private var _vbufB : VertexBuffer3D;
 
		private var _uvBufCube : VertexBuffer3D;
		private var _ibufCube : IndexBuffer3D;
		private var _ibufPlane : IndexBuffer3D;
 
		private var _texture : Texture;
 
		private var _shader : Program3D;
 
		private var _bitmap : Bitmap;
		private var _bitmapData : BitmapData;
 
 
		private function _init() : void
		{
			stage.frameRate = 60.0;
 
			trace(stage.stage3Ds);
 
			_stage3D = stage.stage3Ds[0];
			_stage3D.addEventListener(Event.CONTEXT3D_CREATE, _onContext3D);
			_stage3D.requestContext3D(Context3DRenderMode.AUTO);
 
			var s:Shape = new Shape();
			s.graphics.beginFill(0xFF00FF, 1.0);
			s.graphics.drawEllipse(100, 100, 100, 100);
			s.graphics.endFill();
			s.alpha = 0.5;
			addChild(s);
 
			_bitmapData = new BitmapData(512, 512, true, 0x0);
			_bitmap = new Bitmap(_bitmapData);
			_bitmap.x = 200.0;
			_bitmap.y = 100.0;
			addChild(_bitmap);
		}
 
		private function _onContext3D( e:Event ) : void
		{
			_context3D = _stage3D.context3D;
			_context3D.configureBackBuffer(512, 512, 0, false);
 
 
			_vbufA = _context3D.createVertexBuffer(8, 7);
			_vbufA.uploadFromVector(new <Number>[
				// x,   y,   z,     r,  g,  b,  a
				-0.5, -0.5, -0.5,   1.0, 0.0, 0.0, 0.0,
				+0.5, -0.5, -0.5,   0.0, 1.0, 0.0, 1.0,
				+0.5, +0.5, -0.5,   0.0, 0.0, 1.0, 0.0,
				-0.5, +0.5, -0.5,   1.0, 0.0, 1.0, 1.0,
 
				-0.5, -0.5, +0.5,   1.0, 0.0, 1.0, 1.0,
				+0.5, -0.5, +0.5,   1.0, 1.0, 0.0, 0.0,
				+0.5, +0.5, +0.5,   0.0, 1.0, 1.0, 1.0,
				-0.5, +0.5, +0.5,   0.0, 1.0, 0.0, 0.0
			], 0, 8);
 
			_vbufB = _context3D.createVertexBuffer(8, 7);
			_vbufB.uploadFromVector(new <Number>[
				// x,   y,   z,     r,  g,  b,  a
				-0.5, -0.35, -0.9,   0.0, 1.0, 0.0, 1.0,
				+0.5, -0.35, -0.9,   1.0, 0.0, 0.0, 0.0,
				+0.5, +0.65, -0.9,   1.0, 0.0, 1.0, 1.0,
				-0.5, +0.65, -0.9,   0.0, 0.0, 1.0, 0.0,
 
				-0.5, -0.35, +0.2,   1.0, 1.0, 0.0, 0.0,
				+0.5, -0.35, +0.2,   1.0, 0.0, 1.0, 1.0,
				+0.5, +0.65, +0.2,   0.0, 1.0, 0.0, 0.0,
				-0.5, +0.65, +0.2,   0.0, 1.0, 1.0, 1.0,
			], 0, 8);
 
			_uvBufCube = _context3D.createVertexBuffer(8, 2);
			_uvBufCube.uploadFromVector(new <Number>[
				// u,   v
				0.0, 0.0,
				1.0, 0.0,
				1.0, 1.0,
				0.0, 1.0,
 
				0.0, 0.0,
				1.0, 0.0,
				1.0, 1.0,
				0.0, 1.0
			], 0, 8);
 
			_ibufCube = _context3D.createIndexBuffer(36);
			_ibufCube.uploadFromVector(new <uint>[
				0, 1, 2,   0, 2, 3,
				4, 6, 5,   4, 7, 6,
				0, 7, 4,   0, 3, 7,
				1, 5, 6,   1, 6, 2,
				0, 4, 5,   0, 5, 1,
				3, 6, 7,   3, 2, 6
			], 0, 36);
 
			_ibufPlane = _context3D.createIndexBuffer(6);
			_ibufPlane.uploadFromVector(new <uint>[
				0, 1, 2,   0, 2, 3,
			], 0, 6);
 
 
			var asmVShader:String =
				"mov op, va0  \n" +    //copy position to output 
				"mov v0, va1"; //copy color to varying variable v0
 
			var asmPShaderTex:String =
				"tex oc, v0, fs0 <2d, linear, mipnone>"; //Set the output color to the value interpolated from the three triangle vertices 
 
			_shader = _context3D.createProgram();
			_shader.upload((new AGALMiniAssembler()).assemble(Context3DProgramType.VERTEX, asmVShader),
						   (new AGALMiniAssembler()).assemble(Context3DProgramType.FRAGMENT, asmPShaderTex));
 
			var texBd:BitmapData = (new alphaTextureCl() as Bitmap).bitmapData;
			_texture = _context3D.createTexture(texBd.width, texBd.height, Context3DTextureFormat.BGRA, true);
			_texture.uploadFromBitmapData(texBd);
 
 
			super.addEventListener(Event.ENTER_FRAME, _onEnterFrame);
		}
 
		private function _onEnterFrame( e:Event ) : void
		{
			_context3D.clear(0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Context3DClearMask.ALL);
 
 
			_context3D.setBlendFactors(Context3DBlendFactor.SOURCE_ALPHA, Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA);
			_context3D.setProgram(_shader);
			_context3D.setTextureAt(0, _texture);
 
			_context3D.setVertexBufferAt(0, _vbufA, 0, Context3DVertexBufferFormat.FLOAT_3);
			_context3D.setVertexBufferAt(1, _uvBufCube, 0, Context3DVertexBufferFormat.FLOAT_2);
			_context3D.drawTriangles(_ibufCube, 0, 12);
 
			_context3D.setVertexBufferAt(0, _vbufB, 0, Context3DVertexBufferFormat.FLOAT_3);
			_context3D.setVertexBufferAt(1, _uvBufCube, 0, Context3DVertexBufferFormat.FLOAT_2);
			_context3D.drawTriangles(_ibufCube, 0, 12);
 
 
			_context3D.drawToBitmapData(_bitmapData);
 
			_context3D.present();
 
 
		//	e.currentTarget.removeEventListener(e.type, arguments.callee);
		}
	}
}