Games with Texture Mapping Steve Marschner CS 4620 Cornell - - PowerPoint PPT Presentation

games with texture mapping
SMART_READER_LITE
LIVE PREVIEW

Games with Texture Mapping Steve Marschner CS 4620 Cornell - - PowerPoint PPT Presentation

Games with Texture Mapping Steve Marschner CS 4620 Cornell University Cornell CS4620 Fall 2020 Steve Marschner 1 Recall first definition Texture mapping: a technique of defining surface properties (especially shading parameters) in


slide-1
SLIDE 1

Steve Marschner CS 4620 Cornell University

Steve Marschner • Cornell CS4620 Fall 2020

Games with Texture Mapping

1

slide-2
SLIDE 2

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.

Recall first definition…

2

slide-3
SLIDE 3

Let’s look at some examples of more general uses of texture maps.

Steve Marschner • Cornell CS4620 Fall 2020

Texture mapping: a set of techniques for defining functions on surfaces, for a variety of uses.

A refined definition

3

slide-4
SLIDE 4
  • Early (earliest?) non-decal use of textures
  • Appearance of shiny objects

– Phong highlights produce blurry highlights for glossy surfaces. – A polished (shiny) object reflects a sharp image of its environment.

  • The whole key to a

shiny-looking material is providing something for it to reflect.

(a) (b)

Figure 2. (a). A shiny sphere rendered under photographically acquired real-world illumination. (b). The same sphere rendered under illumination by a point light source.

[Dror, Willsky, & Adelson 2004]

Steve Marschner • Cornell CS4620 Fall 2020

Reflection mapping

4

slide-5
SLIDE 5

Hand with Refmecting Sphere.

  • M. C. Escher, 1935.

lithograph

slide-6
SLIDE 6
  • Recall how we can make mirror reflections in ray tracing

Steve Marschner • Cornell CS4620 Fall 2020

Reflections in ray tracing

6

r = v + 2((n · v)n − v) = 2(n · v)n − v

n r v

slide-7
SLIDE 7
  • If scene is infinitely far away, the color seen by the reflection

ray depends only on the direction of the ray – a two-dimensional function – represent it with a texture!

  • Environment map: texture that maps directions to colors

– one option: axes are (theta, phi) – better option: cube map

Steve Marschner • Cornell CS4620 Fall 2020

Reflection mapping

7

slide-8
SLIDE 8

A spherical panorama, aka. enironment map straight up straight up straight up straight down straight down straight down

  • penfootage.net

due West due East due South due North due East

slide-9
SLIDE 9
  • A function from the sphere to colors,

stored as a texture.

[Blinn & Newell 1976]

Steve Marschner • Cornell CS4620 Fall 2020

Environment map

9

slide-10
SLIDE 10

Steve Marschner • Cornell CS4620 Fall 2020

Spherical environment map

Hand with Refmecting Sphere. M. C. Escher, 1935. lithograph

10

r 1

  • r
slide-11
SLIDE 11

Steve Marschner • Cornell CS4620 Fall 2020 11

Environment Maps

[Paul Debevec]

slide-12
SLIDE 12

Steve Marschner • Cornell CS4620 Fall 2020

Cube map

12

(u, v) = (1, 1) x = y = z (u, v) = (0, 0) x = –y = –z right face has x > |y| and x > |z|

a direction vector maps to the point on the cube that is along that direction. The cube is textured with 6 square texture maps.

slide-13
SLIDE 13

Steve Marschner • Cornell CS4620 Fall 2020 13

[Emil Persson] [Zephyris at en.wikipedia]

slide-14
SLIDE 14
  • A fragment operation

– requires surface normal and a way to get the view direction

  • GLSL handles cubemaps by itself

– you just give it the reflection vector and it figures out where to sample and on which face – sample using textureCube()

  • Don’t overlook built-in functions

– e.g. reflect()

Steve Marschner • Cornell CS4620 Fall 2020

Reflection mapping in GLSL

14

slide-15
SLIDE 15
  • A powerful tool for modeling detail

– used heavily in film production

  • Geometric prerequisites

– texture map representing height field – smooth normals – texture coordinates – dense triangulation

  • In GLSL

– a vertex operation (because it moves geometry) – displace vertices along normals according to texture map value – compute new normal to displaced surface (depends on the slope

  • f the displacement texture)

Steve Marschner • Cornell CS4620 Fall 2020

Displacement mapping

15

slide-16
SLIDE 16

[wikiwand]

slide-17
SLIDE 17

Steve Marschner • Cornell CS4620 Fall 2020 17

Paweł Filip tolas.wordpress.com

base surface displaced surface hand-painted displacement map (detail)

slide-18
SLIDE 18
slide-19
SLIDE 19
  • A powerful tool for modeling detail

– used heavily in film production

  • Geometric prerequisites

– texture map representing height field – smooth normals – texture coordinates – dense triangulation

  • In GLSL

