Introduction to Computer Graphics

Download Report

Transcript Introduction to Computer Graphics

INTRODUCTION TO COMPUTER GRAPHICS

CS 4363/6353

WHAT YOU’LL SEE

• Interactive 3D computer graphics • Real-time • • • • • • 2D, but mostly 3D OpenGL C/C++ (if you don’t know them) The math behind the scenes Shaders Simple and not-so-simple 3D file formats (OBJ and FBX)

WHAT YOU WON’T SEE

• • Applications (though they are useful) • Photoshop/Gimp/Paint.NET

• • • Maya Web graphics Art Character animations • • Very complex Usually require 3 rd party software

WHY?

• Senior Graphics Engineer at Autodesk – 1/6/2012

WHY?

• C/C++ Game Programmer at Addmired – 1/5/2012

WHY?

• Graphics Engineer at LucasArts – 1/4/2012

EARLY GRAPHICS

• • • Das Blinkenlights Dot matrix printers Shortly after printers came the CRT… http://james.seng.sg/files/public/starwar-ascii-art.jpg

EARLY GRAPHICS

• The CRT was able to draw more than ASCII characters. It could draw dots!

http://www.gamasutra.com/view/feature/3900/the_history_of_pong_avoid_missing_.php

EARLY GRAPHICS

• • If you can draw a dot, you can draw a line!

Bresenham’s Line Drawing algorithm http://kobi.nat.uni-magdeburg.de/patrick/uploads/BEng/bresenham_line.png

http://i18.photobucket.com/albums/b106/mspeir/Grid.jpg

THINGS TO NOTE…

• • Everything at this time • was 2D • Looked really bad, but was playable!

• was in real time How did the “animation” work?

INTO THE 3

RD

DIMENSION

• • • Add depth dimension How do you perceive depth everyday?

• • You have two eyes The image for your left eye is different than the right • Brain extracts the differences to understand depth 3DTVs – how do they work?

http://static3.businessinsider.com/image/4b45f3b20000000000533ed7/3d-tv.jpg

BUT WAIT!

• • • Monitors are one “flat image on a flat surface” How do we perceive depth now?

• Farther objects are smaller (foreshortening) • Subtle lighting changes We’ll use mathematics to do this for us http://www.oceansbridge.com/paintings/artists/c/canaletto/oil big/perspective_1765_XX_venice.jpg

• • • • • • • • •

COMMON TERMINOLOGY

Rendering: the entire process of drawing an image to the screen Vertex: a single 3D point (x, y, z) Edge: a line between two vertices Face: Most often 3 vertices and their edges Transformations: moving one or more vertices • Translate: pushing vertices along the x, y or z axis • • Rotate: revolving vertices around some 3D point Scale: increasing or decreasing the distance of vertices from their center Model matrix – a mathematical structure for holding transformations (later) View matrix – another used for holding the viewpoint (camera) Projection matrix – another, used to get images on the screen (later) Rasterization – putting the actual pixels on the screen (final phase of rendering)

TRANSFORMATIONS

• Translate • Rotate • Scale

TERMINOLOGY

(IMAGE FROM THE OPENGL SUPERBIBLE) • Wireframe – rendering only the edges of the model (old games)

• •

TERMINOLOGY

(IMAGE FROM THE OPENGL SUPERBIBLE) Hidden Surface Removal (HSR) – occluded objects can’t be seen Backface culling - drawing only the triangles that are facing the camera

TERMINOLOGY

(IMAGE FROM THE OPENGL SUPERBIBLE) Solid shading (this isn’t a definition) – note that everything’s hard-coded red!

TERMINOLOGY

(IMAGE FROM THE OPENGL SUPERBIBLE) Flat Shading – simulate lighting

TERMINOLOGY

(IMAGE FROM THE OPENGL SUPERBIBLE) Texture mapping – using an image during the rasterization process

• •

TERMINOLOGY

(IMAGE FROM THE OPENGL SUPERBIBLE) Blending – mixing colors by rendering more than one thing in one spot The floor is rendered semi-transparent (yes, there are two cubes)

WHAT ABOUT THIS?

(NON-REAL-TIME)

COORDINATE SYSTEMS

• • We have several spaces: • Local/Object – the coordinate system the mesh was modeled in • • • World – the coordinate system of the virtual environment View/Camera – the coordinate system relative to the camera Clip – windowing system We use mathematics to transform vertices from one space to another

COORDINATE SYSTEMS

(FOR WINDOWING SYSTEMS) • • • Because your screen is flat, we must work with 2D Cartesian Coordinates x = horizontal, y = vertical (0, 0) is origin +y -x +x -y

COORDINATE CLIPPING

• • • When creating a window, we must define where we are in the Cartesian system The window header doesn’t count in this equation Middle of screen is (0, 0) +75 -100 +100 -75

ANOTHER EXAMPLE

• Middle of screen is (75, 100) 0 0 +150 +200

SETTING A WINDOW’S VIEWPORT

• • • • Window size usually doesn’t match clipping size The viewport maps the clipping area to part (or all) of the window Most often, the viewport fills the entire window Sometimes, you want a “Picture in Picture” (PIP) rendering

EXAMPLE – ENTIRE WINDOW

(150, 200) 0 0 1900x1200 Window

PIP EXAMPLE

0 0 (150, 200) 1900x1200 Window

3D COORDINATE SYSTEMS

• • • We live (and think) in 3 dimensions x = horizontal, y = vertical, z = depth (can be RHS or LHS) (0, 0, 0) is origin +y -z -x +z -y http://people.ece.cornell.edu/land/courses/ece4760/FinalProjects/s2010/ky237_zy49/ky237_zy49/index.html

+x

BASIC PROBLEM

• • • • We need to convert our 3D models and display them on a 2D screen To do this, we use projections by defining a viewing volume These “flatten” the 3D world There are two kinds: • Orthographic (aka “parallel”) • • • All objects that have the same dimension are the same size, regardless of distance Viewing volume is rectangular Perspective • • Objects shrink with distance Viewing volume is shaped like a pyramid

EXAMPLE

(UPPER-RIGHT IS A PERSPECTIVE VIEW)

ORTHOGRAPHIC VIEW VOLUME

(YOU CAN SEE THE PARALLEL NOW…) Far clipping plane Near clipping plane

PERSPECTIVE VIEW VOLUME

Near clipping plane Far clipping plane