cs 6958 lecture 13 intro to anti-aliasing, pathtracingcs6958/slides/lec15.pdf · what is aliasing?...

28
CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACING March 3, 2014

Upload: others

Post on 01-Sep-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

CS 6958

LECTURE 13

INTRO TO ANTI-ALIASING,

PATHTRACING

March 3, 2014

Page 2: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

What is Aliasing? 2

Imagine this is our scene

Source: Physically Based Rendering, Pharr & Humphreys

Page 3: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

What is Aliasing? 3

If we render it with our ray tracers…

Source: Physically Based Rendering, Pharr & Humphreys

Page 4: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

What is Aliasing? 4

If we render it with our ray tracers…

Source: Physically Based Rendering, Pharr & Humphreys

Page 5: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

What is Aliasing? 5

Consider our Cornell Box

Page 6: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

What is Aliasing? 6

Consider our Cornell Box

Page 7: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

What is Aliasing? 7

Consider our Cornell Box

Page 8: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Anti-Aliasing

Issue:

Our sampling can’t reconstruct original signal

Nyquist-Shannon sampling theorem

Solution:

better sampling

better reconstruction of original signal

Lots of literature and theory on sampling and

reconstruction techniques

8

Page 9: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Sampling Techniques

currently: through center of each pixel

1 sample not enough! Use many and “average”

how do we pick samples?

uniform

random

jittered

9

Page 10: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Consider a 2x2 image 10

-1 0 1

0

1

Pixel

Page 11: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Pixel centers 11

-1 0 1

0

1

(-0.5, -0.5) (-0.5, 0.5)

(-0.5, 0.5) (0.5, 0.5)

Page 12: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Pixel centers

foreach pixel(i, j)

x = 2.0f *

(j - xres/2.f + 0.5f)/xres;

y = 2.0f *

(i - yres/2.f + 0.5f)/yres;

This is our current

ray generation method

12

-1 0 1

0

1

(-0.5, -0.5) (-0.5, 0.5)

(-0.5, 0.5) (0.5, 0.5)

Page 13: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Sampling a pixel

pick location other

than center

or perturb center

stop when n reached

13

-1 0 1

0

1

(-0.5, -0.5) (-0.5, 0.5)

(-0.5, 0.5) (0.5, 0.5)

Page 14: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Generating pixel samples

inv_width = loadf(0, 2)

inv_height = loadf(0, 5)

14

(x, y)

x + 1/width

y - 1/height

x - 1/width

y - 1/height

x + 1/width

y + 1/height

x - 1/width

y - 1/height

Page 15: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Generating pixel samples

// value between 0, 1

x_off = (trax_rand() - .5f) * 2.f;

y_off = (trax_rand() - .5f) * 2.f;

// scale offsets to pixel coords

x_off *= inv_width;

y_off *= inv_height;

// offset from center

x += x_off; y += y_off;

// generate ray

camera.makeRay(ray, x, y);

15

(x, y)

inv_

heig

ht

inv_width

Page 16: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Different sampling strategies 16

uniform

Source: Physically Based Rendering, Pharr & Humphreys

Page 17: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Different sampling strategies 17

uniform random

Source: Physically Based Rendering, Pharr & Humphreys

Page 18: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Different sampling strategies 18

uniform random jittered

Source: Physically Based Rendering, Pharr & Humphreys

Page 19: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Different sampling strategies 19

uniform random jittered

Source: Physically Based Rendering, Pharr & Humphreys

Difference between random and jittered, is that jittered has only 1 sample

within each cell. It’s still randomly perturbed!

Page 20: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Reconstruction filters

once we have samples, must recombine to get

final color

most popular

box

triangle

Gaussian

20

Page 21: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Putting it all together

foreach pixel

for(number_samples)

x, y = getNewSampleLocation(pixel);

camera.makeRay(ray, x, y);

bvh.intersect(hit, ray);

result += shade( ... ); // box filter

result /= number_samples; // box filter

image.set(pixel, result);

21

Page 22: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Global Illumination

so far, we’ve looked at

point lights (no area)

direct illumination (no inter-reflections)

non-physical Phong shading

fake ambient light term

our world behaves a little differently

we have all the tools to get it (mostly) right!

22

Page 23: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Global Illumination

23

Page 24: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Global Illumination

24

Page 25: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Global Illumination

25

Page 26: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Let’s try to derive path tracing

Board time!

Slides online will include this info

26

Page 27: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

Path tracing algorithm 27

...

for(number_samples)

attenuation = Color(1.f, 1.f, 1.f);

ray = generateNewRay( ... );

while(depth < max_depth) {

HitRecord hit;

bvh.intersect(hit, ray);

result += shade(…) * attenuation;// box filter

attenuation *= mat_color;

r = hemiRay(…);

depth++

}

result /= number_samples; // box filter

// tone map!

image.set(pixel, result);

Page 28: CS 6958 LECTURE 13 INTRO TO ANTI-ALIASING, PATHTRACINGcs6958/slides/Lec15.pdf · What is Aliasing? 3 If we render it with our ray tracers… Source: Physically Based Rendering, Pharr

End

28