380 likes | 612 Views
Computer Graphics CSCI 375. What do I need to know?. Familiarity with Trigonometry Analytic geometry Linear algebra Data structures OOP. Computer Graphics (& Related Areas). Graphics 3D model => 2D image Image processing Computer vision 2D image => 3D model. Applications. Movies
E N D
What do I need to know? • Familiarity with • Trigonometry • Analytic geometry • Linear algebra • Data structures • OOP
Computer Graphics (& Related Areas) • Graphics • 3D model => 2D image • Image processing • Computer vision • 2D image => 3D model
Applications • Movies • Video games • Visualization • Simulation
Image Processing • Manipulate 2D bitmaps • Applies directly to pixel grid • Color correction • Scaling • Blurring • Sharpening
Image Synthesis • Graphics deals with image synthesis • Synthesis of 2D image from 3D scene description is called rendering
Photorealistic Rendering • Indistinguishable from reality • Ray tracing
PhotorealRendering CG Choice Award Gallery: http://forums.cgsociety.org/forumdisplay.php?f=121
Non-Photorealistic Rendering • Non-photoreal rendering • artificial water colors • pencil sketches • paint brushstrokes • Scientific and medical visualization
Computer Vision • 2D images => 3D model • Aspects of AI
Animation • Sequence of images • May be generated by physical simulation • Rigid bodies • Deformable objects • Gasses, liquids • Particle effects • Character animation
Modeling • Creating 3D geometric data • 3ds Max, Maya • Procedural modeling algorithms • Digitizers and computer vision • Mesh simplification
Raster Graphics • Modern displays are raster based • Pixels and subpixels • Old style vector displays
Framebuffer • Framebuffer • Space for final image • Grid of pixels • Colors are usu. 24 bits • Depth (z) • Usu. on GPU
Primitives • Complex scenes built from simpler objects • Objects built from primitives • Point • Line • Triangle
3D Models • Collection of triangles • Each triangle stores 3 vertices • Vertex • position • color • normal
3D Models • struct Vector3 { • float x, y, z; • }; • struct Vertex { • Vector3 position; • }; • struct Triangle { • Vertex vertices[3]; • }; • class Model { • std::vector<Triangle> triangles; • };
Traditional Graphics Pipeline • Primitives processed in stages • Transformation • Lighting • Clipping • Scan conversion • Fragment processing
The Graphics Pipeline Modeling Transformations Illumination (Lighting) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion(Rasterization) Visibility / Display
The Graphics Pipeline Modeling Transformations • Primitives are processed in stages • Each stage forwards result to next stage Illumination (Lighting) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion(Rasterization) Visibility / Display
Transformation • Transformations • Rotation • Translation • Scales • Projection • Matrices
Modeling Transformations Modeling Transformations • 3D models defined in own coordinate system (object/local space) • Modeling transforms orient models within a common coordinate frame (world space) Illumination (Lighting) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion(Rasterization) Object space World space Visibility / Display
Viewing Transformation Modeling Transformations • Maps world space to eye space • Viewing position is transformed to origin & direction is oriented along some axis (usually z) Illumination (Lighting) Viewing Transformation (Perspective / Orthographic) Clipping Eye space Projection (to Screen Space) Scan Conversion(Rasterization) Visibility / Display World space
Projection Modeling Transformations • Objects are projected to 2D image place (screen space) Illumination (Lighting) Viewing Transformation (Perspective / Orthographic) Clipping NDC Screen Space Projection (to Screen Space) Scan Conversion(Rasterization) Visibility / Display
Lighting • Vertex or fragment color • Different light types • Shadows, reflections, and translucency
Lighting Modeling Transformations • Vertices lit according to material properties, surface properties (normal) and light sources • Local lighting model (diffuse, ambient, Phong, etc.) Illumination (Lighting) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion(Rasterization) Visibility / Display
Clipping • Camera and view volume • Culling • Clipping • Outputs visible primitives
Clipping Modeling Transformations • Transform to Normalized Device Coordinates (NDC) • Remove portions of object outside view volume Illumination (Lighting) Viewing Transformation (Perspective / Orthographic) Clipping Eye space NDC Projection (to Screen Space) Scan Conversion(Rasterization) Visibility / Display
Scan Conversion • Scan conversion or rasterization • 2D primitives => pixels • Per-vertex data is interpolated across the triangle
Scan Conversion (Rasterization) Modeling Transformations • Rasterizes primitives into pixels • Interpolate values as we go (color, depth, etc.) Illumination (Lighting) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion(Rasterization) Visibility / Display
Fragment Processing • Output of rasterization • Set of fragments • Z-values • … • Z-buffer algorithm • Texturing and transparency operations
OpenGL • Open Graphics Library (OpenGL) • Standard specification defining a cross-platform API for writing 2D and 3D graphics apps • Cell phones to supercomputers • Developed by SGI in 1992 • Current version 4.4 • Managed by non-profit Khronos Group • Consortium focused on open, royalty-free standards for authoring and acceleration of parallel computing, graphics, and dynamic media (OpenCL, OpenGL, OpenGL ES, WebGL, COLLADA)
Supporting Infrastructure OpenGL Application GLEW GLUT GL GLX, WGL Graphics Drivers Windowing System (X, Windows) GPU
OpenGL Example • Drawing a colored triangle • glBegin (GL_TRIANGLES); • glColor3f (1.0f, 0.0f, 0.0f); • glVertex3f (-1.0f, -1.0f, 0.0f); • glColor3f (0.0f, 1.0f, 0.0f); • glVertex3f (+1.0f, -1.0f, 0.0f); • glColor3f (0.0f, 0.0f, 1.0f); • glVertex3f (0.0f, +1.0f, 0.0f); • glEnd (); • Inefficient; we’ll improve upon this
OpenGL Program Organization • main () { • // Initialize and create window • // Set up key and mouse event handlers • // Initialize OpenGL • // Set up lighting • // Load assets
OpenGL Program Organization (Cont’d) • // Update and render loop • while (userWantsToContinue) { • // Clear screen • // Specify camera position & orientation (pose) • for (Model model : scene) { • // Specify object pose • // Draw model • // Frame completion code (buffer swap) • } • // Cleanup code • }