University of British Columbia News Review: Basic OpenGL Texturing Review: Reconstruction CPSC 314 Computer Graphics • signup sheet for P3 grading • setup • how to deal with: Jan-Apr 2010 • generate identifier: glGenTextures • pixels that are much larger than texels? • Mon/today/Fri signups in class • load image data: glTexImage2D Tamara Munzner • apply filtering, “averaging” • or send email to dingkai AT cs • set texture parameters (tile/clamp/...): glTexParameteri • set texture drawing mode (modulate/replace/...): glTexEnvf • by 48 hours after the due date or you'll lose • drawing marks Textures III • enable: glEnable • pixels that are much smaller than texels ? • bind specific texture: glBindTexture • interpolate • (P4 went out Monday) • specify texture coordinates before each vertex: glTexCoord2f Week 10, Wed Mar 24 http://www.ugrad.cs.ubc.ca/~cs314/Vjan2010 2 3 4 Review: MIPmapping Texture Parameters Bump Mapping: Normals As Texture Bump Mapping • image pyramid, precompute averaged versions • in addition to color can control other • object surface often not smooth – to recreate correctly need complex geometry model material/object properties • can control shape “effect” by locally perturbing surface • surface normal (bump mapping) normal • reflected color (environment mapping) • random perturbation • directional change over region Without MIP-mapping Without MIP-mapping 5 6 7 8 With MIP-mapping With MIP-mapping Bump Mapping Embossing Displacement Mapping Environment Mapping • at transitions • bump mapping gets • cheap way to achieve reflective effect silhouettes wrong • rotate point’s surface normal by θ or - θ • generate image of surrounding • shadows wrong too • map to object as texture • change surface geometry instead • only recently available with realtime graphics • need to subdivide surface 9 10 11 12 Environment Mapping Sphere Mapping Cube Mapping Cube Mapping F • used to model object that reflects • texture is distorted fish-eye view • 6 planar textures, sides of cube surrounding textures to the eye • point camera at mirrored sphere • point camera in 6 different directions, facing • spherical texture mapping creates texture coordinates that • movie example: cyborg in Terminator 2 out from origin correctly index into this texture map • different approaches • sphere, cube most popular A • OpenGL support C • GL_SPHERE_MAP, GL_CUBE_MAP B • others possible too E D 13 14 15 16
Volumetric Texture Principles Cube Mapping Volumetric Texture Volumetric Bump Mapping • define texture pattern over 3D • direction of reflection vector r selects the face of the cube to • 3D function ρ ( x,y,z) Marble be indexed domain - 3D space containing • texture space – 3D space that holds the the object • co-ordinate with largest magnitude texture (discrete or continuous) • e.g., the vector (-0.2, 0.5, -0.84) selects the –Z face • texture function can be digitized or procedural • rendering: for each rendered point P(x,y,z) • remaining two coordinates (normalized by the 3 rd coordinate) • for each point on object compute ρ ( x,y,z) selects the pixel from the face. compute texture from point • e.g., (-0.2, 0.5) gets mapped to (0.38, 0.80). location in space • volumetric texture mapping function/space • common for natural transformed with objects • difficulty in interpolating across faces material/irregular textures Bump (stone, wood,etc…) 17 18 19 20 Procedural Texture Effects: Bombing Procedural Texture Effects Procedural Textures • generate “image” on the fly, instead of • randomly drop bombs of various shapes, sizes and • simple marble orientation into texture space (store data in table) loading from disk • for point P search table and determine if inside shape • often saves space • if so, color by shape function boring_marble(point) • allows arbitrary level of detail • otherwise, color by objects color x = point.x; Procedural Approaches return marble_color(sin(x)); // marble_color maps scalars to colors 21 22 23 24 Perlin Noise: Procedural Textures Perlin Noise: Coherency Perlin Noise: Turbulence Perlin Noise: Turbulence • several good explanations • smooth not abrupt changes • multiple feature sizes • multiple feature sizes • FCG Section 10.1 • add scaled copies of noise • add scaled copies of noise • http://www.noisemachine.com/talk1 coherent white noise • 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/ 25 26 27 28 Perlin Noise: Turbulence Generating Coherent Noise Interpolating Textures Vector Offsets From Grid • multiple feature sizes • just three main ideas • nearest neighbor • weighted average of gradients • add scaled copies of noise • nice interpolation • bilinear • random unit vectors • use vector offsets to make grid irregular • hermite function turbulence(p) • optimization t = 0; scale = 1; • sneaky use of 1D arrays instead of 2D/3D one while (scale > pixelsize) { t += abs(Noise(p/scale)*scale); scale/=2; } return t; 29 30 31 32
Optimization Perlin Marble Procedural Modeling Fractal Landscapes • use turbulence, which in turn uses noise: • save memory and time • textures, geometry • fractals: not just for “showing math” function marble(point) • conceptually: • nonprocedural: explicitly stored in memory • triangle subdivision • 2D or 3D grid x = point.x + turbulence(point); • vertex displacement • populate with random number generator return marble_color(sin(x)) • procedural approach • actually: • recursive until termination condition • compute something on the fly • precompute two 1D arrays of size n (typical size 256) • random unit vectors • often less memory cost • permutation of integers 0 to n-1 • visual richness • lookup • g ( i , j , k ) = G [ ( i + P [ ( j + P [ k ]) mod n ] ) mod n ] • fractals, particle systems, noise http://www.fractal-landscapes.co.uk/images.html 33 34 35 36 Self-Similarity Fractal Dimension Language-Based Generation 1D: Midpoint Displacement • D = log(N)/log(r) • infinite nesting of structure on all scales • L-Systems: after Lindenmayer • divide in half N = measure, r = subdivision scale • Koch snowflake: F :- FLFRRFLF • randomly displace • Hausdorff dimension: noninteger • F: forward, R: right, L: left • scale variance by half Koch snowflake coastline of Britain • Mariano’s Bush: F=FF-[-F+F+F]+[+F-F-F] } • angle 16 D = log(N)/log(r) D = log(4)/log(3) = 1.26 http://spanky.triumf.ca/www/fractint/lsys/plants.html http://www.gameprogrammer.com/fractal.html http://www.vanderbilt.edu/AnS/psychology/cogsci/chaos/workshop/Fractals.html 37 38 39 40 2D: Diamond-Square Particle Systems Particle System Examples Particle Systems Demos • fractal terrain with diamond-square approach • loosely defined • objects changing fluidly over time • general particle systems • fire, steam, smoke, water • generate a new value at midpoint • modeling, or rendering, or animation • http://www.wondertouch.com • objects fluid in form • average corner values + random displacement • key criteria • grass, hair, dust • scale variance by half each time • collection of particles • physical processes • boids: bird-like objects • random element controls attributes • waterfalls, fireworks, explosions • http://www.red3d.com/cwr/boids/ • position, velocity (speed and direction), color, • group dynamics: behavioral lifetime, age, shape, size, transparency • birds/bats flock, fish school, human crowd, dinosaur/elephant stampede • predefined stochastic limits: bounds, variance, type of distribution 41 42 43 44 Particle Life Cycle Particle System Rendering Procedural Approaches Summary • generation • expensive to render thousands of particles • Perlin noise • randomly within “fuzzy” location • simplify: avoid hidden surface calculations • fractals • initial attribute values: random or fixed • each particle has small graphical primitive • L-systems • dynamics (blob) • attributes of each particle may vary over time • particle systems • pixel color: sum of all particles mapping to it • color darker as particle cools off after explosion • can also depend on other attributes • some effects easy • position: previous particle position + velocity + time • not at all a complete list! • temporal anti-aliasing (motion blur) • death • normally expensive: supersampling over time • big subject: entire classes on this alone • age and lifetime for each particle (in frames) • position, velocity known for each particle • or if out of bounds, too dark to see, etc • just render as streak 45 46 47
Recommend
More recommend