INFOGR Computer Graphics Jacco Bikker & Debabrata Panja - - - PowerPoint PPT Presentation

infogr computer graphics
SMART_READER_LITE
LIVE PREVIEW

INFOGR Computer Graphics Jacco Bikker & Debabrata Panja - - - PowerPoint PPT Presentation

INFOGR Computer Graphics Jacco Bikker & Debabrata Panja - April-July 2019 Lecture 5: Graphics Fundamentals Welcome! Todays Agenda: Rasters Colors Ray Tracing Assignment P2 INFOGR Lecture 5 Graphics


slide-1
SLIDE 1

INFOGR – Computer Graphics

Jacco Bikker & Debabrata Panja - April-July 2019

Lecture 5: “Graphics Fundamentals”

Welcome!

slide-2
SLIDE 2

Today’s Agenda:

▪ Rasters ▪ Colors ▪ Ray Tracing ▪ Assignment P2

slide-3
SLIDE 3

Raster Displays

Discretization

INFOGR – Lecture 5 – “Graphics Fundamentals” 3

slide-4
SLIDE 4

Raster Displays

Discretization

Rasterization: “Converting a vector image into a raster image for output on a video display or printer or storage in a bitmap file format.” (Wikipedia) INFOGR – Lecture 5 – “Graphics Fundamentals” 4

slide-5
SLIDE 5

Raster Displays

Rasterization

Improving rasterization:

  • 1. Increase resolution;

INFOGR – Lecture 5 – “Graphics Fundamentals” 5

slide-6
SLIDE 6

Raster Displays

Rasterization

Improving rasterization:

  • 1. Increase resolution;
  • 2. Anti-aliasing;
  • 3. Animation.

INFOGR – Lecture 5 – “Graphics Fundamentals” 6

slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10

Raster Displays

Discretization

π=4

a2+b2=𝑑2 a1+b1=𝑑1

INFOGR – Lecture 5 – “Graphics Fundamentals” 10

slide-11
SLIDE 11

Raster Displays

CRT – Cathode Ray Tube

Physical implementation – origins Electron beam zig-zagging over a fluorescent screen. INFOGR – Lecture 5 – “Graphics Fundamentals” 11

slide-12
SLIDE 12

Raster Displays

CRT – Cathode Ray Tube

0,0 x y

Physical implementation – consequences ▪ Origin in the top-left corner of the screen ▪ Axis system directly related to pixel count INFOGR – Lecture 5 – “Graphics Fundamentals” 12

slide-13
SLIDE 13

Raster Displays

CRT – Cathode Ray Tube

x=1 y=1 0,0 x=-1 y=-1

Physical implementation – consequences ▪ Origin in the top-left corner of the screen ▪ Axis system directly related to pixel count Not the coordinate system we expected… INFOGR – Lecture 5 – “Graphics Fundamentals” 13

slide-14
SLIDE 14

Raster Displays

CRT – Cathode Ray Tube

0,0 x y x=1 y=1 0,0 x=-1 y=-1

Proper screen coordinates ▪ Pixel coordinates are only relevant for the final step: plotting pixels ▪ Decouple the 2D screen coordinates in your game / app from the physical mapping. INFOGR – Lecture 5 – “Graphics Fundamentals” 14

slide-15
SLIDE 15

Raster Displays

Frame rate

PAL: 25fps NTSC: 30fps (actually: 29.97) Typical laptop screen: 60Hz High-end monitors: 120-240Hz Cartoons: 12-15fps Human eye: ‘Frame-less’ Not a raster. How many fps / megapixels is ‘enough’? INFOGR – Lecture 5 – “Graphics Fundamentals” 15

slide-16
SLIDE 16

Raster Displays

Frame rate

Even 100 frames per second may result in a noticeable delay of 30ms. A very high frame rate minimizes the response time of the simulation. Frame 1 Frame 2 Frame 3 Sim 1 Sim 2 Sim 3 Input 1 Input 2 Input 3

0 ms 20 ms 40 ms 60 ms

INFOGR – Lecture 5 – “Graphics Fundamentals” 16

slide-17
SLIDE 17

Raster Displays

Generating images

