In the mytutoriald3d11_16 project, I defined a material light source attribute constant buffer in the light. vs file.
// It is recommended that the const buffer be a multiple of 4 float; otherwise, the const buffer will be fail.
Cbuffer lightmaterialbuffer
{
Float4 lightposition; // The Position of the light source.
Float4 lightcolor; // The color of the light source.
Float4 globalambient; // environmental light reflection coefficient of the light source
Float4 cameraposition; // camera position
Float4 ke; // The self-illumination of the material.
Float4 Ka; // environmental light coefficient of the material
Float4 KD; // diffuse reflection coefficient of the material
Float4 KS; // The highlight coefficient of the material.
Float3 lightdirection; // Parallel Direction
Float shininess; // The highlight index.
};
By defining this const buffer, we can set various attributes of the vertex material and light source in lightshaderclass.
At the same time, I have modified the render and setshaderparameters function interfaces in the lightshaderclass class to pass in various parameters.
Bool render (id3d11devicecontext *, Int, d3dxmatrix, d3dxmatrix, d3dxmatrix, d3dxvector4, d3dxvector4, d3dxvector4,
D3dxvector4, d3dxvector4, d3dxvector4, d3dxvector4, d3dxvector4, d3dxvector3, float );
Bool setshaderparameters (id3d11devicecontext *, d3dxmatrix, d3dxmatrix, d3dxmatrix, d3dxvector4, d3dxvector4, d3dxvector4,
D3dxvector4, d3dxvector4, d3dxvector4, d3dxvector4, d3dxvector4, d3dxvector3, float );
Now we can see that there are many parameters for these two functions, which are very uugly. In the subsequent project, I will only pass in the camera position. Other parameters are directly assigned values in colorshaderclass.
After the program is executed, the effect is as follows:
However, it may be that the normal definition of objects in my cubemodelclass is not displayed at the bottom, left, and bottom of the cube. In the next log, I will redefine the vertex direction in cubemodelclass.
Complete code can be found:
Project File mytutoriald3d11_16
Download Code:
Http://files.cnblogs.com/mikewolf2002/myTutorialD3D11.zip