Texture mix
Typically, a piece of texture data on the polygon is rendered to the off-screen surface used to finally display (of course, the off-screen surface is not used to display, the new texture data is overwritten on the target surface. There is data. However, D3D provides new texture data with the original data, which is a certain proportion, which is a texture mix. Texture mixing can achieve a variety of special effects such as transparency, light, etc., which is extremely commonly used in 3D procedures. The following is part of the following description: 1.Alpha texture blending) When D3D is based on the current material, vertex color, light, and When the texture finally calculates a color of a pixel on a polygon image, if the texture is made, the color (source color) calculates the color (target color) of the corresponding pixel on the target surface, calculates the mixture according to the following formula. The colored colors are placed in the target surface. Mixed color = source color × source mixing coefficient Target color × Object mixing coefficient source mixing coefficient and target mixing coefficient is two numbers between 0.0 and 1.0, the defaults are D3DBLEND_SRCALPHA (source alpha value), D3Dblend_invsrcalpha (1.0 - source alpha value). These two coefficients can be set by idirect3ddevice7 :: setRenderstate, and the first parameter passes to D3DRS_SRCBLEND or D3DRS_DESTBLEND, and the second parameter is incorporated into the D3dblend type. The use steps of Alpha are generally as follows: (1). Set the texture status of the 0th layer via iDirect3ddevice7 :: setTexture and iDirect3dDevice7 :: setTexturestagestate. (2). Painting scene. (3). Change the texture status of the 0th layer. (4). Open alpha blending through iDirect3ddevice7 :: setrenderstate and set the relevant parameters. (5). Repeat (2), (3), (4). It can be seen that "drawing scene" is to repeat it, so this texture is mixed with multiple texture blending. 2. Single Pass Multiple Texture Blending "In" Multiple Texture Memory ", the operation of" drawing scene "is repeated, and time, there is a new technology. "Single multiple texture mix". As the name suggests, this technology is only "drawing scene" once, saving time. D3D enables this mixing through the "Texture Stage", you can put each layer of pattern as a transparent glass drawing the pattern, and then stacked several different patterns of the glass, and the pattern of seeing is quite The final image mixed with texture. D3D provides a mix of eight-layer texture, of course, very few graphics cards support so much, and it is sufficient to use three layers in the program. (1). Texture Stages, see the above illustration, one texture layer has two inputs: arg1, arg2; one action: OP; and an output: Blended Output. Set the input and operation of the texture layer by iDirect3dDevice7 :: setTexturestageState, the output can be used as an input to the next layer, or it can be sent as the final result.
(2). Texture Blending Cascade A series of texture layers in sequence is mixed by the image called "Texture mixed waterfall", the image data begins with water flow from the Layer 0, mixed with new data in each layer After the next layer, until the target surface is finally sent. In D3D, n <= 7 in the above figure, that is, the maximum number of eight layers, the number is numbered from 0 to 7, and the mixing can only start from the 0 layer, but can end at any layer (provided is hardware support), and the middle cannot be There is a jump, that is, once a layer is not mixed, then this layer is the place where the end is over, and the third layer does not participate in mixing, then 4, 5, 6, 7 after the third floor cannot participate in mixing). (3). The parameter of the texture layer is set in DirectX7.0, and the status parameters of the texture layer are functioned via the idirect3ddevice7 :: setTexturestageState function. The declaration is as follows: HRESULT SETTEXTURESTAGESTATE (
DWORD DWStage,
D3DTexturestageStateType DWState,
DWORD DWVALUE
);
The first parameter dwstage specifies which texture layer, starting from 0. For example, set the second layer, it is passed to 2. The second parameter specifies which state. Commonly used:
D3DTSS_COLORARG1: Enter parameter arg1
D3DTSS_COLORARG2: Enter parameter arg2
D3DTSS_COLOROP: Operation OP
The third parameter specifies the value of the status. Commonly used: corresponding to input (arg1 and arg2): D3DTA_DIFFUSE: The value calculated from the Diffuse color of the vertex. D3DTA_CURRENT: The output of the last layer, such as this layer is the 0th layer, equivalent to D3DTA_DIFFUSE. D3DTA_TEXTURE: The texture data of the layer. (You can only use arg1) corresponding to operation (OP): D3DTOP_DISABLE: Turn off the layer. D3DTOP_SELECTARG1: Use the input one (arg1) as an output. D3DTOP_SELECTARG2: Use input 2 (arg2) as an output. D3DTOP_MODULATE: Use arg1 × arg2 as an output. D3DTOP_ADD: Use arg1 arg2 as an output. The use steps of single multiple texture mixing are generally as follows: (1). Set the texture status of the 0th to N layer by idirect3ddevice7 :: setTexture and IDirect3DDevice7 :: SetTexturestagestate. (2). Painting scene. When the hardware does not support "single multi-texture mix", the "multiple texture mix" can be used to achieve the same effect, just to draw multiple times, reduce the speed of the program. Sometimes, after a single multi-texture is mixed, it is also possible to mix and produce more complex effects in Alpha texture.