media @ VU
[] readme course preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthoughts appendix references examples resources _

#### phl-toon.phl

```
sampler2D image;

float pixel = 1.0f / 512.0f;

float4 main( float4 Pos : POSITION0,
float2 Tex : TEXCOORD0 ) : COLOR0
{
int i;
float4 color;
float s[8];
float fx, fy, fxy;

// fetch the original color
color = tex2D( image, Tex );

// fetch the color from neighbours
s[0] = dot(tex2D( image, Tex + float2(-pixel, -pixel) ), .33333f);
s[1] = dot(tex2D( image, Tex + float2( 0.0f,  -pixel) ), .33333f);
s[2] = dot(tex2D( image, Tex + float2( pixel, -pixel) ), .33333f);
s[3] = dot(tex2D( image, Tex + float2(-pixel,  0.0f ) ), .33333f);
s[4] = dot(tex2D( image, Tex + float2( pixel,  0.0f ) ), .33333f);
s[5] = dot(tex2D( image, Tex + float2(-pixel,  pixel) ), .33333f);
s[6] = dot(tex2D( image, Tex + float2( 0.0f,   pixel) ), .33333f);
s[7] = dot(tex2D( image, Tex + float2( pixel,  pixel) ), .33333f);

// compute the Sobel filter
fx = s[2] + s[7] + 2 * s[4] - s[0] - s[5] - 2 * s[3];
fy = s[5] + s[7] + 2 * s[6] - s[0] - s[2] - 2 * s[1];

// fxy = fx * fx + fy * fy;
fxy = abs(fx) + abs(fy);

if (fxy > 0.14)
color = 0.0f;

return color;
}```

[] readme course preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthoughts appendix references examples resources _

(C) A. Eliëns 9/8/2006

You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.