程序代写代做代考 10: The OpenGL Pipeline

10: The OpenGL Pipeline

11: Attribute Maps

COMP5822M: High Performance Graphics
Attribute Maps
Any texture is an attribute map
Typically stores colour / materials
But can store:
Position
Normal
Opacity
Displacement

COMP5822M: High Performance Graphics
Modelling Brick
A texture is always flat
We want it to appear rough
Store roughness in a texture
greyscale = roughness
Bump maps
Displacement maps
Normal maps

COMP5822M: High Performance Graphics
Bump Mapping
Small features are a few pixels in size
Geometric position not really visible
But shading is visible
So change the shading but not the geometry

[Blinn 78]

COMP5822M: High Performance Graphics

Bump Mapping
Store normal vector in a texture
At runtime, convert to WCS & use it
Can be done in the shader
Effective except at silhouette of object

COMP5822M: High Performance Graphics

Surface Frame
Each point has its own surface frame
Defined by normal n, tangent t, bitangent b:
, ,

COMP5822M: High Performance Graphics
Finding the Surface Frame
Consider dS/du and dS/dv
These form a basis for the tangent plane
Not necessarily orthonormal
But still useful
In texture coordinates,

COMP5822M: High Performance Graphics
Computation
We assume that the normal vector is known
And take two edges of a triangle
We will compute them twice:
In spatial coordinates
In texture coordinates
Then use a matrix inverse to convert them

COMP5822M: High Performance Graphics
Spatial Frame
Take the vectors

These form a frame
Now ignore
Since we work in its plane

A
B
C

COMP5822M: High Performance Graphics
Texture Vectors

Compute b,c in texture space
Texture Edge Vectors:

A
B
C

COMP5822M: High Performance Graphics
Setting Up Equations
We can express in texture space:

And convert back to spatial coordinates:

COMP5822M: High Performance Graphics
Matrix Form

COMP5822M: High Performance Graphics
Blinn’s Offset Map
Assume you have a surface frame
Let
Requires access to in fragment shader

COMP5822M: High Performance Graphics
Shading in Tangent Space
Diffuse lighting uses ( is the light vector)
Note that is in the tangent space
is in world coordinates
We need to transform into tangent space
With the inverse matrix of

COMP5822M: High Performance Graphics
Bump Mapping

COMP5822M: High Performance Graphics
Height Mapping
Or use a heightfield to perturb (Blinn, 78)
Each value defines normal perturbation
Then normals are computed from heightmap
Same as terrain, but in tangent space

COMP5822M: High Performance Graphics
Normal Mapping
Currently the preferred method
Store (x,y,z) in (r,g,b) [scaled]
In tangent space
Costs more storage, but less computation
More transformations needed during shading

COMP5822M: High Performance Graphics
Normal Mapping

COMP5822M: High Performance Graphics
Parallax Mapping
Normal mapping doesn’t provide occlusion
So close up geometric detail looks wrong
Perceptually, we expect parallax
Object relations change visually as we move

COMP5822M: High Performance Graphics
Relief Mapping
Essentially, local raytracing near the surface
Test texture samples along view vector
Compare with heightfield for intersection

COMP5822M: High Performance Graphics
Normal vs. Relief Mapping
Normal maps: no self-occlusion
Relief maps: bad silhouettes

COMP5822M: High Performance Graphics
Displacement Mapping
Render more surface details geometrically
Re-tessellate the mesh with extra vertices
Retrieve displacement from texture
Very costly, but high quality
But you can reserve this for zooming in
Aha! We get level-of-detail effects

COMP5822M: High Performance Graphics
Displacement Mapping

COMP5822M: High Performance Graphics
Alpha Mapping
Standard method for translucent objects
Uses alpha channel of images
Alpha is usually opacity
How much light is blocked

COMP5822M: High Performance Graphics
Render Order
ABC, ACB: we get B’s colour
BCA, BAC, CBA: we get B modified by A
CAB: depends on what z buffer has:
: we get B’s colour
: we get C modified by A
: depends on !

C
B
A

COMP5822M: High Performance Graphics
Net Result
Alpha transparency needs back to front order
Z-buffer tends to have nasty artifacts
Least noticeable when
Because then the z buffer is unambiguous

COMP5822M: High Performance Graphics
Procedural Textures
How do we get suitable mottled textures?
Procedural texture generation
Often based on Perlin noise

COMP5822M: High Performance Graphics
Perlin Noise
Powerful
Applies to any dimension
Take random signal
Apply low-pass filter
Blurs high frequencies
Medium-scale noise

Raw noise
Use case

COMP5822M: High Performance Graphics
2D Perlin Noise Setup
Generate 255 vectors
Store in lookup table
Per sample (xi,yj):
Compute random no 0-255
Lookup 2D vector in the table
We can do this repeatedly at runtime
If we store the pseudorandom seed

(x,y)
(xi,yj)
(xi+1,yj)
(xi,yj+1)
(xi+1,yj+1)

COMP5822M: High Performance Graphics
Perlin Noise Usage
For a point (x,y):
Compute the fractional part

Take dot product of and
Use bilinear interpolation on the 4 corners
Gives the final noise value

(x,y)
(xi,yj)
(xi+1,yj)
(xi,yj+1)
(xi+1,yj+1)

COMP5822M: High Performance Graphics