Ray Tracing 23 May 2016 SCG3023 1

Download Report

Transcript Ray Tracing 23 May 2016 SCG3023 1

Ray Tracing

24 April 2020 SCG3023 1

Illumination models & realism

We’ve been using the Phong lighting model for illumination.

Is it realistic?

– – – – – –

Empirical specular term for highlights “Ambient” term for indirect illumination No illumination away from light give shadow like effect, but … No cast shadows No surface interreflection No refraction through transparent or translucent objects – including caustics 24 April 2020 SCG3023 2

Global illumination

Global illumination techniques strive to include all of these physical phenomena.

In practice, they often do not.

Path tracing – simulate light optics Reflections/refractions (glossy objects, caustics) Lens effects Radiosity – simulate light transfer Diffuse-diffuse reflections (color bleeding) Typically very expensive – not interactive.

24 April 2020 SCG3023 3

Forward vs Backward mapping

We’ve been studying the traditional graphics pipeline.

Commonly referred to as forward mapping – objects are transformed into image space to determine pixel coverage.

Ray tracing, a special case of path tracing, transforms pixels into object space to determine object contribution – backward mapping .

24 April 2020 SCG3023 4

Ray tracing

To determine the color of a given pixel: Create a ray from the eye, through the pixel, and into the world Intersect the ray with all objects in the scene Determine the visible surface Directly displaying the first intersection is commonly referred to as ray casting .

As we’ll see later, calling visibility ray tracing “ray casting” misses the point of what “full” ray tracing does different.

24 April 2020 SCG3023 5

Visibility determination

Eyepoint

24 April 2020

Screen

SCG3023

Scene

6

Lighting model

Once we’ve determined which object we can see along a particular ray, we have to determine color.

Assume we had triangles in the scene … we could determine an intersection be first determining if the ray intersects the plane of the triangle, then where, then if “where” is inside.

We can now easily determine: Surface normal View direction Light direction Texture coordinates So we can apply whatever light model we want – Phong for instance.

24 April 2020 SCG3023 7

Shadows

Or we can take our first step toward a “full” ray tracing algorithm: We could trace a shadow-ray from the point of intersection toward the light and determine if some other object blocks the light source.

24 April 2020 SCG3023 8

Inter-object reflections

We could trace a ray off reflective surfaces and determine if they hit objects – if they do we compute the lighting equations for the secondary ray and determine the contribution of this reflection at the first intersection 24 April 2020 SCG3023 9

Refraction

Transparent and translucent objects refract (bend) the light that passes through them. We could compute refracted rays and trace them as well.

We can calculate the angle from the indices of refraction of the two materials which interface at the ray-object intersection.

24 April 2020

n

1  2 sin sin  

r i

n

2

n

1

SCG3023 10

Recursive ray tracing

Full recursive ray tracing (as suggested by Whitted) does all of these at every intersection.

24 April 2020 SCG3023 11

The good & the bad

Good: Transparency Reflections Shadows Conceptually simple / pretty easy to write – no clipping, no projections, no scan conversion Bad: Intersection tests are expensive Intersection tests are expensive Intersection tests are expensive Typical framebuffer

1 million pixels Typical scene « 1 million polygons 24 April 2020 SCG3023 12

Ray-object intersections

In general, we parameterize the ray and find the parameter value where the ray intersects the object.

Doing this for all objects, we keep the smallest non-negative parameter value – that’s the intersection with the first object along the ray.

From the intersection point, we can compute whatever surface properties we need.

How should we represent a ray?

So how do we compute intersections?

24 April 2020 SCG3023 13

Ray representation

What’s a ray?

It has an origin and a direction.

Any point on the ray is just: origin + t•direction So our intersection test just need to solve for t.

24 April 2020 SCG3023 14

Ray-triangle intersection

Triangles are the most common model representation: Lowest common denominator Can use hardware to accelerate Basic approach: Find plane equation (from vertex coordinates) Find intersection between ray and plane Does triangle contain intersection point?

We can interpolate surface properties for this intersection from the vertices, but only if we need to – separate this calculation from the intersection test.

24 April 2020 SCG3023 15

Constructive Solid Geometry

Use Boolean operations to combine simple primitives into complex objects.

CSG models are typically represented as trees, Boolean operators make the nodes and geometric primitives make up the leaves.

A common modeling concept for any kind of rendering, but it’s especially easy to determine what the resulting surface is for ray tracing.

24 April 2020 SCG3023 16

Shadow rays – area lights

We can sample instead … Add up contribution from shadow rays reaching the area light.

Trade-off – instead of on very expensive test, we have several potentially expensive tests.

24 April 2020 SCG3023 17

Shadow rays – translucent shadowing

Translucent objects should cast colored shadows.

We can fake the colored shadows: Find all intersections along the ray.

If an object is translucent, attenuate the light accordingly.

Only give up if we hit an opaque object or too many translucent objects.

What’s wrong with this hack?

24 April 2020 SCG3023 18

Lens effects

Typically, the camera model is that of a pin-hole camera.

We can easily insert a lens into the optical path and get the expected effects.

24 April 2020 SCG3023 19

What bounding volume?

Spheres: Cheap intersection test Typically a poor fit Hard to cluster optimally – see poor fit Axis-aligned bounding boxes (AABBs): Ray-box test we had before – reasonably cheap Easier to get good fits than spheres Trivial clustering Oriented bounding boxes (OBBs): Medium intersection test Very good fit (provably, asymptotically better than AABB) Medium clustering difficulty 24 April 2020 SCG3023 20

Spatial partitioning

Classification of space into non-overlapping portions Uniform-grid Octree k-D tree BSP-tree 24 April 2020 SCG3023 21

Stochastic ray tracing

24 April 2020 SCG3023 22

What can’t ray tracing do?

24 April 2020 SCG3023 23

What can’t ray tracing do?

24 April 2020 SCG3023 24

Radiosity can capture that

Radiosity models the transport of light between surfaces.

Part of full the radiosity solution is computing reflection between every pairing of surfaces.

If you really have time to kill, you could use the BRDF to drive stochastic sampling in a path tracer to get diffuse-diffuse reflections.

It would probably actually be slower than the radiosity solution for less accurate results, but in the limit it would converge to the “right” thing.

24 April 2020 SCG3023 25