Directx11 tutorial 40 texture ing (10)

Source: Internet
Author: User

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

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.