cartoon outlining (cartoon rendering part1)
by F.W. Hardijzer · in Torque Game Engine · 05/31/2003 (3:22 pm) · 113 replies
Ok :)
I've been working on this for about a whole day, and still there are some bugs in it :(
But that doesn't hold me from posting it for others to use :)
so here is the code:
FOR SHAPES
in ts/tsMesh.cc
in TSMesh::render after:
FOR TERRAIN:
in terrain/terrRender.cc
in TerrainRender::renderXFCache after
FOR INTERIORS:
I'm still working on this one, and it's quite difficult (since there are lots of render codes in the interiors,
I've finally gotten some lines over it, but it is pretty glitchy, and will only look good on some interiors,
the $pref::renderOutline for interiors is $Pref::Interior::renderOutline,
and $pref::outlineWidth is $Pref::Interior::outlineWidth...
the reason i changed these vals for interiors is because i can imagine someone wanting terrain and shape, btu not this buggy interior code enabled :)
anyways, enough bullshit, code:
in interior/interiorRender.cc
in void Interior::render
after:
some prefs of this:
$Pref::renderOutline (true/false) render outlines or not
$Pref::outlineWidth (0-10) linewidth of outlines
You are free to use this code for whatever project you'd like, as long as you post every change you make on this forum so others can use it too :)
BUGS:
- enviroment mapped models have 'reflective' lines
Please if you like this stuff, contribute and help us with this!
also if you know anything about cell-shading, try to do that too...
in other words:
FRANK BIGNONE: please post your cell shading stuff from DOP here :(
and another word, noone is allowed to submit this as a resource except for me when i think the code is good enough to be posted as a resource :)
I've been working on this for about a whole day, and still there are some bugs in it :(
But that doesn't hold me from posting it for others to use :)
so here is the code:
FOR SHAPES
in ts/tsMesh.cc
in TSMesh::render after:
S32 drawType = getDrawType(draw.matIndex>>30);
glDrawElements(drawType,draw.numElements,GL_UNSIGNED_SHORT,&indices[draw.start]);
}add/*cell shading*/
bool doOutline=Con::getBoolVariable("$Pref::renderOutline",true);
if (doOutline) {
bool oldlighting=glIsEnabled(GL_LIGHTING);
glDisable(GL_LIGHTING);
F32 oldLineWidth;
int oldcullface;
glGetIntegerv(GL_CULL_FACE,&oldcullface);
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);
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 cell shading*/FOR TERRAIN:
in terrain/terrRender.cc
in TerrainRender::renderXFCache after
U32 vertexCount = mXFIndexBuffer[count + 1];
glDrawElements(mode, vertexCount, GL_UNSIGNED_SHORT, mXFIndexBuffer + count + 2);add://Cell shading
/*cell shading*/
bool doOutline=Con::getBoolVariable("$Pref::renderOutline",true);
if (doOutline) {
/*extra cell shading*/
F32 oldLineWidth;
int oldcullface;
glGetIntegerv(GL_CULL_FACE,&oldcullface);
glGetFloatv(GL_LINE_WIDTH,&oldLineWidth);
F32 lineWidth=Con::getFloatVariable("$Pref::OutlineWidth",2);
glLineWidth(lineWidth);
//glBindTexture(GL_TEXTURE_2D,NULL);
glColor3f(0.0f,0.0f,0.0f);
glCullFace(GL_FRONT);
glPolygonMode (GL_BACK, GL_LINE);
//Draw here
glColor3f(0.0f,0.0f,0.0f);
glDisable(GL_TEXTURE_2D);
glDrawElements(mode, vertexCount, GL_UNSIGNED_SHORT, mXFIndexBuffer + count + 2);
glEnable(GL_TEXTURE_2D);
glLineWidth(oldLineWidth);
glCullFace(GL_BACK);
glPolygonMode (GL_BACK, GL_FILL);
/*end extra cs*/
}
/* end cell shading*/FOR INTERIORS:
I'm still working on this one, and it's quite difficult (since there are lots of render codes in the interiors,
I've finally gotten some lines over it, but it is pretty glitchy, and will only look good on some interiors,
the $pref::renderOutline for interiors is $Pref::Interior::renderOutline,
and $pref::outlineWidth is $Pref::Interior::outlineWidth...
the reason i changed these vals for interiors is because i can imagine someone wanting terrain and shape, btu not this buggy interior code enabled :)
anyways, enough bullshit, code:
in interior/interiorRender.cc
in void Interior::render
after:
if (smRenderMode != 0) {
PROFILE_START(IRO_DebugRender);
debugRender(pMaterials, instanceHandle);
PROFILE_END();
return;
}add://cartoon outline
bool doOutline=Con::getBoolVariable("$Pref::Interior::renderOutline",false);
if (doOutline) {
F32 oldLineWidth=1;
glGetFloatv(GL_LINE_WIDTH,&oldLineWidth);
F32 lineWidth=Con::getFloatVariable("$Pref::Interior::OutlineWidth",2);
glLineWidth(lineWidth);
// Base textures
glBlendFunc(GL_ONE, GL_ZERO);
glDisable(GL_TEXTURE_2D);
glColor3f(0, 0, 0);
for (U32 i = 0; i < sgActivePolyListSize; i++) {
const Surface& rSurface = mSurfaces[sgActivePolyList[i]];
glBegin(GL_LINE_LOOP);
glVertex3fv(mPoints[mWindings[rSurface.windingStart]].point);
S32 skip = rSurface.windingStart + 1;
while (skip < (rSurface.windingStart + rSurface.windingCount)) {
glVertex3fv(mPoints[mWindings[skip]].point);
skip += 2;
}
skip -= 1;
while (skip > rSurface.windingStart) {
if (skip < (rSurface.windingStart + rSurface.windingCount))
glVertex3fv(mPoints[mWindings[skip]].point);
skip -= 2;
}
glEnd();
}
glEnable(GL_TEXTURE_2D);
//return;
}
//End cartoon outlinesome prefs of this:
$Pref::renderOutline (true/false) render outlines or not
$Pref::outlineWidth (0-10) linewidth of outlines
You are free to use this code for whatever project you'd like, as long as you post every change you make on this forum so others can use it too :)
BUGS:
- enviroment mapped models have 'reflective' lines
Please if you like this stuff, contribute and help us with this!
also if you know anything about cell-shading, try to do that too...
in other words:
FRANK BIGNONE: please post your cell shading stuff from DOP here :(
and another word, noone is allowed to submit this as a resource except for me when i think the code is good enough to be posted as a resource :)
About the author
#2
why doesn't anyone reply/contribute ?
06/01/2003 (4:02 am)
I thought i had helped millions of cartoon-game-makers with this :(why doesn't anyone reply/contribute ?
#3
06/01/2003 (4:49 am)
I never posted my code here 'cause i see it more as an hack as something else. Nevertheless, some people ask me by email to have the code (and even pay for it), and i always send them the code for free (and without any support ;) ). You are basically doing the same thing as me ;)
#4
I feel dissapointed...
I once send you an email, and you never responded :'( :'(
can you send it to me please? i would really like to know how you did it...
I was actually thinking of getting out the glDrawElements and draw them 'by hand' but i don't think that'll fix it...
So hereby i ask you, would you please email me that code?
GRTZ DJMystic
djmystic@hardijzer.mine.nu
06/01/2003 (5:51 am)
:'(I feel dissapointed...
I once send you an email, and you never responded :'( :'(
can you send it to me please? i would really like to know how you did it...
I was actually thinking of getting out the glDrawElements and draw them 'by hand' but i don't think that'll fix it...
So hereby i ask you, would you please email me that code?
GRTZ DJMystic
djmystic@hardijzer.mine.nu
#5
06/01/2003 (6:16 am)
I am very interested in this post and will be sure to try it out soon, if you learn anything from the DOP code please be sure to post it
#6
and a link here . My only question is, "can I control the bias od the outline?" As you can see it is outlining in areas it shouldn't, of course it could very well be my shoddy modeling. Either way you have opened the door to a new line of Torque Toon games YEAH
06/01/2003 (6:38 am)
TOO FREAKIN cool, I love it, here is a screenie
and a link here . My only question is, "can I control the bias od the outline?" As you can see it is outlining in areas it shouldn't, of course it could very well be my shoddy modeling. Either way you have opened the door to a new line of Torque Toon games YEAH
#7
06/01/2003 (6:57 am)
@DjMystic : it seems i forgot you or never get your email. Nevertheless, you should have receive it now ;)
#8
open up mirc
type /server www.maxgaming.net -j #garagegames
or www.maxgaming.net has some sort of applett i think, and join channel #garagegames :)
BTW now going to check my email :)
06/01/2003 (7:08 am)
Since you're checking this every x minutes, why don't you come chatting with us?open up mirc
type /server www.maxgaming.net -j #garagegames
or www.maxgaming.net has some sort of applett i think, and join channel #garagegames :)
BTW now going to check my email :)
#9
Nevertheless, i cannot accept your invitation as i have some work to finish and cannot take times to chat.
cul8r
06/01/2003 (7:14 am)
Pal, i know about mirc and irc thanks ;pNevertheless, i cannot accept your invitation as i have some work to finish and cannot take times to chat.
cul8r
#11
Here is a link to the code for those who want to look at it click me
BTW, this is really a hack, so it's the reason i never release it as a resource here. You will find two implementation : one for the outlining and one for the shading. The shapebase file is taken from DoP, so there might be some code dedicated to DoP. These two files will need some work i think to be put in your project and need a lot of cleaning and optimization.
06/01/2003 (12:54 pm)
Ok, you will kill me DJMystic.Here is a link to the code for those who want to look at it click me
BTW, this is really a hack, so it's the reason i never release it as a resource here. You will find two implementation : one for the outlining and one for the shading. The shapebase file is taken from DoP, so there might be some code dedicated to DoP. These two files will need some work i think to be put in your project and need a lot of cleaning and optimization.
#12
I'm going to frie you!
Kentucky Fried Frank!
nah just kidding ;)
who cares...
i will be adding my additions ASAP
and btw i found an extra bug in my (and our) silhouette/outlining code:
- NEVER look into mirrors, framerate drops heavily, and everything looks crap in the mirror
Well thats it :)
as soon as i got franks cell shade code to use lightign and not just use a imagined light source, i will post it here :)
06/01/2003 (3:32 pm)
I'm not going to kill you frank...I'm going to frie you!
Kentucky Fried Frank!
nah just kidding ;)
who cares...
i will be adding my additions ASAP
and btw i found an extra bug in my (and our) silhouette/outlining code:
- NEVER look into mirrors, framerate drops heavily, and everything looks crap in the mirror
Well thats it :)
as soon as i got franks cell shade code to use lightign and not just use a imagined light source, i will post it here :)
#13
06/01/2003 (4:07 pm)
yeah I can't wait
#14
- draw objets 2 times for silhouette + shading and i suspect it draws unecessary vertices
- drawing of transparent object parts where you do not want to delineate it
- adding some bias for the silhouette
- fog + silhouette code not working well
- not working correctly with D3D
06/01/2003 (9:22 pm)
Other known bugs :- draw objets 2 times for silhouette + shading and i suspect it draws unecessary vertices
- drawing of transparent object parts where you do not want to delineate it
- adding some bias for the silhouette
- fog + silhouette code not working well
- not working correctly with D3D
#15
06/01/2003 (10:36 pm)
awesome resource, I added the terrain stuff and it rocks... I tried the shape stuff too, but it really hit the fps, and on things like trees it seemed to not just make an outline of the object, but put lines on every polygon, so I ditched that. Cant wait to check out the improved stuff!
#16
06/02/2003 (5:07 pm)
I tried this. Its fun to look at how much better my models look with it.
#17
Don't just wait for the improved stuff
this is a community, you're supposed to look at stuff, and then if it's not finished, contribute to it
but anyways found another bug, but also fixed it...
- In dark shades/maps the shapes get modelled bright :S (always switched back to white) (fixed)
06/03/2003 (7:17 am)
EricDon't just wait for the improved stuff
this is a community, you're supposed to look at stuff, and then if it's not finished, contribute to it
but anyways found another bug, but also fixed it...
- In dark shades/maps the shapes get modelled bright :S (always switched back to white) (fixed)
#18
then I tried Hardijzer's code..gave it a go...and.......(actually i'm still waiting for it to finish compiling...)..
my guy looks the same?
[edit]
ah, didn't notice the prefs at the end...where do i add these? sorry, menoob x.x
[/edit]
12/27/2004 (6:47 pm)
I tried out Frank's code - didn't work, probably needed a lil tweaking, halted the compiler for a few...but Dog of Prey looks pretty good with it =Dthen I tried Hardijzer's code..gave it a go...and.......(actually i'm still waiting for it to finish compiling...)..
my guy looks the same?
[edit]
ah, didn't notice the prefs at the end...where do i add these? sorry, menoob x.x
[/edit]
#19
12/27/2004 (7:34 pm)
You can type em into the console
Torque Owner F.W. Hardijzer