Secilig 5 h Week, 9 Reflecio wihou Usig he Secil Buffe
Blockig he Reflecio Usig he Secil Buffe Secil Buffe A off-scee buffe fo secial effecs Haig same esoluio as he back buffe a eh buffe To block eeig o ceai as of he back buffe Simle ieface offes a fleible a oweful se of caabiliies like bleig Alicaios: mios, laa shaows
Objecies To gai a uesaig of how he secil buffe woks, how o ceae a secil buffe, a how we ca cool he secil buffe To lea how o imleme mios a usig he secil buffe o ee e eflecios fom beig aw o o-mio sufaces To iscoe how o ee shaows a ee ouble bleig b usig he secil buffe Usig he Secil Buffe Eablig he secil buffe g3deice->sereesae(d3drs_stencienabe, ue);... // o secil wok g3deice->sereesae(d3drs_stencienabe, false); Cleaig he secil buffe o a efaul alue g3deice->clea(,, D3DCEAR_TARGET D3DCEAR_ZBUFFER D3DCEAR_STENCI, ff, 1.f, );
Requesig a Secil Buffe (1) Ceaig a secil buffe a he ime he eh buffe is ceae To secif he foma of he secil buffe also whe secifig he foma of he eh buffe E) hee eh/secil fomas D3DFMT_D4S8D4S8 D3DFMT_D4X4S4 D3DFMT_D15S1D15S1 cf) D3DFMT_D3 Requesig a Secil Buffe ()
The Secil Tes Decisio o block a aicula iel fom beig wie IF ef & mask alue & mask ue THEN acce iel ESE ejec iel Pefome fo ee iel ef-ha-sie oea (HS ef & mask) ANDig alicaio-efie secil efeece alue (ef) wih a alicaio-efie maskig alue (mask) Righ-ha-sie oea (RHS alue & mask) ANDig e i he secil buffe fo he aicula iel (ef) wih alicaio-efie maskig alue (mask) Comaiso oeaio : if ue, he iel is wie Cf) If a iel is wie o he back buffe, i is wie o he eh buffe eihe. Coollig he Secil Tes (1) Secifig he secil efeece alue, he mask alue, a he comaiso oeaio Secil efeece alue: ef Zeo b efaul Useful o see whe oig biwise oeaios g3deice->sereesae(d3drs >SeReeSae(D3DRS_STENCIREF D3DRS_STENCIREF, STENCIREF, 1); Secil mask: mask Maskig (Hiig) bis i boh he ef a alue aiables ffffffff b efaul g3deice->sereesae(d3drs_stencimask, ffff); Secil alue: alue Value i he secil buffe fo he cue iel
Coollig he Secil Tes () Comaiso oeaio: IF ef & mask alue & mask ue THEN acce iel ESE ejec iel g3deice->sereesae(d3drs_stencifunc, D3DCMP_AWAYS); eef eum _D3DCOMPFUNC { D3DCMP_NEVER 1, D3DCMP_ESS, D3DCMP_EQUA 3, D3DCMP_ESSEQUA 4, D3DCMP_GREATER 5, D3DCMP_NOTEQUA 6, D3DCMP_GREATEREQUA 7, D3DCMP_AWAYS 8, D3DCMP_FORCE_DWORD 7ffffff } D3DCOMPFUNC; C Coollig he Secil Tes (3) Comaiso oeaio: (co ) D3DCMP_NEVER: secil es alwas fails (he iel is alwas ejece) D3DCMP_ESS: elace wih < oeao D3DCMP_EQUA: elace wih oeao D3DCMP_ESSEQUA: elace wih oeao D3DCMP_GREATER: elace wih > oeao D3DCMP_NOTEQUA: elace wih! oeao D3DCMP_GREATEREQUA: elace wih oeao D3DCMP_AWAYS: secil es alwas succees (he iel is alwas aw)
Uaig he Secil Buffe (1) Defiig how he secil buffe e shoul be uae base o hee ossible cases: The secil es fails 3Deice->SeReeSae(D3DRS_STENCIFAI, SecilOeaio); The eh es fails 3Deice->SeReeSae(D3DRS_STENCIZFAI, SecilOeaio); The eh hes a secil iles succee 3Deice->SeReeSae(D3DRS_STENCIPASS, SecilOeaio); D3DSTENCIOP_KEEP D3DSTENCIOP_ZERO D3DSTENCIOP_ REPACE D3DSTENCIOP_INVERT D3DSTENCIOP_INCRSAT D3DSTENCIOP_DECRSAT D3DSTENCIOP_ INCR D3DSTENCIOP_DECR Uaig he Secil Buffe () SecilOeaio D3DSTENCIOP_KEEP: kee he secil buffe e D3DSTENCIOP_ZERO: se he secil buffe e o eo D3DSTENCIOP_REPACE: elace he secil buffe e wih he secil-efeece alue D3DSTENCIOP_INCRSAT: iceme he secil buffe e (clam he e o ha maimum) D3DSTENCIOP_DECRSAT: eceme he secil buffe e (clam he e o eo) D3DSTENCIOP_INVERT: ie he bis of he secil buffe e D3DSTENCIOP_INCR: INCR: iceme he secil buffe e (wa o eo) D3DSTENCIOP_DECR: eceme he secil buffe e (wa o he maimum)
Secil Wie Mask Maskig off bis of a alue we wie o he secil buffe ffffffff b efaul 3Deice->SeReeSae(D3DRS >SeReeSae(D3DRS_STENCIWRITEMASK D3DRS_STENCIWRITEMASK, STENCIWRITEMASK, ffff); Mio Demo
Imlemeig Mios o Plaa Sufaces Solig wo oblems Solig wo oblems How o eflec a objec abou a abia lae Aalical Geome Aalical Geome Dislaig he eflecio ol i a mio Secil Buffe Secil Buffe Aalical Geome Aalical Geome Secil Buffe Secil Buffe The Mahemaics of Reflecio (1) The Mahemaics of Reflecio (1) How o comue he eflecio oi ( ) How o comue he eflecio oi of a oi abou a abia lae ( ),, ( ),, ˆ ( ),, kˆ ( ) ˆ ˆ ˆ k q ˆ k kˆ ( ) Mai Mai Mai Mai ˆ ( ),, 1 1 1 1 1 R
The Mahemaics of Reflecio () D3DX liba oies he fucio o ceae he eflecio mai D3DXMATRIX *D3DXMaiReflec( D3DXMATRIX *Ou, CONST D3DXPANE *Plae ); The eflecios abou he hee saa cooiae laes he,, a laes R 1 1 1 1 R 1 1 1 1 R 1 1 1 1 Mio Imlemeaio Oeiew 1. Ree he eie scee as omal. Clea he secil buffe o Back Buffe Secil Buffe 3. Ree he imiies ha make u he mio io he secil buffe ol Secil es: alwas succeeig Secil oeaio: elacig wih 1 if he es asses Back Buffe Secil Buffe 4. Ree he eflece eao o he back buffe a secil buffe
Eablig he Secil Buffe Reeig he Mio
Peaig he Reflecio Comuaio of he Reflecio Mai
Disablig he Deh Buffe Cleaig u
Plaa Shaow Demo Plaa Shaow Shaows ha lie o a lae To ai i ou eceio of whee ligh is beig emie To make he scee moe ealisic Imlemeaio Fiig he shaow a objec cass o a lae a moelig i geomeicall 3D Mah Reeig he shaow wih a black maeial a 5% asaec To ee ouble bleig fom occuig Secil Buffe
Paallel igh Shaows Paallel igh Shaows A a/lae iesecio A a/lae iesecio Ra () Iesecio Poi Plae Iesecio Poi s ( ) s ( ) ( ) s ( ) s s Poi igh Shaows Poi igh Shaows A a/lae iesecio A a/lae iesecio Ra () ( ) Iesecio Poi Plae Iesecio Poi ( ) s ( ) ( ) s ( ) ( ) ( ) s ( ) s s
The Shaow Mai (1) Diecioal igh Shaows Paallel Pojecio Poi igh Shaows Pesecie Pojecio Tasfomaio mai ojecio lae 4D eco ( ),,, iecio o locaio of a ligh 4D eco if w, he is he iecio,,, w if w 1, he is he locaio k w k w S k w w k whee k,,,,,, ( ) ( ) ( w ) w The Shaow Mai () D3DX liba oies he fucio o buil he shaow mai D3DXMATRIX *D3DXMaiShaow( D3DXMATRIX *Ou, CONST D3DXVECTOR4 *igh, ); CONST D3DXPANE *Plae igh: a eco escibig a aallel ligh if w o a oi ligh if w1 Plae: he lae o ojec he shaow io
Usig he Secil Buffe o Pee Double Bleig (1) Double bleig Oelaig iagles will ge blee mulile imes a hus aea ake The shaow eee wih ouble bleig. The shaow eee coecl. Usig he Secil Buffe o Pee Double Bleig () Solig ouble bleig oblem usig he secil buffe To ee wiig oelaig iels Seig he secil es o ol acce iels he fis ime Whe eeig he shaow s iels o he back buffe, makig he coesoig secil buffe eies
Seig he Secil Ree Saes Comuaio of he Shaow Tasfomaio
Reeig he Shaow a Cleaig u Maeials
Dawig he Shaow Eecises (1) Moif he Shaow emo b alig he followig escibe fi. If ou u he Shaow emo a moe he eao (usig he A a D kes) such ha he shaow goes off he floo, ou will obsee ha he shaow sill aw. This ca be fie b emloig he secil echique use fo he Mio emo; ha is mak he secil buffe iels ha coeso wih he floo a he ol ee he shaow iels ha coicie wih he floo.
Eecises () Moif he Shaow emo ogam o ee a oi ligh shaow isea of a aallel ligh shaow.