Textures CS 148: Summer 2016 Introduction of Graphics and Imaging - - PowerPoint PPT Presentation

textures
SMART_READER_LITE
LIVE PREVIEW

Textures CS 148: Summer 2016 Introduction of Graphics and Imaging - - PowerPoint PPT Presentation

Textures CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain http://www.pling.org.uk/cs/cgv.html Texture Mapping A technique for specifying variations in surface reflectance properties of an object Store the


slide-1
SLIDE 1

CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain

Textures

http://www.pling.org.uk/cs/cgv.html

slide-2
SLIDE 2

Texture Mapping

§ A technique for specifying variations in surface reflectance properties of an

  • bject

§ Store the reflectance as an image and “map” it onto the object § The stored image is called a texture map

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 2

slide-3
SLIDE 3

§ A texture map is defied in its own 2D coordinate system, parameterized by (u, v) § Establish a correspondence by assigning (u, v) coordinates to triangle vertices

Texture Correspondence

(0,0) (1,0) (0,1) (1,1)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 3

slide-4
SLIDE 4

OpenGL Texturing Snippet

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4

slide-5
SLIDE 5

§ Then, for each pixel inside a triangle, calculate the pixel’s (u,v) texture coordinates using barycentricinterpolation of the triangle vertices’ texture coordinates

Texture Coordinates

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 5

slide-6
SLIDE 6

Pixel Color

§ Given the pixel’s (u,v) texture coordinates, use interpolation in the texture map to find the pixel’s color

??

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 6

slide-7
SLIDE 7

Pixel Color: Nearest Neighbor

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 7

slide-8
SLIDE 8

Pixel Color: Bilinear Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 8

Linearly Interpolate

slide-9
SLIDE 9

Pixel Color: Bilinear Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 9

Another Linearly Interpolate

slide-10
SLIDE 10

Nearest Neighbor Vs Bilinear

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 10

slide-11
SLIDE 11

Nearest Neighbor Vs Bilinear

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 11

More on this when we discuss “Sampling”

slide-12
SLIDE 12

Screen Space vs. World Space

§ Triangles change shape nonlinearly via perspective transformation, leading to different barycentricweights before and after the perspective transformation § Interpolating in screen space results in texture distortion § Interpolating in world space requires projecting all pixel locations backwards from screen space to world space, which is expensive

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 12

slide-13
SLIDE 13

Texture Distortion

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 13

p’0 p’1 p0 p1 𝑡 ≠ 0.5 𝑢 = 0.5 𝑢: Screen-space parameter 𝑡: World-space parameter

slide-14
SLIDE 14

Texture Distortion

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 14

p’0 p’1 p0 p1 𝑢 ≠ 0.5 𝑡 = 0.5 𝑡: Screen-space parameter 𝑢: World-space parameter

Screen-space and World-space parameters don’t match !

slide-15
SLIDE 15

Texture Distortion

§ Uniform increments along the edge in world space do not correspond to uniform increments along the edge in screen space § Barycentric interpolation (which is linear) does not account for this nonlinearity

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 15

slide-16
SLIDE 16

Mesh Refinement

§ Refinement of the triangle mesh improves the result § A nonlinear function can be approximated as a piecewise linear function if the intervals are small enough § However some errors are still obvious, especially at T- junctions where levels-of-refinement change

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 16

Subdivide

T junction

slide-17
SLIDE 17

Mesh Refinement

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 17

Does not work !

slide-18
SLIDE 18

Perspective Correct Interpolation

§ Find the relationship between the barycentric weights in screen space and those in world space § Use this relationship to compute the world space barycentric weights from the screen space barycentric weights

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 18

slide-19
SLIDE 19

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 19

Two points in world space

slide-20
SLIDE 20

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 20

Two points in world space Interpolation in world space

slide-21
SLIDE 21

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 21

Two points in world space Interpolation in world space Project the interpolated point on the screen

slide-22
SLIDE 22

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 22

Two points in world space Interpolation in world space Project the interpolated point on the screen

slide-23
SLIDE 23

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 23

Interpolation of the same two points in screen space (after projection)

slide-24
SLIDE 24

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 24

Interpolation of the same two points in screen space (after projection) Screen space point and world-space point after projection must match

slide-25
SLIDE 25

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 25

Interpolation of the same two points in screen space (after projection) Screen space point and world-space point after projection must match After algebra

slide-26
SLIDE 26

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 26

Screen Space Triangle World Space Triangle

slide-27
SLIDE 27

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 27

Finally!

slide-28
SLIDE 28

Perspective Correct Interpolation

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 28

Finally!

slide-29
SLIDE 29

Aliasing

What we get What we want

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 29

slide-30
SLIDE 30

