首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >用可编程渲染管线实现phone光照模型

用可编程渲染管线实现phone光照模型

作者头像
逍遥剑客
发布2018-05-23 10:06:01
发布2018-05-23 10:06:01
4780
举报
代码语言:javascript
复制
Ambient Lighting = Ca*[Ga + sum(Atti*Spoti*Lai)] 

Where:

Parameter

Default value

Type

Description

Ca

(0,0,0,0)

D3DCOLORVALUE

Material ambient color

Ga

(0,0,0,0)

D3DCOLORVALUE

Global ambient color

Atteni

(0,0,0,0)

D3DCOLORVALUE

Light attenuation of the ith light. See Attenuation and Spotlight Factor (Direct3D 9).

Spoti

(0,0,0,0)

D3DVECTOR

Spotlight factor of the ith light. See Attenuation and Spotlight Factor (Direct3D 9).

sum

N/A

N/A

Sum of the ambient light

Lai

(0,0,0,0)

D3DVECTOR

Light ambient color of the ith light

代码语言:javascript
复制
Diffuse Lighting = sum[Cd*Ld*(N.Ldir)*Atten*Spot]

Parameter

Default value

Type

Description

sum

N/A

N/A

Summation of each light's diffuse component.

Cd

(0,0,0,0)

D3DCOLORVALUE

Diffuse color.

Ld

(0,0,0,0)

D3DCOLORVALUE

Light diffuse color.

N

N/A

D3DVECTOR

Vertex normal

Ldir

N/A

D3DVECTOR

Direction vector from object vertex to the light.

Atten

N/A

FLOAT

Light attenuation. See Attenuation and Spotlight Factor (Direct3D 9).

Spot

N/A

FLOAT

Spotlight factor. See Attenuation 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,0)

D3DCOLORVALUE

Specular color.

sum

N/A

N/A

Summation of each light's specular component.

N

N/A

D3DVECTOR

Vertex normal.

H

N/A

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,0)

D3DCOLORVALUE

Light specular color.

Atten

N/A

FLOAT

Light attenuation value. See Attenuation and Spotlight Factor (Direct3D 9).

Spot

N/A

FLOAT

Spotlight factor. See Attenuation and Spotlight Factor (Direct3D 9).

代码语言:javascript
复制
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 * 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 );
  
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2008年05月04日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档