textures procedural approaches sampling week 4 thu jun 2
play

Textures, Procedural Approaches, Sampling Week 4, Thu Jun 2 - PowerPoint PPT Presentation

University of British Columbia CPSC 314 Computer Graphics May-June 2005 Tamara Munzner Textures, Procedural Approaches, Sampling Week 4, Thu Jun 2 http://www.ugrad.cs.ubc.ca/~cs314/Vmay2005 Review: Picking Methods manual ray intersection


  1. Texture Coordinate Interpolation � perspective correct interpolation α , β β , γ � α α α β β γ γ γ : � barycentric coordinates of a point P in a triangle � s0 , s1 , s2 : � texture coordinates of vertices � w0 , w1 , w2 : � homogeneous coordinates of vertices (s1,t1) (x1,y1,z1,w1) (s,t)? α ⋅ + β ⋅ + γ ⋅ (s2,t2) s / w s / w s / w (α,β,γ) (α,β,γ) (α,β,γ) (α,β,γ) 0 0 1 1 2 2 = s (x2,y2,z2,w2) (s0,t0) α + β + γ / w / w / w 0 1 2 (x0,y0,z0,w0) ��

  2. Reconstruction (image courtesy of Kiriakos (image courtesy of Kiriakos Kutulakos Kutulakos, U Rochester) , U Rochester) ��

  3. Reconstruction � how to deal with: � pixels that are much larger than texels? � apply filtering, “averaging” � pixels that are much smaller than texels ? � interpolate ��

  4. MIPmapping use “ “image pyramid image pyramid” ” to to precompute precompute use averaged versions of the texture averaged versions of the texture Without MIP- Without MIP -mapping mapping store whole pyramid in store whole pyramid in single block of memory single block of memory �� With MIP- With MIP -mapping mapping

  5. MIPmaps � multum in parvo -- many things in a small place � prespecify a series of prefiltered texture maps of decreasing resolutions � requires more texture storage � avoid shimmering and flashing as objects move � gluBuild2DMipmaps � automatically constructs a family of textures from original texture size down to 1x1 without with ��

  6. MIPmap storage � only 1/3 more space required ��

  7. Texture Parameters � in addition to color can control other material/object properties � surface normal (bump mapping) � reflected color (environment mapping) ��

  8. Bump Mapping: Normals As Texture � object surface often not smooth – to recreate correctly need complex geometry model � can control shape “effect” by locally perturbing surface normal � random perturbation � directional change over region ��

  9. Bump Mapping ��

  10. Bump Mapping ��

  11. Embossing � at transitions � rotate point’s surface normal by � or - � ��

  12. Displacement Mapping � bump mapping gets silhouettes wrong � shadows wrong too � change surface geometry instead � only recently available with realtime graphics � need to subdivide surface ��

  13. Environment Mapping � cheap way to achieve reflective effect � generate image of surrounding � map to object as texture ��

  14. Environment Mapping � used to model object that reflects surrounding textures to the eye � movie example: cyborg in Terminator 2 � different approaches � sphere, cube most popular � OpenGL support � GL_SPHERE_MAP, GL_CUBE_MAP � others possible too ��

  15. Sphere Mapping � texture is distorted fish-eye view � point camera at mirrored sphere � spherical texture mapping creates texture coordinates that correctly index into this texture map ��

  16. Cube Mapping � 6 planar textures, sides of cube � point camera in 6 different directions, facing out from origin ��

  17. Cube Mapping F A C B E D ��

  18. Cube Mapping � direction of reflection vector r selects the face of the cube to be indexed � co-ordinate with largest magnitude � e.g., the vector (-0.2, 0.5, -0.84) selects the –Z face � remaining two coordinates (normalized by the 3 rd coordinate) selects the pixel from the face. � e.g., (-0.2, 0.5) gets mapped to (0.38, 0.80). � difficulty in interpolating across faces ��

  19. Blinn/Newell Latitude Mapping ��

  20. Review: Texture Objects and Binding � texture objects � texture management: switch with bind, not reloading � can prioritize textures to keep in memory � Q: what happens to textures kicked out of memory? � A: resident memory (on graphics card) vs. nonresident (on CPU) � details hidden from developers by OpenGL ��

  21. Volumetric Texture � define texture pattern over 3D domain - 3D space containing the object � texture function can be digitized or procedural � for each point on object compute texture from point location in space � common for natural material/irregular textures (stone, wood,etc…) ��

  22. Volumetric Bump Mapping Marble Bump ��

  23. Volumetric Texture Principles � 3D function ρ � ρ = ρ ( x,y,z) � texture space – 3D space that holds the texture (discrete or continuous) � rendering: for each rendered point P(x,y,z) compute ρ ( x,y,z) � volumetric texture mapping function/space transformed with objects ��

  24. Procedural Textures � generate “image” on the fly, instead of loading from disk � often saves space � allows arbitrary level of detail ��

  25. Procedural Texture Effects: Bombing � randomly drop bombs of various shapes, sizes and orientation into texture space (store data in table) � for point P search table and determine if inside shape � if so, color by shape � otherwise, color by objects color ��

  26. Procedural Texture Effects � simple marble function boring_marble(point) x = point.x; return marble_color(sin(x)); // marble_color maps scalars to colors ��

  27. Perlin Noise: Procedural Textures � several good explanations � FCG Section 10.1 � http://www.noisemachine.com/talk1 � http://freespace.virgin.net/hugo.elias/models/m_perlin.htm � http://www.robo-murito.net/code/perlin-noise-math-faq.html http://mrl.nyu.edu/~perlin/planet/ ��

  28. Perlin Noise: Coherency � smooth not abrupt changes coherent white noise ��

  29. Perlin Noise: Turbulence � multiple feature sizes � add scaled copies of noise ��

  30. Perlin Noise: Turbulence � multiple feature sizes � add scaled copies of noise ��

  31. Perlin Noise: Turbulence � multiple feature sizes � add scaled copies of noise function turbulence(p) t = 0; scale = 1; while (scale > pixelsize) { t += abs(Noise(p/scale)*scale); scale/=2; } return t; ��

  32. Generating Coherent Noise � just three main ideas � nice interpolation � use vector offsets to make grid irregular � optmization � sneaky use of 1D arrays instead of 2D/3D one ��

  33. Interpolating Textures � nearest neighbor � bilinear � hermite ��

  34. Vector Offsets From Grid � weighted average of gradients � random unit vectors ��

  35. Optimization � save memory and time � conceptually: � 2D or 3D grid � populate with random number generator � actually: � precompute two 1D arrays of size n (typical size 256) � random unit vectors � permutation of integers 0 to n-1 � lookup � g ( i , j , k ) = G [ ( i + P [ ( j + P [ k ]) mod n ] ) mod n ] ��

  36. Perlin Marble � use turbulence, which in turn uses noise: function marble(point) x = point.x + turbulence(point); return marble_color(sin(x)) ��

  37. Procedural Approaches ��

  38. Procedural Modeling � textures, geometry � nonprocedural: explicitly stored in memory � procedural approach � compute something on the fly � often less memory cost � visual richness � fractals, particle systems, noise ��

  39. Fractal Landscapes � fractals: not just for “showing math” � triangle subdivision � vertex displacement � recursive until termination condition http://www.fractal-landscapes.co.uk/images.html ��

  40. Self-Similarity � infinite nesting of structure on all scales ��

  41. Fractal Dimension � D = log(N)/log(r) N = measure, r = subdivision scale � Hausdorff dimension: noninteger Koch snowflake coastline of Britain D = log(N)/log(r) D = log(4)/log(3) = 1.26 http://www.vanderbilt.edu/AnS/psychology/cogsci/chaos/workshop/Fractals.html ��

  42. Language-Based Generation � L-Systems: after Lindenmayer � Koch snowflake: F :- FLFRRFLF � F: forward, R: right, L: left � Mariano’s Bush: F=FF-[-F+F+F]+[+F-F-F] } � angle 16 http://spanky.triumf.ca/www/fractint/lsys/plants.html ��

  43. 1D: Midpoint Displacement � divide in half � randomly displace � scale variance by half http://www.gameprogrammer.com/fractal.html ��

  44. 2D: Diamond-Square � diamond step � generate a new value at square midpoint � average corner values + random amount � gives diamonds when have multiple squares in grid � square step � generate new value at diamond midpoint � average corner values + random amount � gives squares again in grid ��

  45. Particle Systems � loosely defined � modeling, or rendering, or animation � key criteria � collection of particles � random element controls attributes � position, velocity (speed and direction), color, lifetime, age, shape, size, transparency � predefined stochastic limits: bounds, variance, type of distribution ��

  46. Particle System Examples � objects changing fluidly over time � fire, steam, smoke, water � objects fluid in form � grass, hair, dust � physical processes � waterfalls, fireworks, explosions � group dynamics: behavioral � birds/bats flock, fish school, human crowd, dinosaur/elephant stampede ��

  47. Particle Systems Demos � general particle systems � http://www.wondertouch.com � boids: bird-like objects � http://www.red3d.com/cwr/boids/ ��

  48. Particle Life Cycle � generation � randomly within “fuzzy” location � initial attribute values: random or fixed � dynamics � attributes of each particle may vary over time � color darker as particle cools off after explosion � can also depend on other attributes � position: previous particle position + velocity + time � death � age and lifetime for each particle (in frames) � or if out of bounds, too dark to see, etc ��

  49. Particle System Rendering � expensive to render thousands of particles � simplify: avoid hidden surface calculations � each particle has small graphical primitive (blob) � pixel color: sum of all particles mapping to it � some effects easy � temporal anti-aliasing (motion blur) � normally expensive: supersampling over time � position, velocity known for each particle � just render as streak ��

  50. Procedural Approaches Summary � Perlin noise � fractals � L-systems � particle systems � not at all a complete list! � big subject: entire classes on this alone ��

  51. Sampling ��

  52. Samples � most things in the real world are continuous � everything in a computer is discrete � the process of mapping a continuous function to a discrete one is called sampling � the process of mapping a discrete function to a continuous one is called reconstruction � the process of mapping a continuous variable to a discrete one is called quantization � rendering an image requires sampling and quantization � displaying an image involves reconstruction ��

  53. Line Segments � we tried to sample a line segment so it would map to a 2D raster display � we quantized the pixel values to 0 or 1 � we saw stair steps, or jaggies ��

  54. Line Segments � instead, quantize to many shades � but what sampling algorithm is used? ��

  55. Unweighted Area Sampling � shade pixels wrt area covered by thickened line � equal areas cause equal intensity, regardless of distance from pixel center to area � rough approximation formulated by dividing each pixel into a finer grid of pixels � primitive cannot affect intensity of pixel if it does not intersect the pixel ��

  56. Weighted Area Sampling � intuitively, pixel cut through the center should be more heavily weighted than one cut along corner � weighting function, W(x,y) � specifies the contribution of primitive passing through the point (x, y) from pixel center Intensity W(x,y) x ��

  57. Images � an image is a 2D function � (x, y) that specifies intensity for each point (x, y) ��

  58. Image Sampling and Reconstruction � convert continuous image to discrete set of samples � display hardware reconstructs samples into continuous image � finite sized source of light for each pixel discrete input values continuous light output ��

  59. Point Sampling an Image � simplest sampling is on a grid � sample depends solely on value at grid points ��

  60. Point Sampling � multiply sample grid by image intensity to obtain a discrete set of points, or samples. Sampling Geometry ��

  61. Sampling Errors � some objects missed entirely, others poorly sampled � could try unweighted or weighted area sampling � but how can we be sure we show everything? � need to think about entire class of solutions! ��

  62. Image As Signal � image as spatial signal � 2D raster image � discrete sampling of 2D spatial signal � 1D slice of raster image � discrete sampling of 1D spatial signal ��%����%� $���������%�����&������&������ �������� ��������������������������������� !"#�� ��

  63. Sampling Theory � how would we generate a signal like this out of simple building blocks? � theorem � any signal can be represented as an (infinite) sum of sine waves at different frequencies ��

  64. Sampling Theory in a Nutshell � terminology � bandwidth – length of repeated sequence on infinite signal � frequency – 1/bandwidth (number of repeated sequences in unit length) � example – sine wave � bandwidth = 2 π � frequency = 1/ 2 π ��

  65. Summing Waves I ��

  66. Summing Waves II � represent spatial signal as sum of sine waves (varying frequency and phase shift) � very commonly used to represent sound “spectrum” ��

  67. 1D Sampling and Reconstruction ��

  68. 1D Sampling and Reconstruction ���

Recommend


More recommend