17
Distributed Ray Tracing Part 1 黃黃黃

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

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

Distributed Ray Tracing Part 1

黃聰賢

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

Ray-Triangle intersection

= >

= >

= >

Octree KD-Tree

Space Partition

Ray-Box intersection

tymin

tymax tx

min

txmax

txmax

tymin

tymax

txmin

ac: center of boxai: normalized side direction of boxhi: positive half length of box

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

eye

x

y0

y1

yiω0 ω1

ωi

light

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) )

Use importance sampling to choose direction

If the direction hits a point yi ,compute the yi direct lighting

Indirect Lighting

eye

x

y0

y1

yi

normalω0

ω1

ωi