CENG 477 Introduction to Computer...

77
CENG 477 Introduction to Computer Graphics Introduction

Transcript of CENG 477 Introduction to Computer...

CENG 477

Introduction to Computer Graphics

Introduction

Computer Graphics

• What is Computer Graphics (CG)?

CENG 477 – Computer Graphics 2

Any use of computers to create and

manipulate images

Tools and algorithms used to make

such pictures, software, and

hardware

Ken Perlin: What you need to show

other people your dreams!Math, physics, and coding!

Computer Graphics

• CG consists of three main subfields:

– Modeling

– Rendering

– Animation

CENG 477 – Computer Graphics 3

Modeling

• Modeling is the process of representing 3D shapes

CENG 477 – Computer Graphics 4

Headus COW Model

Many modeling

techniques exist

Rendering

• Rendering is the actual process of generating an image from a

scene definition file

CENG 477 – Computer Graphics 5

Similar to modeling, there are

various rendering techniques

Animation

• Animation is the process of bringing life to virtual objects

CENG 477 – Computer Graphics 6

The Goal

• The main goal of CG is to create realistic images as fast as

possible

CENG 477 – Computer Graphics 7

The Goal

• This often requires vast computational resources

CENG 477 – Computer Graphics 8

A photo of the LucasFilm Rendering Farm (by Peter Sciretta)

Other Goals

• Besides creating realistic images CG also aims to create

– informative technical illustrations

– architectural drawings

– nonphotorealistic images

– geeky (and very cool) art

CENG 477 – Computer Graphics 9

Application Areas

• CG is extensively used for:

– video games

– animation movies

– visual effects

– CAD/CAM tools

– simulation/training

– scientific visualization

CENG 477 – Computer Graphics 10

2D vs 3D

• Both 2D and 3D rendering falls in the realm of computer

graphics

• Many mobile games are in fact 2D

CENG 477 – Computer Graphics 11

MoBu by Panteon Games

Our primary focus on this course

will be on 3D graphics

This Course

• In this course, we will learn a little bit about all three subfields

within CG

• Our focus will be on 3D rendering but we will touch upon

modeling and animation as well

CENG 477 – Computer Graphics 12

The Overall Pipeline

• Image generation is a result of scene definition realized by

rendering which ultimately is sent to a display device

CENG 477 – Computer Graphics 13

William Thompson et al. Visual perception from a computer graphics perspective. CRC Press, 2011.

The Overall Pipeline

• The output is perceived by a human observer, who may then

interact with the system

CENG 477 – Computer Graphics 14

Display Devices and Perception

• Therefore, graphic algorithms must take into consideration the

target display device and the viewers’ capabilities

– No need to render an 8K image if the target display device is 2K

– No need to render tiny details that cannot be perceived by a human

CENG 477 – Computer Graphics 15

Images and Video

• Also, the output of rendering is an image, also known as a

frame, which can be directly sent to a display device (real-time

rendering) or saved for offline viewing as an image or a

sequence of images stored in a video

• Therefore, as a starting point, it is important to understand the

basic properties of

– images,

– display devices,

– and the human visual system

CENG 477 – Computer Graphics 16

Course Progression

• We will first start with images and displays

CENG 477 – Computer Graphics 17

Course Progression

• We will then talk a little bit of visual perception

CENG 477 – Computer Graphics 18

Course Progression

• Next, we will learn about modeling and rendering

CENG 477 – Computer Graphics 19

Course Progression

• We will finally touch upon animation

CENG 477 – Computer Graphics 20

Text Book

• Our text book will be Fundamentals of Computer Graphics by

Shirley et al.

CENG 477 – Computer Graphics 21

Website

• Our course website is located at:

– www.ceng.metu.edu.tr/courses/ceng477

• Check it out for important news and updates

• Also make sure to regularly check out the newsgroup:

– https://cow.ceng.metu.edu.tr/News/thread.php?group=metu.ceng.course

.477

CENG 477 – Computer Graphics 22

Grading

• 2 midterms

• 1 final

• 4 programming assignments

– Must use C/C++

– Can be done in pairs

– We will learn and use OpenGL in some assignments

• Review the full syllabus at:

– https://odtusyllabus.metu.edu.tr/

CENG 477 – Computer Graphics 23

CENG 477

Introduction to Computer

Graphics

Images, Cameras, Displays

Images and Displays

• Computer graphics is all about creating and displaying

images

• A video is nothing but an image sequence

• A computer game is nothing but many images rendered

at rapid succession

• As such, we should first understand what an image is

and how it is displayed

CENG 477 – Computer Graphics 2

Image

• An image, or a digital image, is an intensity distribution

over a bounded two dimensional region

• More formally, �: ℝ2 → …

CENG 477 – Computer Graphics 3

�width

height

Image

• In practice, we place two restrictions in order handle

images on a computer:

– Discretization

– Data type

CENG 477 – Computer Graphics 4

