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-toon2.phl

```
// Sobel Edge Detector based from ATI Video shader
float sampleDist = 1.0f/512.0f;  // distance one pixel in u/v

sampler2D image : register(s0);

static const float2 offsets[8] =
{
-1, -1,
0, -1,
1, -1,

-1,  0,
// 0,  0, // no center pixel
1,  0,

-1,  1,
0,  1,
1,  1,
};

float4 main(
float4 Pos : POSITION,
float2 texCoord: TEXCOORD0) : COLOR
{

int i =0;
float4 c = .5;
float2 texCoords;
float4 texSamples[8];
float4 color;

color = tex2D( image, texCoord );

for(i =0; i < 8; i++)
{
texCoords = texCoord + sampleDist * offsets[i];    // add sample offsets stored in c10-c17 (inclusive)
// take sample
texSamples[i] =  tex2D( image, texCoords);

//  convert to b&w
texSamples[i] = dot(texSamples[i], .333333f);
}
vertGradient = -(texSamples[0] + texSamples[5] + 2*texSamples[3]);
vertGradient += (texSamples[2] + texSamples[7] + 2*texSamples[4]);

horzGradient = -(texSamples[0] + texSamples[2] + 2*texSamples[1]);
horzGradient += (texSamples[5] + texSamples[7] + 2*texSamples[6]);

// we could approximate by adding the abs value..but we have the horse power

if ( c.r > 0.4f )
color = c;
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.