games with texture mapping
play

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


  1. Games with Texture Mapping Steve Marschner CS 4620 Cornell University Cornell CS4620 Fall 2020 Steve Marschner • 1

  2. Recall 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. Cornell CS4620 Fall 2020 Steve Marschner • 2

  3. A refined definition Texture mapping: a set of techniques for defining functions on surfaces, for a variety of uses. Let’s look at some examples of more general uses of texture maps. Cornell CS4620 Fall 2020 Steve Marschner • 3

  4. Reflection mapping • 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 [Dror, Willsky, & Adelson 2004] 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. Cornell CS4620 Fall 2020 Steve Marschner • 4

  5. Hand with Re fm ecting Sphere . M. C. Escher, 1935. lithograph

  6. Reflections in ray tracing • Recall how we can make mirror reflections in ray tracing n r v r = v + 2(( n · v ) n − v ) = 2( n · v ) n − v Cornell CS4620 Fall 2020 Steve Marschner • 6

  7. Reflection mapping • 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 Cornell CS4620 Fall 2020 Steve Marschner • 7

  8. straight up straight up straight up due East due South due West due North due East straight down straight down straight down A spherical panorama, aka. enironment map openfootage.net

  9. Environment map • A function from the sphere to colors, stored as a texture. [Blinn & Newell 1976] Cornell CS4620 Fall 2020 Steve Marschner • 9

  10. Spherical environment map � r � 1 r � Hand with Re fm ecting Sphere . M. C. Escher, 1935. lithograph Cornell CS4620 Fall 2020 Steve Marschner • 10

  11. Environment Maps [Paul Debevec] Cornell CS4620 Fall 2020 Steve Marschner • 11

  12. Cube map ( u , v ) = (1, 1) x = y = z right face has x > | y | and x > | z | ( u , v ) = (0, 0) x = – y = – 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. Cornell CS4620 Fall 2020 Steve Marschner • 12

  13. [Zephyris at en.wikipedia] [Emil Persson] Cornell CS4620 Fall 2020 Steve Marschner • 13

  14. Reflection mapping in GLSL • 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() Cornell CS4620 Fall 2020 Steve Marschner • 14

  15. Displacement mapping • 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 of the displacement texture) Cornell CS4620 Fall 2020 Steve Marschner • 15

  16. [wikiwand]

  17. base surface hand-painted displacement map (detail) Pawe ł Filip displaced surface tolas.wordpress.com Cornell CS4620 Fall 2020 Steve Marschner • 17

  18. Displacement mapping • 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 of the displacement texture) Cornell CS4620 Fall 2020 Steve Marschner • 19

  19. Bump mapping • 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 Cornell CS4620 Fall 2020 Steve Marschner • 20

  20. INI, sznple results that can be achieved with this IDI, technique. The first pattern, a hand drawn unit tan+ sqrt(Fu'+Fv') cell of bricks was mapped onto the sphere on the cover. sqrt(Fu'+Fv.') lNl/lDl INI/IDI ID’1 INI 50 tan+' ID'l/lNl Bump mapping - -. Figure 8 Hand Drawn Functions [Blinn 1978] : Cornell CS4620 Fall 2020 Steve Marschner • 21

  21. [CS467 slides] Geometry Bump Displacement mapping mapping

  22. [CS467 slides] Geometry Bump Displacement mapping mapping

  23. Bump mapping • 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 Cornell CS4620 Fall 2020 Steve Marschner • 24

  24. Normal mapping • 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” Cornell CS4620 Fall 2020 Steve Marschner • 25

  25. A normal map Cornell CS4620 Fall 2020 Steve Marschner • 26

  26. A normal map Cornell CS4620 Fall 2020 Steve Marschner • 27

  27. A normal map RGB color = XYZ normal Cornell CS4620 Fall 2020 Steve Marschner • 27

  28. A normal map RGB color = XYZ normal R = X component (u direction) Cornell CS4620 Fall 2020 Steve Marschner • 27

  29. A normal map RGB color = XYZ normal R = X component (u direction) G = Y component (v direction) Cornell CS4620 Fall 2020 Steve Marschner • 27

  30. A normal map RGB color = XYZ normal R = X component (u direction) G = Y component (v direction) B = Z component (n direction) Cornell CS4620 Fall 2020 Steve Marschner • 27

  31. Cornell CS4620 Fall 2020 Steve Marschner • 28

  32. Cornell CS4620 Fall 2020 Steve Marschner • 28

  33. Normal mapping [Paolo Cignoni] Cornell CS4620 Fall 2020 Steve Marschner • 29

  34. Normal mapping • 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 Cornell CS4620 Fall 2020 Steve Marschner • 30

  35. Computing tangent vectors • 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 Cornell CS4620 Fall 2020 Steve Marschner • 31

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend