37
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics 1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do • Radiosity

CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

Embed Size (px)

Citation preview

Page 1: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics1

Radiosity

• What we can do with scan line conversion and ray tracing

• What we can’t do

• Radiosity

Page 2: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics2

Types of Illumination

• Scan-line Techniques– Diffuse reflection of light sources– Specular reflection of light sources

• Ray tracing and move advanced scan line techniques– Specular reflection from other objects– Transmission

• Seem like anything is missing, here?

Page 3: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics3

The Big Lie!!!

• Ambient Light!– Does not really exist– It’s faking light reflecting from other surfaces

Page 4: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics4

What really happens

• Light reflects off of surfaces and illuminates other surfaces– Every surface affects every other surface

• One hacky solution– Assume all of the light from all surfaces is averaged into a

single illumination lighting that goes everywhere• That’s what we’ve been calling ambient light.

Page 5: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics5

Ambient Light is an approximation

• Many elements of natural lighting are not modeled well by ambient lighting at all– Corners– Interiors– Moving items

Page 6: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics6

Characteristics of Diffuse Reflection

How will OpenGL draw this box?

What about ray tracing?

What about nature?

Light

Box

Page 7: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics7

Our box on edge

Page 8: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics8

Complex Lighting Environments

• This is really a complicated lighting environment. – There is specular and diffuse reflection everywhere in the

box. – Ray tracing can approximate the specular reflection fairly

well, but not the diffuse reflection. • Let’s just look at diffuse reflection for now.– Note: In the real world diffuse and specular reflection

interact in a complex manner. We’ll get to combining the two later.

Page 9: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics9

Radiosity

• Fundamental principle:

– Conservation of energy

– Light is either absorbed or reflected!

Page 10: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics10

Radiosity

• Every surface is treated as a diffuse reflector and emitter and all surfaces are assumed to conserve light energy. – The rate at which energy leaves the surface, the radiosity,

is the sum of the rates at which the surface reflects or transmits energy from other surfaces and the rate at which the surface emits energy.

• Note: we no longer have disjoint light sources. – Every object in the space is treated the same. – A light source is simply a surface that emits energy.

Page 11: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics11

How do we solve this?

• Simple example: two surfaces

Page 12: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics12

Solving this…

• Every surface’s radiosity is dependent upon the light falling on that surface from other surfaces, – which is a function of their radiosity,

• which will be dependent upon every other surface’s radiosity– which will be dependent upon every other surface’s radiosity

» which will be dependent upon every other surface’s radiosity

– Is it any surprise that we will be either solving or approximating solutions to simultaneous equations?

Page 13: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics13

Pure Radiosity vs. Real World

• Pure Radiosity systems don’t have light sources, surfaces are light sources– Lighted panels are easy to do, as are light bulbs, etc.– Neon is just too cool…

• But, many systems compute reflection from light sources, then augment with the radiosity solution.

Page 14: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics14

Problems with our box

• What do we model?– Surfaces?– Points?

Page 15: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics15

Patches

• Radiosity systems break surfaces into smaller areas called patches– Surfaces are too big for a single radiosity– Points are just too small

Page 16: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics16

The Radiosity Equation

• Bi - The radiosity of patch i.– the rate at which light is emitted. This is units of energy

per unit area per time. – This is what we are computing. Note that this may be a

spectra (color). Do all this stuff for R, G, and B.

• Ei - The emissivity of the patch. – This is the light generated by the patch and is of the same

units as Bi, will be zero for anything that is not a light source.

Bi E i i B jF j i

A j

Ai1jn

Page 17: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics17

The Radiosity Equation

• i - The reflectivity of the surface. – This is equivalent to kdr in the Hall model.

• Bj - The radiosity of some other patch j.• Fj-i - The form factor. – What fraction of energy leaving patch j will arrive at patch

i. – This is dependent upon shape, relative angles, intervening

patches, etc.

• Ai and Aj are the areas of the patches i and j.

Bi E i i B jF j i

A j

Ai1jn

Page 18: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics18

What’s that Aj/Ai ratio?

• For patch j of area Aj, the amount of energy leaving per unit area is Bj. – Since the area can be of any size, we are interested in the

total amount of energy! – This is BjAj.

• But, Bi is also energy per unit area. – So, we divide the total energy getting to Bi from Bj by Ai.

– Hence, the ratio Aj/Ai.

Bi E i i B jF j i

A j

Ai1jn

Page 19: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics19

A Simplification

• The unit area energy leaving patch j is scaled by Fj-iAj.

• Likewise, unit area energy leaving patch i is scaled by Fi-jAi.

• These are symmetrical paths– So, Fi-jAi = Fj-iAj. So, Fj-iAj/Ai = Fi-j

• We can plug that into the above equation and ELIMINATE the areas:

Bi E i i B jF j i

A j

Ai1jn

n

jjijiii FBEB

