Download presentation
Presentation is loading. Please wait.
Published byHortense Gallagher Modified over 9 years ago
1
Advanced Texturing Methods Glenn G. Chappell CHAPPELLG@member.ams.org U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 8, 2003
2
8 Dec 2003CS 3812 Review: Quick & Dirty Texture Generation An easy way to generate a small texture is to begin with a string array, then turn map characters into colors somehow. For an example, see qdtexture.cpp, on the web page.
3
8 Dec 2003CS 3813 Review: Procedural Texture [1/6] Often, the trickiest part of texture mapping is generating the texture image. Possible sources: External images. From photographs, various graphics programs. Reading the frame buffer. Use glReadPixels. Program-generated texture. This is what we look at now. Texture generated “from scratch” by a program is called procedural texture. We look at a technique for procedural-texture generation pioneered by Ken Perlin of New York University.
4
8 Dec 2003CS 3814 Review: Procedural Texture [2/6] Perlin’s idea is to begin with a special “noise” function. Properties: Easy to generate. Random-ish looking. All variation is at about the same scale. All variation has about the same amplitude. Highest, lowest, and average values are about the same for all parts of the image.
5
8 Dec 2003CS 3815 Review: Procedural Texture [3/6] One type of noise we would like to be able to use is 1/f- noise. All frequencies present, with amplitudes proportional to the inverse of the frequency. So “the height of a hill is proportional to its width”. 1/f-noise is the way the real world looks. But it’s a pain to generate. Perlin suggests simulating 1/f-noise: Sum many copies of his noise function, each at twice the frequency and half the amplitude of the previous.
6
8 Dec 2003CS 3816 Review: Procedural Texture [4/6] Another idea of Perlin: “noise with cusps”. Sum as before, but take the absolute value of each noise function before summing them all. Good for cloudy- looking things.
7
8 Dec 2003CS 3817 Review: Procedural Texture [5/6] Perlin’s technique is aimed at 3-D textures. Here we can make objects appear to be cut out of a 3- D block of material. Essentially, let the texture coordinates be the same as the vertex coordinates. Unfortunately, OpenGL 1.1 (which most of us seem to have) does not support 3-D texturing in a system-independent manner. However, we can use Perlin’s techniques to generate 2-D texture simply by taking a slice of a 3-D noise function.
8
8 Dec 2003CS 3818 Review: Procedural Texture [6/6] I have created a package (“Pnoise”) to create a minor variation on Perlin’s noise function. Major differences: His is entirely deterministic. I use an externally seeded pseudo-random number generator. I produce noise functions that “wrap”. The images on the previous slides were generated by my code, not Perlin’s. Specifically: pnoise3d( … ), fnoise3d( … ), filterfnoise3d( …, pnoise_abs). See proctexture.cpp for sample code.
9
8 Dec 2003CS 3819 More on Procedural Texture: Producing Colors [1/2] One piece remains in order to produce interesting procedural textures: Convert a noise function into an image. We need to be able to map noise values (in [–1,1]) to colors (RGB).
10
8 Dec 2003CS 38110 More on Procedural Texture: Producing Colors [2/2] One versatile method: Choose colors for specified values in [–1,1]. Then determine the color associated with a value by lirping between the two nearest specified values. EXAMPLE TIME. –1.0–0.70.21.0 –1.0–0.70.21.00.7
11
8 Dec 2003CS 38111 More on Procedural Texture: Other Methods Other methods for generating procedural texture are possible (and are not really that difficult to come up with). For example: A particle doing a random walk and leaving behind trails of color. This technique was used to generate some of the 3-D textures used in BLUIsculpt. Think of something else …
12
8 Dec 2003CS 38112 Bump Mapping Demo Bump Mapping Like texturing, except look up normals instead of colors. Use the bump-map normal to perturb the usual surface normal. Result: bumpy-looking surface. With a smooth silhouette. Bump mapping requires per-fragment lighting. And therefore it is not well suited to the OpenGL pipeline. But bump mapping is not hard to add to a ray tracer. What do you suppose is a good way to generate a bump map?
13
8 Dec 2003CS 38113 Environment Mapping: Introduction In environment mapping, we simulate mirror-like reflection using texturing. Generate texture coordinates based on the direction that light, originating from the viewer, would reflect off the surface. Need: Viewing location (always (0,0,0) in OpenGL). Vertex coordinates. Surface normal.
14
8 Dec 2003CS 38114 Environment Mapping: Sphere Map A simple environment-mapping technique is to use a sphere map. Take the reflected light direction, add 1 to z, normalize. Use the resulting x, y as texture coordinates. The texture is a fish-eye-lens picture of the environment. E.g., see plate 21 in the red book.
15
8 Dec 2003CS 38115 Environment Mapping: Chrome Mapping Chrome mapping is a type of environment mapping in which we do not attempt to produce a realistic picture of the environment. Just make mirror-like reflections of something. Then objects look metallic, regardless of the incorrect reflections. Note: Some people would not call chrome mapping a type of environment mapping. I would. In particular, it is legal on assignment #11.
16
8 Dec 2003CS 38116 Environment Mapping: OpenGL OpenGL includes automatic texture-coordinate generation. One of the options does a sphere map. In initialization (or whereever): glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); To enable: glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); Disabling is as usual. Normals must be specified. glTexCoord * is not necessary. How to generate the texture, though … ?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.