程序代写代做代考 PowerPoint Presentation

PowerPoint Presentation

10. Textures & Mipmaps

Dr. Hamish Carr

COMP 5812M: Foundations of Modelling & Rendering
Textures & Mapping
An image mapped to a surface
Substitutes for geometric detail

M is the manifold
is the data

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
So . . .
Any property we wish to store on a surface
We convert to an image
Then use texture coordinates to access
Either as an array lookup
Or as a function that we call
Essentially an indirection, like a pointer
Allows us to interpose arbitrary calculation

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Adding Textures
We know how to interpolate texels
If we’re given texture coords for the pixel
So how do we do that?
Start with a point p
Convert to surface parameters (s,t)
Convert to texel indices (i,j)
Retrieve texel colour

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Analytic Solution: Sphere

Given x,y,z on a sphere

Find (θ,φ)
(lat., long.)

Then (i,j)
texture indices

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Textured Sphere

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering

Cylindrical Projection
Simplest map projection: lat. vs. long.

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
From Map to Globe

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Texture Coordinates

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Practical Solution
Give each vertex texture coordinates s,t
Use barycentric interpolation on triangles
Look up the resulting s,t in the image
As (row, col) coordinates
But the coordinates are almost never integers
So we will need interpolation

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Texture Interpolation

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Bilinear Interpolation
Interpolates on a quadrilateral
Iterates linear interpolation twice
Linear along the edges
Commonly used for texture interpolation

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Development

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Bilinear Surface
We get a small height field
Which is smooth / twisted
So we’ll see more of these later

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Code
RGBValue BilinearLookup(Image tex, float s, float t)
{ // BilinearLookup()
int i = s; // truncates s to get i
int j = t; // truncates t to get j
float sParm = s – i; // compute s for interpolation
float tParm = t – j; // compute t for interpolation

// grab four nearest texel colours
RGBValue colour00 = tex[i][j];
RGBValue colour01 = tex[i][j+1];
RGBValue colour10 = tex[i+1][j];
RGBValue colour11 = tex[i+1][j+1];

// compute colours on edges
RGBValue colour0 = colour00 + tParm * (colour01 – colour00);
RGBValue colour1 = colour10 + tParm * (colour11 – colour10);

// compute colour for interpolated texel
return colour1 + sParm * (colour1 – colour0);
} // BilinearLookup()

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Bilinear Interpolation

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Replace vs. Modulate
GL_REPLACE
GL_MODULATE

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
But . . .

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
What Is Happening?
Perspective increases background frequency
No longer band-limited
Result: Moire patterns / aliasing

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Point Sampling

Point sampling is best if it’s dense
Perspective causes frequency to decrease

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Correct Solution
Integrate the light over patches
But this wastes samples on background

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Approximation
Compute patches at half resolution
Repeat recursively
Mipmaps = multum in parvum maps

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Improvement
Choosing transition range is important
And you never quite get it right
So how to make it less abrupt?

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Trilinear Mipmapping
Identify two ranges (distances) near, far

Parametrise pixel distance as:

Use bilinear interpolation twice
Then interpolate between the two colours
Result: trilinear interpolation

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Trilinear Interpolation

Same idea as before, but repeated three times
Development is similar

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Trilinear Equation

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Trilinear Mipmapping

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
More generally
Mipmapping is a special case
We need a more general solution
But scaling up & scaling down are different
And this requires some image processing
Next week

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Mappable Properties
Normal vectors
Colours
Material properties
BSSDFs
Surface deformations
Random seeds (use Nearest Neighbour)
Coefficients for calculations

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
In the Phong Model
Diffuse reflection constant
Specular reflection coefficient
Diffuse, specular, ambient, emissive colours
Specular exponent
Whether or not in a shadow
Extra parameters for lighting equations
All of these can be made (u,v)-dependent

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Some Examples
Environment Mapping
Bump Mapping
Contour Drawing
Volumetric Textures
Video Textures
Procedural Textures
Light Maps
Shadow Maps

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Environment Maps

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Irradiance Mapping
Diffuse surfaces are a different summation
So precompute the lighting on them
Approximates room lighting
Apply to multiple objects

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Bump Mapping
Models small changes in normal vectors
Simulates shadows from surface roughness
Stores per-pixel normal vectors
i) convert (x,y,z) to (r,g,b)
ii) normal perturbation stored as (r,g)
iii) height field stored as (r)

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Volumetric Contours
Why not 3 coordinates?
Specify position in space
Use that to look up texture
Result: marble/wood/cheese
But volumetric textures are expensive

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Video Textures
Store each frame as a slice in 3D
Store (u,v) coordinates for the screen
Set w = t based on the time you render
Result – video plays back on surface

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Light Maps
Precompute lighting from each light source
Store in separate textures
Compute final lighting as sum of active lights
Ignores characters in the scene
But massively speeds up scenery rendering
Leads to shadow maps (next term)

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Projective Lighting
Light coming through a translucent surface
Store the light colour in a texture map

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Texture Design
Pictures (e.g. environment map)
Acquired (scanning devices)
Artist-designed (painted on)
Spherical projection
Texture parametrization / deformation
Texture synthesis
Geometric reduction

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Creating Textures
Given a mesh M with
Vertex positions P
Texture coordinates U
Attribute values A
Render M in 2D
Using U as vertex positions, not P
And the texture will hold the attribute

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Artist Designed
Painted onto a model, uv coords set by hand

