cs130 : computer graphics - ucr · [wikipedia] color representation. alpha channel. graphics...

43
CS130 : Computer Graphics Tamar Shinar Computer Science & Engineering UC Riverside

Upload: others

Post on 20-Mar-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

CS130 : Computer Graphics

Tamar ShinarComputer Science & Engineering

UC Riverside

Page 2: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Raster Devices and Images

Page 3: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Raster Devices

Page 4: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Raster Display

Hearn, Baker, Carithers

Page 5: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Transmissive vs. Emissive Display

[H&

B, Fig. 2-16]

+_

ON ONOFF

LEDs

anode

cathodes

LCD LED

Page 6: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Raster Display

red, green, blue subpixels

Page 7: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

What is an image?

Continuous image

Page 8: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Raster Image

A raster image is 2D array storing pixel values at each pixel

Page 9: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

What is an image?

Raster image

= number of columns

= number of rows

Each pixel value represents the average color of the image over that pixel’s area.

Page 10: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

What is an image?

Raster image

= number of columns

= number of rows

Each pixel value represents the average color of the image over that pixel’s area.

Page 11: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

RGB CMYK

Color Representation

Page 12: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

sRGB color triangle comparison of color gamuts

[wikipedia]

Color Representation

Page 13: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)
Page 14: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Alpha Channel

Page 15: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Graphics Pipeline

Page 16: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Modern graphics system[A

ngel and Shreiner]

Page 17: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

17

Z-buffer Rendering

•Z-buffering is very common approach, also often accelerated with hardware

•OpenGL is based on this approach

3D Polygons Image PixelsGRAPHICS PIPELINE

Page 18: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Choice of primitives

• Which primitives should an API contain?

• small set - supported by hardware, or

• lots of primitives - convenient for user

Page 19: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Choice of primitives

• Which primitives should an API contain?

➡small set - supported by hardware

• lots of primitives - convenient for user

Page 20: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Choice of primitives

• Which primitives should an API contain?

➡small set - supported by hardware

• lots of primitives - convenient for user

Performance is in 10s millions polygons/secportability, hardware support key

Page 21: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Choice of primitives

• Which primitives should an API contain?

➡small set - supported by hardware

• lots of primitives - convenient for user

GPUs are optimized for points, lines, and triangles

Page 22: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Choice of primitives

Other geometric shapes will be built out of these

• Which primitives should an API contain?

➡small set - supported by hardware

• lots of primitives - convenient for user

GPUs are optimized for points, lines, and triangles

Page 23: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Two classes of primitives [A

ngel and Shreiner]

Geometric : points, lines, polygonsImage : arrays of pixels

ff

Page 24: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Point and line segment types [A

ngel and Shreiner]

Page 25: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Polygons• Multi-sided planar element composed of edges and

vertices.• Vertices (singular: vertex) are represented by points • Edges connect vertices as line segments

E1

E3 E2

(x1,y1)

(x2,y2)

(x3,y3)

Page 26: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Valid polygons

• Simple

• Convex

• Flat

Page 27: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Valid polygons

• Simple

• Convex

• Flat

Page 28: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

OpenGL polygons

• Only triangles are supported (in latest versions)

GL_POINTS GL_TRIANGLES

GL_TRIANGLE_STRIP

GL_TRIANGLE_FAN

Page 29: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Other polygons

triangulation

Page 30: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Graphics Pipeline[A

ngel and Shreiner]

ff

Page 31: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Pipelining operations

* +ba

c

An arithmetic pipeline that computes c+(a*b)

Page 32: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

3D graphics pipeline

Vertex processor

Clipper and primitive assembler

RasterizerFragment processor

Vertices Pixels

Geometry: primitives - made of verticesVertex processing: coordinate transformations and colorClipping and primitive assembly: output is a set of primitivesRasterization: output is a set of fragments for each primitiveFragment processing: update pixels in the frame buffer

Page 33: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Graphics Pipeline (slides courtesy K. Fatahalian)

Page 34: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Vertex processing

v0

v1

v2

v3

v4

v5

Vertices

Vertices are transformed into “screen space”

Vertex processor

Clipper and primitive assembler

RasterizerFragment processor

Vertices Pixels

Page 35: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Vertex processing

v0

v1

v2

v3

v4

v5

Vertices

Vertices are transformed into “screen space”

EACH VERTEX IS TRANSFORMED

INDEPENDENTLY

Vertex processor

Clipper and primitive assembler

RasterizerFragment processor

Vertices Pixels

Page 36: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Primitive processing

v0

v1

v2

v3

v4

v5

Vertices

v0

v1

v2

v3

v4

v5

Primitives (triangles)

Then organized into primitives that are clipped and culled…

Vertex processor

Clipper and primitive assembler

RasterizerFragment processor

Vertices Pixels

Page 37: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Rasterization

Primitives are rasterized into “pixel fragments”

Fragments

Vertex processor

Clipper and primitive assembler

RasterizerFragment processor

Vertices Pixels

Page 38: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Vertex processor

Clipper and primitive assembler

RasterizerFragment processor

Vertices Pixels

Rasterization

Primitives are rasterized into “pixel fragments”

EACH PRIMITIVE IS RASTERIZED INDEPENDENTLY

Page 39: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Fragment processing

Shaded fragments

Fragments are shaded to compute a color at each pixel

Vertex processor

Clipper and primitive assembler

RasterizerFragment processor

Vertices Pixels

Page 40: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Vertex processor

Clipper and primitive assembler

RasterizerFragment processor

Vertices Pixels

Fragment processing

EACH FRAGMENT IS PROCESSED INDEPENDENTLY

Fragments are shaded to compute a color at each pixel

Page 41: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Pixel operations

Pixels

Fragments are blended into the frame buffer at their pixel locations (z-buffer determines visibility)

Page 42: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Pipeline entities

v0

v1

v2

v3

v4

v5 v0

v1

v2

v3

v4

v5

Vertices Primitives Fragments

Pixels Fragments (shaded)

Page 43: CS130 : Computer Graphics - UCR · [wikipedia] Color Representation. Alpha Channel. Graphics Pipeline. Modern graphics system ner] 17 ... An arithmetic pipeline that computes c+(a*b)

Graphics pipeline

Primitive Generation

Vertex Generation

Vertex Processing

Fragment Generation

Fragment Processing

Pixel Operations

Fixed-function

Programmable

Memory Buffers Vertex Data Buffers

Textures

Output image (pixels)

Textures

Textures

Primitive Processing

Vertex stream

Vertex stream

Primitive stream

Primitive stream

Fragment stream

Fragment stream

Vertices

Primitives

Fragments

Pixels