Rendering: “The process of generating an image from a 2D or 3D model by means of a computer program.”

(Wikipedia)

Two main methods:

  • 1. Ray tracing: for each pixel: what color do we assign to it?
  • 2. Rasterization: for each triangle, which pixels does it affect?
  • n a raster

INFOGR – Lecture 5 – “Graphics Fundamentals” 17

slide-18
SLIDE 18

Today’s Agenda:

▪ Rasters ▪ Colors ▪ Ray Tracing ▪ Assignment P2

slide-19
SLIDE 19

Colors

Color representation

Computer screens emit light in three colors: red, green and blue. By additively mixing these, we can produce most colors: from black (red, green and blue turned off) to white (red, green and blue at full brightness). In computer graphics, colors are stored in discrete form. This has implications for: ▪ Color resolution (i.e., number of unique values per component); ▪ Maximum brightness (i.e., range of component values). INFOGR – Lecture 5 – “Graphics Fundamentals” 19

slide-20
SLIDE 20

Colors

Color representation

The most common color representation is 32-bit ARGB, which stores red, green and blue as 8 bit values (0..255). Alternatively, we can use 16 bit for one pixel (RGB 565),

  • r a color palette. In that case, one byte is

used per pixel, but only 256 unique colors can be used for the image. INFOGR – Lecture 5 – “Graphics Fundamentals” 20

slide-21
SLIDE 21

Colors

Color representation

INFOGR – Lecture 5 – “Graphics Fundamentals” 21

slide-22
SLIDE 22

Colors

Color representation

INFOGR – Lecture 5 – “Graphics Fundamentals” 22

slide-23
SLIDE 23

Colors

Color representation

INFOGR – Lecture 5 – “Graphics Fundamentals” 23

slide-24
SLIDE 24

Colors

Color representation

Textures can typically safely be stored as palletized images. Using a smaller palette will result in smaller compressed files. INFOGR – Lecture 5 – “Graphics Fundamentals” 24

slide-25
SLIDE 25

Colors

Color representation

Using a fixed range (0:0:0 … 255:255:255) places a cap on the maximum brightness that can be represented: ▪ A white sheet of paper: (255,255,255) ▪ A bright sky: (255,255,255) The difference becomes apparent when we look at the sky and the sheet of paper through sunglasses. (or, when the sky is reflected in murky water) INFOGR – Lecture 5 – “Graphics Fundamentals” 25

slide-26
SLIDE 26

Colors

Color representation

For realistic rendering, it is important to use an internal color representation with a much greater range than 0..255 per color component. HDR: High Dynamic Range; We store one float value per color component. Including alpha, this requires 128bit per pixel. INFOGR – Lecture 5 – “Graphics Fundamentals” 26

slide-27
SLIDE 27

Colors

Color representation

Like pixel coordinates, pixel colors on the physical screen are

  • nly useful for final pixel plotting:

