Title: 3D Textures
13D Textures
22D Texture Maps in Ray-Tracing
- We have seen 2D texture-mapping in OpenGL.
- How do we do 2D texture mapping in ray-tracing?
- Simply generate the (s,t) texture coordinates
from the surface coordinates of the object, and
read from the texture map to get the color.
z
t
Wrapping a texture around a cylinder
t z s q/360
q
s
33D Texture Maps in Ray-Tracing
- A 2D texture map is a pattern that is pasted onto
a surface. - A 3D texture map defines a color at each 3D
coordinate (x,y,z). - 3D texture also called solid texture.
- For example, a 3D wood texture or marble texture
can be defined. - When mapped onto 3D geometry, it is as though the
3D geometry has been carved out of the wood or
marble material.
4Functional 3D Texture Definition
- Whether in 2D or 3D, the texture pattern can be
either defined by a function or by some 2D or 3D
data. - Lets try to generate some nice 3D textures
functionally. - The texture function can be generalized as f,
where f(x,y,z) (r,g,b) - In other words, given 3D coordinates, the texture
function returns a color.
5Noise and Turbulence
- Ken Perlins SIGGRAPH 85 paper An Image
Synthesizer introduces 3D texture-mapping, and
also suggests an approach to generate interesting
3D textures. - The method uses noise and turbulence.
- The noise function is a continuous function that
varies in 3D space at uniform frequency. - Simple noise function
- Create a 3D grid.
- Generate a random number at each grid point.
- Use tri-linear interpolation to get value at any
position. - Turbulence Obtained by mixing several noise
functions together - turb(s,x,y,z) noise(sx,sy,sz)/2
noise(2sx,2sy,2sz)/4 noise(4sx,4sy,4sz)/8 - where s is the scaling factor
- A more general formula for turb is
- You get the above example by setting N3, ab2
N-1
noise (sbix, sbiy, sbiz) ai1
turb(s,x,y,z) S
i0
6Noise and Turbulence
Turbulence
Noise
Scale 4
3
2 1
7Marble Texture Function
- Marble function
- marble(x,y,z) undulate(sin(z A
turb(s,x,y,z))) - where A and s are parameters the user can set to
control the appearance of the marble - The undulate function is a spline-shaped function
that the user can define
undulate(u)
u
8Wood Texture Function
- A simple wood texture with concentric rings
around the center - rings(r) ((int)r) 2
- where r sqrt(x2y2) to make rings about the
z-axis - The value of the function jumps between 0 and 1
- Next Rings of thickness M. Function jumps
between D and DA - wood(x,y,z) D A x rings(r/M)
- Next Add some wobble to the rings
- wood(x,y,z) D A x rings(r/M K sin (q/N))
- where q is the angle about the z axis, and D, A,
M, K and N are user-defined parameters to control
the appearance of the texture - Next Add a twist to the wood grain
- wood(x,y,z) D A x rings(r/M K sin (q/N
Bz)) - where B is also a user-defined parameter
93D Textures in OpenGL
- Using 3D Textures in OpenGL is a straight-forward
extension of 2D textures. - The following functions should look familiar.
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, texWidth,
texHeight, texDepth, 0, dataFormat, dataType,
volTexArray) glEnable(GL_TEXTURE_3D) glTexPara
meteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST) glTexParameteri(GL_TEXTURE_3D,
GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexCoord3f(
sCoord, tCoord, rCoord)