Simtexture Mapping - New2016

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 31

Texture Mapping

CS 010 703 CG
Module-5
What adds visual realism?

Geometry only

Phong shading

Phong shading +
Texture maps
Texture Mapping
Limited ability to generate complex surfaces with geometry.
Images can convey the illusion of geometry.
To model the objects with surface details (brick walls, gravel
roads etc) need surface texture.
A common method of adding surface detail is to map texture
patterns onto object surfaces (Images painted onto polygons to
enhance the visual effect of a scene) and is called texture
mapping or pattern mapping.
They are defined in a rectangular array or as a procedure that
modifies surface intensity values.
Texture Mapping

Texture pattern defined with a rectangular grid of intensity (s, t)


Surface position in the scene referenced with (u, v) object space
coordinates
Pixel positions on the projection plane are referenced with (x, y)
Cartesian coordinates
Texture Mapping

Two methods of Texture mapping :


Map the texture pattern to object surface, then to the
projection plane texture scanning .
Map pixel area onto object surfaces, then to texture space
pixel order scanning/ inverse scanning
Texture Mapping Methods...
Texture Scanning (texture space - object space - pixel space)
Parametric linear function for the mapping from texture space to
object space
u f u ( s, t ) au s bu t cu
v f v ( s, t ) av s bvt cv
Object to image space mapping is accomplished with
concatenation of viewing and projection transformations

Disadvantage of mapping from texture space to pixel space


selected texture patch does not match up with pixel boundaries,
requires calculation of fractional area of pixel coverage
Texture Mapping Methods...
Pixel order scanning/ Inverse scanning
(pixel space - object space - texture space )
Advantage of mapping from pixel space to texture space
- most commonly used
- Avoids pixel sub division calculations
- Allows anti aliasing (filtering) procedures to be applied
Texture Mapping Methods...
Anti aliasing (filtering) procedures
- Project a slightly larger pixel area that includes the centers of
neighbouring pixels and applying a pyramid function to weight the
intensity values in the texture pattern

Disadvantage of mapping from pixel space to texture space


- Requires calculation of inverse viewing & projection
transformation and inverse texture map transformation
Texture Maps
Images applied to polygons to enhance the visual
effect of
a scene
Rectangular arrays of data
Color, luminance, alpha
Components of array texels
Volumetric elements - voxels
Texture Mapping
Texture map is an image, two-dimensional array of
color values (texels)
Texels are specified by textures (s,t) space
At each screen pixel, texel can be used to substitute
a polygons surface property (color)
Map textures (s,t) space to polygons (u,v) space

T V

S U
Texture Mapping
(s,t) to (u,v) mapping can be explicitly set at vertices by
storing texture coordinates with each vertex
computing (s,t) to (u,v) mapping for in-between points:
Watch for aliasing
Watch for many to one mappings
Watch for perspective foreshortening effects and linear
interpolation
Texture Interpolation
The actual texture mapping computations take place
at the scan conversion and pixel rendering stages of
the graphics pipeline
During scan conversion, while looping through the
pixels of a triangle, the txty texture coordinates are
interpolated in a similar way as interpolating the rgb
color and z depth values
As with all other interpolated values, must
precompute the slopes of each coordinate as they
vary across the image pixels in x and y
After interpolating texture coordinates, look up that
pixel in the texture map and use it to color the pixel
Example Texture Map
Example Texture Map
Texture Coordinates
Every polygon has object coordinates and texture
coordinates
Object coordinates describe where polygon
vertices are on the screen
Texture coordinates describe texel coordinates of
each vertex (usually 0 -> 1)
Texture coordinates are interpolated along
vertex-vertex edges
Non-parametric texture
mapping

With non-parametric texture mapping:


Texture size and orientation are fixed
They are unrelated to size and orientation of
polygon
Gives cookie-cutter effect
Parametric texture mapping

With parametric texture mapping,


