Computer Graphics
Marco Tarini Università dell’Insubria
Facoltà di Scienze MFN di Varese Corso di Laurea in Informatica Anno Accademico 2012/13
Lezione 13:
Lezione 13: Lezione 13:
Lezione 13: molti dettagli a poco prezzo:
il texture Mapping
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Memoria RAM nelle schede grafiche
F ram m enti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti in te rp o la ti in te rp o la ti in te rp o la ti in te rp o la ti
Ver ti c i & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti Screen
buffer (RGBA)
Screen buffer 2 (RGBA) Depth buffer Ver ti c i por iettati & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti co m p u ta ti co m p u ta ti co m p u ta ti co m p u ta ti
rasterizer triangoli set-
up rasterizer segmenti set-
up rasterizer
punti set-
up
c om put az ioni per v er tic e
Texture RAM
c om put az ioni per f ram m ent o
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Concetto
• Tessiture:
– una memoria RAM a bordo della scheda video – si può accedere dal fragment shader
• (recentemente anche dal vertex shader) – solo lettura!
– condivisa
– specifiche modalità di accesso
• locazione: locazione 2D (o anche D o 3D)
• interpolazione fra valori vicini
• prefiltering
• …
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texture Mapping: paradigma di memoria
• Nelle operazioni per frammento si può accedere ad una RAM apposita
– la Texture RAM
– strutturata (paginata) in un insieme di Textures ("tessiture") – possibile accedere anche nelle operazioni x vertice
• Ogni tessitura è un array uniforme (*) 1D, 2D o 3D
di Texels (lett: elementi (campioni) di tessitura) (*) cioè: ogni texel è dello stesso tipo
Caso più comune
• Tessiture 2D 2D 2D 2D
• Ogni texel memorizza attributi attributi attributi attributi
di un intorno di un punto della superficie – (es. stesso tipo di quelli che abbiamo associato ai
vertici: normali, colori, parametri materiale...) – utile quando i valori degli attributi variano
più repentinamente sulla superficie
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a 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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texels
• Tipici esempi di texels:
– ogni texel un colore (componenti: R-G-B, o R-G-B-A)
• la tessitura è una "color-map"
– ogni texel una componente alpha
• la tessitura è una "alpha-map"
– ogni texel una normale (componenti: X-Y-Z)
• la tessitura è una "normal-map" o "bump-map“ (in che spazio?)
– ogni texel contiene un valore di specularità
• la tessitura è una “specular-map"
– ogni texel contiene un valore di altezza
• la tessitura è una "displacement-map"
– ...
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Tipica applicazione (quella storica):
rimappare immagini sulla geometria
geometria 3D (insieme di quadrilateri)
+
RGB texture 2D (color-map)
=
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Altro esempio di color-map
+ =
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Altri esempi di color-map
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texture Mapping: Storia
• 1974 introdotto da Ed Catmull
– nella sua Phd Thesis
• Solo nel 1992 (!) si ha text. mapping hardware
– Silicon Graphics RealityEngine
• Dal 92 a oggi:
rapido aumento della diffusione
– strada intrapresa soprattutto da low end graphic boards
• Oggi:
una delle fondamentali primitive di rendering
– la principale tecnica image based di rendering
Ed Catmull
Notazione
Texture 2D
s t
texel
Texture Space
(o "spazio parametrico" o "spazio s-t" o "spazio u-v")
Una Texutre è definita nella regione [0,1] x [0,1]
dello "spazio parametrico"
es: 512 texels
es: 1024 texels
1.0 1.0
Due notazioni
Texture 2D Texture Space
in OpenGL (s,t)
s t
1.0
1.0 u
v
1.0
1.0
Texture Space in DirectX
(u,v)
(0,0)
(0,0)
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texture Space t s
Texture Mapping
• Ad vertice (di ogni triangolo) assegno le sue coordinate s,t nello spazio tessitura
Screen Space
x
0,y
0x
2,y
2x
1,y
1s
0,t
0s
1,t
1s
2,t
2posizione del 1mo vertice
attributi del 1mo vertice
s0,t0 s1,t1
s2,t2
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texture Mapping
• Così in pratica definisco un mapping fra il triangolo 3D e un triangolo di tessitura
Texture Space Screen Space
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texture Mapping
• Ogni frammento
ha le sue coordinate s,t nello spazio tessitura
Texture Space Screen Space
texture look-up
(anche: “texture fetch”)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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texture Mapping
F ram m enti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti in te rp o la ti in te rp o la ti in te rp o la ti in te rp o la ti Ver ti c i & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti
Screen Screen Screen Screen buffer buffer buffer buffer Ver ti c i por iettati & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti co m p u ta ti co m p u ta ti co m p u ta ti co m p u ta ti
rasterizer triangoli set-
up rasterizer segmenti set-
up rasterizer
punti set-
up
c om put az ioni per v er tic e
Texture RAM c om put az ioni per f ram m ent o
interpolo coordinate
texture
coordinate texture interpolate compreso:
coordinate texture
(per vertice!)texture
look-upinterpolo coordinate
texture
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Interpolazione lineare coordinate texture
• Nota: non è esatto per la proiezione prospettica – ma si possono trovare le coord baric. di p in v 1 v 2 v 3
a partire dalle coord baric. di t(p) in t(v 1 ) t(v 2 ) t(v 3 )
V
1V
2V
3p
R 3 R 2
t(p)
t( v
1)
t( v
2) t( v
3)
trasformaz tttt
p ha coord.
baricentriche a,b,c nel triangolo v
1v
2v
3t(p) ha coord.
baricentriche a,b,c nel triangolo t(v
1) t(v
2) t(v
3)
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
La tessitura va caricata in Texture RAM
F ram m enti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti in te rp o la ti in te rp o la ti in te rp o la ti in te rp o la ti Ver ti c i & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti
Screen Screen Screen Screen buffer buffer buffer buffer Ver ti c i por iettati & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti co m p u ta ti co m p u ta ti co m p u ta ti co m p u ta ti
rasterizer triangoli set-
up rasterizer segmenti set-
up rasterizer
punti set-
up
c om put az ioni per v er tic e c om put az ioni per f ram m ent o
Texture RAM
L O A D
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
La tessitura va caricata
1. Da disco a memoria RAM (main)
• (sulla scheda madre)
2. Da memoria RAM main a Texture RAM
• (on board dell'HW grafico)
Operazione 2 piuttosto lenta (1, peggio ancora)
Non fare una volta per frame!
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
La tessitura va caricata: OpenGL
• In OpenGL, per caricare la tessitura n id :
glBindTexture (GL_TEXTURE_2D, id );
glTexImage2D ( GL_TEXTURE_2D,
0, // livello di mipmapping GL_RGB, // formato interno (nella GPU) texWidth, texHeight, // risoluz.
0,
GL_RGB, // formato nella RAM GL_UNSIGNED_BYTE, // (nella RAM) imageData // puntatore ai pixel in RAM );
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Come si assegnano le coordinate texture ai vertici?
F ram m enti & va ryi n g & va ryi n g & va ryi n g & va ryi n g in te rp o la ti in te rp o la ti in te rp o la ti in te rp o la ti Ver ti c i & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti
Screen Screen Screen Screen buffer buffer buffer buffer Ver ti c i por iettati & va ryi n g & va ryi n g & va ryi n g & va ryi n g co m p u ta ti co m p u ta ti co m p u ta ti co m p u ta ti
rasterizer triangoli set-
up rasterizer segmenti set-
up rasterizer
punti set-
up
c om put az ioni per v er tic e
Texture RAM c om put az ioni per f ram m ent o
interpolo coordinate
texture
coordinate texture interpolate compreso:
coordinate texture
(per vertice!)texture
look-upcompreso:
coordinate texture
(per vertice!)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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Come si assegnano le coordinate texture ai vertici?
• Due usi possibili del texture map:
– Computare le coord. texture al volo
• durante il rendering (per vertice)…
– Precomputarle
• e mandarle come attributo x vertice
• (es: salvarle insieme alla mesh)
Dipende dall’applicazione!
Problema difficile: u-v mapping
• Assegnare una coppia di coordinate texutres ad ogni vertice della mesh
– In preprocessing
s t
s t
Problema difficile: “u-v mapping” (“u-v” == “s-t”)
fatto a mano,
oppure automatizzato
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
In OpenGL
• Mandiamo le coord texture come ogni altro attributo
• In GLSL:
– sinomini delle componenti di un vec4:
r g b a x y z w
s t r q
coordinate affini xyz di un punto
componenti rosso verde blu (e alpha) di un colore coordiante texture affini s t (e r,q) (spazio parametrico)
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Come si assegnano le coordinate texture ai vertici?
F ram m enti & va ryi n g & va ryi n g & va ryi n g & va ryi n g in te rp o la ti in te rp o la ti in te rp o la ti in te rp o la ti Ver ti c i & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti
Screen Screen Screen Screen buffer buffer buffer buffer Ver ti c i por iettati & va ryi n g & va ryi n g & va ryi n g & va ryi n g co m p u ta ti co m p u ta ti co m p u ta ti co m p u ta ti
rasterizer triangoli set-
up rasterizer segmenti set-
up rasterizer
punti set-
up
c om put az ioni per v er tic e
Texture RAM c om put az ioni per f ram m ent o
interpolo coordinate
texture
coordinate texture interpolate
texture
look-upcoordinate texture
(eventualmentetrasformate)
compreso:
coordinate texture
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Come si assegnano le coordinate texture ai vertici?
• Due tipi di usi del texture map:
– Assegnarle le coordinate textures al volo
• durante il rendering…
– Precomputarle
• (e salvarle insieme alla mesh)
esempio 1:
oggetti con pattern regolari (a quadretti…)
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Come si assegnano le coordinate texture ai vertici?
F ram m enti & va ryi n g & va ryi n g & va ryi n g & va ryi n g in te rp o la ti in te rp o la ti in te rp o la ti in te rp o la ti Ver ti c i & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti
Screen Screen Screen Screen buffer buffer buffer buffer Ver ti c i por iettati & va ryi n g & va ryi n g & va ryi n g & va ryi n g co m p u ta ti co m p u ta ti co m p u ta ti co m p u ta ti
rasterizer triangoli set-
up rasterizer segmenti set-
up rasterizer
punti set-
up
c om put az ioni per v er tic e
Texture RAM c om put az ioni per f ram m ent o
interpolo coordinate
texture
coordinate texture interpolate
texture
look-upcoordinate texture produco coordinate
texture a partire
dalla posizione
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Coordinate texture create proceduralmente
• Concetto: da (x,y,z ) a (s,t ) – es. linearmente
• In coordinate oggetto, mondo oppure vista – (cioè prima o dopo le trasformazioni)
• Esempi:
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Create automaticamente
• Anche 1D
1D texture!
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Come si assegnano le coordinate texture ai vertici?
• Due classi di soluzioni:
– Assegnarle le coordinate textures al volo
• durante il rendering…
– Precomputarle
• (e salvarle insieme alla mesh)
esempio 2:
envionment mapping
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Environment mapping: sferico
Environment map:
una tessitura che memorizza
il colore dell’ambiente “riflesso”
da ogni normale della semisfera.
Come coordinata tessitura, basta usare la normale (trasformata)!
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Environment mapping: sferico
simula oggetto a specchio che riflette uno sfondo lontano
simula un materiale complesso (a condizioni di luce fisse)
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Environment mapping: cubico
front right back
below above
left
Environment mapping: cubico
F ram m enti & va ryi n g & va ryi n g & va ryi n g & va ryi n g in te rp o la ti in te rp o la ti in te rp o la ti in te rp o la ti Ver ti c i & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti
Screen Screen Screen Screen buffer buffer buffer buffer Ver ti c i por iettati & va ryi n g & va ryi n g & va ryi n g & va ryi n g co m p u ta ti co m p u ta ti co m p u ta ti co m p u ta ti
rasterizer triangoli set-
up rasterizer segmenti set-
up rasterizer
punti set-
up
c om put az ioni per v er tic e
Texture RAM c om put az ioni per f ram m ent o
interpolo coordinate texture 3D
coordinate texture 3D interpolate
proietto sul cubo, accedo alla
faccia corrispondente calcolo
coordinate texture 3D
[-1,+1] x [-1,+1] x [-1,+1]come raggio riflesso raggio riflesso raggio riflesso raggio riflesso (dir. di vista riflessa dalla norm.)
Environment mapping: cubico
front right back
below above
left
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Il texture look-up
F ram m enti & va ryi n g & va ryi n g & va ryi n g & va ryi n g in te rp o la ti in te rp o la ti in te rp o la ti in te rp o la ti Ver ti c i & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti
Screen Screen Screen Screen buffer buffer buffer buffer Ver ti c i por iettati & va ryi n g & va ryi n g & va ryi n g & va ryi n g co m p u ta ti co m p u ta ti co m p u ta ti co m p u ta ti
rasterizer triangoli set-
up rasterizer segmenti set-
up rasterizer
punti set-
up
c om put az ioni per v er tic e
Texture RAM c om put az ioni per f ram m ent o
interpolo coordinate
texture
coordinate texture interpolate compreso:
coordinate texture
(per vertice!)texture
look-uptexture
look-upM 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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
u Texture Look-up:
fuori dai bordi: modo "clamp"
if (u<0) u←0; if (u>1) u←1;
if (v<0) v←0; if (v>1) v←1;
1 1
v
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texture Look-up:
fuori dai bordi: modo "repeat"
u v
1 1
u ← u – [ u ] v ← v – [ v ]
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Tessiture ripetute ripetute ripetute ripetute (tiled textures)
• Tipico utilizzo:
Molto efficiente in spazio!
Nota: deve essere un’immagine “TILEABLE”
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
In OpenGL
glTexParameteri(
GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri(
GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
o
nota:
setto per u e v separatemente
esempio: repeat sulla u u u e clamp sulla v u v v v sono parametri della tessitura. Ogni tessitura caricata in memoria ha i
propri parametri.
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texture Mapping
F ram m enti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti in te rp o la ti in te rp o la ti in te rp o la ti in te rp o la ti Ver ti c i & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti & l o ro a ttr ib u ti
Screen Screen Screen Screen buffer buffer buffer buffer Ver ti c i por iettati & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti & a ttr ib u ti co m p u ta ti co m p u ta ti co m p u ta ti co m p u ta ti
rasterizer triangoli set-
up rasterizer segmenti set-
up rasterizer
punti set-
up
c om put az ioni per v er tic e
Texture RAM c om put az ioni per f ram m ent o
interpolo coordinate
texture
coordinate texture interpolate compreso:
coordinate texture
(per vertice!)texture
look-uptexture
look-upM 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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Texture Look-up
• Un frammento ha coordinate non intere (in texels)
Texture Space Screen Space
texture look-up
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
pixel
Texture Look-up
Texture Space Screen Space
pixel texel
un pixel = meno di un texel
un pixel = più di un texel
minification magnification
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
0.5 1.5 2.5 3.5 4.5 5.5 6.5 0.5
1.5 2.5 3.5 4.5 5.5 6.5 7.5
Caso Magnification
u v
Soluzione 1:
prendo il texel in cui casco
(cioè il texel il cui centro è più vicino alle coordinate u,v
del frammento) equivale ad arrotondare
le coordinate texel ad interi
"Nearest Filtering"
7.5
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Caso Magnification
texture 128x128
Nearest Filtering: risutlato visivo
"si vedono i texel !"
0.5 1.5 2.5 3.5 4.5 5.5 6.5 0.5
1.5 2.5 3.5 4.5 5.5 6.5 7.5
Caso Magnification
u v
Soluzione 2:
Medio il valore dei quattro texel più vicini
Interpolazione Bilineare
7.5 Ripasso:
interpolazione lineare (1D) interpolazione bi-lineare (2D)
Formule...
Caso Magnification
texture 128x128
Bilinear Interpolation: risutlato visivo
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Caso Magnification
• Modo Nearest:
– si vedono i texel
– va bene se i bordi fra i texel sono utili – più veloce
• Modo Interpolazione Bilineare – di solito qualità migliore – può essere più lento
– rischia di avere un effetto "sfuocato"
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Caso Minification
Nearest Filtering Bilinear interpolation
non risolve il problema
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Caso Minification: MIP-mapping
MIP-map level 0
MIP-map level 1
MIP-map level 2
MIP-map level 3
MIP-map level 4 (un solo texel)
MIP-mapping: "Multum In Parvo"
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Mipmap Math
• Definiamo un fattore di scala, ρ=texels/pixel – ρ è il massimo fra ρ x e ρ y
– può variare entro lo stesso triangolo
– può essere derivato dalle matrici di trasformazione – e calcolato nei vertici, interpolato nei frammenti
• il livello di mipmap da utilizzare è: log 2 ρ
– livello 0 = massima risoluzione – se livello<0 cosa significa?
– nota: il livello non è necess. un numero intero
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Caso Minification: MIP-mapping
Bilinear interpolation
non risolve il problema
MIP-mapping
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
Caso Minification: MIP-mapping
0 1 2 3 4 5
altro
esempio
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a
In OpenGL
glTexParameteri(
GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(
GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
oppure
decidere che tipo di magnificazione usare:
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 1 2 / 1 3 ‧ U n i v e r s i t à d e l l ’ I n s u b r i a