Aliasing

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 30

Large texture Small image

Source pixels covers many destination pixels

slide-31
SLIDE 31

Aliasing

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 31

Large texture Small image

Source pixels covers many destination pixels

slide-32
SLIDE 32

MIP Maps

§ Multum in Parvo: Much in little, many in small places § Precomputes the texture maps at multiple resolutions, using averaging as a low pass filter § When texture mapping, choose the image size that approximately gives a 1 to 1 pixel to texel correspondence § The averaging “bakes-in” all the nearby pixels that otherwise would not be sampled correctly

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 32

slide-33
SLIDE 33

MIP Maps

§ 4 neighboring pixels of the higher level are averaged to form a single pixel in the lower level § Starting at a base resolution, you can store EVERY coarser resolution in powers of 2

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 33

slide-34
SLIDE 34

MIP Maps

§ 4 neighboring pixels of the higher level are averaged to form a single pixel in the lower level § Starting at a base resolution, you can store EVERY coarser resolution in powers of 2

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 34

slide-35
SLIDE 35

MIP Maps

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 35

slide-36
SLIDE 36

MIP Maps

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 36

gluBuild2DMipmaps

slide-37
SLIDE 37

Φ

y

Assigning Texture Coordinates

§ For certain surfaces, the (u, v) texture coordinates can be generated procedurally § Example: Cylinder § map the u coordinate from [0, 1] to [0, 2 π] for Φ § map the v coordinate from [0, 1] to [0, h] for y § This wraps the image around the cylinder § For more complex surfaces, (u, v) must be defined per vertex manually or by using proxy objects

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 37

slide-38
SLIDE 38

Proxy Objects – Step 1

  • Assign texture coordinates to intermediate/proxy objects:

§ Example: Cylinder § wrap texture around the outside of the cylinder § not the top or bottom, in order to avoid distorting the texture § Example: Cube § unwrap the cube and map texture over the unwrapped cube § the texture is seamless across some of the edges, but not necessarily

  • thers

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 38

slide-39
SLIDE 39

Proxy Objects – Step 2

§ Map texture coordinates from the intermediate/proxy object to the final object § Three ways of mapping are typically used § Use the intermediate/proxy object’s surface normal § Use the target object’s surface normal § Use rays emanating from center of target object

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 39

slide-40
SLIDE 40

Cube Mapping

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 40 http://learnopengl.com/#!Advanced-OpenGL/Cubemaps

slide-41
SLIDE 41

Projective Texturing

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 41

  • Treat light Source as a
  • Render the scene normally from the actual camera

http://www.nvidia.com/object/Projective_Texture_Mapping.html Segal et. al. SIGGRAPH’92

slide-42
SLIDE 42

Projective Texturing

  • Assign Texture Coordinates (s,t,r) to position (x,y,z)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 42

slide-43
SLIDE 43

Projective Texturing

  • Assign Texture Coordinates (s,t,r) to position (x,y,z)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 43

slide-44
SLIDE 44

Projective Texturing

  • Assign Texture Coordinates (s,t,r) to position (x,y,z)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 44

slide-45
SLIDE 45

Projective Texturing

  • Assign Texture Coordinates (s,t,r) to position (x,y,z)

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 45

So much work just to say (s,t,r) = (x,y,z)

Much easily done in newer OpenGL

slide-46
SLIDE 46

Projective Texturing

  • Use a similar View (from the light’s point of view)

and Projection matrix to transform texture coordinates to NDC (-1 , 1 )

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 46

slide-47
SLIDE 47

Projective Texturing

  • Map NDC (-1 , 1 ) to Texture Coordinate space (0-1)
  • Scale and add Bias

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 47

slide-48
SLIDE 48

Projective Texturing

  • Map NDC (-1 , 1 ) to Texture Coordinate space (0-1)
  • Scale and add Bias

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 48

Final texture coordinates after perspective-correct interpolation of

slide-49
SLIDE 49

Projective Texturing

  • Map NDC (-1 , 1 ) to Texture Coordinate space (0-1)
  • Scale and add Bias

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 49

Final texture coordinates after perspective-correct interpolation of

Hardware does it for you :)

slide-50
SLIDE 50

How To Set Texture Matrices ?

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 50

slide-51
SLIDE 51

How To Set Texture Matrices ?

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 51

Much simpler in newer OpenGL (will discuss later)

slide-52
SLIDE 52

Projective Texturing: Issues

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 52

slide-53
SLIDE 53

Projective Texturing: Issues

CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 53

Severe Aliasing

slide-54
SLIDE 54

CS 148: Summer 2016 Introduction of Graphics and Imaging Zahid Hossain

Textures

http://www.pling.org.uk/cs/cgv.html