Direct3D Lighting and textures

Source: Internet
Author: User

Today we will learn the light source and material inside the Direct3D.

Four types of illumination:
Ambient light Ambient Light An object is not directly irradiated by light, and it can be seen by the light that is reflected by each object. This is called ambient light
Diffuse reflection Light Diffuse light This type of light travels in a particular direction, and when it reaches a certain surface it will reflect evenly around (focusing on the spatial position and direction of the reflected light)
Specular Reflection Light Specular light When such light reaches a surface, it is strictly reflected in one direction.
Self-luminous Emissive Light Self-illumination is the object's own glow.

Opening of ambient light:

Device->setrenderstate (D3drs_ambient,d3dcolor_xrgb ());

Mirror-reflective light on:

Device->setrenderstate (d3drs_specularenable,true);
Three main types of light sources:

Point Light has a color and position, but no direction, it emits light in all directions, and the light is not attenuated by distance

Directional lights (direction light) propagate in the same direction in the scene, with color and orientation, unaffected by attenuation and range.

Spotlight source, in our lives a flashlight consists of an inner cylinder and an outer cylinder, and the light decays gradually from the center to the periphery. Phi and Theta are the inner angle sizes of two cones respectively.

To create a point light:
D3dlight9 light;::zeromemory (&light,sizeof(light)); Type= D3dlight_point;//various light types, now point lightLight. Ambient = D3dxcolor (0.8f,0.8f,0.8f,1.0f);//The following three parameters are ambient light, diffuse light, specular light color valueLight. Diffuse = D3dxcolor (1.0f,1.0f,1.0f,1.0f); light. Specular= D3dxcolor (0.3f,0.3f,0.3f,1.0f); light. Position= D3dxvector3 (0.0f,200.0f,0.0f);//coordinate positionLight. Attenuation0 =1.0f;//The following three parameters are the coefficients of light attenuation along the distanceLight. Attenuation1 =0.0f; Light. Attenuation2=0.0f; Light. Range=300.0f;//The range of illumination, which is effective in some light sourcesDevice->setlight (0, &light);//Set the lightDevice->lightenable (0,true);//turn on the light
To create a directional light:
//Creating directional lightsD3dlight9 light;::zeromemory (&light,sizeof(light)); Type= D3dlight_directional;//Directional LightLight. Ambient = D3dxcolor (0.5f,0.5f,0.5f,1.0f); light. Diffuse= D3dxcolor (1.0f,1.0f,1.0f,1.0f); light. Specular= D3dxcolor (0.3f,0.3f,0.3f,1.0f); light. Direction= D3dxvector3 (0.0f,0.0f,1.0f);D Evice->setlight (0,&Light );D Evice->lightenable (0,true);
To create a spotlight:
D3dlight9 light;::zeromemory (&light,sizeof(light)); Type=D3dlight_spot;light. Position= D3dxvector3 (100.0f,100.0f,100.0f); light. Direction= D3dxvector3 (-1.0f,-1.0f,-1.0f); light. Ambient= D3dxcolor (0.3f,0.3f,0.3f,1.0f); light. Diffuse= D3dxcolor (1.0f,1.0f,1.0f,1.0f); light. Specular= D3dxcolor (0.3f,0.3f,0.3f,0.3f); light. Attenuation0=1.0f; light. Attenuation1=0.0f; light. Attenuation2=0.0f; light. Range=300.0f; light. Falloff=0.1f; light. Phi= D3DX_PI/3.0f; light. Theta= D3DX_PI/6.0f;D Evice->setlight (0,&Light );D Evice->lightenable (0,true);

Material:

Light and material like two good friends, the material properties of the surface of the object determines what color it can reflect the light , and how much can be reflected, the material belongs to an object ,

To learn how to create a material

//To create a material:d3dmaterial9 mtrl;::zeromemory (&mtrl,sizeof(Mtrl)); Mtrl. Ambient= D3dxcolor (0.5f,0.5f,0.7f,1.0f);//indicates the reflectivity of the object surface to ambient light, fill in a color, ARGB value between 0-1Mtrl. Diffuse = D3dxcolor (0.6f,0.6f,0.6f,1.0f);//reflectivity of diffuse reflection lightMtrl. Specular = D3dxcolor (0.3f,0.3f,0.3f,0.3f);//reflectivity of specular reflection lightMtrl. emissive = D3dxcolor (0.0f,0.0f,0.0f,1.0f);//reflectivity of the spontaneous light colorMtrl. Power =0.1f;D Evice->setmaterial (&mtrl);//Set Material

The sum of the brightness of the vertex color of an object has a formula:

Color sum = ambient light + Diffuse reflection light + specular light + spontaneous light

Direct3D Lighting and textures

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.