- texture size and orientation are tied to the polygon.
Idea:
Separate texture space and screen space
Texture the polygon as before, but in texture space
Deform (render) the textured polygon into screen
space

A texture can modulate just about any parameter


diffuse color, specular color, specular exponent,
Implementing texture mapping
A texture lives in it own abstract image coordinates
parameterized by (u,v) in the range ([0..1], [0..1]):
Note : here texture space is defined as (u,v) space
It can be wrapped around many different surfaces:

Computing (u,v) texture coordinates in a ray tracer is fairly


straightforward.
Note: if the surface moves/deforms, the texture goes with
it.
Mapping to texture image
coordinates
The texture is usually stored as an image. Thus, need
to convert from
abstract texture coordinates: (u,v) in the range ([0..1],
[0..1]) to texture image coordinates: (utex,vtex) in the
range ([0.. wtex], [0..htex])
Texture resampling
We need to resample the texture:

A common choice is bilinear interpolation:

T(a,b) T[i x , j y ]
(1 x )(1 y )T[i, j] x (1 y )T[i 1, j]
(1 x ) y T[i, j 1] x y T[i 1, j 1]
Solid textures
Q: What kinds of artifacts might you see from using a
marble veneer instead of real marble?

One solution is to use solid textures:


Use model-space coordinates to index into a 3D texture
Like carving the object from the material

One difficulty of solid texturing is coming up with the


textures.
Solid textures (cont'd)
Here's an example for a vase cut from a solid
marble texture:

Solid marble texture by Ken Perlin, (Foley, IV-21)


Displacement mapping
Textures can be used for more than just color.
In displacement mapping, a texture is used to
perturb the surface geometry itself:

These displacements animate with the surface


~
Q: Do you have to do hidden surface calculations
on Q?
Bump mapping
In bump mapping, a texture is used to perturb the
normal:
Use the original, simpler geometry, Q(u), for hidden surfaces
Use the normal from the displacement map for shading:
~ ~
N = normal[Q(u)]

Q: What artifacts in the images would reveal that


bump mapping is a fake?

University of Texas at
Austin CS384G -
Bump mapping example
Texture #1 Texture #2
Rendered Image
(diffuse color) (bump map)

University of Texas at
Austin CS384G -
Displacement vs. bump mapping
(cont'd)

Original rendering Rendering with bump


map wrapped around a cylinder

Bump map and rendering by Wyvern Aldinger


Bump Mapping
As we said, a texture doesnt always have to represent a color
image
The technique of bump mapping uses a texture to represent
the variable height of a surface
For example, each texel could store a single 8 bit value which
represents some variation from a mean height
Bump mapping is used in conjunction with Phong shading
(interpolating normals across the triangle and applying the
lighting equations per pixel)
The Phong shading provides an interpolated normal per pixel,
which is then further perturbed according to the bump map
This perturbed normal is then used for per-pixel lighting
This allows one to use a bump map to fake small surface
irregularities that properly interact with lighting
Bump mapping is definitely a hack, as a triangle still looks flat
when viewed edge-on. However, it is a very popular technique
and can be very useful for adding subtle shading details
State of the art graphics hardware supports Phong shading,
bump mapping, and per pixel lighting
Bump Mapping
Use textures to modify surface
geometry
Use texel values to modify surface
normals of polygon
Texel values correspond to height field
Height field models a rough surface
Partial derivative of bump map
specifies change to surface normal
Bump Mapping
Displacement Mapping
Bump mapped normals are inconsistent with
actual geometry. Problems arise (shadows).
Displacement mapping actually affects the
surface geometry
Displacement Mapping
The more advanced technique of displacement
mapping starts with the same idea as bump mapping
Instead of simply tweaking the normals, the
displacement mapping technique perturbs the actual
surface itself
This essentially requires dicing the triangle up into
lots of tiny triangles (often about 1 pixel in size)
Obviously, this technique is very expensive, but is
often used in high quality rendering

You might also like