Upload
gavin-daniel
View
218
Download
2
Embed Size (px)
Citation preview
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
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
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
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
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.
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
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
Fundamentals of Computer Graphics 8
Linear MappingLinear mapping isdefined as:
standard window-viewport approach.
)(
)(
minmaxminmax
minmin
minmaxminmax
minmin
vvtt
ttvv
uuss
ssuu
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
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)
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
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 */
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
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>
Fundamentals of Computer Graphics 15
Texture Mapping in OpenGLSTOP HERE!!!