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
Texture Mapping • So we make the shading parameters vary across the surface [Foley et al. / Perlin] Cornell CS4620 Fall 2020 Steve Marschner • 3
Texture mapping • Adds visual complexity; makes appealing images [P ix Cornell CS4620 Fall 2020 Steve Marschner • 4
Texture mapping • Surface properties are not the same everywhere – diffuse color ( ) varies due to changing pigmentation k d – shininess ( ) and specular coefficient ( ) for specular highlight vary p k s 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 Cornell CS4620 Fall 2020 Steve Marschner • 5
A first definition 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. • This is very simple! – but it produces complex-looking effects Cornell CS4620 Fall 2020 Steve Marschner • 6
Examples • Wood gym floor with smooth finish specular parameters p and k s for Blinn-Phong shading – diffuse color varies with position k d – specular properties , are constant k s p • Glazed pot with finger prints – diffuse color is constant k d – roughness and perhaps specular color vary with position p k s • 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 Cornell CS4620 Fall 2020 Steve Marschner • 7
8
9
10
11
Mapping textures to surfaces • 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 Aside: parametric vs. implicit vs. piecewise surface models Cornell CS4620 Fall 2020 Steve Marschner • 12
Mapping textures to surfaces • “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 Cornell CS4620 Fall 2020 Steve Marschner • 13
Texture coordinate functions • 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 ) Cornell CS4620 Fall 2020 Steve Marschner • 14
Three spaces • Surface lives in 3D world space • Every point also has a place where it goes in the image and in the texture. � � y x y s v z x s u image space world space texture space Cornell CS4620 Fall 2020 Steve Marschner • 15
Texture coordinate functions • Define texture image as a function T : D → C – where C is the set of colors for the diffuse component • Diffuse color (for example) at point p is then k d ( p ) = T ( ϕ ( p )) Cornell CS4620 Fall 2020 Steve Marschner • 16
Examples of coordinate functions • A rectangle – image can be mapped directly, unchanged Cornell CS4620 Fall 2020 Steve Marschner • 17
Examples of coordinate functions • For a sphere: latitude-longitude coordinates – maps point to its latitude and longitude ϕ [map: Peter H. Dana] Cornell CS4620 Fall 2020 Steve Marschner • 18
Coordinate functions: non-parametric • 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 Cornell CS4620 Fall 2020 Steve Marschner • 19
Examples of coordinate functions • Planar projection u v Cornell CS4620 Fall 2020 Steve Marschner • 20
Examples of coordinate functions • Spherical projection Cornell CS4620 Fall 2020 Steve Marschner • 21
Examples of coordinate functions • Cylindrical projection spherical cylindrical Cornell CS4620 Fall 2020 Steve Marschner • 22
Examples of coordinate functions • Complex surfaces: project parts to parametric surfaces [Tito Pagan] Cornell CS4620 Fall 2020 Steve Marschner • 23
Examples of coordinate functions 0 9 1 9 2 9 3 4 9 9 5 6 9 9 7 8 9 9 9 9 0 8 1 8 2 8 3 4 8 8 5 6 8 8 7 8 9 8 8 8 • Triangles 0 7 1 7 2 7 3 4 7 7 5 6 7 7 7 8 9 7 7 7 – specify ( u , v ) for each vertex 0 6 1 6 2 6 3 4 6 6 5 6 6 6 7 8 9 6 6 6 0 5 1 5 2 5 3 4 5 5 5 6 5 5 7 8 9 5 5 5 – define ( u , v ) for interior by linear 0 4 1 4 2 4 3 4 4 4 5 6 4 4 7 8 9 4 4 4 (barycentric) interpolation 0 3 1 3 2 3 3 4 3 3 5 6 3 3 7 8 9 3 3 3 0 2 1 2 2 2 3 4 2 2 5 6 2 2 7 8 9 2 2 2 0 1 1 1 2 1 3 4 1 1 5 6 1 1 7 8 9 1 1 1 ( u c , v c ) 0 0 1 0 2 0 3 4 0 0 5 6 0 0 7 8 9 0 0 0 ( u , v ) ( u a , v a ) ( u b , v b ) Cornell CS4620 Fall 2020 Steve Marschner • 24
Texture coordinates on meshes • 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 Cornell CS4620 Fall 2020 Steve Marschner • 25
Example: UVMapper http://www.uvmapper.com Cornell CS4620 Fall 2020 Steve Marschner • 26
Recommend
More recommend