Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
2D Texture Mapping
CS 432 Interactive Computer GraphicsProf. David E. Breen
Department of Computer Science
1E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Slide Creditsn Jonathan Cohen - Johns Hopkins
Universityn Shayan Sarkar - Carnegie Mellon
Universityn Leonard McMillan, Jovan Popovic, Fredo
Durand - MITn Steve Marschner - Cornell Universityn David Luebke - University of Virginian Pat Hanrahan - Stanford University
The Quest for Visual Realism
Photo-textures
The concept isvery simple!
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
������������������������������������������������
0 -
Lecture 15 Slide 25 6.837 Fall 2002
Adding Texture Mapping to IlluminationTexture mapping can be used to alter some or all of the constants in theillumination equation. We can simply use the texture as the final color for the pixel,or we can just use it as diffuse color, or we can use the texture to alter the normal,or... the possibilities are endless!
Phong's Illumination Model
Constant Diffuse Color Diffuse Texture Color Texture used as Label Texture used as Diffuse Color
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
��$��� ����������������$��� ��������������
*��������*��������
## ������� �� ������� ��
## ���������� �������������!���������� �������������!
"��'�����"��'�����
*�����������������*�����������������
## 6����������������������6����������������������
03/14/2002 15-462 Graphics I 15
Difficulties with texture mappingDifficulties with texture mapping
• Another difficulty is how to map a 2D image onto an arbitrary 3D model– Ex: If you wanted to map onto a sphere, you can’t do it without
distorting the texture
Slide13.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide13.jpg
1 of 1 11/13/03 1:29 PM
Slide12.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide12.jpg
1 of 1 11/13/03 3:24 PM
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
���������������������������������������������
1��&����������� ��������������1��&����������� ��������������
*�������(�.����������������*�������(�.����������������
## *�������(�������������(�����������(�*�������(�������������(�����������(�
����������������������
����������������������������������������������������������������
��������������� ������������������������ ���������
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
������������������������������������
�����"�������!�8����� ����9��%������� ���:!������������� ������������ �����"�������!�8����� ����9��%������� ���:!������������� ������������
Slide15.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide15.jpg
1 of 1 11/13/03 3:30 PM
Slide14.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide14.jpg
1 of 1 11/13/03 3:31 PM
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
�*�"���������� ��*��*�""���������� ����������� �
9/����������������������������������� ���9/����������������������������������� ���
����������������������������������������
�/������������������ �����������������/������������������ ����������������
����������
## *�������������������������������������*�������������������������������������
## *��������������������������� � ��������!*��������������������������� � ��������!
Slide16.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide16.jpg
1 of 1 11/13/03 3:32 PM
Slide17.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide17.jpg
1 of 1 11/13/03 3:32 PM
Slide18.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide18.jpg
1 of 1 11/13/03 3:33 PM
Slide19.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide19.jpg
1 of 1 11/13/03 3:34 PM
Slide20.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide20.jpg
1 of 1 11/13/03 3:34 PM
Slide22.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture25/Slide22.jpg
1 of 1 11/13/03 3:35 PM
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
������%����� �������%����� �������%����� �
��������$���!�" �%�������������� ������������������������������������& �����
�������'��(���%�)��*+,+��� ���-�
��������$���!�" �%�������������� ������������������������������������& �����
�������'��(���%�)��*+,+��� ���-�
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
%����� ������������%����� ������������%����� ������������
*�����6������*�����6������
## *��&�����������*��&�����������
## '���������.�����(���� ��� '���������.�����(���� ���������������������!!
7�����������7�����������
## 1���������������1���������������
����6����������6������
## 1������������������1������������������
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
���� ����� �������� ���� ����� ��������
�
$
��
����
��.�/ ��!����0
�1�.�/�/ �� 2 �0�3�/ $� 2 ��0!�/��� 2 �0�3�/��� 2 ��0�0
���%�� .�%���/%���/ ��%��! $��%��! ��10!�%���/���%��! ���%��! ��10!���10
%���/*!�4!��0�.�/*2�05* 6��54
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
�����������%����� ������������%����� �
7 � �������� ����������������������7 � �������� ����������������������
����������������,�������������������������������,���������������
������ ������
*���*�������(������������ ���������������(������������ �������������
��������������������������������������
## )�������������������������������)�������������������������������
*� ���������������� ������������*� ���������������� ������������
������������������(������� ���� ����(������� ���� ��
David Luebke 1/19/99
Antialiasing andAntialiasing andTexture MappingTexture Mapping
ll Texture mapping is uniquely harderTexture mapping is uniquely harder–– Coherent textures present pathologicalCoherent textures present pathological
artifactsartifacts–– Correct filter shape changesCorrect filter shape changes
ll Texture mapping is uniquely easierTexture mapping is uniquely easier–– Textures are known ahead of timeTextures are known ahead of time–– They can thus be They can thus be prefilteredprefiltered
David Luebke 1/19/99
Antialiasing andAntialiasing andTexture MappingTexture Mapping
ll More on texture problemsMore on texture problems–– Coherent texture frequencies becomeCoherent texture frequencies become
infinitely high with increasing distanceinfinitely high with increasing distancenn Ex: checkerboard receding to horizonEx: checkerboard receding to horizon
–– Unfiltered textures lead to Unfiltered textures lead to compressioncompressionnn Ex: pixel covers entire checkerboardEx: pixel covers entire checkerboardnn Unfiltered mapping: pixel is black or whiteUnfiltered mapping: pixel is black or whitenn Moving checkerboard Moving checkerboard ŸŸ flashing pixels flashing pixels
David Luebke 1/19/99
Antialiasing andAntialiasing andTexture MappingTexture Mapping
ll Problem: a square pixel on screenProblem: a square pixel on screenbecomes a curvilinear quadrilateralbecomes a curvilinear quadrilateralin texture map (see W&W, p 140)in texture map (see W&W, p 140)
ll The coverage and area of this shapeThe coverage and area of this shapechange as a function of the mappingchange as a function of the mapping
ll Most texture antialiasing algorithmsMost texture antialiasing algorithmsapproximate this shape somehowapproximate this shape somehow
David Luebke 1/19/99
Antialiasing andAntialiasing andTexture MappingTexture Mapping
ll Mip-mappingMip-mapping–– MIP = MIP = Multim Multim in in Parvo Parvo (many things in(many things in
a small place)a small place)–– Ignores shape change of inverse pixelIgnores shape change of inverse pixel–– But allows But allows sizesize to vary to vary
ll Idea: store texture as a pyramid ofIdea: store texture as a pyramid ofprogressively lower-resolutionprogressively lower-resolutionimages, filtered down from originalimages, filtered down from original
David Luebke 1/19/99
AntialiasingAntialiasing: Mip-Mapping: Mip-Mapping
Depth of Mip-Map
David Luebke 1/19/99
Antialiasing: Mip MappingAntialiasing: Mip Mapping
ll Distant textures use higher levels ofDistant textures use higher levels ofthe the mipmapmipmap
ll Thus, the texture map is Thus, the texture map is prefilteredprefilteredll Thus, reduced aliasing!Thus, reduced aliasing!
David Luebke 1/19/99
Antialiasing: Mip MappingAntialiasing: Mip Mapping
ll WhichWhich level of mip-map to use? level of mip-map to use?–– Think of mip-map as 3-D pyramidThink of mip-map as 3-D pyramid–– Index into mip-map with 3 coordinates:Index into mip-map with 3 coordinates:
u, v, du, v, d (depth) (depth)ll Q:Q: What does d correspond to in the What does d correspond to in the
mip-map?mip-map?ll A: size of the filterA: size of the filter
David Luebke 1/19/99
Antialiasing: Mip MappingAntialiasing: Mip Mapping
ll The size of the filter (i.e., The size of the filter (i.e., dd in the in themip-map) depends on the pixelmip-map) depends on the pixelcoverage area in the texture mapcoverage area in the texture map–– In general, treat d as a continuousIn general, treat d as a continuous
valuevalue–– Blend between nearest mip-map levelBlend between nearest mip-map level
using using tri-lineartri-linear interpolationinterpolation
David Luebke 1/19/99
Antialiasing: Mip MappingAntialiasing: Mip Mapping
ll Q: WhatQ: What’’s wrong with the mip-maps wrong with the mip-mapapproach to approach to prefiltering prefiltering texture?texture?
ll A: Assumes pixel maps to square inA: Assumes pixel maps to square intexture spacetexture space
ll More sophisticated inverse pixelMore sophisticated inverse pixelfilters (see F&vD p 828):filters (see F&vD p 828):–– Summed area tablesSummed area tables–– Elliptical weighted average filteringElliptical weighted average filtering
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
������""���������� ������������������ ��������
)�������,���������������������)�������,�����������������������������
6����������6����������
8������9:�*���������������������8������9:�*���������������������
8�������:�*��������������������������,�8�������:�*��������������������������,���������������������������������������������������������������
8������":�)��������������,����8������":�)��������������,���� ��������������������������������������������������������������������
8������#:8������#: %���������%��������� ������������������;�������������������;��������� ������������������������ ��������������������������� ����������� ��������������������������������0�9������!0�9������!
Slide7.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture26/Slide7.jpg
1 of 1 11/13/03 1:56 PM
Slide13.jpg (JPEG Image, 640x480 pixels) http://www.cs.cornell.edu/Courses/cs417/2003sp/Lectures/Lecture26/Slide13.jpg
1 of 1 11/13/03 1:58 PM
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
)������ ��������"����� �)������ ��������)������ ��������""����� ������ �
���������������� ���������� ������������������������������� ���������� ���������������
������������
## �������������������������������������������� ������ ������
## ���������������������������� ������������ �������������� ������������ ������������
������ �������������!������ �������������!
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
������� �� ��������������� �������� �������� �� ���������� ��������������� ������� �
3�������������3����������������������&�����������������������&����������������
����������������� ������������� ����
<���������:�+���<���������:�+���
��������������� �������������������������
������������������������������ ���!�"������������� �� �������
������������������������������������������
1���.�����������1���.�����������
## ���� ������ ������ �������������� ������ ������ ����������
������������������������������
## ���� ����� ������� ���� ����� �������
2���������.� �����������2���������.� �����������
## � ���������������������������� ���������������������������
� �������� �������
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk003.html
1 of 2 11/13/03 3:46 PM
Slide 3 of 28
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk005.html
1 of 2 11/13/03 4:05 PM
Slide 5 of 28
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk006.html
1 of 2 11/13/03 3:57 PM
Slide 6 of 28
03/14/2002 15-462 Graphics I 32
Environment MappingEnvironment Mapping
• Allows for world to be reflected on an object without modeling the physics
• Map the world surrounding an object onto a cube
• Project that cube onto the object• During the shading calculation:
– Bounce a ray from the viewer off the object (at point P)– Intersect the ray with the environment map (the cube), at point E– Get the environment map’s color at E and illuminate P as if there
were a virtual light source at position E– You see an image of the environment reflected on shiny surfaces
Lecture 15 Slide 28 6.837 Fall 2002
Environment Maps If, instead of using the ray from the surface point to the projectedtexture's center, we used the direction of the reflected ray to index atexture map. We can simulate reflections. This approach is not completelyaccurate. It assumes that all reflected rays begin from the same point.
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk009.html
1 of 2 11/13/03 4:46 PM
Slide 9 of 28
Lecture 15 Slide 29 6.837 Fall 2002
What's the Best Chart?
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk011.html
1 of 2 11/13/03 4:47 PM
Slide 11 of 28
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk010.html
1 of 2 11/13/03 4:48 PM
Slide 10 of 28
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk012.html
1 of 2 11/13/03 4:48 PM
Slide 12 of 28
Lecture 15 Slide 30 6.837 Fall 2002
Reflection Mapping
03/14/2002 15-462 Graphics I 30
Bump MappingBump Mapping
• How do you make a surface look rough?– Option 1: model the surface with many small polygons– Option 2: perturb the normal vectors before the shading
calculation• the surface doesn’t actually change, but shading makes it look that
way• bump map fakes small displacements above or below the true
surface• can use texture-mapping for this• For the math behind it all look at Angel 9.4
Lecture 15 Slide 37 6.837 Fall 2002
Bump MappingTextures can be used to alter the surface normal of an object. This does not change the actualshape of the surface -- we are only shading it as if it were a different shape! This technique iscalled bump mapping. The texture map is treated as a single-valued height function. Thevalue of the function is not actually used, just its partial derivatives. The partial derivatives tellhow to alter the true surface normal at each point on the surface to make the object appearas if it were deformed by the height function.
Since the actual shape of the object does not change, the silhouette edge of the object willnot change. Bump Mapping also assumes that the Illumination model is applied at every pixel(as in Phong Shading or ray tracing).
Sphere w/Diffuse Texture
Swirly Bump Map
Sphere w/Diffuse Texture & Bump Map
Lecture 15 Slide 38 6.837 Fall 2002
Bump mapping
TvuzvuyvuxP )],(),,(),,([=v
vu PPNvvv
¥=
NvuBPPvvv
),(+=¢
D
D+-D-=
2),(),( tsBtsB
Bu
D
D+-D-=
2),(),( tsBtsB
Bv
Compute bump map partialsby numerical differentiation
Initial point
Normal
Simulated elevated point after bump
Variation of normal in u direction
Variation of normal in v direction
43421
vvvv
vD
vvuu PBPBNN ++ª¢
If Pu and Pv are orthogonal and N is normalized: Nv
vPv
uPv
N ¢v
Dv
Dv'P
r
Pr
Lecture 15 Slide 39 6.837 Fall 2002
More Bump Map Examples
Cylinder w/Diffuse Texture Map
Bump Map
Cylinder w/Texture Map & Bump Map
Lecture 15 Slide 40 6.837 Fall 2002
One More Bump Map Example
Notice that the shadow boundaries remain unchanged.
03/14/2002 15-462 Graphics I 31
Bump MappingBump Mapping
• In CG, we can perturb the normal vector without having to make any actual change to the shape.
• What would be the problems with bump mapping?
Original model (5M) Simplified (500) Simple model with bump map
Lecture 15 Slide 41 6.837 Fall 2002
Displacement MappingWe use the texture map to actually move the surface point. This is calleddisplacement mapping. How is this fundamentally different than bumpmapping?
The geometry must be displaced before visibility is determined. Is thiseasily done in the graphics pipeline? In a ray-tracer?
Stochastic Microgeometry forDisplacement Mappingn Reconstruct a stochastic distribution
over a mesh
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk021.html
1 of 2 11/13/03 4:51 PM
Slide 21 of 28
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk022.html
1 of 2 11/13/03 4:52 PM
Slide 22 of 28
Texture and Materials http://graphics.stanford.edu/courses/cs348b-02/lectures/lecture12/walk023.html
1 of 2 11/13/03 4:52 PM
Slide 23 of 28
Lecture 15 Slide 34 6.837 Fall 2002
The Best of All WorldsAll these texture mapping modes are great!
The problem is, no one of them does everything well.
Suppose we allowed several textures to be applied to each primitiveduring rasterization.