forked from: Pixel Bender (液晶ディスプレイ風フィルタ)
forked from Pixel Bender (液晶ディスプレイ風フィルタ) (diff: 1)
------------------------------------------------- 液晶ディスプレイ風フィルタ FULL SCREEN 表示にしてブラウザのサイズを変えても Flash スクリーンのライン表示が維持されている事が確認できます。 -------------------------------------------------
ActionScript3 source code
/**
* Copyright late4 ( http://wonderfl.net/user/late4 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/bMuf
*/
// forked from hakuhin's Pixel Bender (液晶ディスプレイ風フィルタ)
// -------------------------------------------------
//
// 液晶ディスプレイ風フィルタ
//
//
// FULL SCREEN 表示にしてブラウザのサイズを変えても
// Flash スクリーンのライン表示が維持されている事が確認できます。
//
// -------------------------------------------------
package {
import flash.events.*;
import flash.display.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
import flash.system.*;
import flash.geom.*;
import flash.filters.*;
import flash.ui.*;
import flash.media.*;
public class Main extends Sprite {
public function Main() {
// -------------------------------------------------
// コンストラクタ
// -------------------------------------------------
// 100%表示
stage.scaleMode = StageScaleMode.NO_SCALE;
// 左上
stage.align = StageAlign.TOP_LEFT;
stage.align = "TL";
// ビデオを配置
var video_obj : Video = new Video();
addChild(video_obj);
// ストリーム
var connection:NetConnection = new NetConnection();
connection.connect(null);
var netStream:NetStream = new NetStream(connection);
// ビデオとストリームを関連付け
video_obj.attachNetStream(netStream);
// メタデータ取得
var obj:Object = new Object();
obj.onMetaData = function(param:Object):void{
}
netStream.client = obj;
// リソース読み込み開始
load();
// -------------------------------------------------
// 読み込み
// -------------------------------------------------
function load():void{
// 動画のURL
var movie_url:String = "http://actionscript.web.officelive.com/wonderfl/movie000.mp4";
// サウンドをOFF
var trans : SoundTransform = netStream.soundTransform;
trans.volume = 0.0;
netStream.soundTransform = trans;
// 再生開始
netStream.play(movie_url);
// 初期化へ
init();
}
// -------------------------------------------------
// 初期化
// -------------------------------------------------
function init():void{
// ステージサイズ
var w:uint;
var h:uint;
// リサイズ時にフィット
stage.addEventListener(Event.RESIZE,ResizeFunc);
function ResizeFunc(e:Event):void{
w = stage.stageWidth;
h = stage.stageHeight;
video_obj.width = w;
video_obj.height = h;
}
ResizeFunc(null);
// シェーダバイトコード
var binary : ByteArray = CustomFilterGetByteArray();
// シェーダ作成
var shader:Shader = new Shader();
shader.byteCode = binary;
var filter:ShaderFilter = new ShaderFilter(shader);
// パラメータアクセス用
var data : ShaderData = shader.data;
var param : ShaderParameter;
// パラメータ
var width:Number = 4; // ドットの幅
var height:Number = 4; // ドットの高さ
var interval_h:Number = 1; // 水平方向のドット間隔
var interval_v:Number = 1; // 垂直方向のドット間隔
var bits_per_pixel:Number = 4; // 色深度
addEventListener(Event.ENTER_FRAME,function(e:Event):void{
// ドットの幅
param = data.width;
param.value = [width];
// ドットの高さ
param = data.height;
param.value = [height];
// 水平方向のドット間隔
param = data.interval_h;
param.value = [interval_h];
// 垂直方向のドット間隔
param = data.interval_v;
param.value = [interval_v];
// 色深度
param = data.bits_per_pixel;
param.value = [bits_per_pixel];
// 適応
video_obj.filters = [filter];
});
// テキスト表示
var tf : TextField = new TextField();
tf.x = 5;
tf.y = 5;
tf.width = 300;
tf.height = 70;
tf.border = true;
tf.background = true;
tf.alpha = 0.9;
// 書式
var format : TextFormat = new TextFormat();
format.font = "MS ゴシック";
tf.defaultTextFormat = format;
addChild(tf);
addEventListener(Event.ENTER_FRAME,function(e:Event):void{
var str:String = "";
str += "ドットの幅 :" + width + " (上下キーで変更)\n";
str += "ドットの高さ :" + height + " (左右キーで変更)\n";
str += "水平方向のドット間隔:" + interval_h + " (1,2キーで変更)\n";
str += "垂直方向のドット間隔:" + interval_v + " (3,4キーで変更)\n";
str += "色深度 :" + bits_per_pixel + " (5,6キーで変更)\n";
tf.text = str;
});
// キー操作
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown);
function KeyDown(event:KeyboardEvent):void{
if(event.keyCode == Keyboard.UP) height -= 1;
if(event.keyCode == Keyboard.DOWN) height += 1;
if(event.keyCode == Keyboard.LEFT) width -= 1;
if(event.keyCode == Keyboard.RIGHT) width += 1;
if(event.keyCode == 49) interval_h -= 1;
if(event.keyCode == 50) interval_h += 1;
if(event.keyCode == 51) interval_v -= 1;
if(event.keyCode == 52) interval_v += 1;
if(event.keyCode == 53) bits_per_pixel -= 1;
if(event.keyCode == 54) bits_per_pixel += 1;
if(width < 1) width = 1;
if(height < 1) height = 1;
if(interval_h < 0) interval_h = 0;
if(interval_v < 0) interval_v = 0;
if(bits_per_pixel < 1) bits_per_pixel = 1;
if(bits_per_pixel > 255) bits_per_pixel = 255;
};
}
// -------------------------------------------------
// シェーダバイトコード
// -------------------------------------------------
function CustomFilterGetByteArray():ByteArray{
var a:ByteArray = new ByteArray();
var f:Function;
f = a.writeUnsignedInt;
f(0xa5010000); f(0x00a41300); f(0x5363616c); f(0x65576176);
f(0x654c696e); f(0x6546696c); f(0x746572a0); f(0x0c6e616d);
f(0x65737061); f(0x63650073); f(0x63616c65); f(0x20776176);
f(0x65206c69); f(0x6e6500a0); f(0x0c76656e); f(0x646f7200);
f(0x48616b75); f(0x68696e00); f(0xa0087665); f(0x7273696f);
f(0x6e000100); f(0xa00c6465); f(0x73637269); f(0x7074696f);
f(0x6e0090fc); f(0x8ff382c9); f(0x83548343); f(0x8393834a);
f(0x815b8375); f(0x82c5904c); f(0x8f6b82b7); f(0x82e98374);
f(0x8342838b); f(0x835e00a1); f(0x01020000); f(0x0c5f4f75);
f(0x74436f6f); f(0x726400a3); f(0x00047372); f(0x6300a102);
f(0x0401000f); f(0x64737400); f(0xa1010100); f(0x00027769);
f(0x64746800); f(0xa2016d69); f(0x6e56616c); f(0x7565003f);
f(0x800000a2); f(0x01646566); f(0x61756c74); f(0x56616c75);
f(0x65004040); f(0x0000a20c); f(0x64657363); f(0x72697074);
f(0x696f6e00); f(0x83688362); f(0x836782cc); f(0x959d00a1);
f(0x01010000); f(0x01686569); f(0x67687400); f(0xa2016d69);
f(0x6e56616c); f(0x7565003f); f(0x800000a2); f(0x01646566);
f(0x61756c74); f(0x56616c75); f(0x65004040); f(0x0000a20c);
f(0x64657363); f(0x72697074); f(0x696f6e00); f(0x83688362);
f(0x836782cc); f(0x8d8282b3); f(0x00a10101); f(0x02000869);
f(0x6e746572); f(0x76616c5f); f(0x6800a201); f(0x6d696e56);
f(0x616c7565); f(0x00000000); f(0x00a20164); f(0x65666175);
f(0x6c745661); f(0x6c756500); f(0x3f800000); f(0xa20c6465);
f(0x73637269); f(0x7074696f); f(0x6e009085); f(0x95bd95fb);
f(0x8cfc82cc); f(0x83688362); f(0x83678ad4); f(0x8a7500a1);
f(0x01010200); f(0x04696e74); f(0x65727661); f(0x6c5f7600);
f(0xa2016d69); f(0x6e56616c); f(0x75650000); f(0x000000a2);
f(0x01646566); f(0x61756c74); f(0x56616c75); f(0x65003f80);
f(0x0000a20c); f(0x64657363); f(0x72697074); f(0x696f6e00);
f(0x908292bc); f(0x95fb8cfc); f(0x82cc8368); f(0x83628367);
f(0x8ad48a75); f(0x00a10104); f(0x03000f69); f(0x6e746572);
f(0x76616c5f); f(0x636f6c6f); f(0x7200a204); f(0x64656661);
f(0x756c7456); f(0x616c7565); f(0x00000000); f(0x00000000);
f(0x00000000); f(0x003f8000); f(0x00a20c64); f(0x65736372);
f(0x69707469); f(0x6f6e0083); f(0x68836283); f(0x678ad48a);
f(0x7582cc90); f(0x4600a101); f(0x01020002); f(0x62697473);
f(0x5f706572); f(0x5f706978); f(0x656c00a2); f(0x016d696e);
f(0x56616c75); f(0x65003f80); f(0x0000a201); f(0x6d617856);
f(0x616c7565); f(0x00438000); f(0x00a20164); f(0x65666175);
f(0x6c745661); f(0x6c756500); f(0x43800000); f(0xa20c6465);
f(0x73637269); f(0x7074696f); f(0x6e009046); f(0x905b9378);
f(0x001d0400); f(0xc1000010); f(0x001d0200); f(0x10000080);
f(0x00010200); f(0x10020000); f(0x001d0400); f(0x200200c0);
f(0x00040200); f(0x10040080); f(0x00030200); f(0x10040000);
f(0x001a0400); f(0x100200c0); f(0x001d0200); f(0x100400c0);
f(0x001d0400); f(0x100200c0); f(0x00030400); f(0x10040080);
f(0x001d0500); f(0x80040000); f(0x00020500); f(0x800400c0);
f(0x001d0400); f(0x10050000); f(0x001d0500); f(0x800200c0);
f(0x00030500); f(0x80040080); f(0x001d0500); f(0x40050000);
f(0x00010500); f(0x40020000); f(0x001d0400); f(0x80050040);
f(0x001d0500); f(0x800000c0); f(0x00010500); f(0x80020040);
f(0x001d0400); f(0x20050000); f(0x00040500); f(0x80040080);
f(0x00030500); f(0x80040040); f(0x001a0500); f(0x40050000);
f(0x001d0500); f(0x80050040); f(0x001d0500); f(0x40050000);
f(0x00030500); f(0x40040080); f(0x001d0500); f(0x20040040);
f(0x00020500); f(0x20050040); f(0x001d0500); f(0x40050080);
f(0x001d0500); f(0x20050000); f(0x00030500); f(0x20040080);
f(0x001d0500); f(0x10050080); f(0x00010500); f(0x10020040);
f(0x001d0400); f(0x400500c0); f(0x002a0400); f(0x10020000);
f(0x001d0180); f(0x80008000); f(0x00340000); f(0x00018000);
f(0x001d0100); f(0xf303001b); f(0x00350000); f(0x00000000);
f(0x002a0500); f(0x40020040); f(0x001d0180); f(0x40008000);
f(0x00340000); f(0x00018040); f(0x001d0100); f(0xf303001b);
f(0x00350000); f(0x00000000); f(0x00300600); f(0xf1040010);
f(0x001d0700); f(0xf306001b); f(0x00320500); f(0x203f8000);
f(0x001d0500); f(0x10020080); f(0x00020500); f(0x10050080);
f(0x001d0500); f(0x200500c0); f(0x00320500); f(0x103f8000);
f(0x001d0600); f(0x80070000); f(0x00030600); f(0x800500c0);
f(0x001d0500); f(0x10060000); f(0x00030500); f(0x10020080);
f(0x001a0600); f(0x800500c0); f(0x00040500); f(0x10050080);
f(0x00030500); f(0x10060000); f(0x001d0700); f(0x800500c0);
f(0x00320500); f(0x103f8000); f(0x001d0600); f(0x80070040);
f(0x00030600); f(0x800500c0); f(0x001d0500); f(0x10060000);
f(0x00030500); f(0x10020080); f(0x001a0600); f(0x800500c0);
f(0x00040500); f(0x10050080); f(0x00030500); f(0x10060000);
f(0x001d0700); f(0x400500c0); f(0x00320500); f(0x103f8000);
f(0x001d0600); f(0x80070080); f(0x00030600); f(0x800500c0);
f(0x001d0500); f(0x10060000); f(0x00030500); f(0x10020080);
f(0x001a0600); f(0x800500c0); f(0x00040500); f(0x10050080);
f(0x00030500); f(0x10060000); f(0x001d0700); f(0x200500c0);
f(0x00320500); f(0x103f8000); f(0x001d0600); f(0x800700c0);
f(0x00030600); f(0x800500c0); f(0x001d0500); f(0x10060000);
f(0x00030500); f(0x10020080); f(0x001a0600); f(0x800500c0);
f(0x00040500); f(0x10050080); f(0x00030500); f(0x10060000);
f(0x001d0700); f(0x100500c0); f(0x001d0100); f(0xf307001b);
f(0x00360000); f(0x00000000); f(0x00360000); f(0x00000000);
f = a.writeByte;
f(0x00);
return a;
}
}
}
}
// ↓ pbk ファイルのコード
/* -----------------------------------------------------------------------------
パラメータ
width ドットの幅
height ドットの高さ
interval_h 水平方向のドット間隔
interval_v 垂直方向のドット間隔
interval_color ドット間隔の色
bits_per_pixel 色深度
----------------------------------------------------------------------------- */
/*
<languageVersion : 1.0;>
kernel ScaleWaveLineFilter<
namespace : "scale wave line";
vendor : "Hakuhin";
version : 1;
description : "線状にサインカーブで伸縮するフィルタ";
>{
input image4 src; // 入力イメージ
output pixel4 dst; // 出力ピクセル
// -------------------------------------
// パラメータ
// -------------------------------------
parameter float width<
minValue:float(1.0);
defaultValue:float(3.0);
description : "ドットの幅";
>;
parameter float height<
minValue:float(1.0);
defaultValue:float(3.0);
description : "ドットの高さ";
>;
parameter float interval_h<
minValue:float(0.0);
defaultValue:float(1.0);
description : "水平方向のドット間隔";
>;
parameter float interval_v<
minValue:float(0.0);
defaultValue:float(1.0);
description : "垂直方向のドット間隔";
>;
parameter pixel4 interval_color<
defaultValue:pixel4(0,0,0,1);
description : "ドット間隔の色";
>;
parameter float bits_per_pixel<
minValue:float(1);
maxValue:float(256);
defaultValue:float(256);
description : "色深度";
>;
// -------------------------------------
// ピクセルごとに実行される関数
// -------------------------------------
void evaluatePixel(){
// ピクセルの位置を取得
float2 pos = outCoord();
// 水平方向の位置を周期に丸める
float length = width + interval_h;
float x = floor(pos.x / length);
float h = pos.x - (x * length);
pos.x = x * length + interval_h;
// 垂直方向の位置を周期に丸める
length = height + interval_v;
float y = floor(pos.y / length);
float v = pos.y - (y * length);
pos.y = y * length + interval_v;
if(h < interval_h){
// ドット間隔の色を出力
dst = interval_color;
}else if(v < interval_v){
// ドット間隔の色を出力
dst = interval_color;
}else{
// 左上の1ドットを表示
pixel4 color = sampleNearest(src,pos);
float d = bits_per_pixel - 1.0;
color[0] = floor(color[0] * 0.9999999999999999*bits_per_pixel) / d;
color[1] = floor(color[1] * 0.9999999999999999*bits_per_pixel) / d;
color[2] = floor(color[2] * 0.9999999999999999*bits_per_pixel) / d;
color[3] = floor(color[3] * 0.9999999999999999*bits_per_pixel) / d;
dst = color;
}
}
}
*/
