v

7 downloads 281 Views 703KB Size Report
Pixel Footprint. When ray-tracing a pixel, we not only generate a ray through the pixel, but also two offset rays. (through the next horizontal/vertical pixels). p. (x,y).
Physically Based Rendering (600.657) Textures

Pixel Footprint When ray-tracing a pixel, we not only generate a ray through the pixel, but also two offset rays (through the next horizontal/vertical pixels).

p

(x,y)

(x+x,y+y)

Pixel Footprint When ray-tracing a pixel, we not only generate a ray through the pixel, but also two offset rays (through the next horizontal/vertical pixels). We would like to compute the foot-print of the pixel on the surface by looking p p’ at the intersection of the offset ray. (x,y)

(x+x,y+y)

Pixel Footprint When representing (u,v) textures at p, we not only store the coordinates, but also how the position of p changes as we change u and v: p p 2 , : R  R3 u v

n p

(x,y)

(x+x,y+y)

p’

Pixel Footprint When representing (u,v) textures at p, we not only store the coordinates, but also how the position of p changes as we change u and v: p p 2 , : R  R3 u v

Given a change in image plane position (x,y), we can compute the change in (u,v) coordinates:  px  px '     p  py  py '    p  p '   u z   z

p  u    v  v 

n p

(x,y)

(x+x,y+y)

p’

Pixel Footprint Things get more interesting when we consider the reflection of the scene across a specular surface. n p p’

(x,y)

(x+x,y+y)

Pixel Footprint Things get more interesting when we consider the reflection of the scene across a specular surface. Since the surface is specular n rays reflect through the normal. p p’

(x,y)

(x+x,y+y)

Pixel Footprint Things get more interesting when we consider the reflection of the scene across a specular surface. Since the surface is specular n rays reflect through the normal. p And offset rays reflect n' p’ through the offset normal. (x,y)

(x+x,y+y)

Pixel Footprint Since we know how the normal changes as a function of u and v: n n 2 , : R  R3 u v

and we computed how the (u,v) coordinates change as a function of image position: u v u v , , , :RR x x y y

we can approximate the normal at the offset n'  n 

(x,y)

n p n'

p’

(x+x,y+y)

 n u n v  n n  n u n v   y x  y     x    x y  u x v x   u y v y 

Pixel Footprint So, we can compute the reflected direction for the offset ray and intersect with the tangent plane at the point of intersection. n This gives the projection p of the pixel on the n' p’ reflected surface. (x,y)

(x+x,y+y)

Pixel Footprint So, we can compute the reflected direction for the offset ray and intersect with the tangent plane at the  point of intersection. ’ i

i

n p

“Formally”:

i 'i  o '2n' o ' , n'   o  2n o , n  o  2n' o ' , n'  n o , n





o

n'

p’

o’

(x,y)     n  n  n n   o  2  n  x  y  o  o ,  n  x (x+x,y+y) y   n o , n  x y  x y   

  n n  n n  o  2  x  y  o , n  n o , n  n o , x  y y  x y   x

   

   O 2 (x, y, o )  

Image Textures Given the information about how texture coordinates change with respect to image position: u v u v ,

,

,

x x y y

:RR

we would like to sample the texture appropriately.

Image Textures Given the information about how texture coordinates change with respect to image position: u v u v ,

,

,

x x y y

:RR

we would like to sample the texture appropriately. Specifically, we need to compute the footprint of the image pixel in the texture and average the values in the footprint.

MIPMaps We can approximate the footprint by considering the bounding square containing the footprint: u0  , u0   v0  , v0    u u v v     max  , , ,   x y x y 

(x0,y0)

 u v   ,   y y 

(u0,v0)

 u v   ,   x x 

(u0,v0)

MIPMaps We can approximate the footprint by considering the bounding square containing the footprint: u0  , u0   v0  , v0    u u v v     max , , ,   x y x y 

and then average over the  u v   ,   y y  texture values in the square. (u0,v0)

(x0,y0)

 u v   ,   x x 

(u0,v0)

MIPMaps We can approximate the footprint by considering the bounding square containing the footprint: u0  , u0   v0  , v0    u u v v     max , , ,   x y x y 

and then average over the  u v   ,   y y  texture values in the square. (u0,v0)

(x0,y0)

 u v   ,   x x 

Note that this definition of the square doesn’t have to bound the ellipse.

(u0,v0)

MIPMaps Challenge: Averaging might require too many pixels.

MIPMaps Challenge: Averaging might require too many pixels. Solution: Prefilter and sample from appropriate level in hierarchy.

MIPMaps Given change in texture pixels relative to change in image pixels, choose largest extent:  u u v v   d  max  , , ,   x  y  x  y  

