170 likes | 308 Views
Distributed Ray Tracing Part 1. 黃聰賢. Overview. Program Framework Generate Ray Get Nearest Intersection Ray-Triangle Intersection Space Partition Ray-Box Intersection Visibility. Framework. Model view: only glLoadIdentity () Projection: use glLoadIdentity () and glOrtho (…)
E N D
Overview • Program Framework • Generate Ray • Get Nearest Intersection • Ray-Triangle Intersection • Space Partition • Ray-Box Intersection • Visibility
Framework Model view: only glLoadIdentity() Projection: use glLoadIdentity() and glOrtho(…) For i from 0 to screen_width-1 For j from 0 to screen_height-1 Ray r = GenerateRay( … ); Point p = GetNearestIntersection(r); pixel_color = ComputeColor(p); glBegin(GL_POINTS); glColor3f(pixel_color); glVertex2i(i,j); glEnd();
Generate Ray • Input • Eye : • position, direction, up direction • The position of the pixel in the screen : • (i, j) • The screen resolution : • screen_width, screen_height • Projection setting: • near, right, left, top, bottom • Output • Ray : • start position, direction
pixel(i,j) Top i top H Right j near right Ray (0,0) up eye direction W (W/2,H/2) R2 Screen Resolution : W * H R3 Frustum near, right, top eye Right = normalize(eye direction × up direction) Top = normalize(Right ×eye direction) (P.S. top ≠ up) Raydirection = normalize (near * normalize(eye direction) +[(i-W/2)/(W/2)]*right*Right +[(j-H/2)/(H/2)]*top*Top )
Get Nearest Intersection Input : Ray r; Output : Nearest intersection point p; Point temp_point; float t; float distance = FLT_MAX; For each face f { t = ray_triangle(&f, &r, &tmp_point); if( t<distance && t > ε) { distance = t; p = temp_point; } }
Space Partition • Octree • KD-Tree
Ray-Box intersection txmax txmin tymax tymax txmax tymin tymin txmin
ac: center of box ai: normalized side direction of box hi: positive half length of box
Visibility • Shoot a ray to the light and try to get the distance to the nearest intersection point. • If the distance > the distance to the light,add the lighting effect • Space partition can speed up the computation.
light pixel d_L d_hit eye p d_L < d_hit , visibility = 1 light d_L eye d_hit d_L > d_hit , visibility = 0
y0 light y1 eye ω0 yi ω1 ωi x
Direct Lighting • Use Phong Lighting Model. • Add the lighting effect if visibility is one. I * (Kd * dot(N, L) + Ks * pow(dot(E, R), Ns) ) N E L R
Indirect Lighting • Use importance sampling to choose direction • If the direction hits a point yi ,compute the yi direct lighting y0 ω0 y1 normal ω1 eye yi ωi x