Order of drawing

Started by
2 comments, last by Burnt_Fyr 12 years, 5 months ago
Hey..
lets say I have a 3d model and I want to draw it on my screen
so I have to draw all of the polygons of my model

how do I determine what polygons to draw and in what order?

It's also good if you can point me to some guide or article that talks about this subject.

thanks in advance
Advertisement
Maybe you want to google for "culling", and in particular "backface culling" as a start.
backface culling simply cuts away every triangle that faces away from you, wich in the general case of an object on the screen in front of you should be roughly half of them.
Then there is lots of other culling techniques you can use to cut away even more of your geometry, mostly using some kind of spatial data structure to quickly figure out what triangles could be visible and should be considered.

Those are though more focused on things like levels, and not just a single object in front of you.

Order depends mostly on what materials they have.
For hardware acceleration, you want to draw solid triangles starting with the one closest to the camera and work your way back, so the card can do a quick discard of triangles that are behind.
Unless some of them are transparent, then you have to draw any triangles behind them first.

You also want to minimize big state changes, such as changing shaders, wich can have nasty side effects, so you might want to group them by material.

The basic techniques can be found in any book about computer graphics
I read about back-face culling
I tried to implement it but I am having some problems.
I calculate the normal vector and the vector the that points from the polygon to the camera
and then I calculate the dot-product between these two vectors and if the result is greater or equal to zero, I draw the polygon, just like the method says.

however, I get different results from different rotations.

I uploaded an image to show you the problem.
bad drawing
good drawing

what could be the problem?

I read about back-face culling
I tried to implement it but I am having some problems.
I calculate the normal vector and the vector the that points from the polygon to the camera
and then I calculate the dot-product between these two vectors and if the result is greater or equal to zero, I draw the polygon, just like the method says.

however, I get different results from different rotations.

I uploaded an image to show you the problem.
bad drawing
good drawing

what could be the problem?


Make sure that the normal and view vector are in the same space. If you calculate your view vector as eye - vertex, make sure that the vertex position used is in world space(which is most likely where your camera is). Also make sure that the normal vector has been transformed into the same space.

This topic is closed to new replies.

Advertisement