Model silhouette

Recommended Posts

enigmagame    140
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: Screen 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!!

Share on other sites
danw    122
what is your approch of rendering the silhouette?

Share on other sites
enigmagame    140
Quote:
 Original post by danwwhat is your approch of rendering the silhouette?

http://mrl.nyu.edu/~hertzman/hertzmann-intro3d.pdf
Specifically "Object Space Silhouette Detection" (Page 7-6)

Share on other sites
Maverick_24    100
Depending on how the data is stored in the *.obj file, you'll probably be able to calculate the normals yourself. That is actually what I did when i was writing a simple cell-shading/outlining algo.

Example Tri From The File:
Vert 1 ( 0, 0, 0 )
Vert 2 ( 0, 10, 0 )
Vert 3 ( 10, 0, 0 )

If you are using a clockwise winding order you can use the cross product to find the normals. Normal for Vert1, Vert2, and Vert3 in this case would be ( 0, 0, -1 )

Share on other sites
ma_hty    100
Quote:
 Original post by enigmagame...In this rendering, there are some wrong edges.For me is because some normals are wrong. It's correct?...

What do you mean by "wrong edges"? What is the correct one in your mind?

Share on other sites
enigmagame    140
Quote:
 Original post by ma_htyWhat do you mean by "wrong edges"? What is the correct one in your mind?

For me, the correct image is this:
http://img337.imageshack.us/img337/5756/immagineli3.jpg
In the first image are also visible hidden edge, for example look

Share on other sites
glaeken    294
It looks like you're not enabling depth testing or your depth func is wrong.

Share on other sites
enigmagame    140
Quote:
 Original post by glaekenIt looks like you're not enabling depth testing or your depth func is wrong.

No, depth testing is enabled.
How depth function I must use?
Thanks!

glaeken    294

Share on other sites
ma_hty    100
Quote:
Original post by enigmagame
Quote:
 Original post by ma_htyWhat do you mean by "wrong edges"? What is the correct one in your mind?

For me, the correct image is this:
http://img337.imageshack.us/img337/5756/immagineli3.jpg
In the first image are also visible hidden edge, for example look

What do you mean by "hidden edge"? Yours example looks arbitrary to me.

Share on other sites
enigmagame    140
Quote:
 Original post by ma_htyWhat do you mean by "hidden edge"? Yours example looks arbitrary to me.

See this image:
http://img183.imageshack.us/img183/4816/10950779pk2wz1.jpg
Look at, for example, at the red circle.
There are a hidden edges...
Or see this image, is a classic knot model:
http://img171.imageshack.us/img171/9962/17709687gg6.jpg
Thanks!

[Edited by - enigmagame on March 23, 2008 9:48:42 AM]

Share on other sites
ma_hty    100
If "the hidden edges you said" is referring to the edges of objects being occluded, you can clean them up easily using depth test.

Firstly, you need to draw your 3D model to the depth buffer initially (the whole thing, not just the edges). Afterward, you draw the edges you have right now with depth function set to GL_LEQUAL. Hopefully, "the hidden edge you said" will be cleaned up. However, the other edges will become many broken pieces because of z-fighting. At this point, you may also want to try polygon offset to control the z-fighting issue.

Share on other sites
enigmagame    140
Ok, it works!
Thanks!

Share on other sites
enigmagame    140
Hi!
I've a new problems. For example if I try to render a silhouette of this models:
- Utah Teapot
- Cube (simple cube exported in Blender)
This, is the silhouette rendering of Utah Teapot:
http://img186.imageshack.us/img186/5372/64699539kq5.jpg
In this rendering there are a spurious edges...
Otherwise, if I try to render a silhouette of cube, I don't obtain anything!
The past problem, "occluded edge" is solved...
But, for me, the problems are the normals.
How can I solve?
By changing the method?
Thanks!!

Share on other sites
ma_hty    100
I think your routine for the edge determination may have some problem. Debug it carefully first.

Share on other sites
enigmagame    140
Quote:
 Original post by ma_htyI think your routine for the edge determination may have some problem. Debug it carefully first.

I've tried another method. And I've solved, in part, my problems.
This is the code:
void drawSilhouette(GLfloat r, GLfloat g, GLfloat b){	glPolygonMode(GL_FRONT,GL_FILL);	glDepthFunc(GL_LESS);	glEnable(GL_CULL_FACE);	glPolygonMode(GL_FRONT,GL_FILL);	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);	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);}

Silhouette rendering of Utah Teapot:
http://img167.imageshack.us/my.php?image=72086170xb6.jpg
For me, at last, it's correct. Or no?
But I've a problem with "hole" models...
See for example this face:
http://img72.imageshack.us/my.php?image=45893228si1.jpg
How can I fix this problems?
Thanks!

Share on other sites
ma_hty    100
Quote:
 Original post by enigmagame...But I've a problem with "hole" models......

The lines behind the hole doesn't make sense. They just look likes the grid lines of the 3D model instead of silhouette. What are they precisely?

Share on other sites
enigmagame    140
Quote:
 Original post by ma_htyThe lines behind the hole doesn't make sense.

Exactly! Is due to wireframe rendering of the mesh, by the code that I've posted...
If the model doesn't have a hole, for example the Utah Teapot, it works correctly...
How can I fix the problem, when a model have holes?
Thanks!