TIPS: d3d

Source: Internet
Author: User
DirectX compilation path

Before using DirectX SDK, You need to include \ header file path in the title search path, and make sure that this path is placed first in the search path list, because many compilers own the older version of DirectX, the compiler may find the old header files in its own include \ directory, and using these header files is incorrect. The procedure is as follows (VC ++ 6.0 ):
You can set the corresponding path in the tool menu --> Option-> directory-> path list. Make sure that the correct path should be placed in the front.

 Fixed pipe vs programable Pipeline
In the past, during vertex processing and pixel processing, the video card was fixed on hardware.ProgramD3d programmers can only set some parameters, which are actually what you do when calling idirect3ddevice: setrenderstate (). Such a program is automatically executed in idirect3ddevice: drawprimitive, some things are hard to do.
The current video card, specifically the current direct3d, allows you to write such a program to replace the fixed vertex processing process and pixel processing process (Remember, only these two processes, it has nothing to do with interpolation ). Vertex shader (no specific Chinese name yet) is used to replace vertices, and pixel shader is used to replace pixels.

 Two ways to render the mesh model
1. drawsubset method (not optimized );
2. optimized the attribute list of the network model. All surfaces belonging to the same user are grouped together in advance, and drawprimitive or drawindexedprimitive is called to render them.

 Vertex shader register
Use 16 input registers;
The general constant register is a c0-c95, but in ATI radeom 8500 is a c0-c191;
The temporary register consists of 12 registers;
At least 13 Output registers;

 ...

In terms of structure, the direct3d device includes a conversion module, a lighting module, and a grating module.

 Direct3d device status
The direct3d device is a state machine. The application sets the state of the lighting, rendering, and transformation modules, and then transmits data to them during rendering.
(1) Rendering status
The device rendering status controls the behavior of the raster module of the direct3d device. They achieve this by changing the rendering State attributes, the type of coloring algorithm used, the fog attributes, and other raster operations.
The fixed function vertex processing is controlled by the idirect3ddevice9: setrenderstate method and the rendering status of the following devices. Most of these controls do not work when you use a programmable vertex shader.
In addition, the fixed function vertex processing pipeline uses the following methods to set the transformation, material, and illumination.
Idirect3ddevice9: settransform
Idirect3ddevice9: setmaterial
Idirect3ddevice9: setlight
Idirect3ddevice9: lightenable
(2) sampling device status
Setsamplerstate
(3) texture layer status
Settexturestagestate

D3d setrenderstate
(1) Disable illumination processing (enabled by default)
Use the vertex color for rendering. If not disabled, a black polygon will be displayed.
M_pdevice-> setrenderstate (d3drs_lighting, false); // disable illumination because the vertex color is used for rendering.
(2) allow rendering of the back
By default, direct3d only selects the front of the triangle for rendering. When it is rotated to a certain angle and the back is facing the observer, the image disappears, so disable this feature.
M_pdevice-> setrenderstate (d3drs_cullmode, d3dcull_none); // disable the "pick" function to allow rendering of the back
(3) Open the Z Cache
D3dpp. enableautodepthstencel = true;
D3dpp. autodepthstencilformat = d3dfmt_d16; // generate a 16-bit Z Cache
M_pd3d-> createdevice (...)
M_pdevice-> setrenderstate (d3drs_zenable, d3dzb_true); // enable the Z cache and allow deactivating the cache.
M_pdevice-> clear (0, null, d3dclear_target | d3dclear_zbuffer, d3dcolor_xrgb (0,0, 255), 1.0f, 0 );
(4) Normalize the normal vector
Set the rendering State d3drs_normalizenormals to true in the initialization function cd3dwnd: initd3d to ensure that the vertex normal is always a unit vector and is not affected by coordinate transformation, which helps improve the rendering accuracy, but it will increase the processor burden.
M_pdevice-> setrenderstate (d3drs_normalizenormals, true); // automatically normalize the normal vector.
(5) Texture Mixing
When a texture is used, the appearance of the object is calculated by the texture image and material. This process is called texture blending. For details, see the SDK article "texture blending ", the following code sets the Blending Method of the first texture to "texture + material diffuse reflection ":
Pdevice-> settexturestagestate (0, d3dtss_colodrop, d3dtop_add); // operation type: add
Pdevice-> settexturestagestate (0, d3dtss_colorarg1, d3dta_texture); // operation object 1: texture
Pdevice-> settexturestagestate (0, d3dtss_colorarg2, d3dta_diffuse); // calculation object 2: Material

 D3d illumination computing
