Presentation is loading. Please wait.

Presentation is loading. Please wait.

Part II – Photorealistic Rendering (1) Texture (4) CPSC 591/691.

Similar presentations


Presentation on theme: "Part II – Photorealistic Rendering (1) Texture (4) CPSC 591/691."— Presentation transcript:

1 Part II – Photorealistic Rendering (1) Texture (4) CPSC 591/691

2 3D Texture Mapping Each point determines its color without the use of an intermediate map shape (Peachey, 1985; Perlin, 1985) We use the (x,y,z) coordinate to compute the color directly. Most 3D texture functions do not explicitly store a value for each (x, y, z)-coordinate, but use a procedure to compute a value based on the coordinate and thus are called procedural textures. Equivalent to carving an object out of a solid substance

3 Solid Texture Mapping Use x,y,z location of pixel Use location in simple procedure to generate, e.g. Material color to be used in shading calculation Ambient, diffuse, or specular reflection coefficient Opacity Final color World space coordinates v. object space coordinates? Object is ‘carved’ out of textured volume

4 If world space Ok in static scenes Object moves through texture if object animated If object space Texture is ‘fixed’ to object need to inverse transform intersection or need to trace inverse ray in object space

5 Solid Texture Map Coordinates Object Space World Space texture M M -1

6 Stripes on Teapot Find the integer part of the x-, y-, or z- value of each point of the object. If resulting value is even, –then choose red; –else choose white.

