procedural textures - computer science and...

25
Procedural Textures Han-Wei Shen

Upload: hadat

Post on 07-Mar-2018

227 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Procedural Textures

Han-Wei Shen

Page 2: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Procedural Textures

!  Generate texture as you are coloring the fragment

!  Texture map is a function of texture coordinates !  Input: s,t,r !  Output: color,

opacity, or even shading

Page 3: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Make a checker board texture

!  What does this do?

for (int i=0; i<256; i++) for (int j=0; j<256; j++) { int c = ((((i&0x8)==0)^((j&0x8))==0))*255;

texImage[i][j][0] = (GLubyte) c; texImage[i][j][1] = (GLubyte) c; texImage[i][j][2] = (GLubyte) c; texImage[i][j][3] = (GLubyte) 255;

};

Page 4: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Procedural Texture Example

!  Fire

Page 5: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Procedural Texture Example

!  Planet

Page 6: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Procedural Texture Example

!  Cloud and Water

Page 7: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Solid Texturing

!  Procedural textures are often used as “solid textures”

!  Let s = x, t = y, r = z !  No need to

parameterize surfaces !  Objects appear sculpted

out of solid substances

Page 8: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Application of Noise

!  Simulating marble effects

Boring marble Better marble

Page 9: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Noise Function

!  A key ingredient to introduce “controlled” randomness

!  Famous noise function – Perlin Noise !  N(x,y,z) returns a random number in [-1,1], where

(x,y,z) can be an arbitrary 3D point

!  Requirement (unlike white noise): !  Smooth !  Coorelated !  Bandlimited

Page 10: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Basic idea of Perlin Noise

!  Divide the space to a 3D regular lattice !  A pseudo random “wavelet” is assigned

to each lattice point !  The noise value for any arbitrary 3D

point is by “interpolating” its eight nearest lattice point

Page 11: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

3D Lattice

!  The resolution of the lattice does not need to be high as we can repeat it without obvious pattern (no global pattern)

!  The lattice structure makes it easy to find which cell a given (x,y,z) is in !  [i,j,k] = [fl(x), fl(u), fl(z)] fl: floor function !  The cell is then have eight corners: [i,j,k], [i+1, j,

k], [i,j+1, k] …., [i+1,j+1,k+1]

Page 12: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Pseudorandom wavelet

!  Assign a pseudo wavelet value to each lattice point [i,j,k]

!  A wavelet is simply a function that drops off to zero outside of some region (radius 1 for example) and integrates to zero

!  The wavelet is constructed from a pseudorandom gradient (Perlin Noise is a

gradient noise function)

Page 13: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Pseudo random gradients !  Create a table of 255 random gradients uniformly

distributed over a unit sphere !  Choose points uniformly within the cube [-1, 1]^3 !  Throw out any points outside the sphere !  Project surviving points onto the unit sphere (normalize the

point, that is)

!  Then map any [i,j,k] into this table to assign a gradient to each lattice point !  create a permutation table P !  Map [I,j,k] to a gradient G[n] using P

!  n = P[i%256] -> n = P[(n+j) %256] -> n = P[(n+k)%256]

Page 14: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Pseudo random gradients

1. Constructing the Gradient table

for i in [0...255] repeat x = random(-1. ... +1.) y = random(-1. ... +1.) z = random(-1. ... +1.) until x*x + y*y + z*z < 1.0 G[i] = normalize[x, y, z]

2. Get a permutation index for [i,j,k]

fold(i, j, k) { n = P[i mod 256] n = P[(n+j) mod 256] n = P[(n+k) mod 256] } or P[P[P[i]+j]+k]

Lattice [I,j,k] then has the gradient G[fold(i,j,k)]

Page 15: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Pseudo random wavelet

!  It has a value of zero at its center (i.e, lattice point [i,j,k]

!  It has some random chosen gradient at its center (use the gradient to form a linear function

!  It smoothly drops off to zero – using a cubic polynomial

Page 16: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Evaluate the wavelets

!  For any arbitrary point [x,y,z], the wavelet from lattice [i,j,k] is evaluated as: !  [u,v,w] = [x-i,y-j,z-k] !  Weight = drop(u)*drop(v)*drop(w) where drop(t) = 1-3|t|^2+2|t|^3 !  F = G[i,j,k] dot [u,v,w] !  Wavelet = Weight * F

!  The noise value for (x,y,z) is then the sum of eight Wavelets from the point’s cell corners

Page 17: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Improved Perlin Noise

!  Published in 2002 after almost 20 years !  The drop off (or interpolating) function

is changed from 3|t|^2-2|t|^3 to 6|t|^5-15|t|^4+10|t|^3

old new

Page 18: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Variation of Noise function !  Perlin noise is a gradient noise !  Noise can also be generated based on value –

give a random value to each lattice point and use cubic interpolation; not linear interpolation as the noise will look “boxy”

!  Value based noise needs more samples (64) to perform interpolations for any points inside the lattice cell

!  People also use hybrid method – value and gradient (to avoid zero at lattice point as in the gradient noise function)

Page 19: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Application of noise

!  Random surface texture !  Color = white * noise(point)

Page 20: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Application of Noise

!  Colored noise: !  Color = Colorful(Noise(k*point)); k is to

control the feature size. The larger k is, the smaller the feature

Page 21: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Application of Noise

!  The differential of the noise function(Dnoise()) !  Normal += Dnoise(point)

Page 22: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Application of Noise

!  Simulate 1/f noise

1/f noise, is a signal or process with a frequency spectrum such that the power spectral density is proportional to the reciprocal of the frequency. Sometimes pronounced as one over f noise, it is also called flicker noise. In other words, it is a sound that falls off steadily into the higher frequencies, instead of producing all frequencies equally.

Page 23: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Application of Noise

!  1/f bump texture

Page 24: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Application of Noise

!  Turbulence (very useful!!)

Page 25: Procedural Textures - Computer Science and Engineeringweb.cse.ohio-state.edu/~shen.94/5542/Site/Slides_files/noise_short.pdf · Solid Texturing ! Procedural textures are often used

Application of Noise

!  Simulating marble effects

Boring marble Better marble