Download - CS230 : Computer Graphics
![Page 1: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/1.jpg)
CS230 : Computer GraphicsLecture 4
Tamar ShinarComputer Science & Engineering
UC Riverside
![Page 2: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/2.jpg)
Shadows
![Page 3: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/3.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/4.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/5.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/6.jpg)
Reflections
- Reflective_Shader subclass of Phong shader
![Page 7: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/7.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/8.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/9.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/10.jpg)
Distribution Ray Tracing
![Page 11: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/11.jpg)
Anti-aliasing[Shirley and M
arschner]
![Page 12: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/12.jpg)
Soft Shadows[Shirley and M
arschner]
![Page 13: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/13.jpg)
Soft Focus[Shirley and M
arschner]
![Page 14: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/14.jpg)
[Shirley and Marschner]
![Page 15: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/15.jpg)
Fuzzy Reflections[Shirley and M
arschner]
![Page 16: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/16.jpg)
Motion Blur
[Shirley and Marschner]
![Page 17: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/17.jpg)
Acceleration Structures
![Page 18: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/18.jpg)
Acceleration Structures[Shirley and M
arschner]
![Page 19: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/19.jpg)
Bounding boxes[Shirley and M
arschner]
![Page 20: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/20.jpg)
Uniform Spatial Partitioning[Shirley and M
arschner]
![Page 21: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/21.jpg)
Bounding Volume Hierarchy[Shirley and M
arschner]
![Page 22: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/22.jpg)
Graphics Pipeline
![Page 23: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/23.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/24.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/25.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/26.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/27.jpg)
Primitives and Attributes
![Page 28: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/28.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/29.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/30.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/31.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/32.jpg)
Two classes of primitives
Angel and Shreiner
Geometric : points, lines, polygonsImage : arrays of pixels
![Page 33: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/33.jpg)
Point and line segment types
Angel and Shreiner
![Page 34: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/34.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/35.jpg)
Valid polygons
• Simple
• Convex
• Flat
![Page 36: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/36.jpg)
Valid polygons
• Simple
• Convex
• Flat
![Page 37: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/37.jpg)
OpenGL polygons
• Only triangles are supported (in latest versions)
GL_POINTS GL_TRIANGLES
GL_TRIANGLE_STRIP
GL_TRIANGLE_FAN
![Page 38: CS230 : Computer Graphics](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/38.jpg)
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](https://reader031.vdocuments.site/reader031/viewer/2022012415/61703eef44a15d5be40f4c08/html5/thumbnails/39.jpg)
Sample attributes
• Color glClearColor(1.0, 1.0, 1.0, 1.0);
• Point size glPointSize(2.0);
• Line width glLineWidth(3.0);