Raytracing
description
Transcript of Raytracing
![Page 1: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/1.jpg)
Raytracing
Image synthesis using classical optics
![Page 2: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/2.jpg)
RaytracingCreate an image by following the paths
of rays through a scene“Backward raytracing": traces rays out
of the light sources out into the world“Forward raytracing": traces rays out
from the eye (camera) and out into the world and eventually back to the light sources
![Page 3: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/3.jpg)
![Page 4: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/4.jpg)
![Page 5: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/5.jpg)
Forward RaytracingSimplest form (raycasting):
for each pixel on the screen, send a ray out into the world
determine the first surface hit by the ray perform a lighting calculation at that
surface point set the color of the pixel according to the
result of the lighting calculation
![Page 6: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/6.jpg)
Raytracing
screen rays from eye
![Page 7: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/7.jpg)
RaysA ray is a half-line – it has only one end It can be written
p = o + t*d, t in (0,∞)
p is position (vector)o is the origin (vector)d is direction (vector)t is the parameter
![Page 8: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/8.jpg)
Ray Intersection Key computation: intersection of ray with
objects Typically produced by solving an equation:
p = f(t)Say the object is defined by an implicit surface,
g(x,y,z) = 0Then g(f(t)) = 0
Smallest value of t means first intersection
![Page 9: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/9.jpg)
Ray Intersection
![Page 10: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/10.jpg)
Ray-Sphere Intersection Implicit equation of sphere:
(x-xc)2 + (y-yc)2 + (z-zc)2 – R2 = 0 Or, (p-pc)•(p-pc) – R2 = 0
Say ray is given by p(t) = e + t*d
Then(d • d)t2 + 2d•(e - c)t + (e – c)•(e – c) – R2 = 0
![Page 11: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/11.jpg)
Other QuadricsCylinders, ellipsoids, paraboloids,
hyperboloids: all have the property that they are algebraic surfaces of degree 2, aka quadrics
The intersection calculation can be done analytically using the quadratic equation
![Page 12: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/12.jpg)
Lighting CalculationSo… we know where the ray hits the
surfaceBut what does the surface look like?Need to compute lighting at the point of
intersection
![Page 13: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/13.jpg)
Local Lighting CalculationCan use 3-term lighting calculation
local illumination
Raytracing allows us to do global illumination shadows reflected and refracted light
![Page 14: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/14.jpg)
Shadow RaysDecide if a point is in shadow or not
based on new ray intersection testCast ray from intersection point towards
light source If intersection found, point is in shadowOtherwise, not in shadow
![Page 15: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/15.jpg)
Raytracing TreeResolving a ray intersection can result in multiple additional rays
Transmitted rays
Ray intersection
Reflected rays
Shadow ray
![Page 16: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/16.jpg)
Reflected RaysRecursive call to raycast:
ray’s color is (1-c) times the color computed at the surface, plus c times the color computed by a new ray heading out of the surface in the reflected direction
May cast multiple reflected rays at slightly different directions
Need to terminate the recursion: maximum depth minimum energy carried by the ray
![Page 17: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/17.jpg)
![Page 18: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/18.jpg)
Accelerating IntersectionsMajority of work in raytracer in
computing intersectionsSimple-minded method: compute
intersections with every object in scene, take smallest parameter
Need to speed this up bounding geometry spatial partitioning
![Page 19: Raytracing](https://reader035.fdocuments.in/reader035/viewer/2022062501/56816709550346895ddb71f4/html5/thumbnails/19.jpg)
Raytracing vs Z-Buffer Initial intersection test is the hard part
Z-buffer still supremeBut, all kinds of effects with same code
transparency, reflection, shadows, caustics in Z-buffer, bizarre stack of methods
"Embarrassingly parallel": well suited to GPU from process viewpoint – but, recursion not possible on cards