7 Space Filling Stripes jump(x,y,z) = ((int)(x))%2 if (jump == 0) color = white else if (jump == 1) color = red jump(x,y,z) = ((int)(A + x/s.x)%2 if (jump == 0) color = white else if (jump == 1) color = red Uses: modulo divisor % 0…….1…..0 0...s.x...2*s.x..3*s.x

8 Space Filling 2D Checkerboard jump(x,y,z) = ((int)(A+x/s.x)+(int)(A+y/s.y))%2 if (jump == 0) color = white Else if (jump == 1) color = red s.x s.y 2*s.y 2*s.x 0 1 1 0

9 Space Filling 3D Checkerboard jump(x,y,z) = ((int)(A+x/s.x)+(int)(A+y/s.y)+(int)(A+z/s.z))%2 if (jump == 0) color = white Else if (jump == 1) color = red

10 Ramp and Sine Functions A nice ramp: mod(x,a)/a This ramp function has a range of zero to one, as does (sin(x)+1)/2. Magenta to value of zero and yellow to the value one

11 Using a point to compute an index into a color table One way to do this is to keep the fractional part of the x-coordinate, which ranges between zero and one, and multiply it by the number of elements in the color table.

12 Cube of Smoothly Varying Colors Uses fract(x) = x - (floor)(x) Texture(x,y,z) = (1 - |2*fract(x)-1|, 1-|2*fract(y) - 1|, 1-|2*fract(z)-1|) 0….1…..0

13 Rings on Teapot Use the x- and y- components to compute the distance of a point from the object’s center, and truncate the result. If the resulting value is even, –then we choose red; –else we choose white.

14 Rings rings( r ) = (int ( r )) % 2 r = sqrt(x 2 +y 2 ); rings(x,y,z ) = D + A * rings( r/M ) M - thickness

15 Wood Grain rings( r ) = rings ( r/M + k*sin(  /N)) rings( r ) = rings ( r/M + k*sin(  /N+Bz)) Wobble: Twist:  Azimuth around the z-axis  z

16 Wood Grain To tilt the grain, (x’,y’,z’) = T(x,y,z) for some rotational transform T

17 Noise Functions Regular patterns are not as interesting as patterns with some randomness. For texture mapping the randomness is produced by a noise function.

18 Noise Functions Desirable properties (Perlin, 1985): –known range –stationary –band limited –isotropic http://mrl.nyu.edu/perlin/

19 Noise Functions A noise function is essentially a seeded random number generator. It takes an integer as a parameter, and returns a random number based on that parameter. If you pass it the same parameter twice, it produces the same number twice. It is very important that it behaves in this way, otherwise the Perlin function will simply produce nonsense.

20 Here is a graph showing an example noise function. A random value between 0 and 1 is assigned to every point on the X axis.

21 By smoothly interpolating between the values, we can define a continuous function that takes a non-integer as a parameter.

22 The wavelength of a sin wave is the distance from one peak to another. The amplitude is the height of the wave. Amplitude and Frequency (Sin Wave)

23 The red spots indicate the random values defined along the dimension of the function. In this case, the amplitude is the difference between the minimum and maximum values the function could have. The wavelength is the distance from one red spot to the next. Amplitude and Frequency (Noise Wave)

24 The red spots indicate the random values defined along the dimension of the function. In this case, the amplitude is the difference between the minimum and maximum values the function could have. The wavelength is the distance from one red spot to the next. Amplitude and Frequency (Noise Wave)

25 (1-D) Perlin Noise Function : Get lots of such smooth functions, with various frequencies and amplitudes

26 (1-D) Perlin Noise Function : Get lots of such smooth functions, with various frequencies and amplitudes Add them all together to create a nice noisy function + ++ ++=

27 1D Noise Example Deposit random values at integer locations Interpolate through values to get continuous function Sample function at pixel centers 9…1011 121314…

28 1D Noise Example Sample too frequently - no randomness

29 1D Noise Example Sample too sparsely - no continuity

30 Turbulence Add multiple frequencies together Each component similar under scale Fractal e.g. coastline As frequency goes up, amplitude goes down

31 1D Turbulence Example

32

33

34

35

36

37

38

39 (2-D) Perlin Noise Function

40 + ++ ++=

41 Noise Frequency and Amplitude We can change them to vary the nature of the noise. We can vary the effect of the noise by using the expression noise(f*x, f*y, f*z) * a where f controls the frequency and a controls the amplitude. Noise having large amplitudes will result in a greater range of colors. Noise having high frequency will contain more detail. noise(x,y,z)

42 Noise Creation We begin with a noise function

43 Noise Creation We add the same noise function with twice the frequency and half the amplitude

44 Noise Creation The sum of the noise in the second picture plus the noise function with four times the frequency and a quarter of the amplitude.

45 Noise Creation We can continue adding noise of higher and higher frequency until the frequency is so high that something as large as a pixel won’t be able to record it.

46 Noise Creation

47 QUESTION: what amplitude and frequency to use for each one? The 1-D example used twice the frequency and half the amplitude for each successive noise function added. You can create Perlin Noise functions with different characteristics by using other frequencies and amplitudes at each step. –Smooth rolling hills,  large amplitudes for the low frequencies, and very small amplitudes for the higher frequencies. –Very rocky plane  low amplitudes for low frequencies.

48 Persistence Let’s make it simple! Persistence: single number to specify the amplitude of each frequency frequency = 2 i amplitude = persistence i the i th noise function being added

49 the i th noise function being added: 0 1 2 3 4 5 frequency = 2 i amplitude = persistence i

50 Octaves Each successive noise function you add is known as an octave. The reason for this is that each noise function is twice the frequency of the previous one. In music, octaves also have this property.

51 Here is a graph showing an example noise function. A random value between 0 and 1 is assigned to every point on the X axis.

52 By smoothly interpolating between the values, we can define a continuous function that takes a non-integer as a parameter.

53 Let’s make some Noise Functions function IntNoise(32-bit integer: x) x = (x<<13) ^ x; return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0); end IntNoise function a noise function = parameterized random number generator

54 Let’s make some Noise Functions Having created your noise function, you will need to smooth out the values it returns.

55 Linear Interpolation function Linear_Interpolate(a, b, x) return a*(1-x) + b*x end of function three inputs, a and b, the values to be interpolated between, and x which takes a value between 0 and 1

56 Cosine Interpolation function Cosine_Interpolate(a, b, x) ft = x * 3.1415927 f = (1 - cos(ft)) *.5 return a*(1-f) + b*f end of function

57 Cubic Interpolation function Cubic_Interpolate(v0, v1, v2, v3,x) P = (v3 - v2) - (v0 - v1) Q = (v0 - v1) - P R = v2 - v0 S = v1 return Px 3 + Qx 2 + Rx + S end of function

