50

Ray Tracing Advanced Topics - courses.cs.tau.ac.il

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Ray Tracing Advanced Topics - courses.cs.tau.ac.il
Page 2: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Today

Anti-aliasing

Surface Parametrization

Soft Shadows

Global Illumination

Path Tracing

Radiosity

Exercise 2

Page 3: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

SamplingRay Casting is a form of discrete sampling.

Ground Truth:An Exact MathematicRepresentation

Rendered Image:Sampling of the groundTruth at regular intervals

Signal Frequency?Sampling Frequency?

Page 4: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Anti-AliasingAliasing: A distortion or artifact as a result of sampling.

Higher frequency removal

To reproduce the signal fully - Nyquist rate

Signal Sampled

Related problem – Moiré

Page 5: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Anti-Aliasing Staircasing

Pixels on the boundary

Page 6: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Anti-Aliasing Anti-aliasing - The attempt to reduce or eliminate aliasing

artifacts

Page 7: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Uniform Supersampling Instead of sampling one point in every pixel. Sample k2

times (for some n) in uniform intervals

Set the pixel color to the average of the k2 colorssampled

Single Pixel - Single Sample Single Pixel - Multiple Sample

Page 8: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Cast ray through pixel Constructing a ray through a pixel

Parameters:

Eye point – P

View direction - towards

Up direction

Field of view – (xfov, yfov)

Distance to screen – d

right = towards x up

right and up define theorientation of the screen.

P0 and d define where it’s at. P0

up

right

center of screen

Pc yfov

Page 9: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Cast ray through pixelPc = P0 + towards*d

P is the pixel at

(xpixel, ypixel) = (2, 2)

Calculate (xscreen, yscreen)

P = Pc + xscreen*right + yscreen*up

V = (P - P0) / ||P - P0||

ray direction to P.

P0

up

yfov

Pc right

P

V

ray = P0 + t*V

Page 10: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Cast ray through pixel

xfov = 2.0

yfov

= 2

.0

Transforming (xpixel, ypixel) to (xscreen, yscreen)

+y

pixel-width = 320 px

pixel-h

eigh

t = 2

40 p

x

+up

Screen – In Object Space Application Window

+x

+rightPc

Page 11: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Uniform Supersampling

P0

up

yfov

Pc right

P

V

ray = P0 + t*V

Pc = P0 + towards*d

P is the pixel at

(xpixel, ypixel) = (2.5, 2.5)

Calculate (xscreen, yscreen)

P = Pc + xscreen*right + yscreen*up

V = (P - P0) / ||P - P0||

ray direction to P.

do this k2 times, average results.

Pixel coordinates can now have fractions

Page 12: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Uniform SupersamplingWhere should you sample the pixel?

1 sample per

pixel

4 sample per

pixel

9 sample per

pixel

0 ½ 1 0 ½ 1

½

1

0 0

½

1

¼ ¾

¼

¾

Page 13: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Uniform Supersampling Global uniformity:Distance betweenSamples is always the same

What NOT to do:

Two samples in the same point

Page 14: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Uniform Supersampling

Page 15: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Adaptive SupersamplingIf the difference between adjacent samples is too great, divide the pixel to 4 and cast more rays

Smooth pixels need only 4 samples

Edges can still be reproduced smoothly

Reuse common rays

Page 16: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Stochastic Sampling Uniform sampling often still can’t

account for frequency issues

Sub-divide the pixel to a grid

Choose a random point in every cell

Makes the interval of sampling non-uniform

Reduce aliasing by introducing noise

Page 17: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Questions?

Page 18: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Surface ParameterizationHow to add a 2D texture to a surface embedded in 3D?

(x,y,z)

Page 19: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Surface ParameterizationSimple case - rectangular plane

u

v

u [0,1], v [0,1]P = -v * (P3-P1) + u * (P2-P1)

Baricentric coordinates

Equation

P1

P2

P3

P4

P

1. Extract (u,v) from P

2. Get the pixel color at (u,v)

Page 20: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Surface ParameterizationSimple case - rectangular plane

u

v

u [0,1], v [0,1]P = -v * (P3-P1) + u * (P2-P1)

Baricentric coordinates

Equation

P1

P2

P3

P4

P

1. Extract (u,v) from P

2. Get the pixel color at (u,v)

Page 21: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Surface ParameterizationA Little more complex - Sphere

u

v

u [0,1], v [0,1]

1. Extract (u,v) from P

2. Get the pixel color at (u,v)

P

P = (x,y,z) (,,r)

u = , v =

Sphertical Coordinates

Page 22: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Surface ParameterizationGeneral Case – A Triangle Mesh

