Use a programmable rendering pipeline to implement the phone Illumination Model

Source: Internet
Author: User
Ambient Lighting = Ca*[Ga + sum(Atti*Spoti*Lai)] 

Where:

Parameter Default Value Type Description
CA (0, 0, 0) D3dcolorvalue Material ambient color
GA (0, 0, 0) D3dcolorvalue Global ambient color
Atteni (0, 0, 0) D3dcolorvalue Light attenuation of the ith light. See attenuation and spotlight factor (direct3d 9 ).
Spoti (0, 0, 0) D3dvector Spotlight factor of the ith light. SeeAttenuation and spotlight factor (direct3d 9).
Sum N/ N/ Sum of the ambient light
Lai (0, 0, 0) D3dvector Light ambient color of the ith light
Diffuse Lighting = sum[Cd*Ld*(N.Ldir)*Atten*Spot]
Parameter Default Value Type Description
Sum N/ N/ Summation of each light's diffuse component.
CD (0, 0, 0) D3dcolorvalue Diffuse color.
LD (0, 0, 0) D3dcolorvalue Light diffuse color.
N N/ D3dvector Vertex normal
Ldir N/ D3dvector Direction vector from object vertex to the light.
Atten N/ Float Light attenuation. See attenuation and spotlight factor (direct3d 9 ).
Spot N/ Float Spotlight factor. SeeAttenuation and spotlight factor (direct3d 9).
Specular lighting = cs * sum [ls * (N • H) p * atten * Spot]

The following table identifies the variables, their types, and their ranges.

Parameter Default Value Type Description
CS (0, 0, 0) D3dcolorvalue Specular color.
Sum N/ N/ Summation of each light's specular component.
N N/ D3dvector Vertex normal.
H N/ D3dvector Half way vector. See the section on the halfway vector.
P 0.0 Float Specular reflection power. range is 0 to + infinity
Ls (0, 0, 0) D3dcolorvalue Light specular color.
Atten N/ Float Light attenuation value. See attenuation and spotlight factor (direct3d 9 ).
Spot N/ Float Spotlight factor. SeeAttenuation and spotlight factor (direct3d 9).

Float4x4 matviewprojection;
Float4 light_position;
Float4 light_attenuation;
Float4 light_color;
Float4 ambient_color;
Float4 vviewposition;
Float Alpha;

Struct vs_input
{
Float4 position: position0;
Float3 normal: normal0;
Float2 texcoord: texcoord0;
};

Struct vs_output
{
Float4 position: position0;
Float2 texcoord: texcoord0;
Float4 color: color0;
};

Float4 pointlighting (float3 position, float3 normal
, Float3 eyedir, float4 Ambient
, Float3 lightpos, float3 lightatt, float4 lightcolor)
{
Float3 lightdir = normalize (position-lightpos );
Float3 Dis = distance (Position, lightpos );
Float disatt = saturate (1/(lightatt. x + lightatt. y * DIS + lightatt. z * Dis ));
Float angleatt = saturate (-lightdir * normal );
Float3 reflectdir = normalize (reflect (lightdir, normal ));
Float specularatt = POW (saturate (reflectdir * eyedir), alpha );

Return ambient + lightcolor * disatt * (angleatt + specularatt );
}

Vs_output vs_main (vs_input input)
{
Vs_output output;

Output. Position = MUL (input. Position, matviewprojection );
Output. texcoord = input. texcoord;
Float3 eyedir = normalize (vviewposition-input. position );
Output. Color = pointlighting (input. Position, input. Normal
, Eyedir, ambient_color
, Light_position, light_attenuation, light_color );

Return (output );

}

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.