'Pixel Bender' 카테고리의 다른 글
Scketch Shader를 위한 PV3D 튜닝 (0) | 2008.10.07 |
---|---|
Flex와 Pixel Bender로 iChat 흉내내기 (0) | 2008.09.25 |
Human Detector! (2) | 2008.09.25 |
Sketch Shader (0) | 2008.09.18 |
Sobel Operation 의 간단한 응용 (0) | 2008.09.18 |
WRITTEN BY
Scketch Shader를 위한 PV3D 튜닝 (0) | 2008.10.07 |
---|---|
Flex와 Pixel Bender로 iChat 흉내내기 (0) | 2008.09.25 |
Human Detector! (2) | 2008.09.25 |
Sketch Shader (0) | 2008.09.18 |
Sobel Operation 의 간단한 응용 (0) | 2008.09.18 |
package org.papervision3d.materials.shadematerials
{
import fl.motion.Color;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.geom.Matrix;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.core.math.Number3D;
import org.papervision3d.core.proto.CameraObject3D;
import org.papervision3d.core.geom.renderables.Triangle3D;
import org.papervision3d.core.geom.renderables.Vertex3DInstance;
import org.papervision3d.core.material.AbstractSmoothShadeMaterial;
import org.papervision3d.core.math.Matrix3D;
import org.papervision3d.core.proto.LightObject3D;
import org.papervision3d.core.render.data.RenderSessionData;
import org.papervision3d.core.render.draw.ITriangleDrawer;
/**
* @Author Buzzler
*/
public class NormalMaterial extends AbstractSmoothShadeMaterial implements ITriangleDrawer
{
private static var x1:Number;
private static var x0:Number;
private static var x2:Number;
private static var y0:Number;
private static var y1:Number;
private static var y2:Number;
private var camera:CameraObject3D;
private var tmpN:Number3D;
private var tmpL:Number3D;
private var tmpR:uint;
private var tmpG:uint;
private var tmpB:uint;
private var tmpRGB:uint;
public function NormalMaterial(light:LightObject3D, camera:CameraObject3D)
{
super();
this.light = light;
this.camera = camera;
}
private static var useMap:BitmapData;
override public function drawTriangle(face3D:Triangle3D, graphics:Graphics, renderSessionData:RenderSessionData, altBitmap:BitmapData = null, altUV:Matrix = null):void
{
x0 = face3D.v0.vertex3DInstance.x;
y0 = face3D.v0.vertex3DInstance.y;
x1 = face3D.v1.vertex3DInstance.x;
y1 = face3D.v1.vertex3DInstance.y;
x2 = face3D.v2.vertex3DInstance.x;
y2 = face3D.v2.vertex3DInstance.y;
triMatrix.a = x1 - x0;
triMatrix.b = y1 - y0;
triMatrix.c = x2 - x0;
triMatrix.d = y2 - y0;
triMatrix.tx = x0;
triMatrix.ty = y0;
tmpN = face3D.faceNormal.clone();
tmpL = new Number3D(-light.x,-light.y,-light.z);
tmpR = uint((tmpN.x + 1.0) * 127.5);
tmpG = uint((tmpN.y + 1.0) * 127.5);
tmpB = uint((tmpN.z + 1.0) * 127.5);
tmpRGB = (tmpR << 16) | (tmpG << 8) | (tmpB);
graphics.beginFill(tmpRGB, brightness(tmpN, tmpL));
graphics.moveTo( x0, y0 );
graphics.lineTo( x1, y1 );
graphics.lineTo( x2, y2 );
graphics.lineTo( x0, y0 );
graphics.endFill();
renderSessionData.renderStatistics.shadedTriangles++;
}
private function brightness(n1:Number3D, n2:Number3D):Number
{
n1.normalize();
n2.normalize();
var result:Number = Math.acos(Number3D.dot(n1, n2)) - Math.PI / 2;
result = Math.max(result, 0) / (Math.PI / 2);
return 1 - result;
}
}
}
PixelBender Outline View (0) | 2008.11.05 |
---|---|
Flex와 Pixel Bender로 iChat 흉내내기 (0) | 2008.09.25 |
Human Detector! (2) | 2008.09.25 |
Sketch Shader (0) | 2008.09.18 |
Sobel Operation 의 간단한 응용 (0) | 2008.09.18 |
PixelBender Outline View (0) | 2008.11.05 |
---|---|
Scketch Shader를 위한 PV3D 튜닝 (0) | 2008.10.07 |
Human Detector! (2) | 2008.09.25 |
Sketch Shader (0) | 2008.09.18 |
Sobel Operation 의 간단한 응용 (0) | 2008.09.18 |
10분만에 대충 짜놓은거라 꼼꼼하게 살펴보진 말고 그냥 보자.<languageVersion : 1.0;>
kernel HumanDetect
< namespace : "buzzler";
vendor : "Mobsword Systems";
version : 1;
description : "your description";
>
{
input image4 bg;
input image4 mix;
output pixel4 dst;
const pixel4 mask = pixel4(0.0, 0.0, 0.0, 0.0);
void
evaluatePixel()
{
float2 coord = outCoord();
pixel4 pixel_bg = sampleNearest(bg, coord);
pixel4 pixel_mix = sampleNearest(mix, coord);
float r = abs(pixel_bg.r - pixel_mix.r);
float g = abs(pixel_bg.g - pixel_mix.g);
float b = abs(pixel_bg.b - pixel_mix.b);
float a = abs(pixel_bg.a - pixel_mix.a);
if ((r < 0.01)&&(g < 0.01)&&(b < 0.01)&&(a < 0.01))
dst = mask;
else
dst = pixel_mix;
}
}
PixelBender Outline View (0) | 2008.11.05 |
---|---|
Scketch Shader를 위한 PV3D 튜닝 (0) | 2008.10.07 |
Flex와 Pixel Bender로 iChat 흉내내기 (0) | 2008.09.25 |
Sketch Shader (0) | 2008.09.18 |
Sobel Operation 의 간단한 응용 (0) | 2008.09.18 |
texture image
PixelBender Outline View (0) | 2008.11.05 |
---|---|
Scketch Shader를 위한 PV3D 튜닝 (0) | 2008.10.07 |
Flex와 Pixel Bender로 iChat 흉내내기 (0) | 2008.09.25 |
Human Detector! (2) | 2008.09.25 |
Sobel Operation 의 간단한 응용 (0) | 2008.09.18 |
<languageVersion : 1.0;>
kernel SobelFilter
< namespace : "buzzler";
vendor : "Mobsword Systems";
version : 1;
description : "Sobel Operation";
>
{
input image4 src;
output pixel4 dst;
const pixel4 black = pixel4(0.0, 0.0, 0.0, 1.0);
const float low = 1.0;
const float high = 2.0;
const float p_width = 1.0;
void evaluatePixel()
{
float g, gx, gy;
float2 coord = outCoord();
pixel4 sampled;
float tone;
sampled = sampleLinear(src, float2(coord[0]-p_width , coord[1]-p_width));
tone = (sampled.r + sampled.g + sampled.b) / 3.0;
gx += low * tone;
gy += low * tone;
sampled = sampleLinear(src, float2(coord[0] , coord[1]-p_width));
tone = (sampled.r + sampled.g + sampled.b) / 3.0;
gy += high * tone;
sampled = sampleLinear(src, float2(coord[0]+p_width , coord[1]-p_width));
tone = (sampled.r + sampled.g + sampled.b) / 3.0;
gx -= low * tone;
gy += low * tone;
sampled = sampleLinear(src, float2(coord[0]-p_width , coord[1]));
tone = (sampled.r + sampled.g + sampled.b) / 3.0;
gx += high * tone;
sampled = sampleLinear(src, float2(coord[0]+p_width , coord[1]));
tone = (sampled.r + sampled.g + sampled.b) / 3.0;
gx -= high * tone;
sampled = sampleLinear(src, float2(coord[0]-p_width , coord[1]+p_width));
tone = (sampled.r + sampled.g + sampled.b) / 3.0;
gx += low * tone;
gy -= low * tone;
sampled = sampleLinear(src, float2(coord[0] , coord[1]+p_width));
tone = (sampled.r + sampled.g + sampled.b) / 3.0;
gy -= high * tone;
sampled = sampleLinear(src, float2(coord[0]+p_width , coord[1]+p_width));
tone = (sampled.r + sampled.g + sampled.b) / 3.0;
gx -= low * tone;
gy -= low * tone;
g = sqrt(pow(gx, 2.0) + pow(gy, 2.0));
dst = mix(sampled, black, g);
}
}
출력된 이미지 |
입력된 이미지 |
PixelBender Outline View (0) | 2008.11.05 |
---|---|
Scketch Shader를 위한 PV3D 튜닝 (0) | 2008.10.07 |
Flex와 Pixel Bender로 iChat 흉내내기 (0) | 2008.09.25 |
Human Detector! (2) | 2008.09.25 |
Sketch Shader (0) | 2008.09.18 |