39
CS230 : Computer Graphics Lecture 4 Tamar Shinar Computer Science & Engineering UC Riverside

CS230 : Computer Graphics

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS230 : Computer Graphics

CS230 : Computer GraphicsLecture 4

Tamar ShinarComputer Science & Engineering

UC Riverside

Page 2: CS230 : Computer Graphics

Shadows

Page 3: CS230 : Computer Graphics

Shadows

for each pixel do compute viewing ray if ( ray hits an object with t in [0, inf] ) then compute n evaluate shading model and set pixel to that color else set pixel color to the background color

Page 4: CS230 : Computer Graphics

Shadows

for each pixel do compute viewing ray if ( ray hits an object with t in [0, inf] ) then compute n evaluate shading model and set pixel to that color else set pixel color to the background color

Page 5: CS230 : Computer Graphics

Shadows

for each pixel do compute viewing ray if ( ray hits an object with t in [0, inf] ) then compute n // e.g., phong shading for each light

add light’s ambient component compute shadow ray if ( ! shadow ray hits an object ) add light’s diffuse and specular components

else set pixel color to the background color

Page 6: CS230 : Computer Graphics

Reflections

- Reflective_Shader subclass of Phong shader

Page 7: CS230 : Computer Graphics

for each pixel do compute viewing ray if ( ray hits an object with t in [0, inf] ) then compute n evaluate shading model and set pixel to that color else set pixel color to the background color

Reflections

Page 8: CS230 : Computer Graphics

for each pixel do compute viewing ray if ( ray hits an object with t in [0, inf] ) then compute n evaluate shading model and set pixel to that color else set pixel color to the background color

Reflections

Page 9: CS230 : Computer Graphics

for each pixel do compute viewing ray pixel color = cast_ray(viewing ray)

cast_ray: if ( ray hits an object with t in [0, inf] ) then compute n return color = shade_surface else return color = to the background color

shade_surface: color = ... compute reflected ray return color = color + k * cast_ray(reflected ray)

Reflections

Page 10: CS230 : Computer Graphics

Distribution Ray Tracing

Page 11: CS230 : Computer Graphics

Anti-aliasing[Shirley and M

arschner]

Page 12: CS230 : Computer Graphics

Soft Shadows[Shirley and M

arschner]

Page 13: CS230 : Computer Graphics

Soft Focus[Shirley and M

arschner]

Page 14: CS230 : Computer Graphics

[Shirley and Marschner]

Page 15: CS230 : Computer Graphics

Fuzzy Reflections[Shirley and M

arschner]

Page 16: CS230 : Computer Graphics

Motion Blur

[Shirley and Marschner]

Page 17: CS230 : Computer Graphics

Acceleration Structures

Page 18: CS230 : Computer Graphics

Acceleration Structures[Shirley and M

arschner]

Page 19: CS230 : Computer Graphics

Bounding boxes[Shirley and M

arschner]

Page 20: CS230 : Computer Graphics

Uniform Spatial Partitioning[Shirley and M

arschner]

Page 21: CS230 : Computer Graphics

Bounding Volume Hierarchy[Shirley and M

arschner]

Page 22: CS230 : Computer Graphics

Graphics Pipeline

Page 23: CS230 : Computer Graphics

23

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 24: CS230 : Computer Graphics

Pipelining operations

* +ba

c

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

By pipelining the arithmetic operation, the throughput, or rate at which data flows through the system, has been doubledIf the pipeline had more boxes, the latency, or time it takes one datum to pass through the system, would be higherthroughput and latency must be balanced

Page 25: CS230 : Computer Graphics

3D graphics pipeline

Vertex processor

Clipper and primitive assembler

RasterizerFragment processor

Vertices Pixels

Geometry: objects - made of 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

the pipeline is best when we are doing the same operations on many data sets -- good for computer graphics!! where we process larges sets of vertices and pixels in the same manner1. Geometry: objects - made of primitives - made of vertices2. Vertex processing: coordinate transformations and color3. Clipping and primitive assembly: use clipping volume. must be primitive by primitive rather than vertex by vertex. therefore vertices must be assembled into primitives before clipping can take place. Output is a set of primitives.4. Rasterization: primitives are still in terms of vertices -- must be converted to pixels. E.g., for a triangle specificied by 3 vertices, the rasterizer must figure out which pixels in the frame buffer fill the triangle. Output is a set of fragments for each primitive. A fragment is like a potential pixel. Fragments can carry depth information used to figure out if they lie behind other fragments for a given pixel.5. Fragment processing: update pixels in the frame buffer. some fragments may not be visible. texture mapping and bump mapping. blending.

Page 26: CS230 : Computer Graphics

3D graphics pipeline

• optimized for drawing 3D triangles with shared vertices

• map 3D vertex locations to 2D screen locations

• shade triangles and draw them in back to front order using a z-buffer

• speed depends on # of triangles

• most operations on vertices can be represented using a 4D coordinate space - 3D position + homogeneous coordinate for perspective viewing

• 4x4 matrices and 4-vectors

- use varying level of detail - fewer triangles for distant objects1. construct shapes from primitives - points, lines, polygons, images, bitmaps, (mathematical descriptions of objects) - specify the model

Page 27: CS230 : Computer Graphics

Primitives and Attributes

Page 28: CS230 : Computer Graphics

Choice of primitives

• Which primitives should an API contain?

• small set - supported by hardware, or

• lots of primitives - convenient for user

Page 29: CS230 : Computer Graphics

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/sec -- portability, hardware support key

Page 30: CS230 : Computer Graphics

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 31: CS230 : Computer Graphics

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

Other geometric shapes will be built out of these

Page 32: CS230 : Computer Graphics

Two classes of primitives

Angel and Shreiner

Geometric : points, lines, polygonsImage : arrays of pixels

Page 33: CS230 : Computer Graphics

Point and line segment types

Angel and Shreiner

Page 34: CS230 : Computer Graphics

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 35: CS230 : Computer Graphics

Valid polygons

• Simple

• Convex

• Flat

Page 36: CS230 : Computer Graphics

Valid polygons

• Simple

• Convex

• Flat

Page 37: CS230 : Computer Graphics

OpenGL polygons

• Only triangles are supported (in latest versions)

GL_POINTS GL_TRIANGLES

GL_TRIANGLE_STRIP

GL_TRIANGLE_FAN

Page 38: CS230 : Computer Graphics

Other polygons

triangulation

triangulationas long as triangles are not collinear, they will be simple, flat, and convex -- easy to render

Page 39: CS230 : Computer Graphics

Sample attributes

• Color glClearColor(1.0, 1.0, 1.0, 1.0);

• Point size glPointSize(2.0);

• Line width glLineWidth(3.0);