Discretization

• Discretization is the partitioning of the image region to a

non-overlapping grid

• Each cell is called a pixel

CENG 477 – Computer Graphics 5

�width

height

Discretization

• The total number of pixels in an image called image

resolution

• The same term is used for the display devices as well

CENG 477 – Computer Graphics 6

�width

height

Data Type

• Data type represents what can be stored in a pixel

– Bitmaps: �: ℝ2 → { , }– Grayscale: �: ℝ2 → { , , … , }– Color: �: ℝ2 → , ,… ,– Color (generalized): �: ℝ2 → ℝ

CENG 477 – Computer Graphics 7

Bitmap

• A sample bitmap image (1 bpp):

CENG 477 – Computer Graphics 8

Grayscale

• A sample grayscale image (8 bpp):

CENG 477 – Computer Graphics 9

Color

• A sample color image (24 bpp):

CENG 477 – Computer Graphics 10

Color

• In color images, each pixel has three components: red,

green, blue

• Their relative contribution determines the actual color

CENG 477 – Computer Graphics 11

�width

height

Color

• Typically, each color value is an 8-bit integer in [0, 255]

range

• This corresponding space is called the RGB color cube

CENG 477 – Computer Graphics 12

medialooks.com

Storage

• These colors can be stored as interleaved or as planar in

an image file

CENG 477 – Computer Graphics 13

Interleaved Planar

Image Formats

• Images generated by a CG program can be sent to a

display device or written to an image file

CENG 477 – Computer Graphics 14

Scene

Description

File

CG Program

Output

Image

File

Image Formats

• There are hundreds of image formats perhaps the best

well-known being the JPEG format

• A very simple image format is the PPM format:

CENG 477 – Computer Graphics 15

Image Formats

• Despite being simple, the PPM format is very inefficient

due to lack of compression

• How many MBs would an 18 megapixel (MP) plain PPM

image would occupy?

CENG 477 – Computer Graphics 16

∗ ∗ ∗ ∗ .∗ ≅ �

Image Formats

• 3.57 in this formula comes from the expected number of

bytes that each component will occupy:

• The last +1 is for the whitespace between the

components

CENG 477 – Computer Graphics 17

∗ + ∗ + ∗ + ≅ .

Image Formats

• If we used binary PPM (each component is 1 byte) this

produce a file size of 54 MBS for an 18 MP image (still

too much)

• For this reason, compressed image formats are available

– Lossless compression

– Lossy compression

CENG 477 – Computer Graphics 18

Lossless Compression

• With lossless compression, a decoder will read the exact

information that an encoder wrote to a file

• Various lossless compression techniques are used such

as Huffman encoding, run-length encoding, etc.

• A well-known lossless image format is the PNG format

• Efficient for computer generated images but not for

natural (photographic) images due to presence of noise

CENG 477 – Computer Graphics 19

Lossy Compression

• In lossy compression, numerical match between the

input and output is not required

• Some information is lost to improve compression

efficiency

• However, lossy formats can still be visually lossless

• The most well-known lossy format is the JPEG format

CENG 477 – Computer Graphics 20

Lossy vs Lossless

• Assume we encode and decode this data as PPM and

JPEG:

CENG 477 – Computer Graphics 21

JPEG Quality

• A JPEG image with different quality settings:

CENG 477 – Computer Graphics 22

Image Capture

• We defined a color image as �: ℝ2 → , ,… ,• The light intensity (more precisely luminance) in the

world is not restricted to such a set

• Larger and smaller values are clamped (saturated) and

all values are quantized

• Which values get saturated depends on the exposure

setting of the camera

CENG 477 – Computer Graphics 23

Image Capture

• A low exposure image:

CENG 477 – Computer Graphics 24

Image Capture

• A high exposure image:

CENG 477 – Computer Graphics 25

Dynamic Range

• Dynamic range (DR) is defined as the ratio of the highest

luminance to the lowest luminance in a given scene

CENG 477 – Computer Graphics 26

� �

�� = ��

Exposure Control

• Cameras control their exposure to decide on a proper

range:

CENG 477 – Computer Graphics 27

Quantization

• With quantization, world luminance to pixel value

mapping looks like this:

CENG 477 – Computer Graphics 28

Rendering

• Why this matters for CG?

• In CG, we generate images just like a camera captures

images

• Our artificial scene may have luminance values not

limited to [0, 255] range

• As such, we have to mimic what the camera does

CENG 477 – Computer Graphics 29

HDR

• What if we want to capture (or render) the world as it is

without mapping to [0, 255] range?

• We can capture multiple exposures and merge them to

create an HDR image

CENG 477 – Computer Graphics 30

HDR

• HDR image capture process:

CENG 477 – Computer Graphics 31

HDR ImageMerge

HDR

• Unfortunately, HDR images cannot be directly displayed

on standard display devices

• They must be tonemapped first (see Chapter 23 in our

textbook):

