Angel UNM 14 9 PDF
Angel UNM 14 9 PDF
Angel UNM 14 9 PDF
Ed Angel
Professor Emeritus of Computer Science
Founding Director, Arts, Research,
Technology and Science Laboratory
University of New Mexico
Ed Angel
Professor Emeritus of Computer Science
University of New Mexico
pixel
• HTML5 Canvas
- Default front and back color buffers
- Under control of local window system
- Physically on graphics card
• Depth buffer also on graphics card
• Stencil buffer
- Holds masks
• Most RGBA buffers 8 bits per component
• Latest are floating point (IEEE)
• Compressed or uncompressed
• Indexed or RGB
• Bit Format
- little or big endian
• WebGL (and shader-based OpenGL)
lacks most functions for packing and
unpacking
- use texture functions instead
- can implement desired functionality in fragment
shaders 10
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Deprecated Functionality
• glDrawPixels
• glCopyPixels
• glBitMap
gl.readPixels(x,y,width,height,format,type,myimage)
Ed Angel
Professor Emeritus of Computer Science
Founding Director, Arts, Research,
Technology and Science Laboratory
University of New Mexico
Ed Angel
Professor Emeritus of Computer Science
University of New Mexico
memory
source
frame buffer
(destination)
writing into the frame buffer
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 19
Writing Model
replace XOR
OR
Ed Angel
Professor Emeritus of Computer Science
Founding Director, Arts, Research,
Technology and Science Laboratory
University of New Mexico
Ed Angel
Professor Emeritus of Computer Science
University of New Mexico
• Texture Mapping
- Uses images to fill inside of polygons
• Environment (reflection mapping)
- Uses a picture of the environment for texture
maps
- Allows simulation of highly specular surfaces
• Bump mapping
- Emulates altering normal vectors during the
rendering process
Ed Angel
Professor Emeritus of Computer Science
Founding Director, Arts, Research,
Technology and Science Laboratory
University of New Mexico
Ed Angel
Professor Emeritus of Computer Science
University of New Mexico
2D image
3D surface
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 39
Coordinate Systems
• Parametric coordinates
- May be used to model curves and surfaces
• Texture coordinates
- Used to identify points in the image to be mapped
• Object or World Coordinates
- Conceptually, where the mapping takes place
• Window Coordinates
- Where the final image is really produced
parametric coordinates
texture coordinates
window coordinates
world coordinates
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 41
Mapping Functions
parametric cylinder
x = r cos 2p u
y = r sin 2pu
z = v/h
maps rectangle in u,v space to cylinder
of radius r and height h in world coordinates
s=u
t=v
x = r cos 2pu
y = r sin 2pu cos 2pv
z = r sin 2pu sin 2pv
pixel
preimage
Ed Angel
Professor Emeritus of Computer Science
Founding Director, Arts, Research,
Technology and Science Laboratory
University of New Mexico
Ed Angel
Professor Emeritus of Computer Science
University of New Mexico
z x
geometry display
t
image
s 55
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Texture Example
fragment
image texel pipeline processor
c (0.4, 0.2)
b
B C
0, 0 1, 0 s (0.8, 0.4)
var texCoord = [
vec2(0, 0),
vec2(0, 1),
vec2(1, 1),
vec2(1, 0)
];
function quad(a, b, c, d) {
pointsArray.push(vertices[a]);
colorsArray.push(vertexColors[a]);
texCoordsArray.push(texCoord[0]);
pointsArray.push(vertices[b]);
colorsArray.push(vertexColors[a]);
texCoordsArray.push(texCoord[1]);
// etc 63
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Interpolation
Ed Angel
Professor Emeritus of Computer Science
Founding Director, Arts, Research,
Technology and Science Laboratory
University of New Mexico
Ed Angel
Professor Emeritus of Computer Science
University of New Mexico
s
gl.REPEAT gl.CLAMP
texture wrapping wrapping
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 70
Magnification and
Minification
More than one texel can cover a pixel (minification) or
more than one pixel can cover a texel (magnification)
Modes determined by
gl.texParameteri( target, type, mode )
gl.texParameteri(gl.TEXTURE_2D, gl.TEXURE_MAG_FILTER,
GL_NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXURE_MIN_FILTER,
gl.LINEAR);
point linear
sampling filtering
mipmapped mipmapped
point linear
sampling filtering
• Environment Maps
- Start with image of environment through a wide
angle lens
• Can be either a real scanned image or an image created in
OpenGL
- Use this texture to generate a spherical map
- Alternative is to use a cube map
• Multitexturing
- Apply a sequence of textures through cascaded
texture units
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 76
Applying Textures
void main() {
gl_FragColor = color * texture2D( texture, texCoord );
}
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 77
Vertex Shader
var texCoord = [
vec2(0, 0),
vec2(0, 1),
vec2(1, 1),
vec2(1, 0)
];
function quad(a, b, c, d) {
pointsArray.push(vertices[a]);
colorsArray.push(vertexColors[a]);
texCoordsArray.push(texCoord[0]);
pointsArray.push(vertices[b]);
colorsArray.push(vertexColors[a]);
texCoordsArray.push(texCoord[1]);
// etc 80
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Texture Object