16
Advanced Texturing Methods Glenn G. Chappell [email protected] U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 8, 2003

Advanced Texturing Methods Glenn G. Chappell [email protected] U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 8, 2003

Embed Size (px)

Citation preview

Advanced Texturing Methods

Glenn G. [email protected]

U. of Alaska Fairbanks

CS 381 Lecture NotesMonday, December 8, 2003

8 Dec 2003 CS 381 2

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.

8 Dec 2003 CS 381 3

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.

8 Dec 2003 CS 381 4

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.

8 Dec 2003 CS 381 5

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.

8 Dec 2003 CS 381 6

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.

8 Dec 2003 CS 381 7

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 Dec 2003 CS 381 8

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.

8 Dec 2003 CS 381 9

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).

8 Dec 2003 CS 381 10

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.7 0.2 1.0

–1.0 –0.7 0.2 1.00.7

8 Dec 2003 CS 381 11

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 …

8 Dec 2003 CS 381 12

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?

8 Dec 2003 CS 381 13

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.

8 Dec 2003 CS 381 14

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.

8 Dec 2003 CS 381 15

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.

8 Dec 2003 CS 381 16

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 … ?