Docsity

Lecture Slides on Computer Graphics | CAP 4720, Study notes of Computer Graphics

Partial preview of the text

Download Lecture Slides on Computer Graphics | CAP 4720 and more Study notes Computer Graphics in PDF only on Docsity!

Juraj Obert [email protected] http://graphics.cs.ucf.edu/cap4720/fall2008/

Sampling

tex2D(sampler1, vec2(0.27, 0.14)

What do we return from this function call?

1 2

(^3 )

Texture filtering

 Filtering modes:

 Nearest neighbor

 Bilinear

 Mipmapping

 Trilinear

Nearest neighbor

tex2D(sampler1, vec2(0.27, 0.14)

What do we return from this function call?

1 2

(^3 )

Return the nearest texel

  • Texel 2 in this case

Bilinear filtering cont.

1 2

(^3 )

yi – color of the i-th texel ui – u-coordinate of the i-th texel vi – v-coordinate of the i-th texel

(u,v)

A

B

4 2

2

4 3

3 3 4 3

2 1

1 1 2 1

v v

v v

y y y y

u u

u u

y y y y

u u

u u

y y y y

FINAL A B A

B

A

Nearest neighbor vs Bilinear

Nearest neighbor Bilinear

_ _ _ _ _ _ _ _ _

Mipmapping

One Pixel

Pixel covers 0 texels

Mipmapping cont.

Pixel covers 1 texel

Push the object down the negative z-axis

Mipmapping

u

v

d

Texture Interpolation Texture Pyramid

Multum In Parvo (MIP) : Many things in a small place

Creating mipmaps

 Mipmap levels

 0 – full resolution, base texture

 1 – full resolution / 2

 2 – full resolution / 4

 i – full resolution / 2

 Each texel on level i corresponds to 4 texels on

level (i-1)

 Texel on level i is computed as arithmetic average of 4

corresponding texels on level (i-1)

i

Trilinear filtering

 Generalization of bilinear filtering:

1. Find two nearest mipmaps

2. Interpolate color from 4 nearest texels within

each mipmap

3. Interpolate between mipmaps

Nearest neighbor vs Bilinear vs Trilinear

Nearest neighbor Bilinear Trilinear

OpenGL samplers

 Sampler

 Physical unit bound to one texture at a time

 Defines filtering modes

 Defines texture states

// generate texture name, textures have numeric names in OpenGL, i.e. 1, 2, … glGenTextures(1, &tex);

// bind texture to current sampler glBindTexture(GL_TEXTURE_2D, tex);

// define how pixels are aligned in memory (compressed, uncompressed, etc..) glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

// set up filtering modes glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

OpenGL samplers cont.

 Sampler

 Physical unit bound to one texture at a time

 Defines filtering modes

 Defines texture states

// …

// set up texture coordinates modes glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

// tell OpenGL where texels are glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, this->width, this->height, 0, GL_RGB, GL_UNSIGNED_BYTE, this->pixels);

Texture coordinates

 Wrapping state:

 What happen if fragment’s texture coordinates are

outside the range <0.0, 1.0>?

 This means that we want to access texels outside the original texture

 2 options:

 Use border color

 WRAP

 Repeat from beginning

 REPEAT

Examples

U : CLAMP

V : CLAMP

U : REPEAT

V : CLAMP

U : CLAMP

V : REPEAT

U : REPEAT

V : REPEAT