• No results found

11-texture-mapping.ppt

N/A
N/A
Protected

Academic year: 2020

Share "11-texture-mapping.ppt"

Copied!
64
0
0

Loading.... (view fulltext now)

Full text

(1)

Memoria RAM nelle schede grafiche Fr a m m e n ti & a tt ri b u ti in te rp o la ti V e rt ic i & l o ro a tt ri b u

ti Screen buffer

(2)

Texture Mapping

• Nelle operazioni per frammento si può accedere ad una RAM apposita

– la Texture RAM

– strutturata in un insieme di Textures ("tessiture")

• Ogni tessitura è un array

1D, 2D o 3D

(3)

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" – ogni texel contiene un valore di specularità

(4)

Tipica applicazione:

rimappare immagini sulla geometria

geometria 3D (mesh di quadrilateri)

+

RGB texture 2D

(color-map)

(5)
(6)

Altro esempio

(7)

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 primcipale tecnica image based

Ed Catmull

(8)

Notazione

Texture 2D

u v

texel

Texture Space

(o "spazio parametrico" o "spazio u-v")

Una Texutre e' definita nella regione [0,1] x [0,1] dello "spazio parametrico"

5

1

2

te

x

e

ls

1024 texels

(9)

Texture Space

u v

Texture Mapping

• Ad vertice (di ogni triangolo) assegno

le sue coordinate u,v nello spazio tessitura

Screen Space

x0,y0

x2,y2 x1,y1

u0,v0 u1,v1

u2,v2

posizione del 1mo vertice

attributi del 1mo vertice

u0,v0 u1,v1

(10)

Texture Mapping

• Così in pratica definisco un mapping fra il triangolo 3D e un triangolo di tessitura

(11)

Texture Mapping

• Ogni frammento

ha le sue coordinate u,v nello spazio tessitura

Texture Space Screen Space

(12)
(13)

Problema:

interpolazione lineare coordinate texture

• Non vale per la proiezione prospettica!

– era solo una approssimazione

– andava bene quando interpolavamo colori, normali – non va bene quando interpoliamo coordinate texture...

V1

V2 V3

p

3

R

R

2

f(p)

f( v1 )

f( v2 ) f( v3 )

proiezione f

p ha coord.

baricentriche a,b,c

nel triangolo v1 v2 v3

f(p) ha coord.

baricentriche a,b,c

(14)

Problema:

interpolazione lineare coordinate texture

• Esempio:

u v

1 1

u,v= (1,0)

u1,v1= (1,1)

(15)

Problema:

interpolazione lineare coordinate texture

(16)

Soluzione: Correzione Prospettica

• p ha coordinate baricentriche c0 c1 c2

V0

V2 V1

A0,B0 ... A1,B1 ...

A2,B2 ...

p

p

=

c

0

v

0

+

c

1

v

1

+

c

2

v

2

attributi di

p

:

(senza considerare

la "correzione prospettica")

A

p

=

c

0

A

0

+

c

1

A

1

+

c

2

A

2

B

p

=

c

0

B

0

+

c

1

B

1

+

c

2

B

2

(17)

Soluzione: Correzione Prospettica

• p ha coordinate baricentriche c0 c1 c2

V0

V2 V1

A0,B0 ... A1,B1 ...

A2,B2 ...

p

p

=

c

0

v

0

+

c

1

v

1

+

c

2

v

2

attributi di

p

:

(senza considerare

la "correzione prospettica")

w

0

w

1

A

p

=

c

0

A

A

00

+

c

1

A

1

+

c

2

A

2

w

0

A

1

w

1

A

2

w

2

A

p

=

A

p

=

c

0

A

1

0

+

c

1

A

1

1

+

c

2

A

1

2

w

2

(18)

Soluzione: Correzione Prospettica Fr a m m e n ti & a tt ri b u ti in te rp o la ti V e rt ic i & l o ro a tt ri b u ti Screen buffer V e rt ic i p o ri e tt a ti & a tt ri b u ti c o m p u ta ti rasterize r triangoli set -up rasterize r segment i set -up rasterize r punti set -up co m p u ta zi o n i p e r v e rt ic e co m p u ta zi o n i p e r fr a m m e n to attributo originale A applico transofrm. poi calcolo:

A' = A / w

e

