Cel shading
I've recently come up for an idea for a game, but it requires cel shading to work. I know little about it, and I'm looking for a free engine that would support this technique.
Could anyone please tell me a bit about the process and the engines that I should be looking for?
The process of cel shading is extremely simple. Nehe has a tutorial on it and you can also find an implementation here. Instead of having the whole range of colors, you clamp your colors to a handful of toony-like colors, then figure out the closest toon color to the actual color for each point and shade with the toon color instead of the actual color. Typically, you also render the silhouette edges. There are a number of techniques for accomplishing this.
Thanks for the info :-D
Are there any engines that you might recommend that will make this possible/easier, or can you do it on pretty much any engine?
Are there any engines that you might recommend that will make this possible/easier, or can you do it on pretty much any engine?
Quote:Original post by golar
Are there any engines that you might recommend that will make this possible/easier, or can you do it on pretty much any engine?
Ogre! Take a look at the first two screenshots showing Cel Shading. The actual process of using it in Ogre is simply this.
1. Make your regular models and export them into Ogre's format.
2. The material file for the model in the demo looks like this:
// -------------------------------// Cel Shading Section// -------------------------------vertex_program Ogre/CelShadingVP cg{ source Example_CelShading.cg entry_point main_vp profiles vs_1_1 arbvp1 default_params { param_named_auto lightPosition light_position_object_space 0 param_named_auto eyePosition camera_position_object_space param_named_auto worldViewProj worldviewproj_matrix param_named shininess float 10 }}fragment_program Ogre/CelShadingFP cg{ source Example_CelShading.cg entry_point main_fp profiles ps_1_1 arbfp1 fp20}material Examples/CelShading{ technique { pass { vertex_program_ref Ogre/CelShadingVP { // map shininess from custom renderable param 1 param_named_auto shininess custom 1 } fragment_program_ref Ogre/CelShadingFP { // map diffuse from custom renderable param 2 param_named_auto diffuse custom 2 // map specular from custom renderable param 2 param_named_auto specular custom 3 } texture_unit { texture cel_shading_diffuse.png 1d tex_address_mode clamp filtering none } texture_unit { texture cel_shading_specular.png 1d tex_address_mode clamp filtering none tex_coord_set 1 } texture_unit { texture cel_shading_edge.png 1d tex_address_mode clamp filtering none tex_coord_set 2 } } } }
3. Make the .CG script for the actual shading
/* Cel shading vertex program for single-pass rendering In this program, we want to calculate the diffuse and specular ramp components, and the edge factor (for doing simple outlining) For the outlining to look good, we need a pretty well curved model.*/void main_vp(float4 position : POSITION, float3 normal : NORMAL, // outputs out float4 oPosition : POSITION, out float diffuse : TEXCOORD0, out float specular : TEXCOORD1, out float edge : TEXCOORD2, // parameters uniform float3 lightPosition, // object space uniform float3 eyePosition, // object space uniform float4 shininess, uniform float4x4 worldViewProj){ // calculate output position oPosition = mul(worldViewProj, position); // calculate light vector float3 N = normalize(normal); float3 L = normalize(lightPosition - position.xyz); // Calculate diffuse component diffuse = max(dot(N, L) , 0); // Calculate specular component float3 E = normalize(eyePosition - position.xyz); float3 H = normalize(L + E); specular = pow(max(dot(N, H), 0), shininess); // Mask off specular if diffuse is 0 if (diffuse == 0) specular = 0; // Edge detection, dot eye and normal vectors edge = max(dot(N, E), 0);}void main_fp(float diffuseIn : TEXCOORD0, float specularIn : TEXCOORD1, float edge : TEXCOORD2, out float4 colour : COLOR, uniform float4 diffuse, uniform float4 specular, uniform sampler1D diffuseRamp, uniform sampler1D specularRamp, uniform sampler1D edgeRamp){ // Step functions from textures diffuseIn = tex1D(diffuseRamp, diffuseIn).x; specularIn = tex1D(specularRamp, specularIn).x; edge = tex1D(edgeRamp, edge).x; colour = edge * ((diffuse * diffuseIn) + (specular * specularIn));}
Then I think that's about it really. You just load your model in and everything is parsed from the files and viola! Cel-Shaded models. Not that hard, but working with Ogre might take a bit to get used to how it works. Oh, and it's free [smile].
Check out FXComposer (from Nvidia), it has some edge detection/toon shading post processing effects which are quite easy to implement (using render to texture).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement