cs361

32
CS361 Week 10 - Monday

Upload: kesler

Post on 23-Feb-2016

93 views

Category:

Documents


0 download

DESCRIPTION

Week 10 - Monday. CS361. Last time. What did we talk about last time? Global illumination Shadows Projection shadows Soft shadows. Questions?. Project 3. Project 3. Assignment 4. Planar shadows summarized. Project the object onto a plane Gives a hard shadow - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS361

CS361Week 10 - Monday

Page 2: CS361

Last time

What did we talk about last time? Global illumination Shadows

Projection shadows Soft shadows

Page 3: CS361

Questions?

Page 4: CS361

Project 3

Page 5: CS361

Planar shadows summarized Project the object onto a plane

Gives a hard shadow Needs tricks if the object is bigger than the

plane Gets an antishadow if the light is between

occluder and receiver Soften the shadow

Render the shadow multiple times Blur the projection Put gradients around the edges

Page 6: CS361

Shadows on a curved surface Think of shadows from the light's

perspective It "sees" whatever is not blocked by the

occluder We can render the occluder as black

onto a white texture Then, compute (u,v) coordinates of

this texture for each triangle on the receiver There is often hardware support for this

This is known as the shadow texture technique

Page 7: CS361

Shadow texture issues Weaknesses

The program has to know which objects are occluders and which are receivers▪ It has to be careful not to cast onto receivers that do not

have the light blocked (antishadows) Occluders cannot shadow themselves

Strengths If the occluders do not change shape, the shadow

texture can be reused A variation of the idea can be used to make

complicated shadow textures (e.g. Venetian blinds)

Page 8: CS361

Student Lecture: Shadow Volumes and Shadow Mapping

Page 9: CS361

Shadow volumes Shadow volumes are another technique for casting

shadows onto arbitrary objects Setup:

Imagine a point and a triangle Extending lines from the point through the triangle vertices

makes an infinite pyramid If the point is a light, anything in the truncated pyramid under the

triangle is in shadow The truncated pyramid is the shadow volume

Page 10: CS361

Shadow volumes in principle Follow a ray from the eye through a pixel until it hits the object

to be displayed Increment a counter each time the ray crosses a frontfacing face

of the shadow volume Decrement a counter each time the ray crosses a backfacing

face of the shadow volume If the counter is greater than zero, the pixel is in shadow Idea works for multiple triangles casting a shadow

Page 11: CS361

Shadow volumes in practice Calculating this geometrically is tedious and slow in software We use the stencil buffer instead

Clear the stencil buffer Draw the scene into the frame buffer (storing color and Z-data) Turn off Z-buffer writing (but leave testing on) Draw the frontfacing polygons of the shadow volumes on the stencil

buffer (with incrementing done) Then draw the backfacing polygons of the shadow values on the

stencil buffer (with decrementing done) Because of the Z-test, only the visible shadow polygons are drawn

on the stencil Finally, draw the scene but only where the stencil buffer is zero

Page 12: CS361

Shadow volume issues It is possible to use color

or alpha buffers instead If shadow volumes don't

overlap, we can do the information in one pass, with a single bit of information

If the viewer is inside a shadow volume, we have to change the algorithm

If shadow volume planes intersect the near plane of the viewing frustum, bad things happen

Page 13: CS361

Shadow mapping Another technique is to render

the scene from the perspective of the light using the Z-buffer algorithm, but with all the lighting turned off

The Z-buffer then gives a shadow map, showing the depths of every pixel

Then, we render the scene from the viewer's perspective, and darken those pixels that are further from the light than their corresponding point in the shadow map

Page 14: CS361

Another visualizationScene without shadows Scene from the light's

viewpointDepth map from the

light's viewpoint

Depth of the light compared to depth of

the imageDepth test failsScene with shadows

Page 15: CS361

Shadow mapping issues Strengths:

A shadow map is fast Linear for the number of objects

Weaknesses: A shadow map only works for a single light, but you can

combine multiple maps for multiple lights Objects can shadow themselves (a bias needs to be used) Too high of a bias can make shadows look wrong

Page 16: CS361

Shadow map distortion Another issue with shadow maps is that the Z-buffer map

may oversample some areas and undersample others Similar to a texture that is stretched so that some is pixelated

and some is far We can change the view direction and projection so that

the Z-buffer map from the lighting better matches the sampling the eye sees

More complex methods make multiple shadow maps along the view

Page 17: CS361

Percentage closer filtering The shadow map technique does not, by itself,

make soft shadows Soft shadows can be achieved by sampling the four

closest points in the shadow map and interpolating them together

Percentage-closer filtering tries to approximate area lighting with point lights by seeing how much of the nearby surface can see the point light

Page 18: CS361

Ambient Occlusion

Page 19: CS361

Ambient occlusion Ambient lighting is completely even and

directionless As a consequence, objects in ambient

lighting without shadows look very flat Ambient occlusion is an attempt to add

shadowing to ambient lighting

Page 20: CS361

Ambient occlusion theory Without taking occlusion into account, the

ambient irradiance is constant:

But for points that are blocked in some way, the radiance will be less

We use the factor kA(p) to represent the fraction of the total irradiance available at point p

ALπE ),( np

AA LπkE )(),( pnp

Page 21: CS361

Bent normals The ideas used for ambient occlusion can be applied

to other lighting We could use an irradiance map to give diffuse

lighting that is both directed and diffuse As the figure shows, we can weight the surface

normals based on visibility to produce a bent normal We then use the bent normal for doing lookups in the

irradiance map

Page 22: CS361

Computing kA

The trick, of course, is how to compute kA The visibility function approach checks to

see if a ray cast from a direction intersects any other object before reaching a point We average over all (or many) directions to get

the final value Doesn't work (without modifications) for a closed

room Obscurance is similar, except that it is based

on the distance of the intersection of the ray cast, not just whether or not it does

Page 23: CS361

Interreflections Generally, ambient occlusion makes the shadows darker

than they should be In a real global illumination situation, objects interreflect,

redirecting light onto surfaces that are otherwise blocked One way to simulate this is by changing the kA term:

)1(1 amb A

AA k

kk

c

Page 24: CS361

Dynamic computation of ambient occlusion

In static scenes, kA and bent normal nbent can be precomputed

For dynamic scenes, it must be done on the fly

There are object space methods that involve casting rays from every vertex to every other vertex to determine intersections Optimizations can be done that divide

the screen up into hierarchies

Page 25: CS361

Screen space ambient occlusion Screen space ambient occlusion methods have become

popular in recent video games such as Crysis and StarCraft 2 Scene complexity isn't an issue

In Crysis, sample points around each point are tested against the Z-buffer More points that are behind the visible Z –buffer give a more

occluded point A very inexpensive technique is to use an unsharp mask (a

filter that emphasizes edges) on the Z-buffer, and use the result to darken the image

Page 26: CS361

StarCraft 2 ambient occlusion

Page 27: CS361

StarCraft 2 lighting

Page 28: CS361

StarCraft 2 final image

Page 29: CS361

SC2 ambient occlusion

after Patch 1.2

Page 30: CS361

Upcoming

Page 31: CS361

Next time…

Reflection Transmittance Refraction Caustics Subsurface scattering

Page 32: CS361

Reminders

Keep working on Project 3 Due by midnight next Thursday

Keep reading Chapter 9