DX's clarification on the concept of backend removal!

Source: Internet
Author: User

Recently, when rendering the terrain, I found that I set the back rejection mode to CCW. As a result, I cannot display the front of the terrain! I know there is a problem with the mesh weaving Order (but I remember that my mesh was woven clockwise). to thoroughly understand this problem, I checked the DX SDK, it turns out to be a mess! I searched the internet and found that many people were not clear about the problem. So I checked the software engine of André Lamothe again. Here I will make a summary.

DX can be set to remove clockwise triangles (CW) and counter-clockwise triangles (CCW ). but when you pass the coordinates V1, V2, and V3 to the three computer vertices in sequence, how does the computer know whether the triangle defined by these three vertices is clockwise or counterclockwise? This is related to two factors. One is to find the normal surface of the triangle line (this will not change once the vertex coordinates are set ), one is the observed vector at the moment (assuming it is a vector from the camera position to any point on the triangle surface ). for example:

(Note: Because DX uses the left-hand coordinate system, you need to determine the orientation of the normal, instead of the right-hand coordinate system .)

The computer calculates the forward normal by using the equation normal_vector = (v2-v1) x (Cross multiplication) (v3-v1). Assuming that the camera is at the position of the POs

Then the computer needs an auxiliary vector dir_vector = V3 (or any of V1, V2) generated by the following equations-pos.

The computer then performs dot multiplication on the dir_vector and normal_vector vectors. If the result is <0, DX considers the triangle to be clockwise,

If the result is greater than 0, DX considers the triangle to be counter-clockwise. dx then determines whether to render the triangle Based on the Elimination mode you set (d3dcull_ccw or d3dcull_cw.

Therefore, it is concluded that if you weave your triangle in a clockwise order, you should remove d3dcull_ccw in a counterclockwise manner.

Otherwise, use the clockwise elimination method d3dcull_cw.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/diyer2002/archive/2007/06/17/1655146.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.