Programming models and shaders II
I was interested (as many other people before me)...in obtaining a good cartoon shader. The best one "in the market" according to my previous experience so far has been Tomcat cartoon shader. I wanted to be able to obtain a shader that would in any way be close in results to what the tomcat cartoon shader can offer.
The cartoon shaders (according to the customary explanation on them..) have an outline and the shading is leveled.
The outline would be uninteresting if it was just a clean line that just goes around the shapes, so there must be a way to make the "brush stroke" more diverse, but also make it easy for the user to controll. so what is necessary is some kind of a locator that could help in the positioning the width of the brush stroke along the object.
One practical way is using "special " lights that can be used not for lighting on the scene, but for control of the thickness of the outline.
Well, there is a certain loop similar to the gather loop and it is the illuminance loop, and it is gathering information about the lights in the scene, around the object that has the certain shader. And the lightsource () command which is asking about some attributes in the light that is selected in the illuminance loop.
That is where output attributes can be handy. If the light has a certain attribute (in my case it is the attribute whether it is a light for lighting or light for outline controll), then according to that information my shader creates the bump on the outline.
illuminance(P,nf,PI/2){
float useForEdge = 0;
if(lightsource("useForEdge", useForEdge) == 1)
{
if(useForEdge == 1)
{
float bumpiness=1;
lightsource("bumpiness", bumpiness);
df+=Cl*normalize(L).nf*bumpiness;
}
else
cl += Cl * normalize(L).nf;
}
else
cl += Cl * normalize(L).nf;
}
this means that if the light that is illuminating my shader has an useForEdge attribute and it is specifficaly set to 1 which means that it is to be used for the outline then, the edge will be affected according to the value of thelight and the position of the light, (it is like painting the stroke with the light), if not then the outline will be computed as it would be normaly, as the dot product of the incident vector and the normals of the surface, because the outline is going to be drawn in the micropoligons that are perpendicular to the camera.
The level of control on my shader is the minwidth and maxwidth attributes (which need to be closer in value if a rough edge is needed, and minwidth needs to be lower in value than maxwidth for a smooth edge).
this is an example with minwidht and maxwidht with the value of 0.25.
and for smoothness minwidht=0.1, maxwidht=3.5
The effect of the edgelights in the scene is controlled with the bumpiness attribute of the edgelights themselves.
two edgelights with different values of the bumpiness..
This edge shader has also the possibility of applying a texture, so it could be an additional level of control fof the shape of the edge.
And just because of the fact that the edginess factor (which is a float that defines where the edge is) is in the output variables of the shader, the edge could be rendered in a seperate pass and be manipulated in shake.
And another element on my toon shader is the shader that just levels out the luminance (diffuse and ambient of the object) and uses that leveled information to position the layers of color.
And relative to the value of the step size (attributte called cekor)(the lower it is the more leveling there is)
and here is a picture with both