1

Page 20: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics20

How do we solve this?

• We have one massive simultaneous equation– Note that the problem is O(N2)

• A variety of “short-cuts” exist.

– We can solve using Gauss-Seidel iteration, a numerical method for solving simultaneous equations.

n

jjijiii FBEB

1

Page 21: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics21

Solving…

n

jjijiii FBEB

1

n

jjijiii FBBE

1

nnnnnnnnn

n

n

E

E

E

B

B

B

FFF

FFF

FFF

......

1

1

...1

2

1

2

1

21

22222122

11211111

bAx

Page 22: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics22

TNT::Array2D<double> A(patchcnt, patchcnt); TNT::Array1D<double> b(patchcnt);

// Create matrix A and vector b for(i=0; i<patchcnt; i++) { for(int j=0; j<patchcnt; j++) { A[i][j] = -m_patches[i].r * m_patches[i].ff[j]; if(i == j) A[i][j] += 1.; }

b[i] = m_patches[i].e; } // Solve for x JAMA::QR<double> qr(A); TNT::Array1D<double> x = qr.solve(b);

// Result is in x for(i=0; i<patchcnt; i++) { m_patches[i].b = x[i]; }

nnnnnnnn

n

E

E

E

B

B

B

FFF

FFF

FFF

......

1

1

...1

2

1

2

1

222

222222222

1211111

bAx

Page 23: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics23

But, these are radiosities for patches

• Won’t the image look patchy?• No...– We average the colors for patches to make vertex colors

and interpolate

Page 24: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics24

View Independence

• Note that all of the diffuse lighting is view independent– We can compute it once and display it afterwards with

varying views…– Or, we can add this component to other computed light

components• Use ray tracing to compute the specular surface colors, radiosity to

compute the diffuse

Page 25: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics25

Examples

OpenGL Rendering Radiosity Rendering

Page 26: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics26

Form Factors

Patch i

Patch jri

j

nj

ni

i jA A

jiijji

iij dAdAH

rAF

2

coscos1

Ai – Area of patch i

Hij – 1 if path from dAi to dAj exists.

Page 27: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics27

double ainv = 1. / (m_subdivide * m_subdivide); // Inverse of the area of a patch

for(i=0; i<patchcnt; i++) { Patch *patchi = &m_patches[i]; patchi->ff.resize(patchcnt);

for(int j=0; j<patchcnt; j++) { Patch *patchj = &m_patches[j];

// Vector from i to j CGrPoint itoj = patchj->c - patchi->c; itoj.Normalize3();

// Vector from j to i CGrPoint jtoi = -itoj;

// Distance between? double r = (patchi->c - patchj->c).Length3(); r = 1.0;

if(i == j) patchi->ff[j] = 0; else patchi->ff[j] = (Dot3(patchi->n, itoj) * Dot3(patchj->n, jtoi) / (GR_PI * r * r)) * ainv; } }

i jA A

jiijji

iij dAdAH

rAF

2

coscos1

Page 28: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics28

Form Factor Computations

• Direct analytical computation of form factors is not practical– Life is too short for numerical integration…– Instead, we’ll use an approximation technique

Page 29: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics29

Cohen and Greenberg Form Factor Estimation Algorithm

• We are interested in determining Fij, the form factor for light traveling from patch i to patch j. – We’ll approximate this using the following technique

Page 30: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics30

Hemicube

• Create a half cube - called a hemicube - consisting of rectangular square areas called cells:

Ai

Aj

x

yz=Ni

Page 31: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics31

Projecting on Hemicube

• Project all the surfaces onto the surface of the hemicube. This will take 5 different projections to accomplish (why?)

Ai

Aj

x

yz=Ni

Page 32: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics32

Think of this as viewing

• When I view from the center of a patch, the following affects the form factor– How big it appears– The angles to the surface– How far to the projection

• Note the far and large is the same as near and smaller…

• If we use the item buffer algorithm, we can tell what’s closer and not occluded

Page 33: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics33

Projecting on a Hemicube

• We have 5 item buffers, each one for the cells on one face of the hemicube

Ai

Aj

x

yz=Ni

Page 34: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics34

Cells equal parts of the form factor

• Suppose cell p has item j in it.– We add Fp to Fij

– For top faces

– For side facesFp 1

xp2 yp

2 1 2 A

Fp 1

yp2 zp

2 1 2 A

(xp,yp,zp) is center of cell.A is the area of the cell.

Page 35: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics35

Any options other than “hemicube”?• …

Page 36: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics36

Substructuring

• How much do we subdivide?– Too much is costly, not enough looks bad

Substructuring – Compute at one level of subdivision and further divide if we get large differences in intensities

What will we have to recompute?

Page 37: CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Radiosity What we can do with scan line conversion and ray tracing What we can’t do Radiosity

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics37

Substructuring

• Very effective at finding shadow lines, and varying gradients