DirectX tutorial (23) Simple Lighting Model (2)

Source: Internet
Author: User

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

 

 

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.