SHADIG Achmd Bsuki n Rmdijnti Achmd Bsuki, n Rmdijnti - bortorium Computer Vision Politeknik Elektronik egeri Surby (PES-ITS)
Mteri orml Vector Unit Vector Opticl Model Flt Shding Gourud Shding
orml Vector orml Vector dlh vector yng rhny tegk lurus pd lusn (fce) orml Vector dpt diperoleh dri perklin silng (cross-product) dri du vector yng berd pd fce Besr dri orml Vector Vector tegntung pd hsil perklin silngny v 1 v 2 fce v 2 v 1
Unit Vector Unit Vector dlh vektor yng besrny dlh stu stun dn rhny tergntung rh vektor slny. Besr sutu vektor 2 dpt 2 2 diperoleh dengn v vx + vy + vz Agr vektor v menjdi unit vektor mk semu koefisien (v x,v y,v z ) dibgi dengn v
Implementsi Unit Vector vector3d_t unitvector(vector3d_t vec) { int i; flot vec20.; flot vec1,invvec1; for(i0;i<3;i++) vec2+vec.v[i]*vec.v[i]; vec1sqrt(vec2); if (vec1!0.) { invvec11./vec1; for (i0;i<3;i++) vec.v[i]*invvec1; } vec.v[3]1.; return vec; }
Illuminnt Opticl Model ight Vector orml Vector to the Plne α P α Reflection Vector R β Eye V View Vector Direction Vectors R V 1
Mcm-Mcm Opticl Model Diffuse Scttering Speculr Reflection Ambient mbert s w Phong Model
Diffuse Scttering Illuminnt ight Vector orml Vector to the Plne α P Diffuse Sctter Eye I cosα I I k d d s d I s k d MAX(cosα,0) : Intensity of the diffuse component : Intensity of the ight Source : Diffuse reflection coefficient
Speculr Reflection Illuminnt ight Vector orml Vector to Reflection the Plne Vector α R V α β P Eye View Vector
I cos β R I I k n sp sp s sp : : : Speculr Reflection I s k sp R 2( Intensity of Intensity of MAX(cos V ) β,0) the ight Source : Speculr reflection coefficient constnt from experiment n the Speculr Reflection (1- -200)
Speculr Reflection Speculr Reflection 1 1 then 1) 1, 1,( } ) {(1 ) (1 ) (, ) ( 2 2 2 2 ± + + + b b b R R R R R Q
Ambient I I I k s sp : I s k Intensity of the Ambient Reflection : Intensity of the ight Source : Ambient reflection coefficient
mbert w ( Diffuse Scttering + Ambient ) C cos C C s α C s { k d MAX(cos : Reflection Color : Surfce Color α,0) + k }
Phong Model (Diffuse Scttering+Ambient Speculr Reflection) C cosα R C C C s { k : Reflection Color : Surfce Color white C s cos β R d V 2( ) MAX(cosα,0) + : Speculr Color (white) k } + C white k sp MAX(cos n β,0)
Implementsi Phong Model color_t PhongModel(vector3D_t ight,vector3d_t orml, vector3d_t View,color_t col) { flot kspe0.7; // speculr reflection coefficient flot kdif0.6; // diffuse reflection coefficient flot kmb0.4; // mbient light coefficient flot tmp,,rv; color_t ColWhite{1,1,1}; vector3d_t ReflectionVector(2.*(ight*orml)*orml)-ight; tmporml*ight; funcpositive(tmp); tmpreflectionvector*view; RVfuncPositive(tmp); return kdif**col+kspe*power(rv,4)*colwhite+kmb*col; }
Flt Shding Stu fce mempunyi wrn yng sm Flt shding menggunkn model Phong untuk opticl view
Implementsi Flt Shding if(ormlvector.v[2]>0.) { ormlvectorunitvector(ormlvector); fillcolphongmodel(ightvector,ormlvector,viewvector,col); fillpolygon(p,bol.fc[i].umberofvertices,fillcol); } col dlh vribel wrn, yng menytkn wrn dsr dri obyek
Gourud Shding Stu fce mempunyi grdisi wrn yng memperhitungkn tingkt kecerhn pd setip titik pd fce tersebut Dengn Shding ini dihsilkn wrn yng hlus grdisiny Shding ini memerlukn vektor norml pd setip titikny Menggunkn fungsi grdtepolygon untuk menytkn Gourud Shding
Implementsi Gourud Shding for (i0;i<sphere.umberofvertices;i++) { vec[i]point2vector(sphere.pnt[i]); vec[i]mt*vec[i]; nrmvec[i]mt*sphere.ormlvector[i]-zerovector; } Pd setip titik yng terdpt pd obyek, hrus didefinisikn norml vectorny terlebih dhulu. orml vektor setip titik kn menyesuikn rhny berdsrkn mtrik trnsformsi yng dikenkn pd titik
Implementsi Gourud Shding if (0.<normlzi) { for (j0;j<sphere.fc[i].umberofvertices;j++) { buff[j]vector2point2d(vecbuff[j]); ormlvectorunitvector(nrmvecbuff[j]); colbuff[j]phongmodel(ightvector,ormlvector,viewvector,colcyn); } grdtepolygon(buff,colbuff,sphere.fc[i].umberofvertices); } Jumlh wrn pd setip fce sm dengn jumlh titik yng terdpt pd fce tersebut.