ray tracing tutorial. ray casting one type of visibility algorithm
Post on 19-Dec-2015
224 views
TRANSCRIPT
![Page 1: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/1.jpg)
Ray Tracing Tutorial
![Page 2: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/2.jpg)
Ray CastingOne type of visibility algorithm
![Page 3: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/3.jpg)
Basic IdeaRayCast(Camera, Scene, img_w, img_h)
{
for (row=0; row < img_h; row++) {
for (col=0; col< img_h; col++) {
ray = constructRay(camera, row, col);
(hit,color)=getIntersection(ray, scene);
image[row][col] = color;
}
}
return image
}
![Page 4: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/4.jpg)
Constructing Primary Rays
CoP
u
nv
Xmin, Ymin
![Page 5: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/5.jpg)
Constructing Primary Rays
CoP
![Page 6: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/6.jpg)
Constructing Primary Rays
CoP
![Page 7: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/7.jpg)
Constructing Primary Rays
CoP
![Page 8: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/8.jpg)
Gathering all the info from .dat file
Camera specification
• Viewport <width> <height>
• Resolution <x_res> <y_res>
• Camera {perspective, orthographic}
<cop_x><cop_y><cop_z>
<look_x><look_y><look_z>
<up_z><up_y><up_z>
<focal_length>
<near_plane> <far_plane>
CoP point
lookat point
up vector
![Page 9: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/9.jpg)
Visualizing the components
CoP
Look at point
up vector
Width (in pixels)
Height (in pixels)
x_res
y_res
focal length
![Page 10: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/10.jpg)
Constructing the Orthogonal Basis
CoP
Look at point
up vector
u
n
v
n = normalize lookat vector u = n x upv = u x n
![Page 11: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/11.jpg)
Computing Starting Point
CoPu
n
v
X, Y
Beware of units. Pixels versus world units
focal length
![Page 12: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/12.jpg)
Constructing a Primary Ray
CoP
![Page 13: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/13.jpg)
CoP
Cast Ray
Current Pixel Color(0.2,0.8,0.2) due to ambientterm
![Page 14: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/14.jpg)
CoP
Check for Intersections
Current Pixel Color(0.2,0.8,0.2) due to ambientterm
Beware of near and farclipping planes as well
![Page 15: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/15.jpg)
Some Tips• Try the simplest test case you can think of
(eg one sphere, and simple camera location)
• Break Down into steps– Ray Cast in BW with spheres (ensure
generation of primary rays is correct)– Shade with Primary Ray contribution.– Try more complex surfaces
• Normalize, Normalize, Normalize
• Clamp color [0,1]
![Page 16: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/16.jpg)
CoP
Pick Nearest
Current Pixel Color(0.2,0.8,0.2) due to ambientterm
![Page 17: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/17.jpg)
Computing the Surface Lighting Effect
![Page 18: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/18.jpg)
CoP
ConnectLight Ray
Current Pixel Color(0.2,0.8,0.2) due to ambientterm
![Page 19: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/19.jpg)
IR = IR,ambdiff + IR,diffused + IR,specular
IG = IG,ambdiff + IG,diffused + IG,specular
IB = IB,ambdiff + IB,diffused + IB,specular
![Page 20: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/20.jpg)
I = Iambdiff + I diffused + I specular
For example (0.2, 0.8, 0.2) for this material.A constant. Independent of lightingAnd viewing direction
![Page 21: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/21.jpg)
I = Iambdiff + I diffused + I specular
N
LIdiffused = kd Il (N.L)
Compute for all 3 channels. For example (0.1, 0.1, 0.1).
Independent of Viewpoint
![Page 22: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/22.jpg)
I = Iambdiff + I diffused + I specular
N
LIspecular = ks Il (V.R)ns
Compute for all 3 channels. For example (0.2, 0.2, 0.2).
V
R
![Page 23: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/23.jpg)
I = Iambdiff + I diffused + I specular
= (0.2, 0.8, 0.2) + (0.1, 0.1, 0.1) + (0.2, 0.2, 0.2)
= (0.5, 1.0, 0.5)
Clamp to [0,1]
![Page 24: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/24.jpg)
CoP
Current Pixel Color(0.5,1.0,0.5)
ConnectLight Ray
![Page 25: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/25.jpg)
What about areas in shadow?
![Page 26: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/26.jpg)
CoP Current Pixel Color(0.2,0.8,0.2) due toAmbient term
ConnectLight Ray
![Page 27: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/27.jpg)
Ray Tracing• Physical World :
– Photons shoot out from light sources, reflect off surfaces and into the eye.
– Problem : Only small fraction reaches the eye (or image plane). Difficult to simulate.
• Alternative way to simulate :– Reverse the process!– Trace the path backwards i.e from the eye (or
pixels) back to the light sources.– Ray Tracing!
![Page 28: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/28.jpg)
We modify the Ray-Casting algorithm to trace rays bouncing
off the surfaces.
![Page 29: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/29.jpg)
Outer Loop
Select center of projection and window on view plane;
For (each scan line in image) {
For (each pixel in scan line) { 1) Construct ray from center of projection through pixel 2) pixel = trace(ray,1);
}
}
![Page 30: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/30.jpg)
color trace(RT_ray ray, int depth) {Determine closest intersection of ray with an object
if there is an intersection {
1) compute normal at intersection
2) return shade ( closest object hit, ray, intersection, normal, depth)
}
}
Shade will return the cumulative color by recursively calling tracewith depth counter decremented at each invocation.
![Page 31: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/31.jpg)
CoP
ContributionFrom PrimaryRay
(0.5,1.0,0.5)
![Page 32: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/32.jpg)
CoP
ContributionFrom SecondaryRay
(0.5,1.0,0.5)
V2
V1
L (0.8,0.8,0.0)
![Page 33: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/33.jpg)
CoP
Final Pixel Color
(0.5,1.0,0.5)
V2
V1
L (0.8,0.8,0.0)+ =ks
![Page 34: Ray Tracing Tutorial. Ray Casting One type of visibility algorithm](https://reader038.vdocuments.mx/reader038/viewer/2022110207/56649d2b5503460f94a015cc/html5/thumbnails/34.jpg)
The End