58 Smoothed Noise 1-dimensional Smooth Noise (gray curve) 2-dimensional Smooth Noise (right image)

59 1-D Smooth Noise function Noise(x). end function function SmoothNoise_1D(x) return Noise(x)/2 + Noise(x-1)/4 + Noise(x+1)/4 end function

60 2-D Smooth Noise function Noise(x). end function function SmoothNoise_2D(x) corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16 sides = ( Noise(x-1, y) +Noise(x+1, y) +Noise(x, y-1) +Noise(x, y+1) ) / 8 center = Noise(x, y) / 4 return corners + sides + center end function

61 Putting it all together : 1-dimensional Perlin Noise Pseudo code function Noise1 (integer x) x = (x<<13) ^ x; return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0); end function function SmoothedNoise_1 (float x) return Noise(x)/2 + Noise(x-1)/4 + Noise(x+1)/4 end function function InterpolatedNoise_1 (float x) integer_X = int(x) fractional_X = x - integer_X v1 = SmoothedNoise1(integer_X) v2 = SmoothedNoise1(integer_X + 1) return Interpolate(v1, v2, fractional_X) end function

62 Putting it all together : 1-dimensional Perlin Noise Pseudo code … function PerlinNoise_1D (float x) total = 0 p = persistence n = Number_Of_Octaves - 1 loop i from 0 to n frequency = 2 i amplitude = p i total = total + InterpolatedNoise_1(x * frequency) * amplitude end of i loop return total end function

63 Putting it all together : 2-dimensional Perlin Noise Pseudo code function Noise2 (integer x, integer y) n = x + y * 57 n = (n<<13) ^ n; return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0); end function function SmoothNoise_2 (float x, float y) corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16 sides = ( Noise(x-1, y) +Noise(x+1, y) +Noise(x, y-1) +Noise(x, y+1) ) / 8 center = Noise(x, y) / 4 return corners + sides + center end function function InterpolatedNoise_2 (float x, float y) integer_X = int(x) fractional_X = x - integer_X integer_Y = int(y) fractional_Y = y - integer_Y v1 = SmoothedNoise2(integer_X, integer_Y) v2 = SmoothedNoise2(integer_X + 1, integer_Y) v3 = SmoothedNoise2(integer_X, integer_Y + 1) v4 = SmoothedNoise2(integer_X + 1, integer_Y + 1) i1 = Interpolate(v1, v2, fractional_X) i2 = Interpolate(v3, v4, fractional_X) return Interpolate(i1, i2, fractional_Y) end function

64 Putting it all together : 2-dimensional Perlin Noise Pseudo code … function PerlinNoise_2D (float x, float y) total = 0 p = persistence n = Number_Of_Octaves - 1 loop i from 0 to n frequency = 2i amplitude = pi total = total + InterpolatedNoise2(x * frequency, y * frequency) * amplitude end of i loop return total end function

65 (Some) Applications of 1-D Perlin Noise Controlling virtual beings –to constantly adjust the joint positions of a virtual human player, in a game for example, to make it look like it's more alive. Drawing sketched lines –to introduce a waviness to a line drawing algorithm to make it appear as if it's been drawn by hand.

66 (Some) Applications of Perlin Noise 1-D –Controlling virtual beings –Drawing sketched lines 2-D –Landscapes –Clouds –Textures 3-D –3D Clouds –Solid Textures 4-D –Animated 3D Textures and Clouds

67 Noise Functions Desirable properties (Perlin, 1985): –known range –stationary –band limited –isotropic Lattice noise has these desirable properties

68 3D Noise  Lattice Noise It stores a number from the random number generator at each integer lattice point in a 3D array. If a point from the object happens to have integer coordinates, a lattice noise function does a table lookup to find the value to return. If the object’s point has non-integer values, the function uses trilinear interpolation to determine the returned value.

69 Gradient Noise Generates random unit vectors for each integer lattice point, and uses interpolation to find values for non- integer coordinates.

70 3D Noise (x,y,z) Visible point from surface of object Texture value from 3D table or procedure Need controlled randomness => varying but continuous function

