fundamentals of computer graphics part 9 discrete techniques prof.ing.václav skala, csc. university...
TRANSCRIPT
![Page 1: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/1.jpg)
Fundamentals of Computer GraphicsPart 9
Discrete Techniques
prof.ing.Václav Skala, CSc.University of West Bohemia
Plzeň, Czech Republic
©2002Prepared with Angel,E.: Interactive Computer
Graphics – A Top Down Approach with OpenGL, Addison Wesley, 2001
![Page 2: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/2.jpg)
Fundamentals of Computer Graphics 2
Discrete techniques
Polygons, lines and others primitives transformed, rasterized and displayed
API enables major mapping
• texture mapping uses pattern to be put on a surface of an object
• bump mapping – smooth surface is distorted to get variation of the surface
• environmental mapping (reflection maps) – enables ray-tracing like output
![Page 3: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/3.jpg)
Fundamentals of Computer Graphics 3
Discrete techniquesAll three techniques rely on the map being stored as one-, two-
or three-dimensional digital image (!!Texture mapping on a graphics card is limited!!)
Causes ANTIALIASING errors
buffer – a memory block with spatial resolution n x m and with k bits
bitplane – single plane n x m with 1 bit only
pixel – picture element
![Page 4: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/4.jpg)
Fundamentals of Computer Graphics 4
Texture MappingRegular patterns are mapped to an
object’s surface
Two dimensional texture T(s,t)s, t – texture coordinatesstored in texture memory as n x m array of texture elements - texels
Texture map associate a unique point of T with each point on a geometric object – mapped to screen coordinates
![Page 5: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/5.jpg)
Fundamentals of Computer Graphics 5
Texture MappingDifficulties:
- mapping from texture to geometric coordinates
- 2D texture defined over a rectangular region in the texture space -> mapping to 3D region can be quite complex
- rendering based on pixel-to-pixel approach – the inverse mapping from screen coordinates to texture coordinates is needed
- because of shading – mapping areas-to-areas and not point-to-point is required -> antialising problems, moire patterns etc.
![Page 6: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/6.jpg)
Fundamentals of Computer Graphics 6
Texture Mappingpixel (xs, ys) –
corresponds to(x, y, z) on “curved”object
problems with finding inverse mapping
difficulties with mapping
![Page 7: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/7.jpg)
Fundamentals of Computer Graphics 7
Linear MappingMost curved surfaces represented parametrically as
p(u,v) = [x(u,v) , y(u,v) , z(u,v)]T
a point in the texture map T(s,t) is to be mapped to a point on the surface p(u,v) by a linear map
u = as + bt + c v = ds + et + f
(if ae bd mapping is invertible)
- mapping is easy to use
- it does not respectthe curvature of theobject
![Page 8: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/8.jpg)
Fundamentals of Computer Graphics 8
Linear MappingLinear mapping isdefined as:
standard window-viewport approach.
)(
)(
minmaxminmax
minmin
minmaxminmax
minmin
vvtt
ttvv
uuss
ssuu
![Page 9: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/9.jpg)
Fundamentals of Computer Graphics 9
Texture MappingTwo part mapping - steps
1. map the texture a simple 3Dintermediate surface – cylindercube, sphere etc.
2. the surface containing the mapped texture is mapped to the surface being rendered.
Can be applied in geometric or parametric coordinates
![Page 10: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/10.jpg)
Fundamentals of Computer Graphics 10
Texture MappingSuppose a cylinder
x = r cos (2u)
y = r sin (2u)
z = v / h
and u,v (0,1) – then
s = u & t = v
we are able to map the texture WITHOUT distorting its shape
for a sphere the Mercator projection can be used
x = r cos (2u)
y = r sin (2u) cos (2v)
z = r sin (2u) sin (2v)
![Page 11: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/11.jpg)
Fundamentals of Computer Graphics 11
Texture MappingThe second step is to map the texture values on the intermediate
object to the desired surface
Figure shows THREE possible strategies:
• texture value is projected on the surface in the normal direction
• inverse solutionfrom the surfacetexture elementis to be findaccording to thenormal
• if the center of the object is known – intersection with intermediate surface is computed and texture value assigned
![Page 12: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/12.jpg)
Fundamentals of Computer Graphics 12
Texture Mapping in OpenGLOpenGL –
many mappingoptionsincluding 1D, 2D & 3D textures
GLubyte my_texels [512][512]; /* generated somehow */
glTexImage2D(GL_TEXTURE, 0, 3, 512, 512, 0,GL_RGB, GL_UNSIGNED_BYTE, my_texels);
/* 0 & 3 – level & components, 0 – border, format – see latter*/
glEnable(GL_TEXTURE_2D); /* enables texture mapping */
![Page 13: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/13.jpg)
Fundamentals of Computer Graphics 13
Texture Mapping in OpenGL2D textures specification
glTexImage2D(GL_TEXTURE, level, components, width, height, border, format, type, array);
components (1 – 4 ) number of components RGBA to be affected with the map
level & border – parameters for fine control
![Page 14: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/14.jpg)
Fundamentals of Computer Graphics 14
Texture Mapping in OpenGLglBegin(GL_QUAD);
glTexCoord2f(0.0, 0.0);
glVertex2f(x1, y1, z1);
glTexCoord2f(1.0, 0.0);
glVertex2f(x2, y2, z2);
glTexCoord2f(0.0, 1.0);
glVertex2f(x3, y3, z3);
glTexCoord2f(1.0, 1.0);
glVertex2f(x4, y4, z4);
glEnd ( );range of s, t changed to <0,0.5>
![Page 15: Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared](https://reader035.vdocument.in/reader035/viewer/2022062518/56649e8f5503460f94b934c5/html5/thumbnails/15.jpg)
Fundamentals of Computer Graphics 15
Texture Mapping in OpenGLSTOP HERE!!!