28
Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 1 / 28 Textures and noise functions © 1998-2017 Josef Pelikán CGG MFF UK Praha [email protected] http://cgg.mff.cuni.cz/~pepca/

Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 1 / 28

Textures and noise functions© 1998-2017 Josef Pelikán

CGG MFF UK Praha

[email protected]

http://cgg.mff.cuni.cz/~pepca/

Page 2: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 2 / 28

Effect of a texture surface color

parameters of a reflectance model– Phong: kD, kS, h, ..

normal vector– ”bump-map”, normal map– replacement for complicated geometry

➨ simulation of complex natural phenomena– internal structure of a material– random textures (noise synthesis)– fractal textures (deterministic, stochastic)

Page 3: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 3 / 28

2D texture

covers object surface (wallpaper)

➨ texture mapping: [x,y,z] [u,v]– “inverse mapping” function

➨ 2D texture itself: [u,v] color (normal, ..)

u

v

Page 4: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 4 / 28

3D texture represents/simulates internal object quantities

imitates internal material structure (wood, marble, ...)

➨ no need of inverse mapping➨ 3D texture: [x,y,z] color (reflectance, etc.)

▲ for imitating natural materials or phenomena noise functions are often used– pseudo-random continuous

”folding”

Page 5: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 5 / 28

Implementation types precomputed data array (table, raster image)

– often for 2D textures– actual (natural) data, images, stickers, ..– interpolation for better quality (continuity)

algorithm-based textures (procedural)– simple geometric shapes (checkerboard, stripes..)– fractals, stochastic functions (noise, turbulence)

mixed approaches (precomputed table, caching)– computationally-intensive simulations (reaction-

diffusion systems, ..)

Page 6: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 6 / 28

Table-defined texture

u

v

y

x

Page 7: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 7 / 28

Interpolation types➨ w/o interpolation (rounding)

– fast and simple– interference, pixellation artifacts (Wolfenstein 3D)

➨ bilinear interpolation– continuity of the image function (C0)

➨ polynomial interpolation (e.g. using spline function)– higher level continuity (C2 for bi-cubic spline)– computing-intensive (2D case: 9-16 values has to be

combined)

Page 8: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 8 / 28

Bi-linear and bi-cubic interpolationf10 f11

f00

f01b

a f(a,b)

f a b a b f b f

a b f b f

,

11 10

01 00

1

1 1

f21 f22

f11

f12b

a f(a,b)

f03f02f01f00

f10

f20

f30 f31 f32 f33

f23

f13

f a b C a C b fi j iji j

,,

0

3

Ci(t) .. cubic polynomials

Page 9: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 9 / 28

C t

C t pro t

ii

i

1

0 1 0 10

3

Cubic B-spline interpolation

f a b C a C b fi j ijji

,

0

3

0

3

C t t

C t t t

C t t t t

C t t

016

3

116

3 2

216

3 2

316

3

1

3 6 4

3 3 3 1

B-splineblending functions:

for

Page 10: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 10 / 28

Procedural and mixed textures➨ simple geometric shapes, patterns

– checkerboard, regular stripes, stars, ..

➨ imitation of natural processes– often pseudo-random methods are used (noise

synthesis)– fractals, turbulence (clouds, dirt, ..)– reaction-diffusion (animal skin and fur patterns)– 3D random perturbation textures (wood, marble, ..)

Page 11: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 11 / 28

Normal modulation (“bump map”)

➨ imitation of object surface roughness/bumpiness

➨ B(u,v) – local surface displacement function:+ outside, – inside

N

U

V

N’

B(u,v)

N = U × V

P’(u,v) = P(u,v) + B(u,v)· N / |N|

Page 12: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 12 / 28

Normal modulation

N U V

P u v P u v

B u v N

N, ,

,moved point:

N N

u v N V u v N U

N

Bu

Bv

, ,

original normal:

approximation of modified normal vector:

Page 13: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 13 / 28

Noise synthesis

➨ subjectively plausible appearance / shape– imitation of complex natural phenomena– chaotic system results, random diffusions, systems with

[partial] feedback, ..

➨ computing noise function value in a specific point has to be deterministic (repeatable)– distributed computing, super-sampling, ..

➨ required spectral characteristics of a noise (opt.)– uncorrelated (white) noise, frequency-limited noise, ..

Page 14: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 14 / 28

White noise

noise with unlimited spectrum– no correlation of any two result values

➨ example of deterministic white-noise generator:

double RandomTab[RANDOMTABLEN]; // random valuesint Indx[ILEN], Indy[ILEN]; // random permutations

double white_noise_2D ( double x, double y ){ int i = HASH( Indx[LOW_BITS(x)], Indy[LOW_BITS(y)] ); return( RandomTab[ i % RANDOM_TAB_LEN ] );}

uses k lowest mantissa bits LOW_BITS, hash function HASHRandomTab, Indx, Indy are precomputed tables

Page 15: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 15 / 28

Continuous noise

continuous function with limited spectrum– stationary, isotropic (translation- & rotation- invariant)– too short period could be a problem

