Presentation is loading. Please wait.

Presentation is loading. Please wait.

黃聰賢.  Program Framework  Generate Ray  Get Nearest Intersection ◦ Ray-Triangle Intersection ◦ Space Partition ◦ Ray-Box Intersection  Visibility.

Similar presentations


Presentation on theme: "黃聰賢.  Program Framework  Generate Ray  Get Nearest Intersection ◦ Ray-Triangle Intersection ◦ Space Partition ◦ Ray-Box Intersection  Visibility."— Presentation transcript:

1 黃聰賢

2  Program Framework  Generate Ray  Get Nearest Intersection ◦ Ray-Triangle Intersection ◦ Space Partition ◦ Ray-Box Intersection  Visibility

3 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();

4  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

5 Right Top eye up eye direction R 3 Frustum near, right, top R 2 Screen Resolution : W * H Right = normalize(eye direction × up direction) Top = normalize(Right × eye direction) (P.S. top ≠ up) Ray direction = normalize ( near * normalize(eye direction) +[(i-W/2)/(W/2)]*right*Right +[(j-H/2)/(H/2)]*top*Top ) (0,0) W H i j pixel(i,j) right top Ray near (W/2,H/2)

6 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; p = temp_point; }

7 =>=> =>=>

8 =>=>

9

10  Octree  KD-Tree

11 t y min t y max t x min t x max t y min t y max t x min

12 a c : center of box a i : normalized side direction of box h i : positive half length of box

13  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.

14 eye d_L d_hit d_L < d_hit, visibility = 1 light eye d_L d_hit d_L > d_hit, visibility = 0 light pixel p

15 eye x y0y0 y1y1 yiyi ω0ω0 ω1ω1 ωiωi light

16  Use Phong Lighting Model.  Add the lighting effect if visibility is one. N E R L I * (Kd * dot(N, L) + Ks * pow(dot(E, R), Ns) )

17  Use importance sampling to choose direction  If the direction hits a point y i, compute the y i direct lighting eye x y0y0 y1y1 yiyi normal ω0ω0 ω1ω1 ωiωi


Download ppt "黃聰賢.  Program Framework  Generate Ray  Get Nearest Intersection ◦ Ray-Triangle Intersection ◦ Space Partition ◦ Ray-Box Intersection  Visibility."

Similar presentations


Ads by Google