ピクセルベンダーを使用した場合の簡単な効果を次に示します。
実際、
Andre Michelleでそのような効果を最初に見ましたが、彼はSorsを投稿しませんでした。 当時、私は8番目のプレーヤー(AS2)でそれを書きましたが、新しい機能のリリースに伴い、実験を繰り返すことにしました。 冒険がないわけではありませんが、コードはレーキなしで判明しました。レーキは8つで構築する必要がありました。
こちらをご覧ください 。 (5 mb)
書き込みフィルター
変数:
src-最初の入力画像
src2-2番目の入力画像
白-白い色
黒-黒の色
min-出力画像に白または黒を入れることを決定する値
フィルターロジックは次のとおりです。
-(a1)最初の画像の最初のピクセルの色を取得します
-(a2)2番目の画像の最初のピクセルの色を取得する
-(ss)a1 a2から減算
-各色の差ssがminよりも大きい場合、出力画像では最初のピクセルの代わりに白、そうでない場合は黒になります
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
<languageVersion : 1.0;> kernel NewFilter < namespace : "Your Namespace" ; vendor : "Your Vendor" ; version : 1; description : "your description" ; > { input image4 src; input image4 src2; output pixel4 dst; const pixel4 white = float4(1.0, 1.0, 1.0, 1.0); const pixel4 black = float4(0.0, 0.0, 0.0, 0.0); const float min = 0.05; void evaluatePixel() { pixel4 a1 = sampleNearest(src, outCoord()); pixel4 a2 = sampleNearest(src2, outCoord()); pixel4 ss = a1 - a2; dst = (ss.r>min && ss.g>min && ss.b>min) ? white : black; } } * This source code was highlighted with Source Code Highlighter .
プログラムを書く
コードを読むことで問題が生じることはありません。いくつかのことだけを説明します。
bmp1-最新フレームのビデオクリップのインプリント
bmp2-bmp1のフィンガープリント、つまり最新の前のフレーム
bmp3-PixelBenderフィルターを適用した後の結果の画像
cmf-すべてのピクセルから10ピクセルからアルファを減算するフィルター
out-私たちが見る画像、bmp3はすべてのフレームに重ねられ、cmfとblurフィルターも
- パッケージ{
- import flash.display.Bitmap;
- import flash.display.BitmapData;
- import flash.display.Shader;
- import flash.display.ShaderJob;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.filters.BlurFilter;
- import flash.filters.ColorMatrixFilter;
- import flash.geom.Point;
- import flash.media.Video;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.utils.ByteArray;
- [SWF(幅= 376、高さ= 160、backgroundColor = 0x0)]
- パブリック クラス SubstractTvはSpriteを拡張します{
- [埋め込み(ソース= "../assets/kutu.pbj"、mimeType = "application / octet-stream" )]
- private var pbj:クラス。
- private var wid: uint = stage.stageWidth;
- private var hei: uint = stage.stageHeight;
- private var video:ビデオ。
- private var nc:NetConnection;
- private var ns:NetStream;
- private var bmp1:BitmapData;
- private var bmp2:BitmapData;
- private var bmp3:BitmapData;
- private var out :BitmapData;
- private var bmp:ビットマップ。
- private var shader:シェーダー;
- private var shaderJob:ShaderJob;
- private var blur:BlurFilter;
- private var cmf:ColorMatrixFilter;
- パブリック 関数 SubstractTv(){
- nc = 新しい NetConnection();
- nc.connect( null );
- ns = 新しい NetStream(nc);
- ns.client = new Object();
- ns.play( "video.f4v" );
- video = new Video(wid、hei);
- video.attachNetStream(ns);
- bmp1 = 新しい BitmapData(wid、hei、 true );
- bmp2 = bmp1.clone();
- bmp3 = bmp1.clone();
- out = bmp1.clone();
- bmp = new Bitmap( out 、 "auto" 、 true );
- addChild(bmp);
- shader = new Shader( new pbj() as ByteArray);
- shader.data.src.input = bmp1;
- shader.data.src2.input = bmp2;
- createShaderJob();
- addEventListener(Event.ENTER_FRAME、onEnterFrame);
- blur = 新しい BlurFilter(3、3、3);
- cmf = 新しい ColorMatrixFilter([1、0、0、0、0、0
- 0、1、0、0、0、
- 0、0、1、0、0、
- 0、0、0、1、-10]);
- }
- プライベート 関数 onEnterFrame(e:Event): void {
- if (shaderJob.progress!= 1) return ;
- bmp2.draw(bmp1);
- {
- bmp1.draw(ビデオ);
- } catch (e:エラー){}
- createShaderJob();
- out .applyFilter( out 、 out .rect、 new Point()、blur);
- out .applyFilter( out 、 out .rect、 new Point()、cmf);
- out .draw(bmp3);
- }
- プライベート 関数 createShaderJob(): void {
- shaderJob = 新しい ShaderJob(shader、bmp3、wid、hei);
- shaderJob.start();
- }
- }
- }
*このソースコードは、 ソースコードハイライターで強調表示されました。