topical media & game development

talk show tell print

Web3D/VR

shader(s) -- cartoon

cartoon



  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;
  }
  


(C) Æliens 20/08/2009

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.