Texture mapping basics Steve Marschner CS 4620 Cornell University - - PowerPoint PPT Presentation

texture mapping basics
SMART_READER_LITE
LIVE PREVIEW

Texture mapping basics Steve Marschner CS 4620 Cornell University - - PowerPoint PPT Presentation

Texture mapping basics Steve Marschner CS 4620 Cornell University Cornell CS4620 Fall 2020 Steve Marschner 1 Texture mapping Objects have properties that vary across the surface Cornell CS4620 Fall 2020 Steve Marschner 2


slide-1
SLIDE 1

Steve Marschner CS 4620 Cornell University

Steve Marschner • Cornell CS4620 Fall 2020

Texture mapping basics

1

slide-2
SLIDE 2
  • Objects have properties that vary across the surface

Steve Marschner • Cornell CS4620 Fall 2020

Texture mapping

2

slide-3
SLIDE 3
  • So we make the shading

parameters vary across the surface

[Foley et al. / Perlin] Steve Marschner • Cornell CS4620 Fall 2020

Texture Mapping

3

slide-4
SLIDE 4
  • Adds visual complexity; makes appealing images

[P ix Steve Marschner • Cornell CS4620 Fall 2020

Texture mapping

4

slide-5
SLIDE 5
  • Surface properties are not the same everywhere

– diffuse color ( ) varies due to changing pigmentation – shininess ( ) and specular coefficient ( ) for specular highlight vary due to changing finishes and surface contamination

  • Want functions that assign properties to points on the surface

– the surface is a 2D domain – given a surface parameterization, just need function on plane – images are a handy way to represent such functions – can represent using any image representation – raster texture images are very popular

kd p ks

Steve Marschner • Cornell CS4620 Fall 2020

Texture mapping

5

slide-6
SLIDE 6
  • This is very simple!

– but it produces complex-looking effects

Steve Marschner • Cornell CS4620 Fall 2020

Texture mapping: a technique of defining surface properties (especially shading parameters) in such a way that they vary as a function of position on the surface.

A first definition

6

slide-7
SLIDE 7
  • Wood gym floor with smooth finish

– diffuse color varies with position – specular properties , are constant

  • Glazed pot with finger prints

– diffuse color is constant – roughness and perhaps specular color vary with position

  • Adding dirt to painted surfaces
  • Simulating stone, fabric, …

– to approximate effects of small-scale geometry – they look flat but are a lot better than nothing

kd ks p kd p ks

Steve Marschner • Cornell CS4620 Fall 2020

Examples

7

specular parameters p and ks 
 for Blinn-Phong shading

slide-8
SLIDE 8

8

slide-9
SLIDE 9

9

slide-10
SLIDE 10

10

slide-11
SLIDE 11

11

slide-12
SLIDE 12
  • Usually the texture is an image (function of u, v)

– the big question of texture mapping: where on the surface does the image go? – obvious only for a flat rectangle the same shape as the image – otherwise more interesting

Steve Marschner • Cornell CS4620 Fall 2020

Mapping textures to surfaces

12

Aside: parametric

  • vs. implicit
  • vs. piecewise

surface models

slide-13
SLIDE 13
  • “Putting the image on the surface”

– this means we need a function f that tells where each point on the image goes – this looks a lot like a parametric surface function – for parametric surfaces (e.g. sphere, cylinder) you get f for free – Non-parametrically defined surfaces: more to do

Steve Marschner • Cornell CS4620 Fall 2020

Mapping textures to surfaces

13

slide-14
SLIDE 14
  • Function from texture to surface is not what we need

– need to have the inverse of the function f

  • Texture

coordinate fn. – when shading p get texture at φ(p)

Steve Marschner • Cornell CS4620 Fall 2020

Texture coordinate functions

14

slide-15
SLIDE 15
  • Surface lives in 3D world space
  • Every point also has a place where it goes

in the image and in the texture.

Steve Marschner • Cornell CS4620 Fall 2020

Three spaces

15

x y z u v xs ys

  • world space

image space texture space

slide-16
SLIDE 16
  • Define texture image as a function

– where C is the set of colors for the diffuse component

  • Diffuse color (for example) at point p is then

Steve Marschner • Cornell CS4620 Fall 2020

Texture coordinate functions

16

kd(p) = T(ϕ(p)) T : D → C

slide-17
SLIDE 17
  • A rectangle

– image can be mapped directly, unchanged

Steve Marschner • Cornell CS4620 Fall 2020

Examples of coordinate functions

17

slide-18
SLIDE 18
  • For a sphere: latitude-longitude coordinates

– maps point to its latitude and longitude

ϕ

[map: Peter H. Dana] Steve Marschner • Cornell CS4620 Fall 2020

Examples of coordinate functions

18

slide-19
SLIDE 19
  • Many surfaces don’t come with coordinates

– implicit surfaces – random triangle meshes

  • Some surface come with coordinates that are incomplete

– triangle meshes: natural coordinate for each triangle – spline surfaces: natural coordinates for each patch

  • Generally need to be able to compute texture coordinates

from the surface position

Steve Marschner • Cornell CS4620 Fall 2020

Coordinate functions: non-parametric

19

slide-20
SLIDE 20
  • Planar projection

Steve Marschner • Cornell CS4620 Fall 2020

Examples of coordinate functions

20

u v

slide-21
SLIDE 21
  • Spherical projection

Steve Marschner • Cornell CS4620 Fall 2020

Examples of coordinate functions

21

slide-22
SLIDE 22
  • Cylindrical projection

Steve Marschner • Cornell CS4620 Fall 2020

Examples of coordinate functions

22

spherical cylindrical

slide-23
SLIDE 23
  • Complex surfaces: project parts to parametric surfaces

[Tito Pagan]

Steve Marschner • Cornell CS4620 Fall 2020

Examples of coordinate functions

23

slide-24
SLIDE 24
  • Triangles

– specify (u,v) for each vertex – define (u,v) for interior by linear (barycentric) interpolation

(u,v) (uc,vc) (ub,vb) (ua,va)

Steve Marschner • Cornell CS4620 Fall 2020

Examples of coordinate functions

24

1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9

slide-25
SLIDE 25
  • Texture coordinates become per-vertex data like vertex

positions – can think of them as a second position: each vertex has a position in 3D space and in 2D texure space

  • How to come up with vertex (u,v)s?

– use any or all of the methods just discussed – in practice this is how you implement those for curved surfaces approximated with triangles – use some kind of numerical optimization – try to choose vertex (u,v)s to result in a smooth, low distortion map

Steve Marschner • Cornell CS4620 Fall 2020

Texture coordinates on meshes

25

slide-26
SLIDE 26

http://www.uvmapper.com

Steve Marschner • Cornell CS4620 Fall 2020

Example: UVMapper

26

slide-27
SLIDE 27
  • Texels relate to texture coordinates in the same way as

pixels relate to normalized image coordinates

Steve Marschner • Cornell CS4620 Fall 2020

Pixels in texture images (texels)

27

u = l u = r v = b v = t

j

i

i = –.5 i = 3.5 j = 2.5 j = –.5

u = 0 u = 1 v = 0 v = 1

for a texture image

  • f nu by nv pixels

i = round(u nu − 0.5) = floor(u nu) j = round(v nv − 0.5) = floor(v nv)

<latexit sha1_base64="SrRmPjJwzfrPUqON7bvyOunQTpk=">ACmHicdVFdb9MwFHXCV1dg6+BxLxYVaJW6JumKA+IAQ+AxMNAhE1qspxbjYzxw7+iFZF/aH7F/wDcJMNAYMrWTo+5x5f+zgtOdMmDC8/8bNW7fvdDa6d+/d39zqbT/4oqVFGIquVTHKdHAmYDYMPhuFRAipTDUXr2Zq0fVaA0k+KzWZYwL8iJYDmjxDhq0dMP3mBEwPnplbSimy1a3EyxGJh8R4OR08H+ErOuZTKycnQiYMk6X69Zq1a/Ufa7W2VoNFrx+OwqbwdRBdgv7L76ipw8W2t5lktoChKGcaD2LwtIMcw7fxLwmyjDKYdVNrIaS0DNyAjMHBSlAz+smoxV+7JgM51K5JQxu2N8dNSm0Xhap6yIOdV/a2vyX9rMmnw6r5korQFB20G5dhIvA4cZ0wBNXzpAKGKubtiekoUocZ9SzdpjHUQa7cLtCqCDyxVRC0DF1yRB0xQbjMI3FzFzvcqd5R7TZPgZDyeTvZxC/ajKzD9lWA8Hj0fR8n/YPXbZKog3bQI7SLIvQMHaB36BDFiKIL9MPreBv+jv/Kf+u/b1t979LzEP1R/qefVR3I7A=</latexit><latexit sha1_base64="SrRmPjJwzfrPUqON7bvyOunQTpk=">ACmHicdVFdb9MwFHXCV1dg6+BxLxYVaJW6JumKA+IAQ+AxMNAhE1qspxbjYzxw7+iFZF/aH7F/wDcJMNAYMrWTo+5x5f+zgtOdMmDC8/8bNW7fvdDa6d+/d39zqbT/4oqVFGIquVTHKdHAmYDYMPhuFRAipTDUXr2Zq0fVaA0k+KzWZYwL8iJYDmjxD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VRC0DF1yRB0xQbjMI3FzFzvcqd5R7TZPgZDyeTvZxC/ajKzD9lWA8Hj0fR8n/YPXbZKog3bQI7SLIvQMHaB36BDFiKIL9MPreBv+jv/Kf+u/b1t979LzEP1R/qefVR3I7A=</latexit><latexit sha1_base64="LdwnBiPXtrUtS4EZhgs/+2NvCY=">ACmHicdVFdb9MwFHXCV1dg6+BxLxYVaJW6JumKA9I23gAJB4GImxSU1WOc7OZOXbwR7Qq6g/dr9nctEPA4EqWjs+5x9c+TkvOtAnDK8+/d/Bw0etjfbjJ083tzrbz75raRWFmEou1WlKNHAmIDbMcDgtFZAi5XCSXrxf6icVKM2k+GbmJUwLciZYzigxjp1NMOv3uHEwKWplbQiW+xanPSxmFm8h8PB6x6+lXMupXJy0ndiL0naP+5Yq5W1+o+1Wlqr3qzTDQdhU/guiNagi9Z1PNv2NpNMUluAMJQTrSdRWJp+zuGnmNZEGUY5LNqJ1VASekHOYOKgIAXoad1ktMAvHZPhXCq3hMEN+7ujJoXW8yJ1nQUx5/pvbUn+S5tYk4+nNROlNSDoalBuOTYSLwPHGVNADZ87QKhi7q6YnhNFqHf0k4aYx3E2u0CrYrgM0sVUfPABVfkAROU2wCN1exy73KHeVe0yQ4Gg7Ho328AvRLRj/SjAeDt4Ooi+j7sHROsoW2kEv0C6K0Bt0gD6iYxQjiq7QtdfyNvwd/9D/4H9atfre2vMc/VH+1xtzB8e9</latexit>
slide-28
SLIDE 28
  • Mapping from S to D can be many-to-one

– that is, every surface point gets only one color assigned – but it is OK (and in fact useful) for multiple surface points to be mapped to the same texture point – e.g. repeating tiles

Steve Marschner • Cornell CS4620 Fall 2020

Texture coordinate functions

28

slide-29
SLIDE 29
  • In shading calculation, when you need a texture value you

perform a texture lookup

  • Convert (u, v) texture coordinates to (i, j) texel coordinates,

and read a value from the image

  • What if i and j are out of range?

– option 1, clamp: take the nearest pixel that is in the image – option 2, wrap: treat the texture as periodic, so that falling off the right side causes the look up to come in the left

Steve Marschner • Cornell CS4620 Fall 2020

Texture lookups and wrapping

29

ipixel = remainder(ilookup, nx) ipixel = max(0, min(nx − 1, ilookup))

slide-30
SLIDE 30

Steve Marschner • Cornell CS4620 Fall 2020

Wrapping modes

30

clamp wrap