1
Ray Casting
Based on slides of Thomas Funkhouser
3D Rendering
- The color of each pixel on the view plane
Ray Casting Based on slides of Thomas Funkhouser 3D Rendering - - PDF document
Ray Casting Based on slides of Thomas Funkhouser 3D Rendering The color of each pixel on the view plane depends on the radiance emanating from visible surfaces Rays through view plane Simplest method is ray casting View plane Eye
Image RayCast(Camera camera, Scene scene, int width, int height) { Image image = new Image(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit); } } return image; }
Image RayCast(Camera camera, Scene scene, int width, int height) { Image image = new Image(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit); } } return image; }
right back Up direction
P0
t
a r d s
View Plane P V
d
right right = towards x up = frustum half-angle d = distance to view plane P1 = P0 + d*towards - d*tan()*right P2 = P0 + d*towards + d*tan()*right P1 P2
2*d*tan(
P P = P1 + (i/width + 0.5) * 2*d*tan ()*right V = (P - P0) / ||P - P0 || V
Image RayCast(Camera camera, Scene scene, int width, int height) { Image image = new Image(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit); } } return image; }
V
r
V
r
2
V
r
r d thc tca L
V
r
N
Intersection FindIntersection(Ray ray, Scene scene) { min_t = infinity min_primitive = NULL For each primitive in scene { t = Intersect(ray, primitive); if (t < min_t) then min_primitive = primitive min_t = t } } return Intersection(min_t, min_primitive) }
Image RayCast(Camera camera, Scene scene, int width, int height) { Image image = new Image(width, height); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray ray = ConstructRayThroughPixel(camera, i, j); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit); } } return image; }
right back Up direction
P0
t
a r d s
View Plane P V
P0
right back Up direction
P0
t
a r d s
View Plane P V
P0
Cy Sy 1
Cy
Sx
Cx SxSy
Cy
E
t
a r d s
View Plane P
P0
Image RayCast(Camera camera, Scene scene, int width, int height) { Image image = new Image(width, height); Set P0 (as in the previous slide); for (int i = 0; i < height; i++) { p = P0; for (int j = 0; j < width; j++) { Ray ray = E + t * (p – E); Intersection hit = FindIntersection(ray, scene); image[i][j] = GetColor(hit); p += Vx; // move one pixel along the vector Vx } P0 += Vy; // move one pixel along the vector Vy } return image; }