Jump to content
  • Advertisement
Sign in to follow this  
ido098

Order of drawing

This topic is 2586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!