Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Topics

Recent Status Updates

View All Updates

Photo
- - - - -

How is it determined if a face on a model is shown or not

modeling models

Best Answer gregwarner , 15 May 2014 - 01:47 PM

This is called "Back-face culling" and it's a common mechanism in all 3D engines to cull (remove) the back-facing polygons that shouldn't be rendered. Depending on your 3D engine, it may be done slightly differently, but if memory serves, the basic strategy behind this is to look at the order that the polygon's vertices are arranged in: clockwise or anti-clockwise. If my memory is correct, it's the anti-clockwise ordering that indicates a front-facing polygon, and clockwise a back-facing one. So you should remove all the clockwise ordered polygons from the render list.

Again, I could be wrong on that clockwise/anti-clockwise thing. Or maybe different engines do it differently. Check the specs for the engine you're using. Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 Chall

Chall

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 349 posts

Posted 15 May 2014 - 12:22 PM

In every game I've ever played that has models, if you glitch through a visible face, you don't see the faces that make up the non-visible part of the model. How is it calculated which faces to show and which not?


Edited by Chall, 15 May 2014 - 12:22 PM.

Speaks fluent Java

#2 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts

Posted 15 May 2014 - 01:47 PM   Best Answer

This is called "Back-face culling" and it's a common mechanism in all 3D engines to cull (remove) the back-facing polygons that shouldn't be rendered. Depending on your 3D engine, it may be done slightly differently, but if memory serves, the basic strategy behind this is to look at the order that the polygon's vertices are arranged in: clockwise or anti-clockwise. If my memory is correct, it's the anti-clockwise ordering that indicates a front-facing polygon, and clockwise a back-facing one. So you should remove all the clockwise ordered polygons from the render list.

Again, I could be wrong on that clockwise/anti-clockwise thing. Or maybe different engines do it differently. Check the specs for the engine you're using.

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3 Chall

Chall

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 349 posts

Posted 15 May 2014 - 05:37 PM

This is called "Back-face culling" and it's a common mechanism in all 3D engines to cull (remove) the back-facing polygons that shouldn't be rendered. Depending on your 3D engine, it may be done slightly differently, but if memory serves, the basic strategy behind this is to look at the order that the polygon's vertices are arranged in: clockwise or anti-clockwise. If my memory is correct, it's the anti-clockwise ordering that indicates a front-facing polygon, and clockwise a back-facing one. So you should remove all the clockwise ordered polygons from the render list.

Again, I could be wrong on that clockwise/anti-clockwise thing. Or maybe different engines do it differently. Check the specs for the engine you're using.

Well, actually I was writing my own little one. It's not going to be anything special, it's mainly just to add perspective to a primarily 2D game, but some features will be in 3D (Or all of it, if I can find a way to optimize it a bit more, hence this question).

 

I think I know what you mean, but could you elaborate on the way the whole (counter)-clockwise thing works, just so I know we're on same page? (I would ask if what I thought was right, but I just tried typing it, and I just couldn't get the right idea down)

 

[Edit] Tried what I thought you meant, and so after a bit of tuning, I got it working right. Thanks :D


Edited by Chall, 15 May 2014 - 07:23 PM.

Speaks fluent Java

#4 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts

Posted 16 May 2014 - 06:18 AM

Glad you got it working. In case it helps, or if anyone else reading this thread needs it explained, here's a quick explanation:

 

Computers render 3D graphics as a whole bunch of triangles (referred to as "polygons"). Try this experiment: Draw a triangle on a piece of paper. Label the vertices "1", "2", and "3". Hold that paper out in front of you so the ink is facing you. Look at the numbers 1, 2, and 3, and take notice of which direction they go around the triangle. It'll either be clockwise or anti-clockwise. It doesn't matter which, just take note of which way it is.

 

Now, turn the paper so the ink is away from you and you're looking at the back of the paper. Now look at the vertices. (It may help to point the paper at some light so you can look through the paper at the ink on the other side.) Now which way are the vertices going around the triangle? You'll notice that the direction has reversed.

 

It doesn't matter which way you rotate the paper, either. You could hold it so your writing is now upside down, and it'll still be clockwise on one side and anti-clockwise on the other. So rotation about the axis that's parallel to your direction of viewing has no effect. It's only when you rotate it about an axis that's perpendicular to your direction of viewing, i.e., when the polygon is turned to face away from you.

 

3D models are designed such that all their polygons have their vertices numbered in the same direction: either clockwise or anti-clockwise. When designing a 3D engine, you must decide which, and be consistent. For front facing polygons (on the side of the model facing the camera), the clockwise/anti-clockwise direction will indicate to the engine that these faces must be drawn. For faces on the opposite side of the model, the clockwise/anti-clockwise direction will tell the engine not to draw this face.


ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download