➨ Fourier synthesis– tight control of frequency characteristics

➨ interpolation of random grid values– classics – B-splines– Hermite interpolation – gradients (Perlin)– stochastic sample set – sparse convolution (Lewis)

Page 16: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 16 / 28

Regular grid interpolation pre-processing – a regularly distributed system of

pseudorandom values (vectors, tangents, Jacobians)– required probability densities– 1D, 2D or 3D topology– multi-dimensional case – memory saver using a hash

function, see HASH(x,y,z)

interpolation in all other points– separable methods (independent coord. components)– usually quadratic or cubic blending polynomials– 2D: 4 to 16 points, 3D: 8 to 64 points

Page 17: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 17 / 28

Ken Perlin's noise (3D noise)

spectrum is limited (one octave = f ÷ 2f) efficient implementation

precomputed grid of pseudo-random gradient vectors [a,b,c,d]ijk

– [a,b,c]ijk is random unit direction (rejection sampling of the unit sphere)

– dijk is noise value of the grid point [xi,yj,zk]

– support value d’ijk = dijk - aijk· xi - bijk· yj - cijk· zk

Page 18: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 18 / 28

Perlin's noise grid values:

Kijk(x,y,z) = d’ijk + aijk· x + bijk· y + cijk· z

interpolation cubic splines: w(t) = 2|t|3 - 3t2 + 1 for |t| < 1

w(t) = 0 else– support radius = 1 I need only 2D grid points

a x y z w x i w y j w z k a

k z

z

j y

y

i x

x

ijk, ,

111

Page 19: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 19 / 28

Sparse convolution (Lewis) controlled spectral characteristics efficient (scalable) implementation

➨ convolution of 3D filter h(x,y,z) with Poisson

noise :

n x y z u v w h x u y v z w dudv dw, , , , , ,

3

x y z a x x y y z zk k k kk

, , , ,

Page 20: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 20 / 28

Poisson noise convolution

random position: [xk,yk,zk] random amplitude: ak

supp(h) 1

filter h

r0 1

Page 21: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 21 / 28

Sparse convolution

➨ sample density [xk,yk,zk] controls the result quality of the noise– for 10+ samples per supp(h) the quality is indistingui-

shable from an interpolation noise

– sparse convolution can have higher efficiency for normal quality

n x y z a h x x y y z zk k k kk

, , , , Thanks to discrete nature of a Poisson noise :

Page 22: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 22 / 28

Efficient implementation

➨ space division scheme – grid with cell size = r (filter supp(h) radius – usually 1)

➨ each grid cell generates its samples independently, using pseudo-random generator initialized to Seedijk

– Seedijk values are prepared in advance by a differrent random source

– or a hash function can be used: HASH(x,y,z)

Page 23: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 23 / 28

Efficient implementation

➨ for the result Noise(x,y,z) we only need to process a limited number of neighbour cells – 2D: 4 ÷ 9 cells– 3D: 8 ÷ 27 cells

➨ for an isotropic noise (symetrical filter function h) we can precompute h(r2) values into a table– no more square roots in convolution calculations

Page 24: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 24 / 28

Noise function combination

➨ general combination of noise functions with fre-quencies fi, amplitudes ai using drift vectors [xi,yi,zi]:

➨ turbulence simulation:fi = Fi, ai = A-i

a Noise f x x f y y f z zi i i i i i ii

, ,

1

ANoise F x x F y y F z z

ii

ii

ii

ii

, ,

Page 25: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 25 / 28

Applications

➨ random normal modulations (“bump maps”)– illusion of randomly wrinkled object surface– ”citrus peel”

➨ turbulence– fog, clouds, many other modeling

techniques

➨ 3D textures– inner material structure– wood, marble, ..

Page 26: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 26 / 28

Wood imitation

D(x,y,z)

ideal trunk axis

[x,y,z]

r

color B(r)

B D x y z Noise x y z, , , ,

B D x y z Noise x y z Noise x y z, , , , , , 1 1 2

Page 27: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 27 / 28

Marble imitation

D(x,y,z)

ideal geolog. plane (stratum)

[x,y,z]

r

color B(r)

B D x y z Noise x y z, , , , TurbTurb

Page 28: Textures for ray-tracing - Univerzita Karlovapepca/lectures/pdf/pg2-12-textures.en.pdfInterpolation types w/o interpolation (rounding) – fast and simple – interference, pixellation

Textures 2017 © Josef Pelikán, http://cgg.mff.cuni.cz/~pepca 28 / 28

References

K. Perlin: An Image Synthesizer, Computer Graphics, Vol. 19, #3, July 1985, 287-296

K. Perlin, E. M. Hoffert: Hypertexture, Computer Graphics, Vol. 23, #3, July 1989, 253-262

J. P. Lewis: Algorithms for Solid Noise Synthesis, Computer Graphics, Vol. 23, #3, July 1989, 263-270

J. Foley, A. van Dam, S. Feiner, J. Hughes: Computer Graphics, Principles and Practice, 741-745, 1015-1018, 1043-1047