photorealism
play

Photorealism Steve Ash, Rhodes College 2006 T exture Mapping = - PowerPoint PPT Presentation

Photorealism Steve Ash, Rhodes College 2006 T exture Mapping = + = + T exture Mapping C(i, j) P(x, y, z) = + Given the intersection point P between the sphere and ray R , map the Cartesian coordinates ( x, y, z ) of P to ( u, v )


  1. Photorealism Steve Ash, Rhodes College 2006

  2. T exture Mapping = + = +

  3. T exture Mapping C(i, j) P(x, y, z) = + Given the intersection point P between the sphere and ray R , map the Cartesian coordinates ( x, y, z ) of P to ( u, v ) coordinates in the image to pick a color

  4. T exture Mapping C(i, j) P(x, y, z) = + Given the intersection point P between the sphere and ray R , map the Cartesian coordinates ( x, y, z ) of P to ( u, v ) coordinates in the image to pick a color

  5. Polar Coordinates A point in the plane can be described by ( x, y ) coordinates – Cartesian coordinates ( r, θ ) coordinates – Polar coordinates image source: http://en.wikipedia.org/wiki/File:Polar_to_cartesian.svg

  6. Polar => Cartesian Given the ( r, θ ) polar coordinates what are the ( x, y ) Cartesian coordinates x = r cosθ y = r sinθ image source: http://en.wikipedia.org/wiki/File:Polar_to_cartesian.svg

  7. Cartesian => Polar Given the ( x, y ) Cartesian coordinates what are the ( r, θ ) Polar coordinates r = sqrt( x 2 + y 2 ) θ = atan( y / x ) image source: http://en.wikipedia.org/wiki/File:Polar_to_cartesian.svg

  8. Spherical Coordinates A point in 3D space can be described by ( x, y, z ) coordinates – Cartesian coordinates ( r, θ, φ ) coordinates – Spherical coordinates (θ, φ – latitude, longitude) y N U r V ϕ y z x θ x z image source: http://en.wikipedia.org/wiki/File:Coord_system_SZ_0.svg

  9. Spherical => Cartesian Given the ( r, θ, φ ) spherical coordinates what are the ( x, y, z ) Cartesian coordinates x = r sin φ sinθ (based on the second diagram) y = r cos φ z = r sin φ cosθ y N U r V ϕ y z x θ x z image source: http://en.wikipedia.org/wiki/File:Coord_system_SZ_0.svg

  10. Spherical => Cartesian Given the ( x, y, z ) Cartesian coordinates what are the ( r, θ, φ ) Spherical coordinates r = sqrt ( x 2 + y 2 + z 2 ) θ = atan ( x / z ) use C function atan2 ( a, b ) – range is [-π .. π] φ = acos ( y / r ) use C function acos ( a ) – range is [0 .. π] In the context of the ray-tracer the assumption is P ( x, y, z ) is on a sphere centered at the origin – for a sphere not centered at the origin correct the coordinates of P y N U r V ϕ y z x θ x z image source: http://en.wikipedia.org/wiki/File:Coord_system_SZ_0.svg

  11. T exture Mapping C(i, j) P(x, y, z) = + Given the intersection point P between the sphere and ray R , map the Cartesian coordinates ( x, y, z ) of P to ( u, v ) coordinates in the image to pick a color correct (x, y, z) as if sphere is centered at origin convert the Cartesian (x, y, z) to Spherical (r, θ, φ) keep only (θ, φ) range of θ is [ -π .. π ] and of φ is [0 .. π] compute u = f(θ) and v = g(φ) so that range of u and v is [0..1] compute i = u ∙ imageWidth j = v ∙ imageHeight set color of P to color at image [ i ][ j ]

  12. T exture Mapping (Interpolation) C(i, j) P(x, y, z) = + The computed coordinates ( i, j ) will not be integers, in general. To have smooth color change, interpolate the colors of neighboring pixels. (2, 6) (3, 6) UL UR Suppose i = 2 and j = 5.5 C 1 What should we use for C 1 ? LR LL (3, 5) (2, 5)

  13. T exture Mapping (Interpolation) C(i, j) P(x, y, z) = + The computed coordinates ( i, j ) will not be integers, in general. To have smooth color change, interpolate the colors of neighboring pixels. (2, 6) (3, 6) UL UR Suppose i = 2 and j = 5.5 C 1 What should we use for C 1 ? LR LL (3, 5) (2, 5) C 1 = 0.5 ∙ image[ UL ] + 0.5 ∙ image[ LL ]

  14. T exture Mapping (Interpolation) C(i, j) P(x, y, z) = + The computed coordinates ( i, j ) will not be integers, in general. To have smooth color change, interpolate the colors of neighboring pixels. (2, 6) (3, 6) UL UR Suppose i = 2 and j = 5.7 C 1 What should we use for C 1 ? LR LL (3, 5) (2, 5)

  15. T exture Mapping (Interpolation) C(i, j) P(x, y, z) = + The computed coordinates ( i, j ) will not be integers, in general. To have smooth color change, interpolate the colors of neighboring pixels. (2, 6) (3, 6) UL UR Suppose i = 2 and j = 5.7 C 1 What should we use for C 1 ? LR LL (3, 5) (2, 5) C 1 = 0.7 ∙ image[ UL ] + 0.3 ∙ image[ LL ] C 1 = frac ∙ image[ UL ] + (1-frac) ∙ image[ LL ]

  16. T exture Mapping (Interpolation) C(i, j) P(x, y, z) = + The computed coordinates ( i, j ) will not be integers, in general. To have smooth color change, interpolate the colors of neighboring pixels. UL UR Let i 0 = i – floor(i) and i 1 = ceil(i) – i = 1 - i 0 j 1 C 1 C 2 j 0 = j – floor(j) and j 1 = ceil(j) – j = 1 - j 0 i 0 i 1 j 0 LR LL Compute C 1 = j 0 ∙ image[ UL ] + j 1 ∙ image[ LL ] C 2 = j 0 ∙ image[ UR ] + j 1 ∙ image[ LR ] C = i 0 ∙ C2 + i 1 ∙ C1

  17. T exture Mapping (Interpolation) C(i, j) P(x, y, z) = + use % for indices to wrap around The computed coordinates ( i, j ) will not be integers, in the image general. To have smooth color change, interpolate the when looking up neighbors colors of neighboring pixels. UL UR Let i 0 = i – floor(i) and i 1 = ceil(i) – i = 1 - i 0 j 1 C 1 C 2 j 0 = j – floor(j) and j 1 = ceil(j) – j = 1 - j 0 i 0 i 1 j 0 LR LL Compute C 1 = j 0 ∙ image[ UL ] + j 1 ∙ image[ LL ] C 2 = j 0 ∙ image[ UR ] + j 1 ∙ image[ LR ] C = i 0 ∙ C2 + i 1 ∙ C1

  18. Bump Mapping

  19. Bump Mapping = + = +

  20. Bump + T exture + =

  21. Bump Mapping Perturb the normal slightly before returning it – this will cause the illumination equation to compute different rays, and therefore, different shadow patterns L pert L orig N orig N pert ray P C

  22. Bump Mapping Perturbing the normal in 3D calculate vectors U, V that are perpendicular to N (i.e. tangential to sphere) N N u∙U V v∙V U U V N pert = N + u∙U + v∙V Calculating U, V, N vectors using Spherical coordinates: N = (x, y, z) = (sin φ sin θ, cos φ, sin φ cos θ) U = ∂N/ ∂θ = ( cos θ, 0, - sin θ ) V = ∂N/ ∂φ = (cos φ sin θ, -sin φ , cos φ cos θ ) All vectors are already normalized

  23. Bump Mapping Perturbing the normal in 3D calculate vectors U, V that are perpendicular to N (i.e. tangential to sphere) N N u∙U V v∙V U U V N pert = N + u∙U + v∙V The range of u, v is [-1..1] and they are calculated from the bump map using interpolation, i.e. a similar principle as in texture mapping For smoother approximation: u = (image( i + 1, j ) – image( i - 1, j )) / 2 horizontal difference v = (image( i, j + 1 ) – image( i, j - 1 )) / 2 vertical difference

  24. PPM Image Format P6 PPM type identifier 475 238 width height 255 max value per color channel r, g, b ÙÙ×ÎÖÖÙÙ×ÙÙ×ÎÖÖ... triples of rgb values (one byte per channel), Rgbrgbrgbrgbrgb... range is [0..255] -- convert to [0..1] Create a class image that stores the 2D array of colors stored in a PPM image method that loads a PPM image (see Canvas class for saving a PPM image) operator () , so that image(j, j) returns an interpolated value method that converts to grayscale – replace each pixel c(r, g, b) with c’(r’, g’, b’) where r’ = g’ = b’ = 0.299 ∙ r + 0.587 ∙ g + 0.114 ∙ b + + = texture map bump map

  25. Shapes and Decorators getMaterial Shape intersect(Ray r, Intersection i) Sphere T extureDecor BumpDecor data members: shape pointer image map An intersection object stores: t value intersection point p normal at p color at p u, v values at p (in [0..1] ) U, V vectors at p

  26. Shapes and Decorators getMaterial Shape intersect(Ray r, Intersection i) Sphere T extureDecor BumpDecor data members: shape pointer image map An intersection object stores: Sphere::intersect(Ray r, Intersection& i) { t value same as Assignment 8 intersection point p } normal at p color at p u, v values at p (in [0..1] ) U, V vectors at p

  27. Shapes and Decorators getMaterial Shape intersect(Ray r, Intersection i) Sphere T extureDecor BumpDecor data members: shape pointer image map An intersection object stores: t value intersection point p normal at p color at p u, v values at p (in [0..1] ) U, V vectors at p

  28. Shapes and Decorators getMaterial Shape intersect(Ray r, Intersection i) Sphere T extureDecor BumpDecor data members: shape pointer image map An intersection object stores: TextureDecor::intersect(Ray r, Intersection& i) { t value 1. call intersect on the shape intersection point p 2. overwrite the color with the normal at p interpolated color from the map color at p } u, v values at p (in [0..1] ) U, V vectors at p

  29. Shapes and Decorators getMaterial Shape intersect(Ray r, Intersection i) Sphere T extureDecor BumpDecor data members: shape pointer image map An intersection object stores: BumpDecor::intersect(Ray r, Intersection& i) { t value 1. call intersect on the shape intersection point p 2. overwrite the normal with the normal at p perturbed normal from the map color at p } u, v values at p (in [0..1] ) U, V vectors at p

Recommend


More recommend