MetaDiamond

Metaball everyinch 3100℃ 0评论

MetaDiamond类似于Metaball,只不过使用了不同的公式:

PixelBender滤镜代码:

<languageVersion : 1.0;>

kernel MetaDiamonds
<namespace : "MetaDiamonds";
vendor : "Chen Tong";
version : 1;
description : "Fast Metaballs";
>
{
parameter float minThreshold
<
minValue:float(0.0);
maxValue:float(2.0);
defaultValue:float(5.0);
description: "minThreshold";
>;

parameter float3 ball1
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(50.0,50.0,20.0);
description: "ball1, params, x,y,radius";
>;

parameter float3 ball2
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(100.0,100.0,20.0);
description: "ball2, params, x,y,radius";
>;

parameter float3 ball3
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(100.0,100.0,20.0);
description: "ball3, params, x,y,radius";
>;

parameter float3 ball4
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(100.0,100.0,20.0);
description: "ball4, params, x,y,radius";
>;

parameter float3 ball5
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(100.0,100.0,20.0);
description: "ball5, params, x,y,radius";
>;

parameter float3 ball6
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(100.0,100.0,20.0);
description: "ball6, params, x,y,radius";
>;

parameter float3 ball7
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(100.0,100.0,20.0);
description: "ball7, params, x,y,radius";
>;

parameter float3 ball8
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(100.0,100.0,20.0);
description: "ball8, params, x,y,radius";
>;

parameter float3 ball9
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(100.0,100.0,20.0);
description: "ball9, params, x,y,radius";
>;

parameter float3 ball10
<
minValue:float3(0.0,0.0,0.0);
maxValue:float3(640.0,480.0,50.0);
defaultValue:float3(100.0,100.0,20.0);
description: "ball10, params, x,y,radius";
>;

  input image4 src;
  output pixel4 dst;

  void evaluatePixel(){
    dst = sampleNearest(src,outCoord());
    dst.rbg = float3(0,0,0);
    float2 coord = outCoord();
    float sum = 0.0;
    sum += (ball1.z)/(abs(ball1.x-coord.x)+abs(ball1.y-coord.y));
    sum += (ball2.z)/(abs(ball2.x-coord.x)+abs(ball2.y-coord.y));
    sum += (ball3.z)/(abs(ball3.x-coord.x)+abs(ball3.y-coord.y));
    sum += (ball4.z)/(abs(ball4.x-coord.x)+abs(ball4.y-coord.y));
    sum += (ball5.z)/(abs(ball5.x-coord.x)+abs(ball5.y-coord.y));
    sum += (ball6.z)/(abs(ball6.x-coord.x)+abs(ball6.y-coord.y));
    sum += (ball7.z)/(abs(ball7.x-coord.x)+abs(ball7.y-coord.y));
    sum += (ball8.z)/(abs(ball8.x-coord.x)+abs(ball8.y-coord.y));
    sum += (ball9.z)/(abs(ball9.x-coord.x)+abs(ball9.y-coord.y));
    sum += (ball10.z)/(abs(ball10.x-coord.x)+abs(ball10.y-coord.y));
    if(sum >= minThreshold){
        dst.rgb = float3(255,255,255);
    }
  }
}

测试代码类PixelBenderManyMetaDiamonds:
package{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Stage;
import flash.display.Shader;
import flash.display.ShaderPrecision;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.filters.ShaderFilter;
import flash.utils.ByteArray;

[SWF(width=640, height=480)]
public class PixelBenderManyMetaDiamonds extends Sprite{
[Embed(source=’assets/MetaDiamond10.pbj’, mimeType=’application/octet-stream’)]
private static const MetaballsFilter:Class;

private var bmp:Bitmap;
private var bmpd:BitmapData=new BitmapData(640, 480, false, 0);
private var blur:BlurFilter=new BlurFilter(10, 10, 1);
private var metaballsFilter:ShaderFilter;
private var balls:Array = [];
private var numbers:int=10;

public function PixelBenderManyMetaDiamonds(){
bmp=new Bitmap(bmpd);
bmp.smoothing=true;
addChild(bmp);

var ba:ByteArray=new MetaballsFilter() as ByteArray;
var s:Shader=new Shader(ba);
metaballsFilter=new ShaderFilter(s);
metaballsFilter.shader.data.src.image=bmpd;

metaballsFilter.shader.data.minThreshold.value = [20.0];

for(var i:int=0;i

分享&收藏

转载请注明:陈童的博客 » MetaDiamond

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
'; } if( dopt('d_footcode_b') ) echo dopt('d_footcode'); ?>