Software Optical Computing

Source: Internet
Author: User

 

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;
}

 

 

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.