w' = 1 / w

c

0

w

A

0

+

c

1

+

c

2

0

A

1

w

1

A

2

w

2

A

p

=

1

w

0

w

1

1

w

1

2

interpolo

A' e w'

attributo finale del framment

o:

A' / w'

c

(19)

Correzione Prospettica

(20)

Correzione Prospettica

• Texture mapping con correzione prospettica

– anche conosciuto come: • texture mapping perfetto

• metodo dei 3 vettori magici (desueto)

(21)

Nota: la tessitura va caricata Fr a m m e n ti & a tt ri b u ti in te rp o la ti V e rt ic i & l o ro a tt ri b u ti Screen buffer V e rt ic i p o ri e tt a ti & a tt ri b u ti c o m p u ta ti rasterize r triangoli set -up rasterize r segment i set -up rasterize r punti set -up co m p u ta zi o n i p e r v e rt ic e co m p u ta zi o n i p e r fr a m m e n to Texture RAM

(22)

Nota: 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)

Entrambe operazioni piuttosto lente.

(23)

In OpenGL

• Ad esempio:

glEnable(GL_TEXTURE_2D);

glBindTexture (GL_TEXTURE_2D, ID);

glTexImage2D (

GL_TEXTURE_2D,

0, // mipmapping

GL_RGB, // formato interno

imageWidth, imageHeight,

0, // bordo

GL_RGB, // formato nella RAM

(24)
(25)

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)

(26)

Problema difficile: u-v mapping

• Assegnare una coppia di coordinate textures ad ogni vertice della mesh

– In preprocessing

u v

(27)

Problema difficile: u-v mapping

(28)

In OpenGL

• Come ogni altro attributo

(29)
(30)

Come si assegnano le coordinate texture ai vertici?

• Due classi di soluzioni:

– Assegnarle le coordinate textures al volo • durante il rendering…

– Precomputarle

(31)
(32)

Create automaticamente

• Concetto: da (x,y,z) a (u,v) - Linearmente

• In coordinate oggetto o vista

– (prima o dopo la trasformazione)

(33)

Create automaticamente

• Anche 1D

(34)

Come si assegnano le coordinate texture ai vertici?

• Due classi di soluzioni:

– Assegnare le coordinate textures al volo • durante il rendering…

– Precomputarle

(35)

Environment mapping: sferico

Environment map:

una tessitura che memorizza il colore

dell’ambiente “riflesso da ogni normale della semisfera.

(36)

Environment mapping: sferico

simula oggetto a specchio che riflette uno sfondo lontano

(37)

Environment mapping: cubico

front right back

below above

(38)

Environment mapping: cubico Fr a m m e n ti & a tt ri b u ti in te rp o la ti V e rt ic i & l o ro a tt ri b u ti Screen buffer V e rt ic i p o ri e tt a ti & a tt ri b u ti c o m p u ta ti rasterize r triangoli set -up rasterize r segment i set -up rasterize r punti set -up co m p u ta zi o n i p e r v e rt ic e Texture RAM co m p u ta zi o n i p e r fr a m m e n to interpolo coordinat e texture 3D coordinat e texture 3D interpolat e proietto sul cubo, accedo alla faccia corrispondente calcolo coordinate texture 3D

1,+1] x 1,+1] x [-1,+1]

come raggio di vista

(39)

Environment mapping: cubico

front right back

below above

(40)

Environment mapping: cubico e sferico

• Sferico:

– un texel per ogni direzione nella semisfera

• proiettata su un cerchio

– come coordinata texture uso la normale

– per forza effetto "headlight":

• ruoto oggetto mentre punto vista rimane fermo

• Cubico

– un texel per ogni direzione nella sfera

• proiet. sulla sup di un cubo

– come coordinata texture uso la direzione di vista rifelssa dalla normale

(41)

Creazione Automatica Coordinate Texture

glEnable(GL_TEXTURE_GEN_S);

1- abilitarla:

2- scegliere la modalita':

glTexGeni(GL_S , GL_TEXTURE_GEN_MODE , mode )

S, T, R, Q

mode

=

GL_OBJECT_LINEAR

GL_EYE_LINEAR

GL_SPHERE_MAP

computa le coord texture dalle pos nel sist di rif oggetto (prima della trasformazione)