l=0

l=1

l=2

MIPMaps Given change in texture pixels relative to change in image pixels, choose largest extent:  u u v v   d  max , , ,   x  y  x  y  

Find the corresponding level: l  log 2 (d )

MIPMaps Given change in texture pixels relative to change in image pixels, choose largest extent:  u u v v   d  max , , ,   x  y  x  y  

Find the corresponding level: l  log 2 (d )

Sample from the texture at level(s) l.

MIPMaps Given change in texture pixels relative to change in image pixels, choose largest extent:  u u v v   d  max , , ,   x  y  x  y  

Find the corresponding level: l  log 2 (d )

Sample from the texture at level(s) l. This might oversmooth in some directions.

MIPMaps Given change in texture pixels relative to change in image pixels, choose largest extent:  u u v v   d  max , , ,   x  y  x  y  

Find the corresponding level: l  log 2 (d )

Sample from the texture at level(s) l. This might oversmooth in some directions. The storage overhead for the whole hierarchy is only 33%.

Elliptically Weighted Average Given an image pixel (x0,y0) and corresponding texture coordinate (u0,v0), for what values of (u, v) is it true that the corresponding (x, y) is within a unit disk? (x ,y ) 0

(u0,v0)

0

Elliptically Weighted Average Given an image pixel (x0,y0) and corresponding texture coordinate (u0,v0), for what values of (u, v) is it true that the corresponding (x, y) is within a unit disk? (x ,y ) Given (x, y), the corresponding (u, v) is given by: 0

 u   u   x     v   v  x 

u   y  x    v  y  y 

(u0,v0)

0

Elliptically Weighted Average Given an image pixel (x0,y0) and corresponding texture coordinate (u0,v0), for what values of (u, v) is it true that the corresponding (x, y) is within a unit disk? (x ,y ) So the (x, y) corresponding to a given (u, v) is: 0

 u   x    x     y   v  x 

u   y  v  y 

1

 u     v 

(u0,v0)

0

Elliptically Weighted Average  u   x   x     y   v  x 

u   y  v  y 

1

 u     v 

The corresponding (x, y) is in a unit disk if and only if:  x  x y    1

(x0,y0)

 y 

(u0,v0)

Elliptically Weighted Average  u   x   x     y   v  x 

u   y  v  y 

1

 u     v 

The corresponding (x, y) is in a unit disk if and only if:  x  x y    1

(x0,y0)

 y 

 u  u v  ux   y 

v   x  v  y 

1

 u   x  v  x 

u   y  v  y 

1

 u     1  v 

(u0,v0)

Elliptically Weighted Average  u  u v  ux   y 

v   x  v  y 

1

 u   x  v  x 

u   y  v  y 

1

 u     1  v 

The corresponding (x, y) is in a unit disk if and only if: 1

 u u u   u v  xu xv uy   x x  y 

u y v y

u x v x

v u v    x y y  v v v   x y y 

(x0,y0)

 u     1  v 

(u0,v0)

Elliptically Weighted Average  u u u   u v  xu xv uy   x x  y 

u y v y

u v u v    x x y y  v v v v   x x y y 

1

 u     1  v 

The corresponding (x, y) is in a unit disk if and only if: B / 2  A  u v  B/2 C  2

1

 u     1  v 

 u v u v   u   u   v   v  , C       A       , B  2   x   y   x   y   x x y y  2

(x0,y0)

2

2

(u0,v0)

Elliptically Weighted Average  A B / 2  u v  B/2 C  2

1

 u     1  v 

 u v u v   u   u   v   v  , C       A       , B  2   x  y  x  x  y  y      x   y    2

2

2

The corresponding (x, y) is in a unit disk if and only if:

(x0,y0)

 B / 2  u   C B2    AC  u v  A  v  4  B / 2

(u0,v0)

Elliptically Weighted Average  A B / 2  u v  B/2 C 

1

 u     1  v 

2

 u v u v   u   u   v   v  , C       A       , B  2   x  y  x  x  y  y      x   y    2

2

2

The corresponding (x, y) is in a unit disk if and only if:

(x0,y0)

 B / 2  u   C B2    AC  u v  A  v  4  B / 2

C u   Av   Buv E (u , v)  1 2 AC  B / 4 2

2

(u0,v0)

Elliptically Weighted Average The corresponding (x,y) is in a unit disk if and only if: 2 2 C u   Av   Buv

E (u , v) 

AC  B / 4 2

1 (x0,y0)

(u0,v0)

Elliptically Weighted Average The corresponding (x,y) is in a unit disk if and only if: 2 2 C u   Av   Buv

