cs 4363/6353 introduction to computer graphics. what you’ll see interactive 3d computer graphics...

34
CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS

Upload: bethany-morrison

Post on 18-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

CS 4363/6353

INTRODUCTION TO COMPUTER GRAPHICS

Page 2: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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)

Page 3: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

WHAT YOU WON’T SEE• Applications (though they are useful)

• Photoshop/Gimp/Paint.NET

• Maya

• Web graphics

• Art

• Character animations

• Very complex

• Usually require 3rd party software

Page 4: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

Page 5: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

Page 6: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

WHY?• Graphics Engineer at LucasArts – 1/4/2012

Page 7: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

EARLY GRAPHICS• Das Blinkenlights

• Dot matrix printers

• Shortly after printers came the CRT…

http://james.seng.sg/files/public/starwar-ascii-art.jpg

Page 8: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

Page 9: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

• Bresenham’s Line Drawing algorithm

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

http://kobi.nat.uni-magdeburg.de/patrick/uploads/BEng/bresenham_line.png

Page 10: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

THINGS TO NOTE…• Everything at this time

• was 2D

• Looked really bad, but was playable!

• was in real time

• How did the “animation” work?

Page 11: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

INTO THE 3RD 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

Page 12: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

Page 13: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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)

Page 14: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

TRANSFORMATIONS• Translate

• Rotate

• Scale

Page 15: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

TERMINOLOGY(IMAGE FROM THE OPENGL SUPERBIBLE)

• Wireframe – rendering only the edges of the model (old games)

Page 16: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

• 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)

Page 17: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

• Solid shading (this isn’t a definition) – note that everything’s hard-coded red!

TERMINOLOGY(IMAGE FROM THE OPENGL SUPERBIBLE)

Page 18: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

• Flat Shading – simulate lighting

TERMINOLOGY(IMAGE FROM THE OPENGL SUPERBIBLE)

Page 19: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

• Texture mapping – using an image during the rasterization process

TERMINOLOGY(IMAGE FROM THE OPENGL SUPERBIBLE)

Page 20: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

• Blending – mixing colors by rendering more than one thing in one spot

• The floor is rendered semi-transparent (yes, there are two cubes)

TERMINOLOGY(IMAGE FROM THE OPENGL SUPERBIBLE)

Page 21: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

WHAT ABOUT THIS?(NON-REAL-TIME)

Page 22: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

Page 23: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

+x-x

+y

-y

Page 24: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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)

+100-100

+75

-75

Page 25: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

ANOTHER EXAMPLE

+200

0

+150

0

• Middle of screen is (75, 100)

Page 26: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

Page 27: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

EXAMPLE – ENTIRE WINDOW

0

(150, 200)

0

1900x1200 Window

Page 28: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

PIP EXAMPLE

0

(150, 200)

0

1900x1200 Window

Page 29: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

+x-x

+y

-y

+z

-z

http://people.ece.cornell.edu/land/courses/ece4760/FinalProjects/s2010/ky237_zy49/ky237_zy49/index.html

Page 30: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

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

Page 31: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

EXAMPLE(UPPER-RIGHT IS A PERSPECTIVE VIEW)

Page 32: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

ORTHOGRAPHIC VIEW VOLUME(YOU CAN SEE THE PARALLEL NOW…)

Nearclippingplane

Farclippingplane

Page 33: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t

PERSPECTIVE VIEW VOLUME

Nearclippingplane

Farclippingplane

Page 34: CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t