Previous | Next --- Slide 14 of 28
Back to Lecture Thumbnails
ngandhi

The reason for even vs. odd number of piercing is that for every time the ray enters the object, it must also exit. So for an even number of intersections, it means it is outside. Otherwise it is inside.

diegom

This topic got me thinking about shadows in video games. Most video games don't support ray tracing yet almost all of them have shadows. Are shadows in video games implemented using some other methods then?

idontknow

@diegom I think most modern games use a bunch of little tricks all at once to create shadows. For example, Unity (a game engine) can

1) calculate the shadows in advance and just reapply the result as a texture to the surface. this is called light mapping and it's used for scenes where the shadows aren't moving (e.g. a call of duty multiplayer map)

2) use post-processing effects to mimic shadows darkening where two planes intersect (screen space ambient occlusion)

3) use "light probes", which store light information and then computes linear interpolations to mimic light shining on moving objects. this is really neat because when combined with light maps shadows look more convincing

4) approximate light as being uniform and unidirectional throughout a scene rather than originating at a specific point

graphicstar11

I thought this was very interesting because I've always wondered how shadows and light exposure can be depicted so accurately and precisely in graphics. Are there other ways than the ray mesh intersection method to depict shadows?

FeiFeiFei

The reason why odd number of piecing for a close form indicates the point is inside of the form is that, when the ray goes from a point inside, it first goes outside (odd). Then it goes inside, if it piece the surface again. (even) Then at some point it must go outside again following the ray direction (odd). And so forth. So odd number of piecing indicates the point is inside.

bepis

This is really interesting. The ray mesh inside-outside test is surprisingly simple and intuitive. As people have already said, an odd number of piercings means it is inside and an even number means it is outside, because we start outside and in a way flip this inside/outside sign every time we pierce something.

ahhuang

For the one intersection case, I don't see what would prevent you also having a ray that is tangential to one of the mesh vertices as well

keenan

@ahhuang A ray hitting the surface tangentially can happen in principle, but sort of doesn't happen in practice---it's a very rare event! Occasionally it can yield rendering artifacts due to numerical precision issues (e.g., a ray grazing a large flat surface might get you a hit point that is far from the true hit point, similar to this slide).

keenan

@All An awesome idea for getting precise shadows in the real-time graphics pipeline is [shadow volumes], which is based on this same kind of "even/odd" thinking. Imagine you have a point light and a triangle mesh. From the perspective of the light, there are certain edges that are on the silhouette of the mesh (namely: those edges where one neighboring triangle normal has a positive dot product with the light, and the other is negative). So, you take these edges and extrude them along the light direction to create a "shadow volume," which basically corresponds to the volumetric region of space that cannot see the light. You then rasterize the triangles of this shadow volume just like any other triangles. BUT, rather than drawing samples into the color buffer, you draw them into a separate "stencil buffer" that flips a bit on and off each time you write to it. So if there are an odd number of triangles from the shadow volume over a sample, your buffer stores a "1". If there are an even number, you store "0". (At the same time, you don't write anything that's further away than the closest scene object stored in the Z-buffer.). This way you know exactly which fragments are in/out of shadow. No ray tracing needed!

Sadly it only works for hard-edged shadows, and requires that you have a nice, closed, manifold mesh from which you can easily construct a shadow volume. But it's a great-looking technique in cases where it's appropriate.

Shadow volume example