Computing ambient light is more like directly assigning values;
The calculation of the diffuse light is the dot product of the light and the vertex normal;
For the calculation of the mirror reflection, we also need to consider the direction from the vertex to the viewpoint. The default illumination State does not calculate the mirror reflection highlight. To enable the mirroring highlight, set d3drs_specularenable to true;
The three types of illumination are superimposed in the above order to produce a more realistic effect.

 ...

In the Ogre example, robot. mesh is only displayed under DirectX, and OpenGL does not.

 Transform

Pitch ==> X-axis
Yaw ==> Y-axis
Roll => Z-axis

 Shadow Generation Method

Standardmaterial: generate a shadow texture and paste it on the affected model;
Stencilshadow: generates a shadow column to determine whether each vertex is in the shadow;
Shadowmap (texture shadow): generates a shadow depth texture to determine the depth of each vertex and the corresponding Vertex on the texture.

 Collision Detection
AABB (axis-aligned bounding boxes)
OBB (Oriented Bounding Boxes)
3D Rigidbody, generally AABB/OBB first, then perform precise detection (vertex, edge, edge ....).

Simple collision detection can be implemented by yourself. More complex (more accurate and more real) requires a dedicated physical engine. Commercial entities such as physx, Havok, and open-source non-Ode are none.

 Vector

Point product: A. B = | A | B | cos θ. The point product satisfies the exchange law.
Cross Product: AXB

When dot multiplication and cross product exist together, the cross product is first calculated. The vector cross product does not meet the exchange rate, but does not meet the inverse exchange rate: AXB =-(BXA), and the cross product does not meet the combination rate.
The cross product vector is perpendicular to the original two vectors. | AXB | the length equals the product of the sin value between the vector size and the vector angle: | AXB |=| A | B | sin θ, so | AXB | is equal to the area of the parallelogram on both sides of a and B.
If A and B are parallel or any one is 0, AXB = 0.
There are two directions perpendicular to A and B. Which direction does axxb point? By connecting the head of a to the end of B and checking whether the direction from A to B is clockwise or counterclockwise, the direction of AXB can be determined. In the left-hand coordinate system, if A and B are clockwise, AXB points to you; otherwise, stay away from you. In the right-hand coordinate system, the opposite is true. If a and B are clockwise, AXB will stay away from you; otherwise, it will point to you.

 Three methods for obtaining directdraw7.0
OK. If we want to use the latest DirectDraw version 7.0 (because DirectDraw is removed from directx8.0), we need an idirectdraw7 interface. We can use the basic directdrawcreat () function to obtain an idirectdraw 1.0 interface, and then use QueryInterface () to obtain the idirectdraw7 interface. On the other hand, we can use the underlying com function to directly obtain idirectdraw7, or use the directdrawcreatex () function available in directx7.0 to directly create an interface.

 Skeleton skin animation model

A typical skeleton skin animation model saves the following information:
Grid Information
Polygon (material, texture), vertex (Position, normal vector)
Which bones affect this point and affect the weight?
Skeleton Information
All bones form a tree based on parent-child relationship
Transformation Matrix of each skeleton included in the parent Coordinate System
Animation Information
Key Frame (each key frame indicates the transformation matrix, position, orientation, and other changes of each skeleton relative to the parent skeleton coordinate system at this time point ).

 Install 3DS MAX

It is best to install 3DS MAX before DirectX SDK during installation and installation, because it seems that when the dx sdk is installed, the system automatically checks the max version on the local machine, at the same time, a version of the plug-in is generated for the Max file to be exported as the X file. Looks like this...

 D3d light

Environment light
Optical-lawn light source
Direct sunlight-parallel light
Lightning spotlight
The data structure of ambient light color is d3dcolor, while the direct light and material use the same data structure to indicate the color: d3dcolorvalue.

 3D Assembly Line

Data Loading → polygon → local coordinates → world coordinates → elimination, back Elimination → camera coordinates → perspective coordinates → screen coordinates
│ Bytes
Cutting → Rasterization-cutting
Bytes
Illumination (coloring), texture ing, projection

Related Article

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.