codedhead
08-01-2011, 08:50 PM
hi, everyone. I'm implementing my own software renderer. Maybe I'm missing something, but i found a problem : OpenGl supports two sided materials, so before calculating the light for each vertex, it has to decide whether the polygon is facing front or back, then it can choose the right material.
I have read some books, they said that the light calculating is done in world coordinates and back-face culling is done in viewing coordinates. Well, in opengl, i think these two steps can be moved to a same stage, after modelview transforming. This can solve my problem because face can be determined and culled before light calculating. But determining polygon's facing requires more calculation in viewing coordinates, because the sight vector isn't constant for each vertex.
Then I read the opengl specification. It says that facing dertermination is done in window coordinates(after perspective transform and viewport transform?), so the sight vector is constant for any vertex(0,0,-1),and calculating the z component is enough to determine the facing. But here is another problem. Light calculation is done in world/viewing coordinates, and how does it know the polygon facing while the facing determination is in the later stage?
Sorry for my bad English, hope it's clear enough. Thanks!
I have read some books, they said that the light calculating is done in world coordinates and back-face culling is done in viewing coordinates. Well, in opengl, i think these two steps can be moved to a same stage, after modelview transforming. This can solve my problem because face can be determined and culled before light calculating. But determining polygon's facing requires more calculation in viewing coordinates, because the sight vector isn't constant for each vertex.
Then I read the opengl specification. It says that facing dertermination is done in window coordinates(after perspective transform and viewport transform?), so the sight vector is constant for any vertex(0,0,-1),and calculating the z component is enough to determine the facing. But here is another problem. Light calculation is done in world/viewing coordinates, and how does it know the polygon facing while the facing determination is in the later stage?
Sorry for my bad English, hope it's clear enough. Thanks!