– a vertex operation (because it moves geometry) – displace vertices along normals according to texture map value – compute new normal to displaced surface (depends on the slope

  • f the displacement texture)

Steve Marschner • Cornell CS4620 Fall 2020

Displacement mapping

19

slide-20
SLIDE 20
  • Displacement mapping is expensive

– requires densely tessellated geometry – many triangles to rasterize

  • For small displacements, change in normal is most important

– so just do that part; don’t displace the surface

  • Bump mapping is then a fragment operation

– doesn’t require dense tessellation – doesn’t actually displace the surface – gives shading that looks just like displaced surface

Steve Marschner • Cornell CS4620 Fall 2020

Bump mapping

20

slide-21
SLIDE 21

Steve Marschner • Cornell CS4620 Fall 2020

Bump mapping

21

INI, IDI,

INI/IDI

50

ID’1 INI

tan+' ID'l/lNl

tan+

sqrt(Fu'+Fv') sqrt(Fu'+Fv.')

lNl/lDl

  • .

:

[Blinn 1978]

sznple results that can be achieved with this technique. The first pattern, a hand drawn unit cell

  • f bricks was mapped onto the sphere
  • n

the cover.

Figure 8 Hand Drawn Functions

slide-22
SLIDE 22

Geometry Bump mapping Displacement mapping

[CS467 slides]

slide-23
SLIDE 23

Geometry Bump mapping Displacement mapping

[CS467 slides]

slide-24
SLIDE 24
  • Displacement mapping is expensive

– requires densely tessellated geometry – many triangles to rasterize

  • For small displacements, change in normal is most important

– so just do that part; don’t displace the surface

  • Bump mapping is then a fragment operation

– doesn’t require dense tessellation – doesn’t actually displace the surface – gives shading that looks just like displaced surface

Steve Marschner • Cornell CS4620 Fall 2020

Bump mapping

24

slide-25
SLIDE 25
  • Bump mapping is great

– great way to add detail with low cost – bump textures are great for authoring detail

  • But it requires computing slope of displacement

– have to take multiple samples from texture – precision issues easily lead to artifacts

  • So just compute the normal ahead of time

– takes a bit more memory, but so be it – usually stored in a tangent space coordinate system defined by the normal vector and two tangent vectors

  • Normal mapping is so common it’s sometimes just called

“bump mapping”

Steve Marschner • Cornell CS4620 Fall 2020

Normal mapping

25

slide-26
SLIDE 26

Steve Marschner • Cornell CS4620 Fall 2020

A normal map

26

slide-27
SLIDE 27

Steve Marschner • Cornell CS4620 Fall 2020

A normal map

27

slide-28
SLIDE 28

Steve Marschner • Cornell CS4620 Fall 2020

A normal map

27

RGB color = XYZ normal

slide-29
SLIDE 29

Steve Marschner • Cornell CS4620 Fall 2020

A normal map

27

RGB color = XYZ normal R = X component (u direction)

slide-30
SLIDE 30

Steve Marschner • Cornell CS4620 Fall 2020

A normal map

27

RGB color = XYZ normal R = X component (u direction) G = Y component (v direction)

slide-31
SLIDE 31

Steve Marschner • Cornell CS4620 Fall 2020

A normal map

27

RGB color = XYZ normal R = X component (u direction) G = Y component (v direction) B = Z component (n direction)

slide-32
SLIDE 32

Steve Marschner • Cornell CS4620 Fall 2020 28

slide-33
SLIDE 33

Steve Marschner • Cornell CS4620 Fall 2020 28

slide-34
SLIDE 34

Steve Marschner • Cornell CS4620 Fall 2020

Normal mapping

29

[Paolo Cignoni]

slide-35
SLIDE 35
  • Geometric prerequisites

– mesh with smooth normals and texture coordinates – no dense triangulation needed – unit tangent vectors (normalized, orthogonal) – texture map (3 channels) representing normal field

  • Fragment shader logic

– look up normal from map in (tangent-u, tangent-v, normal) space – no finite differencing needed – transform normal into eye (or world) space – use interpolated normal and tangents for this – compute shading as always

Steve Marschner • Cornell CS4620 Fall 2020

Normal mapping

30

slide-36
SLIDE 36
  • How do we get these tangent vectors?

– they need to be stored at vertices on the mesh, like normals

  • For a triangle, there’s a unique linear map from (u,v) to (x,y,z)

– the derivatives of that map are the (non-unit) tangents – can be computed by solving three 2x2 linear systems – math resembles triangle setup for rasterization; details here

  • For displacement/bump mapping you want to leave the

tangents unnormalized and non-orthogonal

  • For normal mapping and other uses it’s often handy to make

the two tangents and the normal into an ONB – use exactly the basis-from-two math that we have used for cameras and manipulators

Steve Marschner • Cornell CS4620 Fall 2020

Computing tangent vectors

31