Skip to main content

History: Enhanced CelShading

Preview of version: 9

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. 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:
Copy to clipboard
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:
Copy to clipboard
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...

History

Information Version
Wed 14 of May, 2025 15:49 GMT-0000 admin attachment conversion 14
Fri 27 of Apr, 2012 00:09 GMT-0000 StrakeFengala 13
Sat 21 of Apr, 2012 01:40 GMT-0000 StrakeFengala 12
Sat 21 of Apr, 2012 01:39 GMT-0000 StrakeFengala Updated ATTENTION text 11
Fri 20 of Apr, 2012 22:36 GMT-0000 StrakeFengala 10
Fri 20 of Apr, 2012 20:23 GMT-0000 StrakeFengala 9
Fri 20 of Apr, 2012 16:53 GMT-0000 StrakeFengala 8
Fri 20 of Apr, 2012 16:48 GMT-0000 StrakeFengala 7
Fri 20 of Apr, 2012 16:46 GMT-0000 StrakeFengala Major revamp 6
Fri 20 of Apr, 2012 15:55 GMT-0000 StrakeFengala 5
Fri 20 of Apr, 2012 15:54 GMT-0000 StrakeFengala 4
Sun 31 of Jul, 2011 22:21 GMT-0000 jacmoe 3
Sun 13 of Mar, 2011 03:22 GMT-0000 StrakeFengala 2
Sun 13 of Mar, 2011 03:19 GMT-0000 StrakeFengala 1