foreach outgoing direction wo
- move light to illuminate surface with a thin beam from wo
- for each incoming direction wi
- move sensor to be at direction wi from surface
- measure incident radiance
-
测得BRDF是四维的,测量十分耗时
-
固定了摄像机之后,光源要整个走一遍球面,才能覆盖所有的光源方向,如果下次换一下相机的方向,就又要把光源在整个球面走一遍,这就叫curse of dimentionality
for each rasterized screen sample (x,y):
- (u,v) = evaluate texture coordinate at (x,y)
- texcolor = texture.sample(u,v);
- set sample's color to texcolor
-
shade(p, wo)
- Randomly choose N directions wi~pdf
- Lo = 0.0
- For each wi
- Trace a ray r(p, wi)
- If ray r hit the light
- Lo += (1 / N) * L_i * f_r * cosine / pdf(wi)
- Return Lo
-
shade(p, wo)
- Randomly choose N directions wi~pdf
- Lo = 0.0
- For each wi
- Trace a ray r(p, wi)
- If ray r hit the light
- Lo += (1 / N) * L_i * f_r * cosine / pdf(wi)
- Else If ray r hit an object at q
- Lo += (1 / N) * shade(q, -wi) * f_r * cosine / pdf(wi)
-
-Return Lo
-
ray_generation(camPos, pixel)
- Uniformly choose N sample positions within the pixel
- pixel_radiance = 0.0
- For each sample in the pixel
- Shoot a ray r(camPos, cam_to_sample)
- If ray r hit the scene at p
- pixel_radiance += 1 / N * shade(p, sample_to_cam)
- Return pixel_radiance
-
shade(p, wo)
- Manually specify a probability P_RR
- Randomly select ksi in a uniform dist. in [0, 1]
- If (ksi > P_RR) return 0.0;
- Randomly choose ONE direction wi~pdf(w)
- Trace a ray r(p, wi)
- If ray r hit the light
- Return L_i * f_r * cosine / pdf(wi) / P_RR
- Else If ray r hit an object at q
- Return shade(q, -wi) * f_r * cosine / pdf(wi) / P_RR
-
至此得出不太高效的正确path tracing算法
-
-
Samples(采样率)可认为是path,SPP(samples per pixel)就是一个像素打出多少path
shade(p, wo)
- # Contribution from the light source.
- Uniformly sample the light at x’ (pdf_light = 1 / A)
- L_dir = L_i * f_r * cos θ * cos θ’ / |x’ - p|^2 / pdf_light
-
-
- # Contribution from other reflectors.
- L_indir = 0.0
- Test Russian Roulette with probability P_RR
- Uniformly sample the hemisphere toward wi (pdf_hemi = 1 / 2pi)
- Trace a ray r(p, wi)
- If ray r hit a non-emitting object at q
- L_indir = shade(q, -wi) * f_r * cos θ / pdf_hemi / P_RR
- Return L_dir + L_indir
-
shade(p, wo)
- # Contribution from the light source.
- Uniformly sample the light at x' (pdf_light = 1 / A)
- Shoot a ray from p to x’
- If the ray is not blocked in the middle
- L_dir = L_i * f_r * cos θ * cos θ’ / |x' - p|^2 / pdf_light
-
-
- # Contribution from other reflectors.
- L_indir = 0.0
- Test Russian Roulette with probability P_RR
- Uniformly sample the hemisphere toward wi (pdf_hemi = 1 / 2pi)
- Trace a ray r(p, wi)
- If ray r hit a non-emitting object at q
- L_indir = shade(q, -wi) * f_r * cos θ / pdf_hemi / P_RR
- Return L_dir + L_indir
-