71 Integer Lattice Deposit random values at integer grid points Use 256x256x256 volume

72 Interpolate values within cube d110 d000 d100 d010 d001 d101 d111 d011 fx = FRACT(x) fy = FRACT(y) fz = FRACT(z) d00 = d000+fx(d100-d000) d10 = d010+fx(d110-d010) d01 = d001+fx(d101-d001) d11 = d011+fx(d111-d011) Use tri-linear interpolation (x,y,z) d = d0+fz(d1-d0) d0 = d00+fy(d10-d00) d1 = d01+fy(d11-d01)

73 Noise, Turbulence, Marble NoiseTable[256]: random values [0, 1] Index[256]: random permutation of values 0:255 #define PERM(x) index[x & 255] #define INDEX(ix,iy,iz) PERM( ix + PERM(iy + PREM(iz))) Float latticeNoise(i,j,k) Return NoiseTable[INDEX(i,j,k)]

74 Turbulence Turb(s,x,y,z) = (1/2)  1/2 k ) noise(2 k,x,y,z) Noise(s,x,y,z) Scale point by s, add 1000 Get integer (ix,iy,iz) and fractional parts (fx,fy,fz) Get cell lattice noise values d000,d001,d010,d011, d100,d101,d110,d111 Do the trilinear interpolation by fx,fy,fz

75 Noise Maxima and Minima In lattice noise, always occur at regularly-spaced intervals, since it first fixes values to the (integer) positions of the lattice and interpolates to obtain intermediate values. The regularity of these maxima and minima can be noticeable to an observer, as demonstrated in this slide. Gradient noise does not suffer from this problem.

76 Texture Generation using 3D Perlin Noise Standard 3 dimensional Perlin noise 4 octaves, persistence 0.25 and 0.5

77 Texture Generation using 3D Perlin Noise Low persistence.

78 Texture Generation using 3D Perlin Noise Mixing several Perlin functions. A Perlin function with low persistence was used to define the shape of the blobs. The value of this function was used to select from two other functions, one of which defined the stripes, the other defined the blotchy pattern. The stripes were defined by multiplying the first Perlin Function by some number (about 20) then taking the cosine.

79 Texture Generation using 3D Perlin Noise A marble texture can be made by using a Perlin function as an offset to a cosine function. texture = cosine( x + perlin(x,y,z) )

80

81 Texture Generation using 3D Perlin Noise Very nice wood textures can be defined. The grain is defined with a low persistence function like this: g = perlin(x,y,z) * 20 grain = g - int(g) The very fine bumps you can see on the wood are high frequency noise that has been stretched in one dimension. bumps = perlin(x*50, y*50, z*20) if bumps <.5 then bumps = 0 else bumps = 1t

82

83 Black-and-white spotted teapot gray = noise(x,y,z) if(gray > threshold) choose white else choose black

84 Marble Perturbing stripes

85 Psychedelic Teaopot by perturbing a "pinwheel texture" to produce an index into a color table.

86 Wood-grained Object By using noise to vary the ring shape and the inter-ring distance, we can create reasonably realistic wood.

87 Iridescence Effect by combining the color from a color table with the object’s original color. Adding noise to perturb the color table lookup creates a mother-of-pearl effect.

88 Procedural functions for geometry Volume density functions describe the geometry of gases and are similar to solid texturing procedures in that they take a point in three- dimensional space as input and return a value. Instead of returning a color, they return a density value. The cloud in this image is a procedurally altered metaball created by David Ebert.

89 This still is from the movie "Getting Into Art", by David Ebert and displays another example another example of a volume density function.

90 noise sin(x + sum 1/f( |noise| )) sum 1/f(noise) sum 1/f( |noise| )

91 noise

92 sum 1/f(noise)

93 sum 1/f( |noise|)

94 sin(x + sum 1/f( |noise| ))

95 Flame: noise scales in x,y, translates in z

96 Clouds: noise translates in x and z

97 Clouds without 1/f(|noise|):


Download ppt "Part II – Photorealistic Rendering (1) Texture (4) CPSC 591/691."

Similar presentations


Ads by Google