Enhanced CelShading        

Changes

  • April 21 - Fixed: program only worked under OpenGL. Link to forum thread on topic.

Intro

This is an enhanced version of Ogre's CelShading CG program and material. It adds the support of decal textures, dynamic ambient lighting, specular texture mapping, and light attenuation. You can use the fixed-function pipeline values to alter the colors of the shader: ambient, diffuse, emissive, and specular. Keep in mind that when using this shader, it will take more resources than the basic example that comes with Ogre.

Currently only point lights and directional lights are supported. Your GPU must support at least the 'ps_2_x' profile. No spotlights yet.

The Code

The material is single-pass which supports a good number of lights. You can tweak the maximum number of lights in the .program and .cg file to support more or less if you want to increase performance.

CelShading.material
CelShading.program
CelShading.cg

Images

Both "cel_shading_diffuse.png" and "cel_shading_specular.png" used in this example are basically both the same image, but they are separate in case someone wants to tweak them individually. So only one file is provided and you must copy the image and rename it to "cel_shading_specular.png"

Image:
 Plugin disabled
Plugin file cannot be executed.

Ogre.material Example

Here is an example that replaces the materials of the "Ogrehead.mesh" object:
import * from "CelShading.material"

material Ogre/Skin
{
	technique
	{
		pass : CelShadingDecalSpec
		{	
			//specular 0.4 0.6 0.4 32
			specular 1 1 1 32
			
			texture_unit decal {
				texture GreenSkin.jpg }
			texture_unit specMap {
				texture GreenSkin.jpg }
		}
	}
}
material Ogre/Tusks
{
	technique
	{
		pass : CelShadingDecal
		{
			diffuse 0.75 0.75 0.75
			
			texture_unit decal {
				texture tusk.jpg }
		}
	}
}
material Ogre/Earring
{
	technique
	{
		pass : CelShading
		{
			ambient 0.8 0.8 0
			diffuse 0.8 0.8 0
			specular 1 1 1 8
		}
	}
}
material Ogre/Eyes
{
	technique
	{
		pass : CelShading
		{
			ambient 1 0.4 0.4
			diffuse 1 0.7 0
			emissive 0.3 0.1 0
			specular 1 0.8 0.5 128
		}
	}
}

Edge Outline Vertex Shader Experiment

Description

StrakeFengala: I did a little experimenting with different ways that you can add an edge outline around a mesh. Many are not satisfied with the current outlining because it is cheap and only looks good on smooth models. This is still not the best method and the algorithm is terrible and has many quirks, but I find it looks better than the original edge shading method found in the OGRE package. I do not recommend this for professional use.

The way this materials works is that it uses a second pass and colors that pass entirely black (or the specified edge color). The vertexes of this second pass are pushed back a little away from the object and the vertices are extruded along their normals, but are not pushed forward or backward any further.

A link to the original forum thread can be found here: http://www.ogre3d.org/forums/viewtopic.php?p=422160#p422160

The Code

Outline.material
Outline.program
VertEdge.cg

Ogre.material Example

Here is an example that replaces the materials of the "Ogrehead.mesh" object:
import * from "CelShading.material"
import * from "Outline.material"

material Ogre/Skin
{
	technique
	{
		pass : CelShadingDecalSpec
		{	
			//specular 0.4 0.6 0.4 32
			specular 1 1 1 32
			
			texture_unit decal {
				texture GreenSkin.jpg }
			texture_unit specMap {
				texture GreenSkin.jpg }
		}
		pass : OutlineExperiment {
			set $sinkScale 4 }
	}
}
material Ogre/Tusks
{
	technique
	{
		pass : CelShadingDecal
		{
			diffuse 0.75 0.75 0.75
			
			texture_unit decal {
				texture tusk.jpg }
		}
		pass : OutlineExperiment {
			diffuse 0.1 0.1 0.1 }
	}
}
material Ogre/Earring
{
	technique
	{
		pass : CelShading
		{
			ambient 0.8 0.8 0
			diffuse 0.8 0.8 0
			specular 1 1 1 8
		}
		pass : OutlineExperiment {
			diffuse 0.2 0.2 0 }
	}
}
material Ogre/Eyes
{
	technique
	{
		pass : CelShading
		{
			ambient 1 0.4 0.4
			diffuse 1 0.7 0
			emissive 0.3 0.1 0
			specular 1 0.8 0.5 128
		}
		pass : OutlineExperiment {
			diffuse 0.25 0.15 0 }
	}
}

To-Do

  • Re-implement the black-edge shading found in the OGRE cel-shading sample?
  • Add support for spotlights?
  • In the edge outline experiment, the outlines glow in the dark if they are colored. Something might need to be done about that...