質問

How does DirectX determine polygon winding orders? I'm curious in particular about backface culling. From researching this I have seen it suggested that DX calculates a surface normal and takes the dot product of that and the camera vector, and culls if that is > 0.

Firstly, is this the technique that DirectX actually employs? Secondly, if this is the case, given that there two normals to every surface - one opposed to the other - how does DirectX know which normal to use?

役に立ちましたか?

解決

No that's not the technique used, neither opengl or directx have a concept of a camera view vector. What happens is that the vertices are transformed into normalized-device-coordinate space (by first letting the user transform to post projective space in the vertex shader and subsequently dividing xyz components by w). Within that coordinate system we can use the x and y components of the vertices to compute the 'signed area' of the triangle.

    float signedArea = 0;   
    for( int k = 1; k < output->count; k++ ) {
        signedArea += (output->vertices[k - 1].values[0] * output->vertices[k - 0].values[1]);
        signedArea -= (output->vertices[k - 0].values[0] * output->vertices[k - 1].values[1]);
    }

Depending on whether the vertices are evaluated clock-wise or counter-clock-wise these give a positive or negative area. Viewing a triangle from behind, would make positive area negative and vice versa. And this value is subsequently used in determining whether to rasterize front-, back- or both font- & back- facing triangles.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top