Now we try to change the box texture and use a DDS file with Alpha wirefence. Dds,
Use DirectX texture tool to open the file interface as follows:
In fact, in this figure, some pixels have alpha values and some pixels have alpha values of 0. We can click View-alpha channel only to see the following figure. The Alpha value of the black part is 0:
Now we paste this figure to the box. The program running effect is as follows:
We add the following code in lighttex. PS. Pay attention to the use of clip functions.
Float3 n = normalize (input. worldnormal );
Float4 texturecolor = shadertexture. Sample (sampletype, input. Tex );
// Obtain the Alpha value from the texture map
Float alpha = shadertexture. Sample (sampletype, input. Tex).;
// If Alpha is less than 0.25, discard the current Pixel
Clip (alpha-0.25 );
After the program is executed, the effect is as follows:
The program running result is good, but the back of the fence box is removed. Next we try to add a function to the d3dclass to disable and enable the cullmode function. When the box is rendered, remove the back.
Void d3dclass: enablebackcullmode (bool B)
{
D3d11_rasterizer_desc rasterdesc;
Hresult result;
// Sets the grating description to specify how the polygon is rendered.
Rasterdesc. antialiasedlineenable = false;
If (B)
Rasterdesc. cullmode = d3d11_cull_back;
Else
Rasterdesc. cullmode = d3d11_cull_none;
Rasterdesc. depthbias = 0;
Rasterdesc. depthbiasclamp = 0.0f;
Rasterdesc. depthclipenable = true;
Rasterdesc. fillmode = d3d11_fill_solid; // d3d11_fill_solid
Rasterdesc. frontcounterclockwise = false;
Rasterdesc. multisampleenable = false;
Rasterdesc. scissorenable = false;
Rasterdesc. slopescaleddepthbias = 0.0f;
// Create a raster status
Result = m_device-> createrasterizerstate (& rasterdesc, & m_rasterstate );
If (failed (result ))
{
HR (result );
Return;
}
// Set the grating status to take effect
M_devicecontext-> rssetstate (m_rasterstate );
}
When rendering a box in graphicsclass, we add the following code:
// Turn off the back when rendering the box.
M_d3d-> enablebackcullmode (false );
// Use light shader for rendering
Result = m_lighttexshader-> render (m_d3d-> getdevicecontext (), m_cubemodel-> getindexcount (), worldmatrix3, viewmatrix, projectionmatrix,
Light, material, camera, m_texmanager-> createtex (m_d3d-> getdevice (), string ("wirefence. Dds ")));
M_d3d-> enablebackcullmode (true );
// Open the back to remove
M_d3d-> enablebackcullmode (true );
The final running effect of the program is as follows:
Complete code can be found:
Project File mytutoriald3d11_41
Download Code:
Http://files.cnblogs.com/mikewolf2002/d3d1139-49.zip
Http://files.cnblogs.com/mikewolf2002/pictures.zip