Document 7445887

Download Report

Transcript Document 7445887

Advanced Computer Graphics:
Texture
James Gain
Department of Computer Science
University of Cape Town
[email protected]
Advanced Computer GraphicsCollaborative
Visual Computing Laboratory
Objectives
To motivate for surface detail.
To introduce the different forms of texture mapping:
• Two-dimensional
• Volumetric
• Bump.
To discuss texture sampling issues.
23/05/2016
Advanced Computer Graphics
2
Motivation for Surface Detail
Without Surface Detail
With Surface Detail
So far, we have assumed:
•
perfectly smooth, uniformly coloured surfaces.
This is unrealistic. In reality surfaces are:
•
23/05/2016
Multi-coloured (e.g. a painting, bottle label, page in a book), bumpy
(e.g. almost every surface, few things are perfectly smooth), and
textured (e.g. wood, leaves)
Advanced Computer Graphics
3
Types of Surface Detail
Micro-faceting: use objects with hundreds of small
polygons. Becomes prohibitively expensive.
2. Surface Detail polygons: Smaller polygons placed across
the surface of larger polygons. Do not add to visible
surface determination costs.
3. Texture mapping: “Wallpaper” an image across the
surface of an object. Adds detail as part of rendering
rather than modelling.
1.
23/05/2016
Advanced Computer Graphics
4
Surface Detail Polygons
Using many small differently coloured polygons is impractical because
of rendering costs.
Alternative: Surface Detail Polygons
•
•
•
•
23/05/2016
Overlay co-planar polygons
(e.g. doors, windows) onto a
base polygon (e.g. a wall).
In visible surface determination,
surface-detail polygons are
ignored.
In rendering, the surface-detail
polygons take precedence
over the base.
Not a serious contender. Only
good for broad scale detail.
Advanced Computer Graphics
5
Basic Texture Mapping
A texture is simply an image (or a procedure for generating an image),
with a 2D co-ordinate system.
Each 3D object is parametrized in 2D (u, v) texture space.
Screen pixels map to part of an object’s surface and that part of the
surface maps to a portion of the texture.
Can be visualized as wrapping an image around an object.
23/05/2016
Advanced Computer Graphics
6
Texture Coordinates
Each point on an object needs to have associated texture
coordinates:
• Polygon: Assign (u, v) co-ordinates to each vertex.
•
•
•
23/05/2016
Commercial modelling systems use a variety of projections:
spherical, cylindrical, planar to assign texcoords over an
entire object.
Plane: Give u-axis and v -axis directions in the plane.
Cylinder: One axis goes up the cylinder, the other axis
around.
Surface: Assign each parameter of a surface Q( s, t ) to u
and v . (e.g. s  u, t  v )
Advanced Computer Graphics
7
Texture Issues
Sliding - The texture can be translated, rotated and scaled
relative to a surface by an affine co-ordinate transformation
of
.
(u, v)
Seams - If the texture joins without visual discontinuity
across opposite edges then repetition can be used to cover
an entire object with a single small texture.
Interpolation - During polygon scan conversion care must be
taken in interpolating texture co-ordinates. Have to
compensate for perspective projection so that the texture is
correctly foreshortened.
Aliasing – like all discrete techniques, texture maps suffer
from sampling problems.
23/05/2016
Advanced Computer Graphics
8
Sampling
Basic approach assumes square texel (texture element) geometry. This produces
poor visual results.
Alternative: Treat each texel (texture element) in a texture map as an (r,g,b)
value at a point.
A projected pixel may:
Cover Several Texels
(oversampling)
23/05/2016
Advanced Computer Graphics
Fall between Texels
(undersampling)
9
Handling UnderSampling
The texture co-ordinates of the pixel’s centre are found.
The value at this point in the texture map is a combination of
surrounding texels.
Interpolation Methods:
1.
2.
3.
4.
23/05/2016
Nearest neighbour: the pixel value is that of the nearest texel. [Fast
with many artefacts]
Bilinear reconstruction: the pixel value is the weighted mean of the
surrounding texels. [Reasonably fast but blurry]
Biquadratic reconstruction: use a quadratic function of distance to
weight the mean [slower, good results]
Bicubic reconstruction [even slower, slightly better results]
Advanced Computer Graphics
10
Handling OverSampling
There are several solutions if the pixel covers a large area of the texture:
1.
2.
3.

23/05/2016
Basic Area: Texels are treated as rectangles. Their contribution is
weighted by the texel area covered by a pixel.
Filters: A filter (e.g. Gaussian) is used, centred on the pixel centre.
Can be very expensive if a single pixel covers a large area of the
texture map.
Multi-resolution Textures: Store multiple
versions of the same texture at different
resolutions. Use interpolation between
maps to get pixel values.
MIP Maps (Multum in Parvo – many
things in a small space) are an efficient
way to store these textures.
Advanced Computer Graphics
11
Summary
What can a texture map modify?
•
•
•
•
Any, or all, of the colour components
Transparency
Reflectivity
Decaling (blend texture with the object’s colour)
Problems:
1.
2.
3.
23/05/2016
Veneer Effect: textures appear to be wall-papered onto the surface.
Looks unrealistic in carved objects.
Seams: The match between the shape of a texture (rectangular) and
object may cause visible distortion and seams. Classic case: a globe.
Bumpy surfaces: A lot of texture is caused by bumps on the surface.
Advanced Computer Graphics
12
Bump Mapping
The surface normal is used in calculating
both diffuse and specular reflection.
Bump mapping modifies the direction of
the surface normal so that the surface
appears more or less bumpy.
A 2D function (bump map) can be
used to vary the surface normal
smoothly across the plane.
But bump mapping doesn’t change the object’s silhouette.
Displacement mapping fixes this by actually adjusting the
position of vertices in polygonal fragments but it is very
expensive.
23/05/2016
Advanced Computer Graphics
13
Solid Textures
Texture mapping applies a 2D
to a surface
Solid textures have colour defined
every point in space
Permits the modelling of objects
that appear to be carved from a
solid material (e.g. wood, marble).
Simplifies the mapping to texture
However, creating 3D texture maps
cannot be done by hand. It requires
procedural textures (e.g. fractals).
23/05/2016
Advanced Computer Graphics
texture
for
space.
From Perlin, K. “An Image
Synthesizer”, SIGGRAPH
1985
14
Simple Texture Mapping in OpenGL
setup:
• glTexImage2D(GL_TEXTURE_2D,
•
level, components,
width, height, border, format, type, image);
Texture pattern is stored in a width x height array image with
type array elements and components colour depth. level and
border give finer control associated with MIP-mapping and joining
of textures.
Example:
•
•
glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB,
GL_UNSIGNED_BYTE, my_image);
A 512x512 RGB texture with 8 bits of resolution for each of 3 colours
and no special features.
coordinates:
• glTexCoord3f(u,
v); associates texture coordinates with a
vertex.
23/05/2016
Advanced Computer Graphics
15