CELL SHADIG? (2D filter)

there is a 2d filter for cell shading in BGE?

There are the Toon shaders in the material settings. As far as a 2D filter, Blender does not have a built in cell shading filter. One can be made with a custom 2D filter. I have not seen cell shading done as a post process effect before, and I am not sure what benefits it would bring compared to doing it in the material shader.

for outline
duplicate your mesh
give it a black shadeless material
select all faces then alt + s in edit mode and scale mesh a little bit
invert the directions the normals of object
check backface culling

MAN1.blend (975 KB)

here’s an example

Theres the duplicate mesh example likee Kashi$h suggested and it is used quite frequently I think. I think the problem people run into with that method is that your polycount doubles. And as Kupoman said, there are a number of filters out there. This one has given me the best results of the ones ive tried and hasnt chewed up performance.


(The Cell shading looks a little better if you click the pic to enlarge), and I dont have the materials set right for toon shading either which is why the boots are shiny, its just the filter. With the filter and right material setup you could come up with something real nice I think.

I dont know who the author is to give credit to, but I know I found it here on BA somewhere back in the depths. Heres the whole code


 uniform sampler2D bgl_RenderedTexture;
    uniform sampler2D bgl_DepthTexture;
    void main()
    {
       float depth = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy).r;
       float depth2 = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy + vec2(0,0.002)).r;
       float depth3 = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy + vec2(0.002,0)).r;
       
       float fac = abs(depth-depth2) + abs(depth-depth3);
       
       float intensity = 1000;
       vec4 sub = vec4(fac*intensity,fac*intensity,fac*intensity,0);
       
       gl_FragColor = texture2D( bgl_RenderedTexture, gl_TexCoord[0].xy ) - sub;
    }
    
    
    
    #CHANGE FLOAT INTENSITY FOR LINE THICKNESS



Its short and simple…just paste that in your text editor and point a custom2d filter actuator to that text file

Thanks superflip, thats a really great filter.
Is it possible to apply it only one some objects and not on the whole scene?

HO THX for the 2d filter but this is like a really compact ssao, but good:yes:

I get error on line 1 bgl_RenderedTexture;

cool,
this work without error (last line)


uniform sampler2D bgl_RenderedTexture;
uniform sampler2D bgl_DepthTexture;
void main()
{
   float depth = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy).r;
   float depth2 = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy + vec2(0,0.002)).r;
   float depth3 = texture2D( bgl_DepthTexture, gl_TexCoord[0].xy + vec2(0.002,0)).r;
   
   float fac = abs(depth-depth2) + abs(depth-depth3);
   
   float intensity = 1000;
   vec4 sub = vec4( fac*intensity,  fac*intensity,  fac*intensity, 0);
   
   gl_FragColor = texture2D( bgl_RenderedTexture, gl_TexCoord[0].xy ) - sub;
}




//CHANGE FLOAT INTENSITY FOR LINE THICKNESS

i not know if is C, but is not python for sure :wink:

ok thanks :smiley: regarding toon shading found this on shadertoy.

https://www.shadertoy.com/view/4slSWf

could you use the cartoon edges part? I wonder how much of the webgl shaders you can translate to OpenGL SL they gotta be close, or the exact same.

wow this shader seems awesome, and doesn’t just do outline but can edge detect front geometry.
gonna try and pick out the code for the shader only and see if I can piece it up to a 2d custom filter.

https://www.shadertoy.com/view/4s23WV

This is a great filter, but can you change the edges color?