E (u , v) 

AC  B / 4 2

1 (x0,y0)

Since the value of E is the square ratio of the distance of (u,v) from the origin relative to the length of the ellipse: P ( x0 , y0 ) 

 E ( u ,v ) / 2 T ( u , v ) e 

( u ,v )| E ( u u 0 ,v  v0 ) 1  E ( u ,v ) / 2

e

( u ,v )| E ( u u 0 ,v  v0 ) 1

(u0,v0)

Elliptically Weighted Average Challenge: Averaging might require too many pixels.

(x0,y0)

(u0,v0)

Elliptically Weighted Average Challenge: Averaging might require too many pixels. Solution: 1. Use the MIPMap hierarchy and average data using the level corresponding to the smaller dimension.

Elliptically Weighted Average Challenge: Averaging might require too many pixels. Solution: 1. Use the MIPMap hierarchy… 2. Cheat by pretending the smaller dimension is larger.

Elliptically Weighted Average Challenge: Averaging might require too many pixels. Solution: 1. Use the MIPMap hierarchy… 2. Cheat by pretending the smaller dimension is larger. This will cause over-smoothing along the narrower direction but will bound the total number of pixels required for averaging

Elliptically Weighted Average ~ 2 ~ ~ 2 E (u , v)  A u  B uv  Cv  1

Question: Given the equation for the ellipse how do we find the (u,v) bounds of the rectangle?

Elliptically Weighted Average ~ 2 ~ ~ 2 E (u, v)  Au  Buv  Cv  1

Answer: Lagrange multipliers.

Elliptically Weighted Average ~ 2 ~ ~ 2 E (u, v)  Au  Buv  Cv  1

Answer: Lagrange multipliers. For the u-range, we would like to find the minimum/maximum of the function:  u (u , v)  u

subject to the constraint that: E (u , v)  1

Elliptically Weighted Average ~ 2 ~ ~ 2 E (u, v)  Au  Buv  Cv  1

Answer: u (u, v)  u

This means that we must have: u (u, v)  E (u, v)

Elliptically Weighted Average ~ 2 ~ ~ 2 E (u, v)  Au  Buv  Cv  1

Answer: u (u, v)  u

This means that we must have:  u (u , v)  E (u , v)



~ ~ ~ ~ (1,0)   2 Au  Bv,2Cv  Bu



Elliptically Weighted Average ~ 2 ~ ~ 2 E (u, v)  Au  Buv  Cv  1

Answer: u (u, v)  u

This means that we must have:  u (u , v)  E (u , v)



~ ~ ~ ~ (1,0)   2 A u  B v,2Cv  B u ~ Bu ~ ~ 2Cv  B u  0  v   ~ 2C



Elliptically Weighted Average ~ 2 ~ ~ 2 E (u, v)  Au  Buv  Cv  1

Answer:

~ Bu v ~ 2C

Plugging this in gives:

~  Bu  1  E  u , ~  2C  

Elliptically Weighted Average ~ 2 ~ ~ 2 E (u, v)  Au  Buv  Cv  1

Answer:

~ Bu v ~ 2C

Plugging this in gives:

~  Bu  1  E  u, ~  2C   ~ ~ 2 ~ 2 ~  B u  ~ B u  1  A u  B u   ~   C   ~   2C   2C 

Elliptically Weighted Average ~ 2 ~ ~ 2 E (u, v)  Au  Buv  Cv  1

Answer:

~ Bu v ~ 2C

Plugging this in gives:

~  Bu  1  E  u, ~  2C   ~ ~ 2 ~ 2 ~  B u  ~ B u  1  A u  B u   ~   C   ~   2C   2C  ~ 4C u ~ ~ ~2 4 AC  B

Procedural Textures Explicitly represent the texture as a function (in 2D or 3D) and evaluate the function to get the color/height.

Procedural Textures Explicitly represent the texture as a function (in 2D or 3D) and evaluate the function to get the color/height. Examples: Perlin Noise, waves, marble, etc.

Procedural Textures Many of these functions are obtained using a base function f(x) and summing the contribution over a number of octaves: f s ( x)   w f (2 x) or i

i

i

f s ( x)   w f ( 2 x ) i

i

i

Procedural Textures Many of these functions are obtained using a base function f(x) and summing the contribution over a number of octaves: f s ( x)   w f (2 x) or i

i

i

f s ( x)   w f (2 x) i

i

If the function f(x) has well understood frequency content, we can band-limit by discarding highfrequency terms or replacing with their average.

i

Procedural Textures Note that these noise functions can either be used as the colors/heights themselves, or they can be used to noisily offset into another texture map.