computer graphics memoria ram nelle schede...
TRANSCRIPT
1
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
Fra
mm
en
ti
& a
ttributi
& a
ttributi
& a
ttributi
& a
ttributi
inte
rpola
tiin
terp
ola
tiin
terp
ola
tiin
terp
ola
ti
Ve
rtic
i
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi Screen
buffer
(RGBA)
Screen
buffer 2
(RGBA)
Depth
buffer
Ve
rtic
i p
ori
etta
ti
& a
ttributi
& a
ttributi
& a
ttributi
& a
ttributi
com
puta
ticom
puta
ticom
puta
ticom
puta
ti
rasterizer
triangoli
set-
up
rasterizer
segmenti
set-
up
rasterizer
punti
set-
up
com
puta
zio
ni
per
vert
ice
Texture
RAM
com
puta
zio
ni
per
fram
mento
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 2D2D2D2D
• Ogni texel memorizza attributiattributiattributiattributi
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"
– ...
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 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
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
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: 5
12
texe
ls
es: 1024 texels
1.0
1.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
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)
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
Texture Space
t
s
Texture Mapping
• Ad vertice (di ogni triangolo) assegno
le sue coordinate s,t nello spazio tessitura
Screen Space
x0,y0
x2,y2
x1,y1
s0,t0
s1,t1
s2,t2
posizione del
1mo vertice
attributi del
1mo vertice
s0,t0s1,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 SpaceScreen 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 SpaceScreen 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
Fra
mm
en
ti
& a
ttributi
& a
ttributi
& a
ttributi
& a
ttributi
inte
rpola
tiin
terp
ola
tiin
terp
ola
tiin
terp
ola
ti
Ve
rtic
i
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
Screen Screen Screen Screen
bufferbufferbufferbuffer
Ve
rtic
i p
ori
etta
ti
& a
ttributi
& a
ttributi
& a
ttributi
& a
ttributi
com
puta
ticom
puta
ticom
puta
ticom
puta
ti
rasterizer
triangoli
set-
up
rasterizer
segmenti
set-
up
rasterizer
punti
set-
up
com
puta
zio
ni
per
vert
ice
Texture RAM
com
puta
zio
ni
per
fram
mento
interpolo
coordinate
texture
coordinate
texture
interpolate
compreso:
coordinate
texture(per vertice!)
texture
look-up
interpolo
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 v1 v2 v3
a partire dalle coord baric. di t(p) in t(v1) t(v2) t(v3)
V1
V2
V3
p
3R
2R
t(p)
t( v1 )
t( v2 )
t( v3 )
trasformaz tttt
p ha coord.
baricentriche a,b,c
nel triangolo v1 v2 v3
t(p) ha coord.
baricentriche a,b,c
nel triangolo t(v1) t(v2) t(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 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
Fra
mm
en
ti
& a
ttributi
& a
ttributi
& a
ttributi
& a
ttributi
inte
rpola
tiin
terp
ola
tiin
terp
ola
tiin
terp
ola
ti
Ve
rtic
i
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
Screen Screen Screen Screen
bufferbufferbufferbuffer
Ve
rtic
i p
ori
etta
ti
& a
ttributi
& a
ttributi
& a
ttributi
& a
ttributi
com
puta
ticom
puta
ticom
puta
ticom
puta
ti
rasterizer
triangoli
set-
up
rasterizer
segmenti
set-
up
rasterizer
punti
set-
up
com
puta
zio
ni
per
vert
ice
com
puta
zio
ni
per
fram
mento
Texture RAM
L O A D
4
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 mipmappingGL_RGB, // formato interno (nella GPU)texWidth, texHeight, // risoluz.0, GL_RGB, // formato nella RAMGL_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?
Fra
mm
en
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
inte
rpola
tiin
terp
ola
tiin
terp
ola
tiin
terp
ola
ti
Ve
rtic
i
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
Screen Screen Screen Screen
bufferbufferbufferbuffer
Ve
rtic
i p
ori
etta
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
com
puta
ticom
puta
ticom
puta
ticom
puta
ti
rasterizer
triangoli
set-
up
rasterizer
segmenti
set-
up
rasterizer
punti
set-
up
com
puta
zio
ni
per
vert
ice
Texture RAM
com
puta
zio
ni
per
fram
mento
interpolo
coordinate
texture
coordinate
texture
interpolate
compreso:
coordinate
texture(per vertice!)
texture
look-up
compreso:
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!
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
Problema difficile: u-v mapping
• Assegnare una coppia di coordinate texutres
ad ogni vertice della mesh
– In preprocessing
s
t
s
t
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
Problema difficile: “u-v mapping” (“u-v” == “s-t”)
fatto a mano,
oppure automatizzato
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
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?
Fra
mm
en
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
inte
rpola
tiin
terp
ola
tiin
terp
ola
tiin
terp
ola
ti
Ve
rtic
i
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
Screen Screen Screen Screen
bufferbufferbufferbuffer
Ve
rtic
i p
ori
etta
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
com
puta
ticom
puta
ticom
puta
ticom
puta
ti
rasterizer
triangoli
set-
up
rasterizer
segmenti
set-
up
rasterizer
punti
set-
up
com
puta
zio
ni
per
vert
ice
Texture RAM
com
puta
zio
ni
per
fram
mento
interpolo
coordinate
texture
coordinate
texture
interpolate
texture
look-up
coordinate
texture(eventualmente
trasformate)
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?
Fra
mm
en
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
inte
rpola
tiin
terp
ola
tiin
terp
ola
tiin
terp
ola
ti
Ve
rtic
i
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
Screen Screen Screen Screen
bufferbufferbufferbuffer
Ve
rtic
i p
ori
etta
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
com
puta
ticom
puta
ticom
puta
ticom
puta
ti
rasterizer
triangoli
set-
up
rasterizer
segmenti
set-
up
rasterizer
punti
set-
up
com
puta
zio
ni
per
vert
ice
Texture RAM
com
puta
zio
ni
per
fram
mento
interpolo
coordinate
texture
coordinate
texture
interpolate
texture
look-up
coordinate
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!
6
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
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
Fra
mm
en
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
inte
rpola
tiin
terp
ola
tiin
terp
ola
tiin
terp
ola
ti
Ve
rtic
i
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
Screen Screen Screen Screen
bufferbufferbufferbuffer
Ve
rtic
i p
ori
etta
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
com
puta
ticom
puta
ticom
puta
ticom
puta
ti
rasterizer
triangoli
set-
up
rasterizer
segmenti
set-
up
rasterizer
punti
set-
up
com
puta
zio
ni
per
vert
ice
Texture RAM
com
puta
zio
ni
per
fram
mento
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 riflessoraggio riflessoraggio riflessoraggio riflesso
(dir. di vista
riflessa dalla norm.)
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
7
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
Fra
mm
en
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
inte
rpola
tiin
terp
ola
tiin
terp
ola
tiin
terp
ola
ti
Ve
rtic
i
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
Screen Screen Screen Screen
bufferbufferbufferbuffer
Ve
rtic
i p
ori
etta
ti
& v
ary
ing
& v
ary
ing
& v
ary
ing
& v
ary
ing
com
puta
ticom
puta
ticom
puta
ticom
puta
ti
rasterizer
triangoli
set-
up
rasterizer
segmenti
set-
up
rasterizer
punti
set-
up
com
puta
zio
ni
per
vert
ice
Texture RAM
com
puta
zio
ni
per
fram
mento
interpolo
coordinate
texture
coordinate
texture
interpolate
compreso:
coordinate
texture(per vertice!)
texture
look-up
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
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 uuuu e clamp sulla vvvv
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
Fra
mm
en
ti
& a
ttributi
& a
ttributi
& a
ttributi
& a
ttributi
inte
rpola
tiin
terp
ola
tiin
terp
ola
tiin
terp
ola
ti
Ve
rtic
i
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
& loro
att
ributi
Screen Screen Screen Screen
bufferbufferbufferbuffer
Ve
rtic
i p
ori
etta
ti
& a
ttributi
& a
ttributi
& a
ttributi
& a
ttributi
com
puta
ticom
puta
ticom
puta
ticom
puta
ti
rasterizer
triangoli
set-
up
rasterizer
segmenti
set-
up
rasterizer
punti
set-
up
com
puta
zio
ni
per
vert
ice
Texture RAM
com
puta
zio
ni
per
fram
mento
interpolo
coordinate
texture
coordinate
texture
interpolate
compreso:
coordinate
texture(per vertice!)
texture
look-up
texture
look-up
8
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
• Un frammento ha coordinate
non intere (in texels)
Texture SpaceScreen 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 SpaceScreen 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 !"
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 2:
Medio il valore dei quattro texel
più vicini
Interpolazione Bilineare
7.5
Ripasso:
interpolazione lineare (1D)
interpolazione bi-lineare (2D)
Formule...
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
Bilinear Interpolation: risutlato visivo
9
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 interpolationnon 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 è: log2 ρ
– 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 interpolationnon 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
2345
altro
esempio
10
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
In OpenGL
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,modo );
modo = GL_NEARESTGL_LINEARGL_NEAREST_MIPMAP_NEARESTGL_LINEAR_MIPMAP_NEARESTGL_NEAREST_MIPMAP_LINEARGL_LINEAR_MIPMAP_LINEAR
dove
decidere che tipo di minifacazione usare:
interpolazione
trilineare