Othman Ahmad – screenshot CC BY-SA 3.0

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Texture Boundaries
What do we do at the edge of the texture?
We know that we can clamp or repeat
Repeating works for a torus or flat sheet

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Texture Seams
Most surfaces are genus 0
A torus is genus 1
Which means we can’t just use repeat
And we end up with seams in the textures
Or map (project) each surface to a sphere
Which we can cover with a single texture

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Texture Distortion
Texture details are unevenly distributed
How do we use texels efficiently?

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Texture Synthesis
Write code to create texture
Not good for humans
Pretty good for some tasks
Fourier Synthesis
Perlin Noise
Reaction-Diffusion
Data-Driven

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Fourier Synthesis
Define a sum of sines & cosines
Use that for a mottled appearance

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Perlin Noise
Randomise some points
Use spline curves / surfaces to interpolate
Use this to generate an image

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Reaction-Diffusion
Models pigment production in skin
Useful for animal coats, &c.
Essentially a small numerical simulation

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Data-Driven Generation
Use a small travelling window
Pick a matching window in sample image
Copy next pixel based on that

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Image (Re-)Synthesis
Huge overlap with image processing

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
Summary
Texture mapping is an indirection
Allows mapping any property to surface
Therefore used as a lookup mechanism
Either in an array or in a function
Many, many variations
Geometry underneath drives a lot of it
So we will come back to these next term

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering

Brief Article

The Author

October 16, 2017

b00 = f(0, 0)

b01 = f(0, 1)

b10 = f(1, 0)

b11 = f(1, 1)

f(0, t) = t · b01 + (1� t) · b00

f(1, t) = t · b11 + (1� t) · b10

f(s, t) = s · f(1, t) + (1� s) · f(0, t)
= s · (t · b11 + (1� t) · b10) + (1� s) · (t · b01 + (1� t) · b00)
= b11st+ b10s� b10st+ b01t� b01st+ b00 � b00s� b00t+ b00st
= (b11 � b10 � b01 + b00) st+ (b10 � b00) s+ (b01 � b00) t+ b00

1

Brief Article

The Author

October 16, 2017

b00 = f(0, 0)

b01 = f(0, 1)

b10 = f(1, 0)

b11 = f(1, 1)

f(0, t) = t · b01 + (1� t) · b00

f(1, t) = t · b11 + (1� t) · b10

f(s, t) = s · f(1, t) + (1� s) · f(0, t)
= s · (t · b11 + (1� t) · b10) + (1� s) · (t · b01 + (1� t) · b00)
= b11st+ b10s� b10st+ b01t� b01st+ b00 � b00s� b00t+ b00st
= (b11 � b10 � b01 + b00) st+ (b10 � b00) s+ (b01 � b00) t+ b00

1

HandBrake 0.9.8 2012071800

(s, t, u)(0, t, u) (1, t, u)
(0, 0, u) (1, 0, u)

(0, 1, u) (1, 1, u)

(0, 0, 0) (1, 0, 0)

(0, 1, 0) (1, 1, 0)

(0, 0, 1) (1, 1, 1)

(0, 1, 1) (1, 1, 1)

(s, t, u)(0, t, u) (1, t, u)
(0, 0, u) (1, 0, u)
(0, 1, u)
(1, 1, u)
(0, 0, 0) (1, 0, 0)
(0, 1, 0) (1, 1, 0)
(0, 0, 1) (1, 1, 1)
(0, 1, 1)
(1, 1, 1)

f x, y, z( ) = a xyz + b yz + c xz + d  xy + ex + fy + gz + h
a = b111 − b110 − b101 − b011 + b100 + b010 + b001 + b000
b = b011 − b010 − b001 + b000
c = b101 − b100 − b001 + b000
d = b110 − b100 − b010 + b000
e = b100 − b000
f = b010 − b000
g = b001 − b000
h = b000

fx,y,z
( )
=a xyz+b yz+c xz+d xy+ex+fy+gz+h
a=b
111
-b
110
-b
101
-b
011
+b
100
+b
010
+b
001
+b
000
b=b
011
-b
010
-b
001
+b
000
c=b
101
-b
100
-b
001
+b
000
d=b
110
-b
100
-b
010
+b
000
e=b
100
-b
000
f=b
010
-b
000
g=b
001
-b
000
h=b
000