computa le coord texture dalle pos nel sist di rif camera

(dopo la MODEL-VIEW)

computa come coord texture il raggio di vista rifelsso – usa la

normale

(42)

Creazione Automatica Coordinate Texture

glTexGenfv(GL_S, GL_EYE_PLANE , v);

3- scegliere il piano

S, T, R, Q

EYE OBJECT

o

vettore di 4 elementi

coordinata texture prodotta = v

T

• pos_vertice

(43)
(44)

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

(45)

Texture Look-up:

fuori dai bordi: modo "repeat"

u

v

1 1

(46)

Tessiture

ripetute

• Tipico utilizzo:

Molto efficiente in spazio!

(47)

In OpenGL

glTexParameteri( GL_TEXTURE_2D,

GL_TEXTURE_WRAP_S, GL_CLAMP );

glTexParameteri( GL_TEXTURE_2D,

GL_TEXTURE_WRAP_S, GL_REPEAT );

o

nota: setto per u e v

separatemen te

esempio: repeat sulla u e clamp sulla v

sono parametri della tessitura. Ogni tessitura caricata in memoria ha i propri

(48)
(49)

Texture Look-up

• Un frammento ha coordinate non intere (in texels)

Texture Space Screen Space

(50)

pixel

Texture Look-up

Texture Space Screen Space

pixel texel

un pixel = meno di un texel

un pixel = più di un texel

(51)

Caso Magnification

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"

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

u v

(52)

Caso Magnification

texture 128x128

Nearest Filtering:

risultato visivo

(53)

Caso Magnification

Soluzione 2:

Medio il valore dei quattro texel più vicini

Interpolazione Bilineare

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

u v

(54)

Caso Magnification

texture 128x128

(55)

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

(56)

Caso Minification

Nearest Filtering Bilinear interpolation

(57)

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)

(58)

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?

(59)

Caso Minification: MIP-mapping

Bilinear interpolation

(60)

Caso Minification: MIP-mapping

0 1 2 3 4 5

(61)

In OpenGL

glTexParameteri( GL_TEXTURE_2D,

GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameteri( GL_TEXTURE_2D,

GL_TEXTURE_MAG_FILTER, GL_LINEAR );

oppure

(62)

In OpenGL

glTexParameteri( GL_TEXTURE_2D,

GL_TEXTURE_MIN_FILTER,

modo );

modo = GL_NEAREST

GL_LINEAR

GL_NEAREST_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR

dove

decidere che tipo di minificazione usare:

interpolazion e

(63)

In OpenGL

• Caricare sulla scheda

i vari livelli di mipmapping.

– uno per uno:

glTexImage2D (

GL_TEXTURE_2D,

i, // MIP-map level

GL_RGB, // formato interno

imageWidth, imageHeight,

0, // bordo

GL_RGB, // formato nella RAM

(64)

In OpenGL

• Caricare sulla scheda

i vari livelli di mipmapping.

– tutti insieme (con la libreria glu):

glTexImage2D (

GL_TEXTURE_2D,

0, // MIP-map level

GL_RGB, // formato interno

imageWidth, imageHeight,

0, // bordo

GL_RGB, // formato nella RAM

GL_UNSIGNED_BYTE, imageData);

References

Related documents

shall be sent, if to the Agent at the address set forth in the Appointment Data and Information section of said Agreement, and if to Company at: Forethought Life Insurance

In identifying the drivers of financial reporting quality, proxied by earnings management (EM), prior literature has drawn attention to the association between corporate EM

Transboundary conservation and international cooperation on wetlands management should be promoted in the context of existing multilateral environmental agreements for

The future implementation of sustainable CBT in Shaglli serves as a model to increase tourism revenue throughout rural communities in Ecuador.. Plan

The effects of the calculated segregation energies on defect concentrations and electrostatic potential in the grain boundary region are investigated using a thermodynamic

As there can be many non-linear relationships, how to calculate the distance between these values is very important. We consider using the method of numerical calculation of

Software numerical combustion analysis showed that the total energy output per unit mass increases, as Hydrogen dosage increases. Relationship can be described in

We investigated the expression of the Alzheimer’s disease-related metabolic brain pattern (ADRP) in 18 F-FDG-PET scans of 44 controls, 27 patients with mild cognitive impairment