CS代考计算机代写 Computer Graphics CSI4130 – Winter 2019

Computer Graphics CSI4130 – Winter 2019
Jochen Lang
EECS, University of Ottawa Canada

This Lecture
• 3D Texturing Mapping
– Textbook:Chapter11.2 – 3D texture mapping
– Proceduraltextures
– Noise textures
CSI4130 Computer Graphics

3D Textures Mapping
• Specify a color everywhere in 3D space (e.g. in object coordinates)
– 3D Volume texture
CSI4130 Computer Graphics

3D Texture Mapping
• Easier than 2D texture mapping
– Define a texture value (e.g. colour) everywhere in space
– Look up the value in the texture map only for surface points – No parameterization (hard) of surfaces
– But photographic images are only 2D
• Different approaches to texturing
– Proceduraltextures
– Look-up tables (e.g., 2D/3D images)
CSI4130 Computer Graphics

3D Textures:
Trilinear Texture Interpolation
– Same idea as bilinear texture mapping but in 3D – Scene point (u,v,w) textured from map (i,j,k)
CSI4130 Computer Graphics

Procedural Texturing
• Use some function (or stochastic process) to determine the value of the texture
– Noise textures, e.g., Perlin noise [Perlin, SIGGRAPH 1985] – Function, e.g., stripe texture
Color stripe( Point p, double w ) {
if (sin(p.x*PI/w) > 0 )
return black;
else
return white;
}
CSI4130 Computer Graphics

Solid Noise Texture
• Idea
– Like to colour object randomly but not too random
• Must have some consistency across pixels • Random pixel colour not useful
CSI4130 Computer Graphics

Perlin Noise [SIGGRAPH 1985]
– Generate an array of random unit vectors
– Look up one of these vectors based on a pseudo-random hash function
– Use Hermite interpolation to avoid mach bands
ACM Copyright Notice: Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee.
CSI4130 Computer Graphics

Implementation: Index Coloring
Perlin noise (unevenly) mapped into 8 colors
CSI4130 Computer Graphics

Perlin Noise Overview
– Idea is to put random unit vector on to a grid
• The grid is mapped with a pseudo random hash function to the coordinate that we would like to associate the noise with.
– These random vectors will be used as gradient vectors
• E.g., for texturing, normal mapping or other texture technique
Dot product with position Hermite Interpolation
Over the complete grid
Image Source: Lars Huttar
CSI4130 Computer Graphics

Solid Noise: Selection of an Unit Vector from an Array at Random
– Array of n unit vectors
• Select one, 􏰗,􏰜,􏰢, at random with hash function
• Unit vectors themselves are stored in the array randomly – Hash Function
• Array P of length n (e.g., ) with pseudo-random numbers
• Evaluate hash function based on texture map indicies
􏰗,􏰜,􏰢
CSI4130 Computer Graphics

Solid Noise:
Hermite Cubic Interpolation in 3D
– Noise is weighted average of the 8 surrounding texels • trilinear interpolation
– Hermite cubic weighting function
CSI4130 Computer Graphics
Random Unit Vector

Implementation:
Hermite Cubic Interpolation
– Hermite cubic weighting function
– GLSL provides function smoothstep
• performs Hermite interpolation between two values,
based on a third value between 0..1 • Works with vectors as well
• Example:
const vec3 zeroV = vec3( 0.0, 0.0, 0.0 ); const vec3 oneV = vec3( 1.0, 1.0, 1.0 ); vec3 uvw = smoothstep(zeroV,oneV,abs(_uvw));
CSI4130 Computer Graphics

Implementation:
Use of Random Unit Vector

What about?
Random Unit Vector dot Offset – u,v,w are between -1 and 1 (offsets)
– i,j,k are the actual texture indices (texels)
float noisePoint( vec3 _ijk, vec3 _uvw ) {
vec3 hermiteT = smoothstep(zeroV,oneV,abs(_uvw)); return hermiteT.s * hermiteT.t * hermiteT.p *
dot(gamma(_ijk),_uvw);
}
CSI4130 Computer Graphics

Solid Noise
• Solid noise is between -1…1
– Need to scale and shift, e.g.,
– Or take absolute value (shown here)
• use b/w (shown here) or use two colors
CSI4130 Computer Graphics

Noise Modification
– Turbulence function (Perlin)
• Combine turbulence function with stripe pattern
• Sum of scaled copies of itself
􏰗
􏰗
ACM Copyright Notice: Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee.
CSI4130 Computer Graphics
􏰣
􏰗

Implementation: Turbulence Function
– Turbulence function (Perlin) – no stripes • Sum of scaled copies of itself
CSI4130 Computer Graphics

Turbulent Stripes
• Idea:
– Two colour stripe pattern based on blend parameter t
– Disturb regular value of t by noise with turbulent noise function f
CSI4130 Computer Graphics

Implementation:
Turbulent Stripes for Teapot
– Coordinates:
• x-y plane is parallel to the bottom
• z axis is pointing up
• stripes appear on circumference
• adding turbulent noise makes the stripes less boring
CSI4130 Computer Graphics

Aside: Rejection Sampling
• Steps in rejection sampling
– generate random values of a convenient function which
encloses the desired function
– reject samples generated outside desired function and accept sample inside
• Example
– Sampling directions in 2D with random points – Random x and y values
Too many samples in the blue directions compared to the white directions
CSI4130 Computer Graphics

Random Unit Vectors
• Solid noise or random rotation axis as in the box lab
• Unit Vectors
– Generaterandomvectorswith
– Need unit sphere, i.e., unit cube too large
• reject samples outside
• and normalize the remaining
􏰎􏰑 􏰏􏰑 􏰐􏰑
CSI4130 Computer Graphics

Implementation: Random 3D Unit Vectors
• Uses rejection sampling of directions
– generate random values in a cube but reject samples
generated outside of sphere and accept samples inside
• Unit Vectors
• Generate random vectors with -1 <= x, y, z <= 1 – Need unit sphere, i.e., unit cube too large • reject samples outside (and normalize the remaining) do { glMatrix.vec3.set(randVec, 2.0*Math.random()-1.0, 2.0*Math.random()-1.0, 2.0*Math.random()-1.0); len2 = glMatrix.vec3.sqrLen(randVec); } while ( len2 > 1.0 );
glMatrix.vec3.scale( randVec, randVec, 1.0/Math.sqrt(len2));
CSI4130 Computer Graphics

Next Lecture: Other Texturing Techniques
• Bump Mapping
• Displacement Mapping
• Environment Maps
• Shadow Mapping
CSI4130 Computer Graphics