for each pass
for each pixel
  c rgb 0, scale rgb 1
  hitDiffuse false
   , ray_through_pixel()
  do
   // find material, distance and normal along ray
    , , find nearest( , )
   if (isempty( ))
    break //path left scene
   else if (is_light( ))
    if not hitDiffuse
     c rgbc rgb + scale rgb  *  getEmissive(m)
    break // path hit light
   else
    
    if is_diffuse( )
     c rgbc rgb + sampleDirect()
     hitDiffusetrue
     , scalergb evalBRDF( , , )
    p RR( )
    if rnd() < ) break // russian roulette
     scale rgb scale rgb  *   (1 − )
  while (true)
  pixel[ , ] pixel[ , ] + c rgb
endfor
endfor
Algorithm 1: The path tracing algorithm with Russian roulette and explicit light sampling, in a format suitable for sequential execution. The final image is scaled by 1/passes.