Techniques related to texture ing in DirectX

Source: Internet
Author: User
1. First of all, I think there are too many options for D3D texture ing, which gives people a dazzling feeling. In addition, it is not easy to distinguish the differences between different options at first glance, I don't know how to use these options, or how they correspond to previous experiences. These options include:
  • Dark mapping
  • Animated Dark mapping
  • Blending with Material Diffuse Color
  • Darkmap with Material Diffuse Color
  • Glow mapping
  • Detail mapping
  • Modulate mapping
  • Blending with Frame Buffer
  • Trillinear Filtering
  • Clamp Addressing Mode
  • Mirror Once
  • Border Color.
The main APIs used are:
  • HRESULT SetSampleState (
DWORD Sampler, // texture stage no. D3DSAMPLERSTATETYPE type, // DWORD value of the samplerstate type) // The samplerstate value. It is used to specify the texture filtering method and the clamping method (tiling/clamping) and the mirole mode.
  • HRESULT SetTextureStageState (DWORD Stage, // texture Stage no. D3DSAMPLERSTATETYPE type, // DWORD value of samplerstate type) // samplerstate value

It is used to provide additional operation functions for multiple texture units that use fixed functions. Including texture coordinates, color operations, alpha operations, convex/convex ing, and environment ing.
--------------------------------------------
2. texture coordinates
For a single vertex, up to eight sets of texture coordinates (D3DFVF_TEX1 to D3DFVF_TEX8) can be used. You can use D3DTSS_TEXCOORDINDEX to select a specific set of texture coordinates:

M_pd3dDevice-> SetTexture (0, m_pWallTexture );
M_pd3dDevice-> SetTextureStateState (0, D3DTSS_TEXCOORDINDEX, 0 );
M_pd3dDevice-> SetTexture (1, m_pWallTexture );
M_pd3dDevice-> SetTextureStateState (1, D3DTSS_TEXCOORDINDEX, 1 );

The first texture uses the first texture coordinate of the vertex, and the second texture uses the second texture coordinate of the vertex. Of course, the second texture can also use the first group of texture coordinates, depending on the situation.

--------------------------------------------
3. Four texture addressing modes

The texture addressing method is something I only know after querying other websites, because I have never touched on the texture ing method before using openGL, therefore, this part seems a little difficult.

Generally, the assigned U and V texture coordinate values are within the range of 0.0 to 1.0 (including them ). However, if we allocate texture coordinates out of this range, we may get some special texture effects. By setting the texture addressing mode, we can control the texture coordinates when they exceed the range. The texture addressing mode is used to do this.

Wrapping texture addressing mode

Image addressing mode

This mode is determined by the D3DTADDRESS_MIRRORONCE Member of the D3DTEXTUREADDRESS Enumeration type. It is a new texture addressing mode introduced from DirectX8, similar to a combination of image modes in the clamping mode. The texture is then used as an image between-1.0 and 1.0, and the image is clamped out of the range.

------------------------------------- 4. In simple terms, texture Wrapping is the basic way to change the Direct3D grating to use texture coordinates to perform grating operations on Texture polygon. When we perform a grating operation on a polygon, the system performs interpolation between the texture coordinates of each polygon vertex to determine the texture pixels used on each pixel of the polygon. Generally, the system regards the texture as A two-dimensional plane, and interpolation is performed on the line between two points A and B in the plane. If the U and V coordinates of vertex A are (0.8, 0.3) and point B is (0.1,. 9), the line for interpolation is shown in:


Note that the shortest line at the points A and B passes through the middle part of the texture. The use of U and V texture Wrapping affects the selection of the shortest line between texture coordinates in the U and V directions of Direct3D. Now we assume that 0.0 and 1.0 overlap, so by definition, texture Wrapping will cause the grating to select the shortest distance between texture coordinate settings. We can think that a texture Wrapping in one direction is to let the system think that a texture is wrapped on a cylinder, just as in:

In the U direction, we perform Wrapping, which affects the system's interpolation operation on texture coordinates. Using the same two vertices A and B, we can see that the shortest line between them no longer passes through the middle part of the texture; it now crosses the border between 0.0 and 1.0. Wrapping in the V direction is similar to Wrapping, except that the texture's cylinder is lying on the ground. Wrapping at the same time in the U and V directions is complicated. In this case, we can think of the texture as a garden or a donut.
It is explained in detail, that is to say, if it is packaged in the U direction, the minimum distance line segment in the U direction will be taken and interpolation will be performed on the segment; if it is packaged in the V direction, take the smallest distance line segment in the V direction and perform interpolation. The texture can be imagined as a ring by U & V.
Note that after texture packaging is enabled, the texture coordinates outside of [0, 1] will become invalid values, so texture packaging cannot be shared in various texture addressing modes.
----------------------------------------------

5. texture filtering and Anti-Aliasing (Anti-image Anti-Aliasing)

Texture filtering and anti-image filtering solve the same problem, that is, the problem of screen aliasing. The difference is that arts and science filtering solves the problem of sawtooth in the texture ing process, the anti-sample solution solves the tooth on the edge of the ry.

  • MipMap: It is a special texture that consists of a series of textures for resolution classification.

A mipmap is a series of textures. Each texture is the same as the previous one, but the resolution is lower than the previous one. The height and width of each image in the mipmap are 1/2 lower than that of the previous one. Mipmap is not necessarily a square.
High-resolution mipmap images are used for objects close to the observer. When the object is gradually away from the observer, use a low-resolution image. Mipmap can improve the rendering quality of the scenario, but it consumes a lot of memory.
Direct3D depicts mipmap as a series of interconnected surfaces. A high-resolution texture is located at the beginning and associated with the next level of texture. Similarly, textures are connected to each other and gradually arranged to the level with the smallest resolution.
The following illustration shows an example. This set of textures is a container label in a 3D scenario. When we create a mipmap, the texture with the highest resolution is the first one in this set of textures. The width and height of each texture in this mipmap are 1/2 of the width of the previous texture. In this way, the maximum resolution texture is 256x256, the next texture is 128x128, and the last texture is 64x64.
We have a maximum distance to see this label. If the observer approaches the label from a distance, the minimum texture is first displayed in the scenario, and its size is 64x64.

When the observer enters the label, we use a texture with a higher resolution. When the observer reaches the nearest allowed distance, we use the texture with the highest resolution.

This method can simulate the texture perspective effect and reduce the amount of computing during processing. This method is faster than applying a texture to different resolutions.
Direct3D can access the texture settings closest to the resolution we want to output in the mipmap and map pixels to its texture pixel space. If the final image resolution is in the middle of the Resolution of the mipmap texture, Direct3D checks the texture pixels in the two textures and fuses their color values.

The correct parameters provided to CreateTexture () can automatically create the MipMap texture.
  • Texture filtering methods: Last point sampling, linear texture filtering, unique filter, and hybrid filter

Filtering is a method used to obtain a map element from a texture map through a given UV coordinate. A 64*64 texture is mapped to a polygon of 400*400 pixels, which may result in the Sawtooth caused by amplification. This is called the amplification problem; when a 64*64 texture is mapped to a 10*10 pixel polygon, a screen pixel maps to multiple texture elements, and jitters occur due to alternate pixel occupation. To solve this problem, we need to use the texture filtering method. In the default graphics card settings, the texture filtering method is controlled by the driver.

Recent point sampling is the simplest filtering method. As the name suggests, it is to use the element closest to the pixel as the color. Align the texture coordinates to the nearest integer, and then use the texture map at the integer coordinates as the final color. This method may cause some errors when processing the graphic border.

Linear texture filtering uses bilinear texture filtering in Direct3D. It calculates the average value of the four elements closest to the sampling point. The configuration is as follows:
M_pd3Device-> SetSamplerState (0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
M_pd3Device-> SetSamplerState (0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );

Three-linear filtering: select the two closest mipmaps to filter them in bilinear mode into two ideal-sized mipmaps, then filter the corresponding pixels in the thick mipmap based on the ideal mip-level combination. The configuration is as follows:
M_pd3Device-> SetSamplerState (0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
M_pd3Device-> SetSamplerState (0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
M_pd3Device-> SetSamplerState (0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );

Heterosexual Filtering: the disadvantage of bilinear filtering and tri-linear filtering is that they use square Sampling areas to sample graphics, if the texture is side-oriented to the viewpoint, a distortion effect called "" will occur. In this case, the ing of ry sizes stretched by perspective projection is mapped back to the texture space, so that the texture is stretched during projection, so as to obtain better depth details and precise display. The code for filtering with the opposite sex is as follows:
M_pd3Device-> SetSamplerState (0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC );
M_pd3Device-> SetSamplerState (0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC );
M_pd3Device-> SetSamplerState (0, D3DSAMP_MAXD3DTEXF_ANISOTROOPY, 16 );

  • Reverse sample: The Reverse sample is a default feature in DirectX.

Full Screen anti-sample (FSAA): Uses full screen multi-sample to sample each pixel and then performs hybrid output, in this way, adjust the brightness around each diagonal line in the image to hide the Sawtooth effect on the ride, which produces partial blur effects along these edges. A more advanced multi-sample method is called maskable multisampling )".

  • Alpha hybrid

Alpha hybrid does not know how to get this chapter to introduce it. It may be to use this chapter without a program to introduce the basic knowledge of this chapter. Let me write it here.

The principle of alpha mixing is very simple. It is to use a hybrid factor to overlay the color to be drawn into the frame cache and the color in the current frame cache. Therefore, it can be rendered multiple times to achieve many special effects. The corresponding code is as follows:
M_pd3dDevice-> SetRenderState (D3DRS_ALPHABLENDENABLE, TRUE );
M_pd3dDevice-> SetRenderState (D3DRS_SRCBLEND, D3DBLEND_ZERO );
M_pd3dDevice-> SetRenderState (D3DRS_DESTBLEND, D3DBLEND_SRCCOLOR );

The "Wrapping" texture addressing mode is determined by the D3DTADDRESS_WRAP Member of the D3DTEXTUREADDRESS Enumeration type. It allows Direct3D to repeat the texture at each integer node (integer junction. Suppose we want to create a square element and declare the texture coordinates as (0.0, 0.0), (0.0, 3.0), (3.0, 3.0), and (3.0, 0.0 ). If the texture addressing mode is set, the texture can be repeated three times in the U and V directions ., As shown in:

The effect of this texture addressing mode is similar to that of the image mode, but it is essentially different.

Image Texture addressing mode

The image texture addressing mode is determined by the D3DTADDRESS_MIRROR Member of the D3DTEXTUREADDRESS Enumeration type, which enables Direct3D to mirror the texture at each integer boundary. We want to create a square element in which the coordinates are (0.0, 0.0), (0.0, 3.0), (3.0, 3.0), and (3.0, 0.0 ). We set the image texture addressing mode. The texture is repeated three times in the U and V directions, and each row and column have an image relationship with adjacent rows and columns. As shown in:

Clamp texture addressing mode

The "Clamp" texture addressing mode is determined by the D3DTADDRESS_CLAMP Member of the D3DTEXTUREADDRESS Enumeration type, which causes Direct3D to clamp texture coordinates within the range of [0.0, 1.0. That is to say, it uses only one texture and then erased the color of the edge pixel. We create a square element with the texture address allocated as (0.0, 0.0), (0.0, 3.0), (3.0, 3.0), and (3.0, 0.0 ). In this case, the clamp texture addressing mode is set. The texture will only be used once, And the pixel color of the top and last columns will extend to the top and rightmost segments of the elements, as shown in:

 

Border color texture addressing mode

The "edge color" texture addressing mode is determined by the D3DTADDRESS_BORDER Member of the D3DTEXTUREADDRESS Enumeration type. It enables Direct3D to use any color, that is, the border color, when the texture coordinates exceed the range.

Shows a texture-used element, which uses a red border color:

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.