This chapter tries to use texture determine, or texture array. In PS, two textures are used. The final pixel color is light color * texture 1 Sampling color * texture 2 sampling color, we mainly want to achieve the following results:
Combine the two images and the colors produced by the light to generate an image:
Create a lighttex2.ps file, which defines:
// Two textures, which can be used for texture mixing, bump mapping, and so on
Texture2d shadertexture [2];
Samplerstate sampletype;
...
Float4 texturecolor1 = shadertexture [0]. Sample (sampletype, input. Tex );
Float4 texturecolor2 = shadertexture [1]. Sample (sampletype, input. Tex );
...
Texturecolor = saturate (texturecolor1 + texturecolor2)/2.0 );
// 2.2 is a Gamma Correction Value
Finalcolor = finalcolor * POW (texturecolor, 2.2)
In addition, we define a lighttex2shaderclass specifically used to process lightex2.vs and lighttex2.ps. In this class, we use
// Configure the PS shader resource.
Devicecontext-> pssetshaderresources (0, 2, texarray );
Load a texture array.
The last step is the modification of the graphics rendering class. We draw another wall on the left, which uses a texture while the front wall uses texture fusion.
M_textures [0] = m_texmanager-> createtex (m_d3d-> getdevice (), string ("stone01.dds "));
M_textures [1] = m_texmanager-> createtex (m_d3d-> getdevice (), string ("dirt01.dds "));
...
// Perform the translation operation to obtain the final model world matrix.
D3dxmatrixrotationx (& worldmatrix1,-1.57); // PAI/2
D3dxmatrixtranslation (& worldmatrix2, 0.0, 0.0, 8.0 );
D3dxmatrixmultiply (& worldmatrix3, & worldmatrix1, & worldmatrix2 );
Result = m_lighttex2shader-> render (m_d3d-> getdevicecontext (), m_planemodel-> getindexcount (), worldmatrix3, viewmatrix, projectionmatrix,
Light, material, camera, m_textures );
If (! Result)
{
Return false;
}
// Perform the translation operation to obtain the final model world matrix.
D3dxmatrixrotationz (& worldmatrix1,-1.57); // PAI/2
D3dxmatrixtranslation (& worldmatrix2,-10.0, 0.0, 0.0 );
D3dxmatrixmultiply (& worldmatrix3, & worldmatrix1, & worldmatrix2 );
Result = m_lighttexshader-> render (m_d3d-> getdevicecontext (), m_planemodel-> getindexcount (), worldmatrix3, viewmatrix, projectionmatrix,
Light, material, camera, m_texmanager-> createtex (m_d3d-> getdevice (), string ("stone01.dds ")));
If (! Result)
{
Return false;
}
The program execution interface is as follows:
Complete code can be found:
Project File mytutoriald3d11_35
Download Code:
Http://files.cnblogs.com/mikewolf2002/d3d1127-28.zip
Http://files.cnblogs.com/mikewolf2002/pictures.zip