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

Ambient Lighting = Ca*[Ga + sum(Atti*Spoti*Lai)] 

Where:

ParameterDefault valueTypeDescription
Ca(0,0,0,0)D3DCOLORVALUEMaterial ambient color
Ga(0,0,0,0)D3DCOLORVALUEGlobal ambient color
Atteni(0,0,0,0)D3DCOLORVALUELight attenuation of the ith light. See Attenuation and Spotlight Factor (Direct3D 9).
Spoti(0,0,0,0)D3DVECTORSpotlight factor of the ith light. See Attenuation and Spotlight Factor (Direct3D 9).
sumN/AN/ASum of the ambient light
Lai(0,0,0,0)D3DVECTORLight ambient color of the ith light

Diffuse Lighting = sum[Cd*Ld*(N.Ldir)*Atten*Spot]
ParameterDefault valueTypeDescription
sumN/AN/ASummation of each light's diffuse component.
Cd(0,0,0,0)D3DCOLORVALUEDiffuse color.
Ld(0,0,0,0)D3DCOLORVALUELight diffuse color.
NN/AD3DVECTORVertex normal
LdirN/AD3DVECTORDirection vector from object vertex to the light.
AttenN/AFLOATLight attenuation. See Attenuation and Spotlight Factor (Direct3D 9).
SpotN/AFLOATSpotlight 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.

ParameterDefault valueTypeDescription
Cs(0,0,0,0)D3DCOLORVALUESpecular color.
sumN/AN/ASummation of each light's specular component.
NN/AD3DVECTORVertex normal.
HN/AD3DVECTORHalf way vector. See the section on the halfway vector.
P0.0FLOATSpecular reflection power. Range is 0 to +infinity
Ls(0,0,0,0)D3DCOLORVALUELight specular color.
AttenN/AFLOATLight attenuation value. See Attenuation and Spotlight Factor (Direct3D 9).
SpotN/AFLOATSpotlight factor. See Attenuation 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 * 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 );
  
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值