Page 23: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Questions?

Page 24: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Area Light So far we’ve see only “ideal” light sources

Light from infinity

Point Light

Spot Light

These produce“Hard Shadows”

To Create a realisticShadow one option isto use a morerealistic light source

Directed Light

Point Light

Area Light

Page 25: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Area Light Point light - Hard Shadows

Full ShadowUmbra

Lighs Source

Page 26: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Area Light Simple area light - simulated using a uniform grid of point

lights.

Full ShadowUmbra

Soft ShadowPenumbra

Lighs Source

Page 27: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Area Light Disadvantages of the simple uniform method:

Very time consuming

If the grid resolution is low, artifacts appear in the shadows.

Page 28: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Area LightMonte-Carlo Area light

Light is modeled as a sphere

Highest intensity in the middle. Gradually fade out.

Shoot n rays to random points in the sphere

Average their value.

Page 29: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte Carlo vs Las Vegas Two types of randomized, probabilistic methods for

constructing an algorithm

Results are statistic – Has an expectancy E(X) to be correct.

Monte Carlo:

Has a predictable time complexity.

Result may not be correct.

Better results the more you run it

Las Vegas:

Time complexity not guaranteed

Always returns the correct answer

Convert Monte-Carlo to Las-Vegas?

LasVegas

MonteCarlo

E(X)proofTime

proofE(X)Result

Page 30: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Global IlluminationIn the real world light is everywhere.

Reflects in every direction from every surface onto every surface.

Anywhere in the world, light comes from infinite directions around.

In the lighting equation we’ve used the Ambient intensity to approximate this.

Page 31: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Path Tracing Conventional Ray Tracing:

Cast rays from eye through each pixel

Trace secondary rays to light sources and reflections

Page 32: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Path Tracing A generalization of the concept of Monte-Carlo area light

Cast rays from eye through each pixel in a hemisphere

Cast random rays from the visible point, average contributions

Page 33: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Path Tracing Cast rays from eye through each pixel

Cast random rays from the visible point, average contributions

Recurse

Page 34: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Path Tracing Cast rays from eye through each pixel

Cast random rays from the visible point

Recurse, accumulate contributions

Page 35: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Ray Tracing Cast random rays from the visible point

Recurse, accumulate contributions

Sample light from all points we visited

Page 36: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Path Tracing1 random ray per pixel, 1 level recursion

Page 37: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Path Tracing16 random rays per pixel, 3 level recursion

Page 38: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Path Tracing64 random rays per pixel, 3 level recursion

Page 39: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Path Tracing64 random rays per pixel, 3 level recursion

NoticeColor Bleed

To White ball

Page 40: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Monte-Carlo Path Tracing16 random rays per pixel100 level recursion

16 random rays per pixel1 level recursion

Page 41: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Glossary Ray Casting:

Cast rays from eye through each pixel, find first hit

Ray Tracing:

Cast rays from eye through each pixel, find first hit

Recourse- Ray changes course/divides into few rays

Accumulate all results.

Path Tracing

Cast rays from eye through each pixel, find first hit

Recourse- Shoot random rays in the reflect hemisphere

Accumulate All results

1-3 rays per recursion step

1-100 rays per recursion step

Page 42: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Glossary Direct Illumination

Find a interaction between objects and emitters of light

“How much light from light source X hits this point”

Ray Tracing

Global Illumination

Find interaction between objects and complete environment

“How much light hits this point”, “Indirect lighting”

Path Tracing

Faked with The Ambient constant in the light equation.

Radiosity

Photon mapping

Page 43: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Radiosity (simplified)

A different approach to Global Illumination

Divide the scene into a set of small areas

The radiosicy of a patchis the total amount of lightemitted from it

Calculate all the amountof light a patch receives fromall other patches.

Calculate the radiosity

Iterate.

Page 44: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

RadiosityCalculating the amount of light a patch receives

Construct a “Hemicube” on the patch

Render the scene on the hemicube

Average the color.

Page 45: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Radiosity

Rendering ona hemicube

Page 46: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Radiosity

Initial StateFirst Iteration

Light emitted = Color * Light received

Page 47: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Radiosity

32nd iteration320th Iteration

Compute light emissions once,

View from any angle!

Page 48: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Radiosity

Direct Illumination Radiosity

Page 49: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Radiosity – Surface Subdivision Using a uniform mesh?

Wasteful. Smooth areas don’t need a great level of detail

Hierarchical subdivision

Areas with large changes get subdivided.

Page 50: Ray Tracing Advanced Topics - courses.cs.tau.ac.il

Ray Tracing exercise

Pair up!