Code
D3dxcolor scenelightmgr: caldirectionallight (d3dxvector3 /* F3verpos */ , D3dxvector3 f3normal, d3dxvector3 f3lightdir,
D3dxcolor f4lightcolor)
{
D3dxcolor f4outcol ( 0 , 0 , 0 , 1 );
D3dxvec3normalize (&F3lightdir,&F3lightdir );
D3dxvector3 invdir = - F3lightdir;
Float F0 = D3dxvec3dot ( & F3normal, & Invdir );
If (F0 > = 0 )
F4outcol = F0 * F4lightcolor;
F4outcol.= 1;
ReturnF4outcol;
}
D3dxcolor scenelightmgr: calpointlight (d3dxvector3 f3verpos, d3dxvector3 f3normal, d3dxvector3 f3lightpos, d3dxcolor f4lightcolor,
Float Frange, d3dxvector3 f3attenuation)
{
D3dxcolor f4outcol ( 0 , 0 , 0 , 1 );
D3dxvector3 f3lightvec = F3lightpos - F3verpos;
Float Fradius = D3dxvec3length ( & F3lightvec );
If (Fradius <= Frange)
{
D3dxvec3normalize ( & F3lightvec, & F3lightvec );
Float F0 = D3dxvec3dot ( & F3normal, & F3lightvec );
Float Fatten = 1 ;
If (F0 > = 0 )
{
Fatten = 1 - Pow (fradius / Frange, f3attenuation. X );
// Fatten = 1.f/ (f3attenuation. x + f3attenuation. y * fradius + f3attenuation. z * fradius );
If (Fatten < 0 )
Fatten = 0 ;
If (Fatten > 1 )
Fatten = 1 ;
F4outcol=F0*F4lightcolor*Fatten;
}
}
F4outcol.= 1;
ReturnF4outcol;
}
D3dxcolor scenelightmgr: calspotlight (d3dxvector3 f3verpos, d3dxvector3 f3normal, d3dxvector3 f3lightpos, d3dxvector3 f3lightdir,
D3dxcolor f4lightcolor, Float Frange, d3dxvector3 f3attenuation, Float Ffalloff,
Float Ftheta, Float Fphi)
{
D3dxcolor f4outcol ( 0 , 0 , 0 , 1 );
D3dxvector3 f3lightvec = F3lightpos - F3verpos;
float fradius = d3dxvec3length ( & f3lightvec );
If (fradius <= frange)
{< br> d3dxvec3normalize ( & f3lightvec, & f3lightvec );
d3dxvec3normalize ( & f3lightdir, & f3lightdir );
FloatF0=D3dxvec3dot (&F3normal,&F3lightvec );
FloatFatten= 1;
If (F0 > = 0 )
{
D3dxvector3 invlightvec = - F3lightvec;
Float Frho = D3dxvec3dot ( & Invlightvec, & F3lightdir ); // DOT (-f3litvec, normalize (f3lightdir ));
Float Fcostheta = Cosf (ftheta / 2 );
Float Fcosphi = Cosf (fphi / 2 );
If (Frho > Fcostheta)
Fatten = 1 ;
Else If (Frho < Fcosphi)
Fatten = 0 ;
Else
{
Fatten = Pow (frho - Fcosphi) / (Fcostheta - Fcosphi), ffalloff );
If (Fatten < 0 )
Fatten = 0 ;
If (Fatten > 1 )
Fatten = 1 ;
}
Fatten * = 1 - Pow (fradius / Frange, f3attenuation. X );
// Fatten * = 1.f/ (f3attenuation. x + f3attenuation. y * fradius + f3attenuation. z * fradius );
If (Fatten < 0 )
Fatten = 0 ;
If (Fatten > 1 )
Fatten = 1 ;
F4outcol=F0*F4lightcolor*Fatten;
}
}
F4outcol.= 1;
ReturnF4outcol;
}