PDA

View Full Version : Model silhouette


enigma
03-21-2008, 09:28 AM
I must render the silhouette of an arbitrary 3D model.
The models are in OBJ format.
First I have follow this to read obj file:
http://cggmwww.csie.nctu.edu.tw/courses/cgu/2002/prog1.htm
It works, but only if in the file are stored vertex normals.
For example:

v -1.500976 13.063408 0.460043
vn -0.461797 0.858629 -0.222485
vt 0.000000 0.000000

But if the vertex normals are not stored in this manner, I'm not able to found a silhouette.
So, I have tried this code for read obj file:
http://www.gamedev.net/community/forums/topic.asp?topic_id=330992&forum_id=12&gforum_id=0
(third post, objread.h).
Whit this code, vertex normal are manually generated.
It works, but with some problems, for example:
http://img522.imageshack.us/img522/6122/10950779pk2.th.jpg (http://img522.imageshack.us/my.php?image=10950779pk2.jpg)
In this rendering, there are some wrong edges.
For me is because some normals are wrong. It's correct?
How can I solve this problem?
Thanks!!

yakul
03-21-2008, 10:03 AM
I am not sure what you are trying to do.
But if you want a fast outline rendering, you should take a look at this:
http://graphics.cs.brown.edu/games/FeatureEdges/index.html

enigma
03-29-2008, 08:29 AM
Hi!
I've found and I tried to use this code:

void drawSilhouette(GLfloat r, GLfloat g, GLfloat b)
{
glPolygonMode(GL_FRONT,GL_FILL);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.0,0.0);

//Here I draw my model with GL_TRIANGLES

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

glColor3f(r, g, b);
glLineWidth(1.0);
glDepthFunc(GL_LEQUAL);
glPolygonMode(GL_BACK, GL_LINE);
glCullFace(GL_FRONT);

//Here I draw my model with GL_TRIANGLES

glDisable(GL_BLEND);

glDepthFunc(GL_LESS);
glCullFace(GL_BACK);
glDisable(GL_CULL_FACE);
}

It works correctly, see for example this silhouette rendering of Utah Teapot:
http://img167.imageshack.us/img167/9200/72086170xb6.th.jpg (http://img167.imageshack.us/my.php?image=72086170xb6.jpg)
But I've a problem if the model has a holes, see for example this rendering of a head:
http://img72.imageshack.us/img72/4696/45893228si1.th.jpg (http://img72.imageshack.us/my.php?image=45893228si1.jpg)
How can I fix this problem?
In the other cases the method run correctly!
Thanks!

Mattias Gustavsson
03-29-2008, 12:08 PM
well, easiest way would be to fix the model, so it no longer has any holes :-)

starstutter
03-29-2008, 10:38 PM
well, easiest way would be to fix the model, so it no longer has any holes :-)

I hate to say it, but he's right. Your 3D models should never have holes in them.

enigma
04-01-2008, 12:11 PM
I hate to say it, but he's right. Your 3D models should never have holes in them.
Ok, no holes... :-)
Otherwise, in this case, I must use another method...
Thanks!

Vilem Otte
04-02-2008, 11:07 AM
Well, you can render silhouettes with holes using pixel comparing and some value to compare when it's silhouette and when not, anyway it has to run as post processing effect in a pixel shader.