Do Do not not us use int integer co colors cla clamped to

  • [0..2

[0..255] int internally, unle unless you ha have a a go good rea eason for

  • r th

this. INFOGR – Lecture 5 – “Graphics Fundamentals” 27

slide-28
SLIDE 28

Today’s Agenda:

▪ Rasters ▪ Colors ▪ Ray Tracing ▪ Assignment P2

slide-29
SLIDE 29

PART 1: Introduction & shading (today, Thursday) PART 2: Reflections, refraction, absorption (next week) PART 3: Path Tracing (later)

INFOGR – Lecture 5 – “Graphics Fundamentals” 29

Ray Tracing

slide-30
SLIDE 30

Ray Tracing: World space ▪ Geometry ▪ Eye ▪ Screen plane ▪ Screen pixels ▪ Primary rays ▪ Intersections ▪ Point light ▪ Shadow rays Light transport ▪ Extension rays Light transport INFOGR – Lecture 5 – “Graphics Fundamentals” 30

Ray Tracing

slide-31
SLIDE 31

Ray Tracing: World space ▪ Geometry ▪ Eye ▪ Screen plane ▪ Screen pixels ▪ Primary rays ▪ Intersections ▪ Point light ▪ Shadow rays Light transport ▪ Extension rays Light transport INFOGR – Lecture 5 – “Graphics Fundamentals” 31

Ray Tracing

slide-32
SLIDE 32

Ray Tracing

INFOGR – Lecture 8 – “Ray Tracing”

slide-33
SLIDE 33

Ray Tracing: World space ▪ Geometry ▪ Eye ▪ Screen plane ▪ Screen pixels ▪ Primary rays ▪ Intersections ▪ Point light ▪ Shadow rays Light transport ▪ Extension rays Light transport Note: We are calculating light transport backwards. INFOGR – Lecture 5 – “Graphics Fundamentals” 33

Ray Tracing

slide-34
SLIDE 34

Ray Tracing

INFOGR – Lecture 8 – “Ray Tracing”

slide-35
SLIDE 35

INFOGR – Lecture 5 – “Graphics Fundamentals” 35

Ray Tracing

slide-36
SLIDE 36

INFOGR – Lecture 5 – “Graphics Fundamentals” 36

Ray Tracing

slide-37
SLIDE 37

Physical basis

Ray tracing uses ray optics to simulate the behavior of light in a virtual environment. It does so by finding light transport paths: ▪ From the ‘eye’ ▪ Through a pixel ▪ Via scene surfaces ▪ To one or more light sources. At each surface, the light is modulated. The final value is deposited at the pixel (simulating reception by a sensor).

  • T. Whitted, “An Improved Illumination Model for Shaded Display”, ACM, 1980.

INFOGR – Lecture 5 – “Graphics Fundamentals” 37

Ray Tracing

slide-38
SLIDE 38

Intersections

Ray definition

A ray is an infinite line with a start point: 𝑞(𝑢) = 𝑃 + 𝑢𝐸, where 𝑢 > 0.

struct Ray { float3 O; // ray origin float3 D; // ray direction float t; // distance };

The ray direction is generally normalized. INFOGR – Lecture 5 – “Graphics Fundamentals” 38

slide-39
SLIDE 39

Ray setup

A ray is initially shot through a pixel on the screen plane. The screen plane is defined in world space: Camera position: E = (0,0,0) View direction: 𝑊 Screen center: C = 𝐹 + 𝑒𝑊 Screen corners: p0 = 𝐷 + −1,1,0 , 𝑞1 = 𝐷 + 1,1,0 , 𝑞2 = 𝐷 + (−1, −1,0) From here: ▪ Change FOV by altering 𝑒; ▪ Transform camera by multiplying E, 𝑞0, 𝑞1, 𝑞2 with the camera matrix. INFOGR – Lecture 5 – “Graphics Fundamentals” 39

Intersect

Only if 𝑊 = (0,0,1) of course.

slide-40
SLIDE 40

Ray setup

Point on the screen: 𝑞 𝑣, 𝑤 = 𝑞0 + 𝑣 𝑞1 − 𝑞0 + 𝑤(𝑞2 − 𝑞0), 𝑣, 𝑤 ∈ [0,1) Ray direction (before normalization): 𝐸 = 𝑞 𝑣, 𝑤 − 𝐹 Ray origin: 𝑃 = 𝐹 𝑞1 𝑞0 𝑞2 𝐹 INFOGR – Lecture 5 – “Graphics Fundamentals” 40

Intersect

𝑞2 − 𝑞0

slide-41
SLIDE 41

Ray intersection

Given a ray 𝑞(𝑢) = 𝑃 + 𝑢𝐸, we determine the smallest intersection distance 𝑢 by intersecting the ray with each of the primitives in the scene. Ray / plane intersection: Plane: p ∙ 𝑂 + 𝑒 = 0 Ray: 𝑞(𝑢) = 𝑃 + 𝑢𝐸 Substituting for 𝑞(𝑢), we get 𝑃 + 𝑢𝐸 ∙ 𝑂 + 𝑒 = 0 𝑢 = −(𝑃 ∙ 𝑂 + 𝑒)/(𝐸 ∙ 𝑂) 𝑄 = 𝑃 + 𝑢𝐸 𝑞1 𝑞0 𝐹 INFOGR – Lecture 5 – “Graphics Fundamentals” 41

Intersect

𝑞2

slide-42
SLIDE 42

Intersect

Ray intersection

Ray / sphere intersection: Sphere: 𝑞 − 𝐷 ∙ 𝑞 − 𝐷 − 𝑠2 = 0 Ray: 𝑞(𝑢) = 𝑃 + 𝑢𝐸 Substituting for 𝑞(𝑢), we get 𝑃 + 𝑢𝐸 − 𝐷 ∙ 𝑃 + 𝑢𝐸 − 𝐷 − 𝑠2 = 0 𝐸 ∙ 𝐸 𝑢2 + 2𝐸 ∙ 𝑃 − 𝐷 𝑢 + (𝑃 − 𝐷)2−𝑠2 = 0 𝑏𝑦2 + 𝑐𝑦 + 𝑑 = 0 → 𝑦 = −𝑐 ± 𝑐2 − 4𝑏𝑑 2𝑏 𝑏 = 𝐸 ∙ 𝐸 𝑐 = 2𝐸 ∙ (𝑃 − 𝐷) 𝑑 = 𝑃 − 𝐷 ∙ 𝑃 − 𝐷 − 𝑠2 𝐹 Negative: no intersections INFOGR – Lecture 5 – “Graphics Fundamentals” 42 𝑞1 𝑞0 𝑞2

slide-43
SLIDE 43

Ray Intersection

Efficient ray / sphere intersection:

void Sphere::IntersectSphere( Ray ray ) { vec3 c = this.pos - ray.O; float t = dot( c, ray.D ); vec3 q = c - t * ray.D; float p2 = dot( q, q ); if (p2 > sphere.r2) return; t -= sqrt( sphere.r2 – p2 ); if ((t < ray.t) && (t > 0)) ray.t = t; // or: ray.t = min( ray.t, max( 0, t ) ); }

Note: This only works for rays that start outside the sphere. O 𝐸 Ԧ 𝑑 t Ԧ 𝑟 𝑞2

Intersect

INFOGR – Lecture 5 – “Graphics Fundamentals” 43

slide-44
SLIDE 44

Today’s Agenda:

▪ Rasters ▪ Colors ▪ Ray Tracing ▪ Assignment P2

slide-45
SLIDE 45

Checkpoint

INFOGR – Lecture 5 – “Graphics Fundamentals” 45

Math Basics

▪ vector != point ▪ planes, normals ▪ spheres ▪ dot product, cross product

Assignment P1

▪ template ▪ rgb colors in 32-bit ▪ coordinate systems in practice ▪ OpenGL in C# ▪ vertex buffers & shaders

Checkpoint 1: MIDTERM on May 16nd Checkpoint 2: P2 on May 28th

slide-46
SLIDE 46

Assignment 2: ”Write a 2D ray tracer.” ▪ Using the template ▪ Floating point pixels ▪ Pretty easy minimal specs ▪ Tons of extra challenges

Assignment 2

INFOGR – Lecture 5 – “Graphics Fundamentals” 46 https://ncase.me/sight-and-light

slide-47
SLIDE 47

Assignment 2: ”Write a 2D ray tracer.” ▪ Work in C#, C++, Java, ... ▪ Work alone or in pairs ▪ Special challenges ▪ Fastest ray tracer ▪ Smallest ray tracer

Assignment 2

INFOGR – Lecture 5 – “Graphics Fundamentals” 47

slide-48
SLIDE 48

Assignment 2

INFOGR – Lecture 5 – “Graphics Fundamentals” 48 www.youtube.com/watch?time_continue=37&v=iIIu7kPCN-8 medium.com/@jerry.ylilammi/making-of-newton-protocol-e9ccde41af30

slide-49
SLIDE 49

Assignment 2: ”Write a 2D ray tracer.” ▪ Assignment now online ▪ Deadline: May 28.

Assignment 2

INFOGR – Lecture 5 – “Graphics Fundamentals” 49

slide-50
SLIDE 50

Today’s Agenda:

▪ Rasters ▪ Colors ▪ Ray Tracing ▪ Assignment P2

slide-51
SLIDE 51

INFOGR – Computer Graphics

Jacco Bikker & Debabrata Panja - April-July 2019

END OF lecture 5: “Graphics Fundamentals”

Next lecture: “More on Ray Tracing”