View
221
Download
0
Category
Preview:
Citation preview
Program Framework Generate Ray Get Nearest Intersection
◦ Ray-Triangle Intersection◦ Space Partition◦ Ray-Box Intersection
Visibility
Overview
Model view: only glLoadIdentity()Projection: use glLoadIdentity() and glOrtho(…)
For i from 0 to screen_width-1For 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();
Framework
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
Generate Ray
Right
Top
eye
up eyedirection
R3 Frustumnear, right, top
R2 ScreenResolution : 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
Raynear
(W/2,H/2)
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;
}}
Get Nearest Intersection
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.
Visibility
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
Use Phong Lighting Model. Add the lighting effect if visibility is one.
Direct Lighting
NE
R L
I * (Kd * dot(N, L) + Ks * pow(dot(E, R), Ns) )
Recommended