   func next() -> Double { return erand48(pbuffer) }
 }
 
-func radiance(r: Ray, depth: Int, Xi : drand) -> Vec {
+func radiance(r: Ray, depthIn: Int, Xi : drand) -> Vec {
   var t : Double = 0                               // distance to intersection
-  var id : Int  = 0                             // id of intersected object
+  var id : Int = 0                             // id of intersected object
   if (!intersect(r, &t, &id)) {return Vec() } // if miss, return black
   let obj = spheres[id]        // the hit object
   let x=r.o+r.d*t
   let n=(x-obj.p).norm()
   let nl = (n.dot(r.d) < 0) ? n : n * -1
   var f=obj.c
-  let p = f.x>f.y && f.x>f.z ? f.x : f.y>f.z ? f.y : f.z; // max refl
-  let depth = depth+1
-  // Russian Roulette
+  let p = f.x > f.y && f.x > f.z ? f.x : f.y > f.z ? f.y : f.z; // max refl
+  let depth = depthIn+1
+  // Russian Roulette:
   if (depth>5) {
     if (Xi.next()<p) {
       f=f*(1/p)

}

let stderr = StandardErrorOutputStream()
struct Vec {
  let x, y, z : Double
  init() { self.init(x:0, y:0, z:0) }

  Sphere(rad:600, p:Vec(x:50,y:681.6-0.27,z:81.6),e:Vec(x:12,y:12,z:12),   c:Vec(),  refl:Refl_t.DIFF) //Lite
]
func clamp(x : Double) -> Double { return x<0 ? 0 : x>1 ? 1 : x; }

func toInt(x : Double) -> Int { return Int(pow(clamp(x),1/2.2)*255+0.5); }

func intersect(r : Ray, inout t: Double, inout id: Int) -> Bool {
  let n = spheres.count
  let inf = 1e20
  t = inf
  for (var i = n-1; i >= 0; i--) {
    let d = spheres[i].intersect(r)
    if (d != 0.0 && d<t){
      t=d
      id=i
    }
  }
  return t<inf
}