CENG 477 – Computer Graphics 32

HDR Image

Tonemap

LDR Image

Display

HDR

• HDR images can also be saved in HDR file formats such

as .hdr and .exr

• Novel HDR displays allow direct display of HDR imagery:

CENG 477 – Computer Graphics 33

HDR ImageStandard display

HDR display

LDR Image

Display

See http://hdr.sim2.it/ for more info on HDR displays

Display Devices

• Generated images are sent to a display device via the video card

• Therefore, understanding the basic properties of display devices is important

CENG 477 – Computer Graphics 34

Display Devices

• There are numerous types of display devices

• But they all share some basic properties

CENG 477 – Computer Graphics 35

• CRT

• Plasma

• LCD

• LED

• OLED

• E-ink

• …

Display Devices

• The digital RGB signals sent from the video card are

translated into analog voltages in the display device

• These voltages determine the luminance emitted from

each pixel

• However, voltage to luminance relationship is nonlinear

CENG 477 – Computer Graphics 36

Gamma

• This nonlinearity is called the display gamma

– E.g. twice the pixel value (twice the voltage) does not result in twice the luminance

• Also, zero RGB value does not mean zero luminance

due to leaking light and reflections off the screen

• A simplified display model is:

CENG 477 – Computer Graphics 37

= �� +Output

luminanceContrast Voltage Gamma Brightness

Gamma

• Measured gamma of NEC Spectraview 241:

CENG 477 – Computer Graphics 38

• Measurements

are taken at

intervals of 10

• Ideal is a

gamma value

of 2.2

Gamma Correction

• Most display devices have a gamma value around 2.2

• Gamma correction is performed to account for this non-

linearity:

– The input signal is raised to the power Τ� before being stored

• This allows the luminance received by a camera to be

linearly proportional the luminance emitted by a display

device

• Cameras are non-linear primarily due to gamma

correction

CENG 477 – Computer Graphics 39

Gamma Correction

CENG 477 – Computer Graphics 40

Gamma Correction

• In CG, we must also apply gamma correction as the last

step of the rendering process

• Without gamma correction, we may obtain unnaturally

dark images

CENG 477 – Computer Graphics 41

nvidia.com

See

http://http.developer.nvidia.com/GPUGems3/gpugems3

_ch24.html

for more information

CENG 477

Introduction to Computer Graphics

Human Visual System

Human Visual System

• The HVS consists of the eyes, parts of the

brain, and the connecting pathways

between the two

• It is a complex system that even today not

entirely understood

• We will briefly touch upon its basic

working principles

CENG 477 – Computer Graphics 2

wikipedia.com

The Eye

• Vision starts at the eyes

CENG 477 – Computer Graphics 3

The Eye

• Light entering the eye is focused on the fovea (inside retina)

by the lens

CENG 477 – Computer Graphics 4

Retina

• This light is absorbed by two types of photosensitive cells on

the retina

– Rods

– Cones

CENG 477 – Computer Graphics 5

Rods and Cones

• While being more numerous than cones, rods do not exist in

the fovea and there is only single type of rods

– That is why our night vision is not sharp and colorful

• Rods are active under low light conditions

CENG 477 – Computer Graphics 6

Cones

• Cones are very dense in the fovea

• There are three types of cones: long, medium, short

• Cones are active at normal light conditions

CENG 477 – Computer Graphics 7

Cones

• Each cone type is responsive to a

different color

• Their relative contribution

determines the perceived color of

an object

• Their combined contribution

determines the perceived

brightness of an object

CENG 477 – Computer Graphics 8

(255, 0, 0) (0, 255, 0) (0, 0, 255)

The primary reason that color is typically represented as an

RGB triplet is because we also have three types of cones

Non-linearity

• The human response to light is non-linear (logarithmic)

• In other words, cameras and the eye has a somewhat similar

non-linearity

CENG 477 – Computer Graphics 9

Non-linearity

• Therefore, equal change in luminance does not map to equal

change in perceived brightness (depending on the gamma of

your monitor you may not observe this effect)

CENG 477 – Computer Graphics 10

(0, 0, 0) (50, 50, 50) (100, 100, 100)Approximate

light intensity

Larger perceived

step

Smaller perceived

step

Non-linearity

CENG 477 – Computer Graphics 11

• This can be explained by the perceived brightness curve:

Output Intensity

Per

ceiv

ed B

rightn

ess

Perception and Graphics

• Understanding visual perception allows for various

optimizations in computer graphics

CENG 477 – Computer Graphics 12

Ferwerda et al. 1997: A Model of Visual Masking for Computer Graphics

Summary

• In CG, images (frames) are rendered and then are either

written to a file or directly sent to a display device to be

perceived by an observer

CENG 477 – Computer Graphics 13

We learned the fundamentals

of images, displays, and vision

Next we will learn about the

fundamentals of image

generation

Check out Chapters 1, 2, and 3 from the

textbook until next week!