MetaDonut

Metaball everyinch 3449℃ 0评论

MetaDonut使用的公式如下:

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(5.0);
defaultValue:float(3.0);
description: "minThreshold";
>;

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


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

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

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

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

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

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

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

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

parameter float4 ball10
<
minValue:float4(0.0,0.0,0.0,0.0);
maxValue:float4(640.0,480.0,100.0,100.0);
defaultValue:float4(50.0,50.0,50.0,50.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.w - sqrt( (ball1.x-coord.x)*(ball1.x-coord.x) + (ball1.y-coord.y)*(ball1.y-coord.y) )));
    sum += ball2.z / (abs(ball2.w - sqrt( (ball2.x-coord.x)*(ball2.x-coord.x) + (ball2.y-coord.y)*(ball2.y-coord.y) )));
    sum += ball3.z / (abs(ball3.w - sqrt( (ball3.x-coord.x)*(ball3.x-coord.x) + (ball3.y-coord.y)*(ball3.y-coord.y) )));
    sum += ball4.z / (abs(ball4.w - sqrt( (ball4.x-coord.x)*(ball4.x-coord.x) + (ball4.y-coord.y)*(ball4.y-coord.y) )));
    sum += ball5.z / (abs(ball5.w - sqrt( (ball5.x-coord.x)*(ball5.x-coord.x) + (ball5.y-coord.y)*(ball5.y-coord.y) )));
    sum += ball6.z / (abs(ball6.w - sqrt( (ball6.x-coord.x)*(ball6.x-coord.x) + (ball6.y-coord.y)*(ball6.y-coord.y) )));
    sum += ball7.z / (abs(ball7.w - sqrt( (ball7.x-coord.x)*(ball7.x-coord.x) + (ball7.y-coord.y)*(ball7.y-coord.y) )));
    sum += ball8.z / (abs(ball8.w - sqrt( (ball8.x-coord.x)*(ball8.x-coord.x) + (ball8.y-coord.y)*(ball8.y-coord.y) )));
    sum += ball9.z / (abs(ball9.w - sqrt( (ball9.x-coord.x)*(ball9.x-coord.x) + (ball9.y-coord.y)*(ball9.y-coord.y) )));
    sum += ball10.z / (abs(ball10.w - sqrt( (ball10.x-coord.x)*(ball10.x-coord.x) + (ball10.y-coord.y)*(ball10.y-coord.y) )));
    if(sum >= minThreshold){
        dst.rgb = float3(100,75,96);
    }
  }
}

AS类PixelBenderManyMetaDonuts
package{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Shader;
import flash.display.ShaderPrecision;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.filters.ShaderFilter;
import flash.utils.ByteArray;

[SWF(width=640, height=480)]
public class PixelBenderManyMetaDonuts extends Sprite{
[Embed(source=’assets/MetaDonut10.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;
private var w:Array = [];

public function PixelBenderManyMetaDonuts(){
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

分享&收藏

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

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

表情

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

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