computer graphics 2 lecture 7: texture mapping benjamin mora 1 university of wales swansea pr. min...
TRANSCRIPT
![Page 1: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/1.jpg)
Computer Graphics 2Lecture 7:TextureMapping
Benjamin Mora 1University of Wales
Swansea
Pr. Min ChenDr. Benjamin Mora
![Page 2: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/2.jpg)
Content
2Benjamin MoraUniversity of Wales
Swansea
• Texture Mapping at the very beginning.• Perspectively Correct Texture Mapping.• Texture Filtering.• Muti-Texturing.• Texture Mapping as an n-Dimensional
function.• Other use of Texture Mapping.
– Spherical and Cube mapping. – Shadow Mapping– Bump Mapping
![Page 3: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/3.jpg)
Texture Mapping at the very beginning
3Benjamin MoraUniversity of Wales
Swansea
![Page 4: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/4.jpg)
Texture Mapping
4Benjamin MoraUniversity of Wales
Swansea
![Page 5: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/5.jpg)
Texture Mapping
5Benjamin MoraUniversity of Wales
Swansea
![Page 6: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/6.jpg)
Texture Mapping
6Benjamin MoraUniversity of Wales
Swansea
• Initial Goal: Get surfaces that are more consistent by mapping images (textures) on the primitives of the scene.
• Usually 2D, but textures can also be 1D or 3D.• For every vertex, the programmer must specify their coordinates
inside the texture image.
![Page 7: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/7.jpg)
Texture Mapping Coordinates
7Benjamin MoraUniversity of Wales
Swansea
• n-Dimensional (Usually 2D) Texture coordinates are provided for every vertex of the 3D Mesh. – Coordinates usually considered between 0 and 1.
• Texture coordinates are then linearly interpolated inside the triangle at the intersection point.
Rasterization Linear Interpolation
p0 vdir
p(t)
Ray-tracing
![Page 8: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/8.jpg)
Texture Mapping Coordinates
8Benjamin MoraUniversity of Wales
Swansea
Texture
(0.5, 1)
(0, 0)
(1, 1)
(1, 0)
(0, 0)
(0.5, 0.333)
![Page 9: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/9.jpg)
Linear Interpolation inside a simplex
9Benjamin MoraUniversity of Wales
Swansea
• Simplex= A n-dimensional generalization of a triangle.– n=1 => a line.
– n=2 => a triangle.
– n=3 => a tetrahedron.
• Linear Interpolation inside a triangle:
γf123= (1- γ) f12 + γ f13
0 ≤ α, β, γ ≤ 1
f1
f2
f12 f13f123
α βf12= (1- α) f1 + α f2
f13= (1- β) f1 + β f3
f3
![Page 10: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/10.jpg)
Linear Interpolation inside a simplex
10Benjamin MoraUniversity of Wales
Swansea
• Properties– The weights of f1,f2,f3 represent the barycentric coordinates.
– The set of points having the same interpolated value (isosurface) represents a line
– Extension to 3D (tetrahedron) is trivial• The set of points having the same interpolated value (isosurface)
represents a plane
f123=((1- α)(1-γ)+(1- β)γ ) f1 + (α)(1-γ) f2 + βγ f3
f123=a1f1+a2f2 +a3f3, with a1+a2+a3=1
3
7 6
Isosurface (f=5)
![Page 11: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/11.jpg)
Texture Mapping on graphics cards
11Benjamin MoraUniversity of Wales
Swansea
• OpenGL interpolates the texture coordinates for every rasterized fragment and then fetch the pixel from the texture.
• Textures are stored on the graphics board memory and are highly optimized.– Huge memory bandwidth thanks to specialized hardware.
![Page 12: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/12.jpg)
Perspectively correct Texture Mapping
12Benjamin MoraUniversity of Wales
Swansea
![Page 13: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/13.jpg)
Issue With Graphics Hardware TM
13Benjamin MoraUniversity of Wales
Swansea
• Ray-Tracing interpolates texture coordinates at the (3D) intersection.
• Basic Graphics Hardware would project the triangle first on the image plane, and then linearly interpolate coordinates & color.– Incorrect due to the non-linearity aspect of perspective projection.
Image Plane
vdir
View PointDistance Ratio=0.5
Distance Ratio!=0.5
![Page 14: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/14.jpg)
Issue With Graphics Hardware TM
• Correct coordinate Interpolation:
• Biased estimation:
14Benjamin MoraUniversity of Wales
Swansea
View Pointα
p2(u2, z2)
p1(u1, z1)
A texture coordinate
Vertex Depth
21
2
2
1
1
111
1
zz
zu
zu
u
21 ..1 uuu
![Page 15: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/15.jpg)
Texture Filtering
15Benjamin MoraUniversity of Wales
Swansea
![Page 16: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/16.jpg)
Texture MIP-Mapping
16Benjamin MoraUniversity of Wales
Swansea
• Mipmap textures are used to decrease the bandwidth required to load the texture and to improve cache coherence.
• Can also improve quality for objects that are far away.
http://en.wikipedia.org/wiki/Mipmap
Pixels
![Page 17: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/17.jpg)
Texture MIP-Mapping
17Benjamin MoraUniversity of Wales
Swansea
• Mipmaps can be automatically generated or specified by the programmer.
• Texture are always magnified or minified.• Bilinear, trilinear or anisotropic filtering helps when the
texture is magnified.• Issue with MIP-Mapping:
– Transition between Mipmap levels can be visible inside the image.
– Tri-linear texture filtering reduces the artefact by interpolating texels from the 2 closest mipmap levels.
![Page 18: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/18.jpg)
Texture MIP-Mapping
18Benjamin MoraUniversity of Wales
Swansea
http://developer.nvidia.com/object/Anisotropic_Filtering_OpenGL.html
![Page 19: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/19.jpg)
Texture MIP-Mapping
19Benjamin MoraUniversity of Wales
Swansea
http://developer.nvidia.com/object/Anisotropic_Filtering_OpenGL.html
![Page 20: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/20.jpg)
Multi-Texturing
20Benjamin MoraUniversity of Wales
Swansea
![Page 21: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/21.jpg)
Multi-Texturing: Example
21Benjamin MoraUniversity of Wales
Swansea
*
![Page 22: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/22.jpg)
Multi-Texturing
22Benjamin MoraUniversity of Wales
Swansea
• Multiple ways to blend textures.– Originally additive or multiplicative was
supported on Graphics hardware.– Arbitrary blending is now possible on Graphics
hardware with the use of fragments program.
• Every advanced game/software nowadays makes use of Multitexturing.– See next slides…
![Page 23: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/23.jpg)
Texture Mapping as an n-Dimensional function
23Benjamin MoraUniversity of Wales
Swansea
![Page 24: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/24.jpg)
TM as an n-Dimensional function
24Benjamin MoraUniversity of Wales
Swansea
• Concept of texturing can be extended, and textures can be 1D, 2D, 3D.
• A texture can be seen as a way to represent a 1D, 2D or 3D function.– f(x), f(x,y), f(x,y,z).– Bounded interval (eg. [0..1, 0..1] in 2D).– Regular interval sampling.
• Can be used to represent anything…– Vertex displacement.– Noise.– Shading function (E.G., BRDFs).
![Page 25: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/25.jpg)
1D Textures
25Benjamin MoraUniversity of Wales
Swansea
• Useful for representing things like– Hair and line texturing.– 1D functions not implemented on hardware
• E.g. ArcTan.
– Look-up tables.– Arbitrary data in 1D arrays.
![Page 26: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/26.jpg)
3D Textures
26Benjamin MoraUniversity of Wales
Swansea
• Useful for representing things like– Marble– Fire– Fog– Fur
From NVidia Demo, Werewolf
![Page 27: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/27.jpg)
3D Textures
27Benjamin MoraUniversity of Wales
Swansea
• Volume Rendering applications– Medical datasets
![Page 28: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/28.jpg)
Other use of Texture Mapping
28Benjamin MoraUniversity of Wales
Swansea
![Page 29: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/29.jpg)
Environment mapping
29Benjamin MoraUniversity of Wales
Swansea
• Useful for simulating/faking reflections & refractions– Proposed by Blinn and Newell.
• The coordinates of the normal on two axes perpendicular to the view direction are used as texture coordinates.
• Spherical mapping.– single image used
• Cube mapping.– 6 faces of a cube represent a cube map texture.– More accurate than spherical mapping.
![Page 30: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/30.jpg)
Environment mapping
30Benjamin MoraUniversity of Wales
Swansea
• Spherical mapping. (a single image)
http://www.sgi.com/misc/grafica/texmap/
![Page 31: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/31.jpg)
Environment mapping
31Benjamin MoraUniversity of Wales
Swansea
• Cube Mapping
Textures Provided by NVidia
![Page 32: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/32.jpg)
Shadow Mapping
32Benjamin MoraUniversity of Wales
Swansea
• A way to provide more or less accurate shadows
• An alternative to shadow volumes for shadows on graphics hardware. – Not seen in this course.
![Page 33: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/33.jpg)
Shadow Mapping
33Benjamin MoraUniversity of Wales
Swansea
With Shadows Without Shadows
Cass Everitt, Ashu Rege and Cem Cebenoyan. Hardware Shadow Mapping. Available at: http://developer.nvidia.com/object/hwshadowmap_paper.html
![Page 34: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/34.jpg)
Shadow Mapping
34Benjamin MoraUniversity of Wales
Swansea
From Mark Kilgard’s shadow mapping presentation at GDC 2001.
Cass Everitt, Ashu Rege and Cem Cebenoyan. Hardware Shadow Mapping. Available at: http://developer.nvidia.com/object/hwshadowmap_paper.html
![Page 35: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/35.jpg)
Shadow Mapping
35Benjamin MoraUniversity of Wales
Swansea
Figure 2. A shadow mapped scene rendered from the eye’s point of view (left), the scene as rendered from the light’s point of view (center), and the corresponding depth/shadow map (right).
Cass Everitt, Ashu Rege and Cem Cebenoyan. Hardware Shadow Mapping. Available at: http://developer.nvidia.com/object/hwshadowmap_paper.html
![Page 36: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/36.jpg)
Shadow Mapping
36Benjamin MoraUniversity of Wales
Swansea
Figure 5. A very low resolution shadow map is used to demonstrate the difference between nearest (left) and linear (right) filtering for shadow maps. Credit: Mark Kilgard.
Cass Everitt, Ashu Rege and Cem Cebenoyan. Hardware Shadow Mapping. Available at: http://developer.nvidia.com/object/hwshadowmap_paper.html
![Page 37: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/37.jpg)
Shadow Mapping
37Benjamin MoraUniversity of Wales
Swansea
• Render an image (Shadow map) from the viewpoint.• The theoretical position of every pixel in the final image is
then compared to the actual shadow map value. (To test its visibility from the light source).
• The algorithm must allow for a small margin error in the computation.
• Produce aliasing at the penumbra border. Use of high-resolution map is required.
• The scene is rendered once per light source.• Simpler than volumetric shadows.
![Page 38: Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora](https://reader035.vdocuments.net/reader035/viewer/2022070410/56649f1f5503460f94c37564/html5/thumbnails/38.jpg)
Bump Mapping
38Benjamin MoraUniversity of Wales
Swansea
• Idea (Blinn): Modifying the normal vector of an object before shading to add details to the surface.
• The perturbation can be procedural (vertex programs or fragment programs) or texture-based.
Blinn, James F. Simulation of Wrinkled Surfaces, Computer Graphics, Vol. 12 (3), pp. 286-292 SIGGRAPH-ACM (August. 1978).
http://en.wikipedia.org/wiki/Bump_mapping