1 / 29

Computer Graphics

Lezione 8: attributi per vertice. asdad asdsad fadf asdf asdf asdf asd asdfasdf asd fasdf asdasdf asd asdf asd asdf asd asdf asd. Università dell’Insubria Facoltà di Scienze MFN di Varese Corso di Laurea in Informatica Anno Accademico 200 6 /0 7. Computer Graphics. asdad asdsad

elsu
Download Presentation

Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lezione 8: attributi per vertice asdad asdsad fadf asdf asdf asdf asd asdfasdf asd fasdf asdasdf asd asdf asd asdf asd asdf asd Università dell’Insubria Facoltà di Scienze MFN di Varese Corso di Laurea in Informatica Anno Accademico 2006/07 Computer Graphics asdad asdsad fadf asdf asdf asdf asd asdfasdf asd fasdf asdasdf asd asdf asd asdf asd asdf asd Marco Tarini asdad asdsad fadf asdf asdf asdf asd asdfasdf asd fasdf asdasdf asd asdf asd asdf asd asdf asd

  2. Preambolo: • Le coordinate baricentriche M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  3. Cosa è un segmento? V2 V1 o o con M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  4. Cosa è un segmento? 0.5 v1 + 0.5 v2 0.0 v1 + 1 v2 0.75 v1 + 0.25 v2 0.1 v1 + 0.9 v2 0.66 v1 + 0.33 v2 ≪ x è una interpolazionedi v1 e v2 ≫ 1 v1 + 0 v2 V2 posso definirlo cosi': un segmento di vertici v1e v2 é l'insieme di tutti i punti x esprimibili come x = a v1 + b v2 a e b scalari positivi con a + b = 1 V1 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  5. Parentesi notazione estrapolazione: x = a v1 + b v2 a e b scalari positivicon a + b = 1 x V2 V1 interpolazione: x = a v1 + b v2 a e b scalari positivicon a + b = 1 V2 x V1 (quindi 0 ≤ a ≤ 1 e 0 ≤ b ≤ 1 ) M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  6. Cosa è un triangolo? V3 V2 V1 o o con ≪ é l'insieme di tutti i punti x tali che... ≫ M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  7. Cosa è un triangolo? p q V3 V2 q = k1 v1 + k2v2 k1 + k2= 1 k1,k2 > 0 V1 p = h1 v3 + h2q h1 + h2= 1 h1,h2 > 0 esercizio: sostituiamo e... M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  8. Cosa è un triangolo? V3 V2 un triangolo di vertici v1v2v3 é l'insieme di tutti i punti x esprimibili come x = a1 v1 + a2 v2 + a3 v3 a1a2a3 scalari positivi a1+a2 + a3= 1 V1 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  9. Per esempio... 0 v1 + 0 v2 + 1 v3 0 v1 + 1 v2 + 0 v3 0.33 v1 + 0.33 v2 + 0.33 v3 (il baricentro del triangolo) 0.65 v1 + 0.2 v2 + 0.15 v3 0.5 v1 + 0.5 v2 + 0 v3 (punto in mezzo al lato v1 v2) V3 V2 V1 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  10. Ebbene... V3 V2 dati a1a2a3 scalari tali positivi con a1+a2 + a3= 1 → x = a1 v1 + a2 v2 + a3 v3 é un punto del triangolo V1 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  11. Ma anche... V3 V2 dato un punto p nel triangolo → esistono unici a1a2a3tali che p = a1 v1 + a2 v2 + a3 v3 e a1a2a3sono positivi e a somma 1 V1 diciamo che a1a2a3 sono le coordinate baricentriche di p M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  12. Le coordinate baricentriche p • Concetto F O N D A M E N T A L E V3 V2 p ha coordinate baricentriche (a1a2a3) sse p = a1 v1 + a2 v2 + a3 v3 V1 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  13. Le coordinate baricentricheInterpretazione fisica (storica) (buffa) p p ha coordinate baricentriche (a1a2a3) sse é il baricentro di: V3 V1 a3 Kg V2 a2 Kg a1 Kg M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  14. Le coordinate baricentricheInterpretazione geometrica 1 k 1 h V3 p V2 V1 p = v1 + h (v2-v1 )+ k (v3-v1 ) M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  15. Coordinate baricentriche: improtante proprietà f( v3 ) V3 f( v2 ) trasformazione affine f f(p) p V2 f( v1 ) V1 p ha coord. baricentriche a,b,c nel triangolo v1v2v3 f(p) ha coord. baricentriche a,b,c nel triangolo f(v1)f(v2) f(v3) M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  16. Le coordinate baricentrichecome rapporti fra aree p • Quali sono le coord baricentriche di un punto p? V3 A1 A2 A3 V2 V1 p = a1 v1 + a2 v2 + a3 v3 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  17. Preambolo: • Le coordinate baricentriche M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  18. Attributi nel pipeline set-up rasterizer triangoli set-up set-up rasterizer segmenti rasterizer punti ogni frammento avrà una valore interpolato degli attributiper vertice associamo degli attributiai vertici che mandiamo es: colore RGB qui gli attributi possono subirevarie compuatzioni qui gli attributi vengono interpolati pixel finali (nello screen-buffer) Frammenti & attributi interpolati Vertici proiett & attributi computati Vertici & loro attributi set-up rasterizer triangoli computazioniper vertice computazioniper frammento M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  19. Attributi nella rasterizzazione • Quindi il rasterizer deve fare DUE cose: 1 trovare i frammenti che compongono la primitiva • e.g. i frammenti interni al triangolo 2 interpolare gli attributi per questi frammenti • tramite le coordinate baricentriche • Il rasterizer produce frammenti CON attributi associati M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  20. Attributi nella rasterizzazione NOTA: vero solo per le trasformazioni affini. E' solo una approssimazione per la distorsione prospettica • Idea: • lavoriamo su R2 f( v3 ) V3 f( v2 ) trasformazione affine f f(p) p V2 f( v1 ) V1 f(p) ha coord. baricentriche a,b,c nel triangolo f(v1)f(v2) f(v3) p ha coord. baricentriche a,b,c nel triangolo v1v2v3 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  21. Scan-line rasterizer & attributi • Otteniamo gli attributi per frammentointerpolando gli attributi per verticelungo segmenti (linearmente) • Equivalente ad usare le coordinate baricentriche del frammentocome pesi M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  22. Scan-line rasterizer & attributi p q f • Interpoliamo gli attributi: • linearmente sui bordi • e in ogni scanline, tra gli estremi dello span v1 a1 p interpolato fra a2 e a1 q interpolato fra a0 e a1 f interpolato fra pe q v2 a2 v0 a0 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  23. Scan-line rasterizer & attributi p q f • Lo stesso per tutti gli attributi Ottimaizzatione: si puo' calcolare incrementalme. vediamo come → v1 a1, b1, c1... v2 a2, b2, c2... v0 a0, b0, c0... M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  24. Scan-line rasterizer & attributi Primo frammento prodotto: ha come attributo a0 ogni volta che mi sposto 1 pixel a dx: aumento di una costante dx ogni volta che mi sposto 1 pixel in alto: aumento di una costante dy a2 a1 a0 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  25. Scan-line rasterizer & attributi Primo frammento prodotto: ha come attributo a0 ogni volta che mi sposto 1 pixel a dx: aumento di una costante dx ogni volta che mi sposto 1 pixel in alto: aumento di una costante dy a2 a1 8 passi 9 dx + 8 dy = a1 - a0 a0 9 passi M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  26. Scan-line rasterizer & attributi Primo frammento prodotto: ha come attributo a0 ogni volta che mi sposto 1 pixel a dx: aumento di una costante dx ogni volta che mi sposto 1 pixel in alto: aumento di una costante dy a2 a1 11 passi 9 dx + 8 dy = a1 - a0 a0 dx + 11 dy = a2 - a0 risolvo nella fase di SET-UP di quel triangolo 1 passo M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  27. Edge functions e attributi p • Per i rastertizzatori basati su edge-functions: • useremo la regola delle aree: V3 p = a1 v1 + a2 v2 + a3 v3 A1 A2 A3 V2 V1 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  28. Parentesi: area di un triangolo il "diviso due" lo possimo ignorare. Tanto ci interessano solo i rapporti fra le aree • In R3 posso calcolarla con il prodotto esterno e nel caso particolare di R2 ? proviamo... V3 d1 A V1 d2 V2 A = | d1 x d2 | /2 = | (v3 – v1) x (v2 – v1 ) | /2 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

  29. FlashBack: Edge functions NO n q SI • La funzione il cui segno ci dice in quale semipiano siamo p = (x0 , y0) n = ( - ( y1 -y0 ) , x1 -x0) f(q) = n‧q - n‧p v0=(x0, y0 ) totale: l'edge functionper un latoè la coord baricentrica ralativa al vertice opposto (dopo aver diviso per la somma delle 3 edge functions) v1=(x1, y1 ) v2 M a r c o T a r i n i ‧ C o m p u t e r G r a p h I c s ‧ 2 0 0 6 / 0 7 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a

More Related