Cel Shading / Outlining Revisited
by Drew Robson · in Torque Game Engine · 07/09/2007 (7:15 am) · 1 replies
Hi all,
I've implemented object outlining for DTS objects in TGE as per this resource: Cel Shading Code
This is a screenshot of D3D rendering of the test level.
This is a screenshot of OpenGL rendering of the test level.
As you can see some lines/polys are being outlined when they shouldn't. Has anyone successfully used this resource, or have any idea of how to fix this? Code below.
Is anyone still interested in doing cel shading with TGE?
I've implemented object outlining for DTS objects in TGE as per this resource: Cel Shading Code
This is a screenshot of D3D rendering of the test level.
This is a screenshot of OpenGL rendering of the test level.
As you can see some lines/polys are being outlined when they shouldn't. Has anyone successfully used this resource, or have any idea of how to fix this? Code below.
Is anyone still interested in doing cel shading with TGE?
/*cell shading*/
bool doOutline=Con::getBoolVariable("$Pref::renderOutline",true);
if (doOutline)
{
// new addition
glEnable (GL_POLYGON_OFFSET_LINE);
glPolygonOffset (2.5, 0.9); // arguments are factor and units - tweek theese
glEnable (GL_LINE_SMOOTH);
bool oldlighting=glIsEnabled(GL_LIGHTING);
glDisable(GL_LIGHTING);
F32 oldLineWidth;
glGetFloatv(GL_LINE_WIDTH,&oldLineWidth);
F32 lineWidth=Con::getFloatVariable("$Pref::OutlineWidth",2);
glLineWidth(lineWidth);
glCullFace(GL_FRONT);
glPolygonMode (GL_BACK, GL_LINE);
glDepthFunc(GL_LEQUAL);
bool old2dtex=glIsEnabled(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_2D);
F32 oldcolor[4];
glGetFloatv(GL_CURRENT_COLOR,oldcolor);
glColor4f(0.0f,0.0f,0.0f,1.0f); // Outline Color
for (S32 i=0; i<primitives.size(); i++)
{
TSDrawPrimitive & draw = primitives[i];
AssertFatal(draw.matIndex & TSDrawPrimitive::Indexed,
"TSMesh::render: rendering of non-indexed meshes no longer supported");
S32 drawType = getDrawType(draw.matIndex>>30);
glDrawElements(drawType,draw.numElements,GL_UNSIGNED_SHORT,&indices[draw.start]);
}
glColor4fv(oldcolor);
if (old2dtex) glEnable(GL_TEXTURE_2D);
glDepthFunc(GL_LEQUAL);
glLineWidth(oldLineWidth);
glColor3f(1.0f,1.0f,1.0f);
glCullFace(GL_BACK);
glPolygonMode (GL_BACK, GL_FILL);
if (oldlighting) glEnable(GL_LIGHTING);
// End Addition
glDisable (GL_POLYGON_OFFSET_FILL);
glDisable (GL_LINE_SMOOTH);
}
/* end cell shading*/
Torque 3D Owner David Stocker