reb
Class RaytraceSphere

Object
  extended by common:Generic
      extended by reb:RaytraceGeneric
          extended by reb:RaytraceSphere

class 
RaytraceGeneric:RaytraceSphere



Ultra Fractal Source

Toggle UF Source Code Display

 Class RaytraceSphere(RaytraceGeneric) {
 public:
   import "common.ulb"
   import "dmj5.ulb"
 ;  import "reb.ulb"
   func RatytraceSphere(Generic pparent)
     Raytracegeneric.Raytracegeneric(0)
     init()
   endfunc
 
   func Init()
     Raytracegeneric.Init()
 
     ; create the sphere array
     is = new @isph(0)
     is.recurse()
     nsph = is.fk
     zsort = is.zsort
     rcen = is.crad
     bradius = is.bradius
     circles = is.circles
     showc = is.showc
 
     ;find the boundaries of sphere set
     is.findbound(is.s,is.fk,xmin, ymin, zmin, xmax, ymax, zmax)
 
     ;  initialize origin, ray, normal, and half angle vectors
     norm = new Vector(0,0,0,0)
     pnorm = new Vector(0,0,0,0)
     hang = new Vector(0,0,0,0)
     rOrigin = new Vector(0,0,0,0)
     rRay = new Vector(0,0,0,0)
     rInternal = new Vector(0,0,0,0)
     rRefract = new Vector(0,0,0,0)
     rBackSph = new Vector(0,0,0,0)
 
     ; initial bool arrays
     int i = 0
     while i < 10
       inter[i] = false
       ispl[i] = false
       flrrfl[i] = false
       i = i + 1
     endwhile
     isplane = false
 
     ; load the sphere arrays
     i = 0
     setlength(cen,is.fk)
     setlength(z,is.fk)
     setlength(rad,is.fk)
     setlength(lev,is.fk)
     setlength(gen,is.fk)
      while i < nsph
        cen[i] = is.s.sph[i].fcen
        z[i] = is.s.sph[i].fz
        rad[i] = is.s.sph[i].frad
        lev[i] = is.s.sph[i].flevel
        gen[i] = is.s.sph[i].fgen
 
        ;set each sphere object to null
 ;       is.s.sph[i] = 0
        i = i + 1
      endwhile
 
      ; set array object to null
 ;     is = 0
 
     ; create the plane array
     int j = 0
     planes = 0
     if @pset == "floor" || @pset == "back"  || @pset == "left"  || \
          @pset == "right" || @pset == "top"
       planes = 1
     elseif @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "left-right" \
            || @pset == "left-top" || @pset == "right-top"
       planes = 2
     elseif @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset == "floor-right-top" \
            || @pset == "back-right-top" || @pset ==  "left-right-top"
       planes = 3
     elseif @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "back-left-right-top"
       planes = 4
     elseif @pset == "open box"
       planes = 5
     endif
     if planes > 0
       pa = new @paar(planes)
       setlength(pfade,planes)
       setlength(pd,planes)
       setlength(pnx,planes)
       setlength(pny,planes)
       setlength(pnz,planes)
       setlength(planeno,planes)
       while j < planes
         pd[j] = 1e308
         if j == 0
           if @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
                    || @pset == "floor-right" || @pset == "floor-top" \
                    || @pset == "floor-back-left"|| @pset == "floor-back-right"\
                    || @pset == "floor-left-right" || @pset == "floor-back-top" \
                    || @pset ==  "floor-left-top" || @pset == "floor-right-top" \
                    || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
                    || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
                    || @pset == "open box"
             pa.pl[j] = new Plane(@p1A,@p1B,@p1C,@p1D)
             pfade[j] = @p1F
             planeno[j] = 1
           elseif @pset == "back" || @pset == "back-left" || @pset == "back-right" \
                    || @pset == "back-top" || @pset ==  "back-left-right" \
                    || @pset == "back-left-top" || @pset == "back-right-top" \
                    || @pset == "back-left-right-top"
             pa.pl[j] = new Plane(@p2A,@p2B,@p2C,@p2D)
             pfade[j] = @p2F
             planeno[j] = 2
           elseif @pset == "left" || @pset == "left-right" || @pset == "left-top" \
                  || @pset ==  "left-right-top"
             pa.pl[j] = new Plane(@p3A,@p3B,@p3C,@p3D)
             pfade[j] = @p3F
             planeno[j] = 3
           elseif @pset == "right" || @pset == "right-top"
             pa.pl[j] = new Plane(@p4A,@p4B,@p4C,@p4D)
             pfade[j] = @p4F
             planeno[j] = 4
           elseif @pset == "top"
             pa.pl[j] = new Plane(@p5A,@p5B,@p5C,@p5D)
             pfade[j] = @p5F
             planeno[j] = 5
           endif
           pnx[j] = pa.pl[j].pnx
           pny[j] = pa.pl[j].pny
           pnz[j] = pa.pl[j].pnz
         elseif j == 1
           if @pset == "floor-back" || @pset == "floor-back-left" \
              || @pset == "floor-back-right" || @pset == "floor-back-top" \
              || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
              || @pset == "floor-back-right-top" || @pset == "open box"
             pa.pl[j] = new Plane(@p2A,@p2B,@p2C,@p2D)
             pfade[j] = @p2F
             planeno[j] = 2
           elseif @pset == "floor-left" || @pset == "back-left" \
              || @pset == "floor-left-right" || @pset ==  "floor-left-top" \
              || @pset ==  "back-left-right" || @pset == "back-left-top" \
              ||@pset == "floor-left-right-top" || @pset == "back-left-right-top"
             pa.pl[j] = new Plane(@p3A,@p3B,@p3C,@p3D)
             pfade[j] = @p3F
             planeno[j] = 3
           elseif @pset == "floor-right" || @pset == "back-right" \
              || @pset == "left-right" || @pset == "floor-right-top" \
              || @pset == "back-right-top" || @pset ==  "left-right-top"
             pa.pl[j] = new Plane(@p4A,@p4B,@p4C,@p4D)
             pfade[j] = @p4F
             planeno[j] = 4
            elseif @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top"
              pa.pl[j] = new Plane(@p5A,@p5B,@p5C,@p5D)
              pfade[j] = @p5F
              planeno[j] = 5
           endif
           pnx[j] = pa.pl[j].pnx
           pny[j] = pa.pl[j].pny
           pnz[j] = pa.pl[j].pnz
         elseif j == 2
           if @pset == "floor-back-left" || @pset == "floor-back-left-right" \
              || @pset == "floor-back-left-top"  || @pset == "open box"
             pa.pl[j] = new Plane(@p3A,@p3B,@p3C,@p3D)
             pfade[j] = @p3F
             planeno[j] = 3
           elseif @pset == "floor-back-right" || @pset == "floor-left-right" \
              || @pset ==  "back-left-right"|| @pset == "floor-back-right-top" \
              ||@pset == "floor-left-right-top" || @pset == "back-left-right-top"
             pa.pl[j] = new Plane(@p4A,@p4B,@p4C,@p4D)
             pfade[j] = @p4F
             planeno[j] = 4
           elseif @pset == "floor-back-top" || @pset ==  "floor-left-top" \
              || @pset == "back-left-top" || @pset == "floor-right-top" \
              || @pset == "back-right-top" || @pset ==  "left-right-top"
             pa.pl[j] = new Plane(@p5A,@p5B,@p5C,@p5D)
             pfade[j] = @p5F
             planeno[j] = 5
           endif
           pnx[j] = pa.pl[j].pnx
           pny[j] = pa.pl[j].pny
           pnz[j] = pa.pl[j].pnz
         elseif j == 3
           if @pset == "floor-back-left-right"  || @pset == "open box"
             pa.pl[j] = new Plane(@p4A,@p4B,@p4C,@p4D)
             pfade[j] = @p4F
             planeno[j] = 4
           elseif @pset == "floor-back-left-top" || @pset == "floor-back-right-top"\
              ||@pset == "floor-left-right-top" || @pset == "back-left-right-top"
             pa.pl[j] = new Plane(@p5A,@p5B,@p5C,@p5D)
             pfade[j] = @p5F
             planeno[j] = 5
           endif
           pnx[j] = pa.pl[j].pnx
           pny[j] = pa.pl[j].pny
           pnz[j] = pa.pl[j].pnz
         elseif j == 4
           if  @pset == "open box"
             pa.pl[j] = new Plane(@p5A,@p5B,@p5C,@p5D)
             pfade[j] = @p5F
             planeno[j] = 5
           endif
           pnx[j] = pa.pl[j].pnx
           pny[j] = pa.pl[j].pny
           pnz[j] = pa.pl[j].pnz
         endif
         j = j + 1
       endwhile
     endif
 
 
     ; initialize the plugins
     m_TrapTexture = new @f_traptexture(this)
     m_TrapTexture_plane1 = new @f_traptexture_plane1(this)
     m_TrapTexture_plane2 = new @f_traptexture_plane2(this)
     m_TrapTexture_plane3 = new @f_traptexture_plane3(this)
     m_TrapTexture_plane4 = new @f_traptexture_plane4(this)
     m_TrapTexture_plane5 = new @f_traptexture_plane5(this)
     m_TrapColor = new @f_trapcolor(this)
     m_TrapColor_plane1 = new @f_trapcolor_plane1(this)
     m_TrapColor_plane2 = new @f_trapcolor_plane2(this)
     m_TrapColor_plane3 = new @f_trapcolor_plane3(this)
     m_TrapColor_plane4 = new @f_trapcolor_plane4(this)
     m_TrapColor_plane5 = new @f_trapcolor_plane5(this)
     m_MergeColor = new @f_colormerge(this)
     m_MergeColor_plane1 = new @f_colormerge_plane1(this)
     m_MergeColor_plane2 = new @f_colormerge_plane2(this)
     m_MergeColor_plane3 = new @f_colormerge_plane3(this)
     m_MergeColor_plane4 = new @f_colormerge_plane4(this)
     m_MergeColor_plane5 = new @f_colormerge_plane5(this)
     m_MergeLight = new @f_lightmerge(this)
   endfunc
 
 ;-------------------------------------------------
 ; Function to determine object intersections with rays
 ; The maximum recursion level is currently set to 10
 ; @param origin = ray origin as a vector
 ; @param ray = ray as a vector
 ; @param regress = regression level
 ; @param rsi = object index - passed back from recursion
 ; @param dif = diffuse lighting parameter - passed back from recursion
 ; @param sbr = specular lighting paramer - passed back from recursion
 ; @param scolor = color of the intersected object
 ;------------------------------------------------
   ; Call Intersect() after viewpoint
   bool func Intersect(Vector origin, Vector ray, int ®ress, int &rsi, \
                  float &dif, float &sbr, color &scolor)
     int i = 0
     float bi = 0
     float ci = 0
     float arg = 0
     float ti1 = 0
     float ti2 = 0
     ; initialize distance to infinity
     float d = 1e308
     float ti = 0
     isplane = false
     floorrfl = false
     reg = regress
     inter[reg] = false
     shad[reg] = false
     refval = @refval
     float ctheta = 0
     float ctheta2 = 0
     float ortheta = 0
     float dirtheta = 0
     float comp = 0
     int oldrsi = 0
     passed = false
 
     ; determine the closest ray/sphere intersection
     ; check for bounding volume
     if !BoundXY(#pixel*#magn/2*@boundadj) || !@boundary
       while i < nsph
         if (i != rsi &&((@showbase || (rad[i] < bradius ) && (real(cen[i])*@sa+imag(cen[i])*\
           @sb+z[i]*@sc <= @pd||!@slice))&&(!circles || \
           circles && ((!showc && rad[i] != rcen) || showc)))  && rad[i] > 0)
 
           bi = ray.m_x*(origin.m_x-real(cen[i]))+ray.m_y*(origin.m_y-imag(cen[i]))+\
                ray.m_z*(origin.m_z-z[i])
           ci = (origin.m_x-real(cen[i]))^2+(origin.m_y-imag(cen[i]))^2+\
                (origin.m_z-z[i])^2-rad[i]^2
           arg = bi*bi-ci
           if (arg > 0) ; ray intersects sphere
             ti1 = -bi - sqrt(arg)
             ti2 = -bi + sqrt(arg)
             if ti1 > ti2 ; find smallest ti
               ti = ti2
             else
               ti = ti1
             endif
             if ti > 0 &&  ti < d
               inter[reg] = true
               d = ti
             ; sphere parameters for the intersected sphere
               si[reg] = i
               rsi = si[reg]
             endif
           endif
         endif
         i = i + 1
         if inter[reg] && zsort && reg == 0
           i = nsph
         endif
       endwhile
     endif
 
     ; if planes are present, check for closest intersection and
     ; compare to sphere distance. Select closest
     i = 0
     if @pset > 0
       while i < planes
         ortheta = pnx[i]*origin.m_x+pny[i]*origin.m_y+pnz[i]*origin.m_z
         dirtheta = pnx[i]*ray.m_x+pny[i]*ray.m_y+pnz[i]*ray.m_z
         pd[i] = -(ortheta+pa.pl[i].pspot)/dirtheta
         if pd[i] > 0 && pd[i] < 1e308 && pd[i] < d && !isnan(pd[i]) && !isinf(pd[i])
           isplane = true
           inter[reg] = true
           d = pd[i]
           pj = i
         endif
         i = i + 1
       endwhile
     endif
 
 
     ; code for lighting and coloring
     if inter[reg]
       ; intersection point
       xi[reg] = ray.m_x*d + origin.m_x
       yi[reg] = ray.m_y*d + origin.m_y
       zi[reg] = ray.m_z*d + origin.m_z
 
       ; look for shadows - sphere on sphere if sphere the closest
       ; object
 
       if @shadow
         int j = 0
         while j < @nlight
           d = 1e308
           ti = 0
           i = 0
           while i < nsph
             if (i != rsi) && ((@showbase || (rad[i] < bradius ) \
                 && (real(cen[i])*@sa+imag(cen[i])*\
                 @sb+z[i]*@sc <= @pd||!@slice))&&(!circles || \
                 circles && ((!showc && rad[i] != rcen) || showc)))  \
                 && rad[i] > 0
 
               bi = lar.m_elements[j].m_x*(xi[reg]-real(cen[i]))+\
                    lar.m_elements[j].m_y*(yi[reg]-imag(cen[i]))+\
                    lar.m_elements[j].m_z*(zi[reg]-z[i])
               ci = (xi[reg]-real(cen[i]))^2+\
                    (yi[reg]-imag(cen[i]))^2+\
                    (zi[reg]-z[i])^2-rad[i]^2
               arg = bi*bi-ci
               if (arg > 0) ; ray intersects sphere
                 ti1 = -bi - sqrt(arg)
                 ti2 = -bi + sqrt(arg)
                 if ti1 > ti2 ; find smallest ti
                   ti = ti2
                 else
                   ti = ti1
                 endif
                 if ti > 0 &&  ti < d
                   shad[reg] = true
                 endif
               endif
             endif
             i = i + 1
             if shad[reg] && zsort
               i = nsph
             endif
           endwhile
           j = j + 1
         endwhile
       endif
 
       ; normal at intersection point on sphere if sphere the
       ; closest object
       if !isplane
         norm.init((xi[reg]-real(cen[si[reg]]))/rad[si[reg]],\
                                 (yi[reg]-imag(cen[si[reg]]))/rad[si[reg]], \
                                 (zi[reg]-z[si[reg]])/rad[si[reg]], 0)
       endif
 
       ; normal at intersection point on plane if plane the
       ; closest object
       if isplane
           norm.init(pnx[pj],pny[pj],pnz[pj],0)
           diffdotz = norm.m_z*ray.m_z
       endif
 
       ;
       ;---------------------------------------
       ; textures
       ;---------------------------------------
       ;
       ; sphere textures
        if @f_traptexture != DMJ_TrapShapeFlat && !isplane
          norm.Normalize(norm)
         ; perturb the normals with the textures
          pz = 0
          if @cent
            pz = (xi[reg] + flip(yi[reg])-cen[si[reg]])/rad[si[reg]]
          else
            pz = (xi[reg] + flip(yi[reg]))/rad[si[reg]]
          endif
           if @sphmap
            pz = pz*(1+|pz|)*@sphsize *0.5
          endif
          m_TrapTexture.Init(pz)
          ptexture = m_TrapTexture.Iterate(pz)
          complex tx = m_trapTexture.GetTransformedPoint()
          if @texflavor == 0
             tx = tx*@p_texturestrength
             norm.init(norm.m_x+real(tx),norm.m_y+imag(tx),norm.m_z+cabs(tx),0)
          endif
        endif        
        norm.Normalize(norm)
 
        ; plane textures
        if isplane
          if planeno[pj] == 1
            if @f_traptexture_plane1 != DMJ_TrapShapeFlat
             ; perturb the normals with the textures
              pz = 0
              float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
              complex pang = (0,1)^(ang*2/#pi)
              if !@pper1
                pz = #pixel*pang
              else
                pz = xi[reg]+ flip(yi[reg])*pang
                pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
              endif
              m_TrapTexture_plane1.Init(pz)
              ptexture = m_TrapTexture_plane1.Iterate(pz)
              complex tx = m_trapTexture_plane1.GetTransformedPoint()
              if @texflavor_plane1 == 0
                 tx = tx*@p_texturestrength_plane1
                 norm.init(norm.m_x+real(tx),norm.m_y+imag(tx),norm.m_z+cabs(tx),0)
              endif
            endif
          elseif planeno[pj] == 2
            if @f_traptexture_plane2 != DMJ_TrapShapeFlat
             ; perturb the normals with the textures
              pz = 0
              float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
              complex pang = (0,1)^(ang*2/#pi)
              if !@pper2
                pz = #pixel*pang
              else
                pz = xi[reg]+ flip(yi[reg])*pang
                pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
              endif
              m_TrapTexture_plane2.Init(pz)
              ptexture = m_TrapTexture_plane2.Iterate(pz)
              complex tx = m_trapTexture_plane2.GetTransformedPoint()
              if @texflavor_plane2 == 0
                 tx = tx*@p_texturestrength_plane2
                 norm.init(norm.m_x+real(tx),norm.m_y+imag(tx),norm.m_z+cabs(tx),0)
              endif
            endif
          elseif planeno[pj] == 3
            if @f_traptexture_plane3 != DMJ_TrapShapeFlat
             ; perturb the normals with the textures
              pz = 0
              float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
              complex pang = (0,1)^(ang*2/#pi)
              if !@pper3
                pz = #pixel*pang
              else
                pz = xi[reg]+ flip(yi[reg])*pang
                pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
              endif
              m_TrapTexture_plane3.Init(pz)
              ptexture = m_TrapTexture_plane3.Iterate(pz)
              complex tx = m_trapTexture_plane3.GetTransformedPoint()
              if @texflavor_plane3 == 0
                 tx = tx*@p_texturestrength_plane3
                 norm.init(norm.m_x+real(tx),norm.m_y+imag(tx),norm.m_z+cabs(tx),0)
              endif
            endif
          elseif planeno[pj] == 4
            if @f_traptexture_plane4 != DMJ_TrapShapeFlat
             ; perturb the normals with the textures
              pz = 0
              float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
              complex pang = (0,1)^(ang*2/#pi)
              if !@pper4
                pz = #pixel*pang
              else
                pz = xi[reg]+ flip(yi[reg])*pang
                pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
              endif
              m_TrapTexture_plane4.Init(pz)
              ptexture = m_TrapTexture_plane4.Iterate(pz)
              complex tx = m_trapTexture_plane4.GetTransformedPoint()
              if @texflavor_plane4 == 0
                 tx = tx*@p_texturestrength_plane4
                 norm.init(norm.m_x+real(tx),norm.m_y+imag(tx),norm.m_z+cabs(tx),0)
              endif
            endif
          elseif planeno[pj] == 5
            if @f_traptexture_plane5 != DMJ_TrapShapeFlat
             ; perturb the normals with the textures
              pz = 0
              float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
              complex pang = (0,1)^(ang*2/#pi)
              if !@pper5
                pz = #pixel*pang
              else
                pz = xi[reg]+ flip(yi[reg])*pang
                pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
              endif
              m_TrapTexture_plane5.Init(pz)
              ptexture = m_TrapTexture_plane5.Iterate(pz)
              complex tx = m_trapTexture_plane5.GetTransformedPoint()
              if @texflavor_plane5 == 0
                 tx = tx*@p_texturestrength_plane5
                 norm.init(norm.m_x+real(tx),norm.m_y+imag(tx),norm.m_z+cabs(tx),0)
              endif
            endif
          endif        
         norm.Normalize(norm)
       endif
 
       ;
       ;---------------------------------------
       ; illumination parameters
       ;---------------------------------------
       ;
        ; distance squared to light(s). Index is the light number.
        lds[0] = (@lightx-xi[reg])^2 + (@lighty-yi[reg])^2 + (@lightz-zi[reg])^2
        lf = @lightx^2 + @lighty^2 + @lightz^2
        if @nlight > 1
          lds[1] = (@lightx2-xi[reg])^2 + (@lighty2-yi[reg])^2 + (@lightz2-zi[reg])^2
          lf = lf + @lightx2^2 + @lighty2^2 + @lightz2^2
        endif
        if @nlight > 2
          lds[2] = (@lightx3-xi[reg])^2 + (@lighty3-yi[reg])^2 + (@lightz3-zi[reg])^2
          lf = lf + @lightx3^2 + @lighty3^2 + @lightz3^2
        endif
        if @nlight > 3
          lds[3] = (@lightx4-xi[reg])^2 + (@lighty4-yi[reg])^2 + (@lightz4-zi[reg])^2
          lf = lf + @lightx4^2 + @lighty4^2 + @lightz4^2
        endif
        if @nlight > 4
          lds[4] = (@lightx5-xi[reg])^2 + (@lighty5-yi[reg])^2 + (@lightz5-zi[reg])^2
          lf = lf + @lightx5^2 + @lighty5^2 + @lightz5^2
        endif
          lf = lf/@nlight
 
        ; diffuse value
        i = 0
        diffuse[reg] = 0
        while i < @nlight
          diffuse[reg] = diffuse[reg] + lar.m_elements[i].dot(norm)/lds[i]
          i = i + 1
        endwhile
        diffuse[reg] = diffuse[reg]*lf*@bright/@nlight
        ; specular value
        if !isplane
          i = 0
          while i < @nlight
            ray.sub(lar.m_elements[i],hang)
            hang.normalize(hang)
            specular[reg,i] = -hang.dot(norm)
            if specular[reg,i] < 0
              specular[reg,i] = 0
            endif
            specular[reg,i] = specular[reg,i]^shiny[i]*lf*sbright[i]/lds[i]
            if shad[0]
              specular[reg,i] = 0
            endif
            if @texflavor == 1
              specular[reg,i] = (specular[reg,i]+\
                    ptexture*@p_texturestrength)
            endif
            speccol[reg,i] = blend(@ambient,spec[i],specular[reg,i])
            if i == 0
              rspec[reg] = speccol[reg,i]
              rsbright[reg] = sbright[i]
            else
              rspec[reg] = rspec[reg] + speccol[reg,i]
              rsbright[reg] = rsbright[reg] + sbright[i]
            endif
            i = i + 1
          endwhile
          rspec[reg] = rspec[reg]/@nlight
          scolor = rspec[reg]
          rsbright[reg] = rsbright[reg]/@nlight
          sbr = rsbright[reg]
        endif
        if @texflavor == 1 && !isplane
          diffuse[reg] = (diffuse[reg]+ptexture*@p_texturestrength)/\
                              (1+ptexture*@p_texturestrength)
        endif
        if isplane
          if planeno[pj] == 1 && @texflavor_plane1 == 1
            diffuse[reg] = (diffuse[reg]+ptexture*@p_texturestrength_plane1)/\
                              (1+ptexture*@p_texturestrength_plane1)
          elseif planeno[pj] == 2 && @texflavor_plane2 == 1
            diffuse[reg] = (diffuse[reg]+ptexture*@p_texturestrength_plane2)/\
                              (1+ptexture*@p_texturestrength_plane2)
          elseif planeno[pj] == 3 && @texflavor_plane3 == 1
            diffuse[reg] = (diffuse[reg]+ptexture*@p_texturestrength_plane3)/\
                              (1+ptexture*@p_texturestrength_plane3)
          elseif planeno[pj] == 4 && @texflavor_plane4 == 1
            diffuse[reg] = (diffuse[reg]+ptexture*@p_texturestrength_plane4)/\
                              (1+ptexture*@p_texturestrength_plane4)
          elseif planeno[pj] == 5 && @texflavor_plane5 == 1
            diffuse[reg] = (diffuse[reg]+ptexture*@p_texturestrength_plane5)/\
                              (1+ptexture*@p_texturestrength_plane5)
          endif
        endif
 
        oldrsi = rsi
        if @refract
          refval = (1-@refracval)*@reflcorr
        endif
 
 
        bool inreflect = false
 
 ;        ; sphere reflections off of a plane - one level only
 ;        ; this may be overwriting the normal plane coloring creating a bug
 ;        if (@reflect || @refract) && reg == 0 && isplane && inter[0]
 ;          ; calculate the reflected ray and the origin vector
 ;          rorigin.init(xi[reg],yi[reg],zi[reg],0)
 ;         ;   create reflection vector from the plane
 ;          ctheta = norm.dot(ray);-lxt*vx-lyt*vy-lzt*vz  ; N.I
 ;          ctheta = -ctheta
 ;          rray.init(ray.m_x+2*norm.m_x*ctheta, ray.m_y+2*norm.m_y*ctheta, \
 ;                   ray.m_z+2*norm.m_z*ctheta, 0)
 ;          rray.normalize(rray)
 ;
 ;           i = 0
 ;           d = 1e308
 ;           ti = 0
 ;          while i < nsph
 ;            if (i != rsi &&((@showbase || (rad[i] < bradius ) && (real(cen[i])*@sa+imag(cen[i])*\
 ;              @sb+z[i]*@sc <= @pd||!@slice))&&(!circles || \
 ;              circles && ((!showc && rad[i] != rcen) || showc)))  && rad[i] > 0)
 ;
 ;              bi = rray.m_x*(rorigin.m_x-real(cen[i]))+rray.m_y*(rorigin.m_y-imag(cen[i]))+\
 ;                   rray.m_z*(rorigin.m_z-z[i])
 ;              ci = (rorigin.m_x-real(cen[i]))^2+(rorigin.m_y-imag(cen[i]))^2+\
 ;                   (rorigin.m_z-z[i])^2-rad[i]^2
 ;              arg = bi*bi-ci
 ;              if (arg > 0) ; ray intersects sphere
 ;                ti1 = -bi - sqrt(arg)
 ;                ti2 = -bi + sqrt(arg)
 ;                if ti1 > ti2 ; find smallest ti
 ;                  ti = ti2
 ;                else
 ;                  ti = ti1
 ;                endif
 ;                if ti > 0 &&  ti < d
 ;                  inter[1] = true
 ;                  reg = 1
 ;                  regress = 1
 ;                  floorrfl = true
 ;                  d = ti
 ;                ; sphere parameters for the intersected sphere
 ;                  si[reg] = i
 ;                  rsi = si[reg]
 ;                endif
 ;              endif
 ;            endif
 ;            i = i + 1
 ;          endwhile
 ;          if floorrfl
 ;
 ;           ; intersection point
 ;            xi[reg] = rray.m_x*d + rorigin.m_x
 ;            yi[reg] = rray.m_y*d + rorigin.m_y
 ;            zi[reg] = rray.m_z*d + rorigin.m_z
 ;
 ;            norm.init((xi[reg]-real(cen[si[reg]]))/rad[si[reg]],\
 ;                                     (yi[reg]-imag(cen[si[reg]]))/rad[si[reg]], \
 ;                                     (zi[reg]-z[si[reg]])/rad[si[reg]], 0)
 ;
 ;            ; sphere textures
 ;            if @f_traptexture != DMJ_TrapShapeFlat
 ;              norm.Normalize(norm)
 ;             ; perturb the normals with the textures
 ;              pz = 0
 ;              if @cent
 ;                pz = (xi[reg] + flip(yi[reg])-cen[si[reg]])/rad[si[reg]]
 ;              else
 ;                pz = (xi[reg] + flip(yi[reg]))/rad[si[reg]]
 ;              endif
 ;               if @sphmap
 ;                pz = pz*(1+|pz|)*@sphsize *0.5
 ;              endif
 ;              m_TrapTexture.Init(pz)
 ;              ptexture = m_TrapTexture.Iterate(pz)
 ;              complex tx = m_trapTexture.GetTransformedPoint()
 ;              if @texflavor == 0
 ;                 tx = tx*@p_texturestrength
 ;                 norm.init(norm.m_x+real(tx),norm.m_y+imag(tx),norm.m_z+cabs(tx),0)
 ;              endif
 ;            endif        
 ;            norm.Normalize(norm)
 ;
 ;            ; illumination parameters
 ;            ; distance squared to light(s). Index is the light number.
 ;            lds[0] = (@lightx-xi[reg])^2 + (@lighty-yi[reg])^2 + (@lightz-zi[reg])^2
 ;            lf = @lightx^2 + @lighty^2 + @lightz^2
 ;            if @nlight > 1
 ;              lds[1] = (@lightx2-xi[reg])^2 + (@lighty2-yi[reg])^2 + (@lightz2-zi[reg])^2
 ;              lf = lf + @lightx2^2 + @lighty2^2 + @lightz2^2
 ;            endif
 ;            if @nlight > 2
 ;              lds[2] = (@lightx3-xi[reg])^2 + (@lighty3-yi[reg])^2 + (@lightz3-zi[reg])^2
 ;              lf = lf + @lightx3^2 + @lighty3^2 + @lightz3^2
 ;            endif
 ;            if @nlight > 3
 ;              lds[3] = (@lightx4-xi[reg])^2 + (@lighty4-yi[reg])^2 + (@lightz4-zi[reg])^2
 ;              lf = lf + @lightx4^2 + @lighty4^2 + @lightz4^2
 ;            endif
 ;            if @nlight > 4
 ;              lds[4] = (@lightx5-xi[reg])^2 + (@lighty5-yi[reg])^2 + (@lightz5-zi[reg])^2
 ;              lf = lf + @lightx5^2 + @lighty5^2 + @lightz5^2
 ;            endif
 ;              lf = lf/@nlight
 ;
 ;            ; diffuse value
 ;            i = 0
 ;            diffuse[reg] = 0
 ;            while i < @nlight
 ;              diffuse[reg] = diffuse[reg] + lar.m_elements[i].dot(norm)/lds[i]
 ;              i = i + 1
 ;            endwhile
 ;            diffuse[reg] = diffuse[reg]*lf*@bright/@nlight
 ;            ; specular value
 ;            if isplane
 ;              i = 0
 ;              while i < @nlight
 ;                ray.sub(lar.m_elements[i],hang)
 ;                hang.normalize(hang)
 ;                specular[reg,i] = -hang.dot(norm)
 ;                if specular[reg,i] < 0
 ;                  specular[reg,i] = 0
 ;                endif
 ;                specular[reg,i] = specular[reg,i]^shiny[i]*lf*sbright[i]/lds[i]
 ;                if shad[0]
 ;                  specular[reg,i] = 0
 ;                endif
 ;                if @texflavor == 1
 ;                  specular[reg,i] = (specular[reg,i]+\
 ;                        ptexture*@p_texturestrength)
 ;                endif
 ;                speccol[reg,i] = blend(@ambient,spec[i],specular[reg,i])
 ;                if i == 0
 ;                  rspec[reg] = speccol[reg,i]
 ;                  rsbright[reg] = sbright[i]
 ;                else
 ;                  rspec[reg] = rspec[reg] + speccol[reg,i]
 ;                  rsbright[reg] = rsbright[reg] + sbright[i]
 ;                endif
 ;                i = i + 1
 ;              endwhile
 ;              rspec[reg] = rspec[reg]/@nlight
 ;              scolor = rspec[reg]
 ;              rsbright[reg] = rsbright[reg]/@nlight
 ;              sbr = rsbright[reg]
 ;            endif
 ;            if @texflavor == 1
 ;              diffuse[reg] = (diffuse[reg]+ptexture*@p_texturestrength)/\
 ;                                  (1+ptexture*@p_texturestrength)
 ;            endif
 ;          endif
 ;        endif
 
 
        ; sphere reflections
        if (@reflect || (@refract && @refracval^(reg) > 0.005)) && regress < 9 \
              && refval^(reg) > 0.005 && !isplane
          inreflect = true
          regress = regress + 1
          reg = regress
          ; calculate the reflected ray and the origin vector
          rorigin.init(xi[reg-1],yi[reg-1],zi[reg-1],0)
         ;   create reflection vector [R = I+2*N*(N.I)]
          ctheta = norm.dot(ray);-lxt*vx-lyt*vy-lzt*vz  ; N.I
          ctheta = -ctheta
          rray.init(ray.m_x+2*norm.m_x*ctheta, ray.m_y+2*norm.m_y*ctheta, \
                   ray.m_z+2*norm.m_z*ctheta, 0)
          rray.normalize(rray)
          inter[reg] = intersect(rorigin, rray, regress, rsi, diffuse[reg], sbr, scolor)
          if inter[reg]
            si[reg] = rsi
            rspec[reg] = scolor
            diffuse[reg] = diffuse[reg-1]
            rsbright[reg] = sbr
          endif
        endif
        if @refract && regress < 8 && @refracval^(reg) > 0.005  && !isplane
           ; increment the regression counter if a reflection vector was sent
          if oldrsi != rsi || !inreflect
            regress = regress + 1
            reg = regress
          endif
 
          rorigin.init(xi[reg-1],yi[reg-1],zi[reg-1],0)
          ctheta = norm.dot(ray)  ; N.I
          ctheta = -ctheta
           ; calculate the internal refraction ray.
           ; T = [I/rfi-(ctheta2-ctheta/rfi)*N]
           ; Snell's law: sin(angle1)/sin(angle2) = rf2/rf1 = rfi
          ctheta2 = sqrt(1 - (1-ctheta^2)/@rfi^2) ; T.I
          comp = ctheta2 - ctheta/@rfi
          rinternal.init(ray.m_x/@rfi-norm.m_x*comp,ray.m_y/@rfi-norm.m_y*comp,\
                         ray.m_z/@rfi-norm.m_z*comp,0)
          rinternal.normalize(rinternal)
 
           ; calculate the intersection at the back of the sphere
          bi = rinternal.m_x*(rorigin.m_x-real(cen[oldrsi]))+\
               rinternal.m_y*(rorigin.m_y-imag(cen[oldrsi]))+\
               rinternal.m_z*(rorigin.m_z-z[oldrsi])
          ci = (rorigin.m_x-real(cen[oldrsi]))^2+\
               (rorigin.m_y-imag(cen[oldrsi]))^2+\
               (rorigin.m_z-z[oldrsi])^2-rad[oldrsi]^2
 
          arg = bi*bi-ci
 
          if (arg > 0) ; ray intersects sphere
            ti1 = -bi - sqrt(arg)
            ti2 = -bi + sqrt(arg)
            if ti1 < ti2 ; find largest ti
              ti = ti2
            else
              ti = ti1
            endif
          endif
          float xb = rorigin.m_x+rinternal.m_x*ti
          float yb = rorigin.m_y+rinternal.m_y*ti
          float zb = rorigin.m_z+rinternal.m_z*ti
 
          ; calculate the surface normal at the back of the sphere
          norm.init(-(xb-real(cen[oldrsi]))/rad[oldrsi],\
                              -(yb-imag(cen[oldrsi]))/rad[oldrsi], \
                              -(zb-z[oldrsi])/rad[oldrsi], 0)
          norm.Normalize(norm)
 
          ; calculate the refraction vector from the back of the sphere
          ctheta = norm.dot(rinternal)  ; N.I
          ctheta = -ctheta
          ctheta2 = sqrt(1 - (1-ctheta^2)*@rfi^2) ; T.I
          comp = ctheta2 - ctheta*@rfi
          rrefract.init(rinternal.m_x*@rfi-norm.m_x*comp,rinternal.m_y*@rfi-norm.m_y*comp,\
                         rinternal.m_z*@rfi-norm.m_z*comp,0)
          rrefract.normalize(rrefract)
          rBackSph.init(xb,yb,zb,0)
 
          ; determine the next sphere intersection
          inter[reg] = intersect(rbacksph, rrefract, regress, oldrsi, diffuse[reg], sbr, scolor)
          if sin(real(acos(ctheta))) <= 1/@rfi
            passed = true
          endif
          if inter[reg]
             si[reg] = oldrsi
             rspec[reg] = scolor
             diffuse[reg] = diffuse[reg-1]
             rsbright[reg] = sbr
          endif
       endif
 
     endif
 
 
     return inter[reg]
   endfunc
 
   bool func BoundXY(complex grid)
     bool outside = false
     float dx = (xmax+xmin)/2
     float dy = (ymax+ymin)/2
     float x = (xmax-xmin)/2
     float y = (ymax-ymin)/2
     if ((real(grid)-dx)^2/x^2 + (imag(grid)-dy)^2/y^2 - 1 > 0.01)
       outside = true
     endif
     return outside
   endfunc
 
   color func Result()
     color return_color = rgba(0,0,0,1)
     color boundary_color = rgb(0.5,0.5,0.5)
     color flrclr = rgba(0,0,0,0)
     color tempflr[10]
     color base[10]
     color temp = rgba(0,0,0,1)
     color cpat = rgba(0,0,0,1)
     int i = 0
     cp = false
      if @f_trapcolor != ColorTrapNoColor
        while i <= reg
          cp = true
          pz = 0
          if @centp
            pz = (xi[i] + flip(yi[i])-cen[si[i]])/rad[si[i]]
          else
            pz = (xi[i] + flip(yi[i]))/rad[si[i]]
          endif
          if @sphmapp
            pz = pz*(1+|pz|)*@sphsizep *0.25
          endif
          m_TrapColor.Init(pz)
          colpat[i] = m_TrapColor.Iterate(pz)
          ispl[i] = isplane
          flrrfl[i] = floorrfl
          i = i + 1
        endwhile
      endif
 
        ; base coloring
      float ctype = 0
      i = 0
      while i <= reg
        if @selctype == "index"
          ctype = (si[i] % @mod)/@mod
        elseif @selctype == "level"
          ctype = (lev[si[i]] % @mod)/@mod
        elseif @selctype == "generator"
          ctype = (gen[si[i]] % @mod)/@mod
        elseif @selctype == "position"
          ctype = (cabs(cen[si[i]])%@mod)/@mod
        elseif @selctype == "size"
          ctype = ((@mod/rad[si[i]])%@mod)/@mod
        elseif @selctype == "size threshold"
          if rad[si[i]] < @rthresh
            ctype = 0
          else
            ctype = 0.5
          endif
        endif
        base[i] = gradient(ctype)
        i = i + 1
      endwhile
      if inter[0]
        ispl[0] = isplane
        flrrfl[0] = floorrfl
        base[0] = compose(base[0],hsl(hue(base[0]),sat(base[0]),\
                         @lumfac*lum(base[0])), 1-diffuse[0]^2)
        if passed
          base[0] = blend(@backdrop,base[0],@blendval)
        endif
        return_color = m_MergeLight.FullMerge(base[0], rspec[0], \
                         rsbright[0])
        tempflr[0] = return_color
      else
        color return_color = rgba(0,0,0,1)
      endif
      i = 1
      while i <= reg
        ispl[i] = isplane
        flrrfl[i] = floorrfl
      if inter[i]
        base[i] = compose(base[i],hsl(hue(base[i]),sat(base[i]),\
                       @lumfac*lum(base[i])), 1-diffuse[i]^2)
        if passed && @refract
          base[i] = blend(@backdrop,base[i],@blendval)
        endif
        temp = m_MergeLight.FullMerge(base[i], rspec[i], \
                         rsbright[i])
        if @refract
          float lm = (1-lum(base[i]))/@tradj
          lm = 1 - lm
          base[i] = hsla(hue(base[i]),sat(base[i])/@tradj,lm,1/@tradj)
          temp = m_MergeLight.FullMerge(base[i], rspec[i], 1)
        endif
        if @reflect
          if !floorrfl
            return_color = blend(return_color,temp,refval^i)
          else
            return_color = temp
          endif
        elseif @refract
          return_color = blend(return_color,temp,@refracval^i)
            return_color = blend(return_color,temp,refval^i)
          if @pset != 0
            return_color = blend(@backdrop,return_color,@blendval)
          endif
        endif
        tempflr[i] = return_color
      endif
      i = i + 1
      endwhile
 
      if inter[0] && cp
        cpat = colpat[0]
      endif
      i = 1
      while i <= reg
        if inter[i]
          temp = colpat[i]
          if @reflect
            if !floorrfl
              cpat = blend(cpat,temp,refval^i)
            else
              cpat = temp
            endif
          elseif @refract
            if !floorrfl
              cpat = blend(cpat,temp,refval^i)
            else
              cpat = temp
            endif
            cpat = blend(cpat,temp,@refracval^i)
          endif
        endif
        i = i + 1
      endwhile
 
      if cp
        if @nmerge == 1
          temp = cpat
          cpat = return_color
          return_color = temp
        endif
      endif
      return_color = m_MergeColor.FullMerge(cpat, return_color, @opacity)
      if shad[0]
        return_color = blend(return_color,@ambient,@shadval)
      endif
      if @displaybound && !BoundXY(#pixel*#magn/2*@boundadj)
        return_color = blend(boundary_color, return_color,0.5)
      endif
     i = 0
     cp = false
     if planeno[pj] == 1
       if @f_trapcolor_plane1 != ColorTrapNoColor
         cp = true
         float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
         complex pang = (0,1)^(ang*2/#pi)
         if !@pper1
           pz = #pixel*pang
         else
           pz = xi[reg]+ flip(yi[reg])*pang
           pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
         endif
         m_TrapColor_plane1.Init(pz)
         colpat[reg] = m_TrapColor_plane1.Iterate(pz)
       endif
       if inter[reg] && cp
         cpat = colpat[reg]
       endif
       if @usepgrad1
         flrclr = gradient(pj/planes)
       else
         flrclr = @plplaincolor1
       endif
       if @f_traptexture_plane1 != DMJ_TrapShapeFlat && reg > 0
         if @texflavor_plane1 == 0
           flrclr = blend(flrclr,tempflr[reg],@adjdif1*(norm.m_x+norm.m_y+ norm.m_z)/3)
         else
           flrclr = blend(flrclr,tempflr[reg],\
                        @adjdif1*ptexture*@p_texturestrength_plane1/\
                              (1+ptexture*@p_texturestrength_plane1))
         endif
       endif
       if cp
         if @nmerge_plane1 == 1
           temp = cpat
           cpat = flrclr
           flrclr = temp
         endif
         flrclr = m_MergeColor_plane1.FullMerge(cpat, flrclr, @opacity_plane1)
       endif
       if reg == 0
         flrclr = blend(@plambient1,flrclr,@adjdif1*diffuse[0])
       else
         float dcorr = 1-pd[reg]/sqrt(lf)*2
         if dcorr < 0
           dcorr = 0
         elseif dcorr > 1
           dcorr = 1
         endif
         flrclr = blend(tempflr[reg],flrclr,dcorr)
       endif
       if @tpfade1
         flrclr = rgba(red(flrclr),green(flrclr),blue(flrclr),@adjdif1*diffuse[reg]/pfade[pj])
       endif
       if shad[0]
         flrclr = compose(flrclr,@ambient,@shadval)
       endif
       if reg > 0
          flrclr = compose(flrclr,tempflr[reg],1-@flr2sph)
       endif
     elseif planeno[pj] == 2
       if @f_trapcolor_plane2 != ColorTrapNoColor
         cp = true
         float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
         complex pang = (0,1)^(ang*2/#pi)
         if !@pper2
           pz = #pixel*pang
         else
           pz = xi[reg]+ flip(yi[reg])*pang
           pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
         endif
         m_TrapColor_plane2.Init(pz)
         colpat[reg] = m_TrapColor_plane2.Iterate(pz)
       endif
       if inter[reg] && cp
         cpat = colpat[reg]
       endif
       if @usepgrad2
         flrclr = gradient(pj/planes)
       else
         flrclr = @plplaincolor2
       endif
       if @f_traptexture_plane2 != DMJ_TrapShapeFlat && reg > 0
         if @texflavor_plane2 == 0
           flrclr = blend(flrclr,tempflr[reg],@adjdif2*(norm.m_x+norm.m_y+ norm.m_z)/3)
         else
           flrclr = blend(flrclr,tempflr[reg],\
                        @adjdif2*ptexture*@p_texturestrength_plane2/\
                              (1+ptexture*@p_texturestrength_plane2))
         endif
       endif
       if cp
         if @nmerge_plane2 == 1
           temp = cpat
           cpat = flrclr
           flrclr = temp
         endif
         flrclr = m_MergeColor_plane2.FullMerge(cpat, flrclr, @opacity_plane2)
       endif
       if reg == 0
         flrclr = blend(@plambient2,flrclr,@adjdif2*diffuse[reg])
       else
         float dcorr = 1-pd[reg]/sqrt(lf)*2
         if dcorr < 0
           dcorr = 0
         elseif dcorr > 1
           dcorr = 1
         endif
         flrclr = blend(tempflr[reg],flrclr,dcorr)
       endif
       if @tpfade2
         flrclr = rgba(red(flrclr),green(flrclr),blue(flrclr),@adjdif2*diffuse[reg]/pfade[pj])
       endif
       if shad[0]
         flrclr = compose(flrclr,@ambient,@shadval)
       endif
       if reg > 0
        flrclr = compose(flrclr,tempflr[reg],1-@flr2sph)
       endif
     elseif planeno[pj] == 3
       if @f_trapcolor_plane3 != ColorTrapNoColor
         cp = true
         float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
         complex pang = (0,1)^(ang*2/#pi)
         if !@pper3
           pz = #pixel*pang
         else
           pz = xi[reg]+ flip(yi[reg])*pang
           pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
         endif
         m_TrapColor_plane3.Init(pz)
         colpat[reg] = m_TrapColor_plane3.Iterate(pz)
       endif
       if inter[reg] && cp
         cpat = colpat[reg]
       endif
       if @usepgrad3
         flrclr = gradient(pj/planes)
       else
         flrclr = @plplaincolor3
       endif
       if @f_traptexture_plane3 != DMJ_TrapShapeFlat && reg > 0
         if @texflavor_plane3 == 0
           flrclr = blend(flrclr,tempflr[reg],@adjdif3*(norm.m_x+norm.m_y+ norm.m_z)/3)
         else
           flrclr = blend(flrclr,tempflr[reg],\
                        @adjdif3*ptexture*@p_texturestrength_plane3/\
                              (1+ptexture*@p_texturestrength_plane3))
         endif
       endif
       if cp
         if @nmerge_plane3 == 1
           temp = cpat
           cpat = flrclr
           flrclr = temp
         endif
         flrclr = m_MergeColor_plane1.FullMerge(cpat, flrclr, @opacity_plane3)
       endif
       if reg == 0
         flrclr = blend(@plambient3,flrclr,@adjdif3*diffuse[reg])
       else
         float dcorr = 1-pd[reg]/sqrt(lf)*2
         if dcorr < 0
           dcorr = 0
         elseif dcorr > 1
           dcorr = 1
         endif
         flrclr = blend(tempflr[reg],flrclr,dcorr)
       endif
       if @tpfade3
         flrclr = rgba(red(flrclr),green(flrclr),blue(flrclr),@adjdif3*diffuse[reg]/pfade[pj])
       endif
       if shad[0]
         flrclr = compose(flrclr,@ambient,@shadval)
       endif
       if reg > 0
        flrclr = compose(flrclr,tempflr[reg],1-@flr2sph)
       endif
     elseif planeno[pj] == 4
       if @f_trapcolor_plane4 != ColorTrapNoColor
         cp = true
         float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
         complex pang = (0,1)^(ang*2/#pi)
         if !@pper4
           pz = #pixel*pang
         else
           pz = xi[reg]+ flip(yi[reg])*pang
           pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
         endif
         m_TrapColor_plane4.Init(pz)
         colpat[reg] = m_TrapColor_plane4.Iterate(pz)
       endif
       if inter[reg] && cp
         cpat = colpat[reg]
       endif
       if @usepgrad4
         flrclr = gradient(pj/planes)
       else
         flrclr = @plplaincolor4
       endif
       if @f_traptexture_plane4 != DMJ_TrapShapeFlat && reg > 0
         if @texflavor_plane4 == 0
           flrclr = blend(flrclr,tempflr[reg],@adjdif4*(norm.m_x+norm.m_y+ norm.m_z)/3)
         else
           flrclr = blend(flrclr,tempflr[reg],\
                        @adjdif4*ptexture*@p_texturestrength_plane4/\
                              (1+ptexture*@p_texturestrength_plane4))
         endif
       endif
       if cp
         if @nmerge_plane4 == 1
           temp = cpat
           cpat = flrclr
           flrclr = temp
         endif
         flrclr = m_MergeColor_plane4.FullMerge(cpat, flrclr, @opacity_plane4)
       endif
       if reg == 0
         flrclr = blend(@plambient4,flrclr,@adjdif4*diffuse[reg])
       else
         float dcorr = 1-pd[reg]/sqrt(lf)*2
         if dcorr < 0
           dcorr = 0
         elseif dcorr > 1
           dcorr = 1
         endif
         flrclr = blend(tempflr[reg],flrclr,dcorr)
       endif
       if @tpfade4
         flrclr = rgba(red(flrclr),green(flrclr),blue(flrclr),@adjdif4*diffuse[reg]/pfade[pj])
       endif
       if shad[0]
         flrclr = compose(flrclr,@ambient,@shadval)
       endif
       if reg > 0
        flrclr = compose(flrclr,tempflr[reg],1-@flr2sph)
       endif
     elseif planeno[pj] == 5
       if @f_trapcolor_plane5 != ColorTrapNoColor
         cp = true
         float ang = atan2(pa.pl[pj].pb-flip(pa.pl[pj].pa))
         complex pang = (0,1)^(ang*2/#pi)
         if !@pper5
           pz = #pixel*pang
         else
           pz = xi[reg]+ flip(yi[reg])*pang
           pz = real(pz) + flip(imag(pz)+zi[reg]*(1-diffdotz))
         endif
         m_TrapColor_plane5.Init(pz)
         colpat[reg] = m_TrapColor_plane5.Iterate(pz)
       endif
       if inter[reg] && cp
         cpat = colpat[reg]
       endif
       if @usepgrad5
         flrclr = gradient(pj/planes)
       else
         flrclr = @plplaincolor5
       endif
       if @f_traptexture_plane5 != DMJ_TrapShapeFlat && reg > 0
         if @texflavor_plane5 == 0
           flrclr = blend(flrclr,tempflr[reg],@adjdif5*(norm.m_x+norm.m_y+ norm.m_z)/3)
         else
           flrclr = blend(flrclr,tempflr[reg],\
                        @adjdif5*ptexture*@p_texturestrength_plane5/\
                              (1+ptexture*@p_texturestrength_plane5))
         endif
       endif
       if cp
         if @nmerge_plane5 == 1
           temp = cpat
           cpat = flrclr
           flrclr = temp
         endif
         flrclr = m_MergeColor_plane5.FullMerge(cpat, flrclr, @opacity_plane5)
       endif
       if reg == 0
         flrclr = blend(@plambient5,flrclr,@adjdif5*diffuse[reg])
       else
         float dcorr = 1-pd[reg]/sqrt(lf)*2
         if dcorr < 0
           dcorr = 0
         elseif dcorr > 1
           dcorr = 1
         endif
         flrclr = blend(tempflr[reg],flrclr,dcorr)
       endif
       if @tpfade5
         flrclr = rgba(red(flrclr),green(flrclr),blue(flrclr),@adjdif5*diffuse[reg]/pfade[pj])
       endif
       if shad[0]
         flrclr = compose(flrclr,@ambient,@shadval)
       endif
       if reg > 0
        flrclr = compose(flrclr,tempflr[reg],1-@flr2sph)
       endif
     endif
     ; debugging comment:
     ; both return_color and flrclr return the reflected spheres!
     if !isplane || (isplane && floorrfl)
       return return_color
     else
       return flrclr
     endif
   endfunc
 
   bool inter[10]
   bool isplane
   bool ispl[10]
   int reg
   bool floorrfl
   bool flrrfl[10]
 protected:
   InvertSphere is
   PlaneArray pa
   TrapShape m_TrapTexture
   TrapShape m_TrapTexture_plane1
   TrapShape m_TrapTexture_plane2
   TrapShape m_TrapTexture_plane3
   TrapShape m_TrapTexture_plane4
   TrapShape m_TrapTexture_plane5
   ColorTrap m_TrapColor
   ColorTrap m_TrapColor_plane1
   ColorTrap m_TrapColor_plane2
   ColorTrap m_TrapColor_plane3
   ColorTrap m_TrapColor_plane4
   ColorTrap m_TrapColor_plane5
   DefaultColorMerge m_MergeColor
   DefaultColorMerge m_MergeColor_plane1
   DefaultColorMerge m_MergeColor_plane2
   DefaultColorMerge m_MergeColor_plane3
   DefaultColorMerge m_MergeColor_plane4
   DefaultColorMerge m_MergeColor_plane5
   IllumColorMerge m_MergeLight
   Vector norm
   Vector pnorm
   Vector hang
   Vector rOrigin
   Vector rRay
   Vector rInternal
   Vector rRefract
   Vector rBackSph
   float rsbright[10]
   float xi[10]
   float yi[10]
   float zi[10]
   color colpat[10]
   color rspec[10]
   float sitrans[10]
   float lds[5]
   bool shad[10]
   complex cen[]
   float z[]
   float rad[]
   int lev[]
   int gen[]
   float rcen
   int nsph
   bool zsort
   float bradius
   bool circles
   bool showc
   bool cp
   float ptexture
   complex pz
   float xmin
   float ymin
   float zmin
   float xmax
   float ymax
   float zmax
   float refval
   bool passed
   float pfade[]
   float pnx[]
   float pny[]
   float pnz[]
   float pd[]
   float diffdotz
   int pj
   int planes
   int planeno[]
   float lf
   bool sphtoplane
 
 default:
   title = "Raytrace Spheres"
   int param v_raytracespheres
     caption = "Version (Raytrace Spheres)"
     default = 100
     hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
     visible = @v_raytracespheres < 100
   endparam
   heading
     caption = "Illumination model"
     expanded = false
   endheading
   param selctype
     caption = "Coloring mode"
     default = 1
     enum = "index" "level" "generator" "position" "size" "size threshold"
   endparam
   heading
     text = "For the 'generator' option the modulus should equal the \
                number of generator spheres. For this condition no two \
                spheres of the same color will touch (except for Mobius)."
     visible = @selctype == "generator"
   endheading
   heading
     text = "  Tetrahedron: 4; Cube: 7; Octahedron: 7; \
               Dodecahedron: 13; Circle: circles + 1; Mobius: 4."
     visible = @selctype == "generator"
   endheading
   heading
     text = "Specular parameters are found under 'Light parameters'."
   endheading
   int param mod
     caption = "Color modulus"
     default = 8
     visible = @selctype != "size threshold"
   endparam
   float param rthresh
     caption = "size threshold"
     default = 0.03
     visible = @selctype == "size threshold"
   endparam
   float param bright
     caption = "Total brightness"
     default = 0.9
     min = 0
   endparam
   float param lumfac
     caption = "Luminosity factor"
     default = 0.2
     min = 0
     max = 1
   endparam
   IllumColorMerge param f_lightmerge
     caption = "Light Merge"
     default = IllumColorMerge
   endparam
   color param ambient
     caption = "Ambient color"
     default = rgba(0.05,0.05,0.05,1)
   endparam
   bool param shadow
     caption = "Shadows"
     default = false
   endparam
   float param shadval
     caption = "Shadow value"
     default = 0.5
     visible = @shadow
   endparam
   bool param reflect
     caption = "Reflections"
     default = false
     visible = !@refract
   endparam
   float param refval
     caption = "Reflect value"
     default = 0.5
     visible = @reflect && !@refract
   endparam
   float param flr2sph
     caption = "Plane to sphere"
     default = 0.5
     min = 0
     max = 1
     visible = (@reflect || @refract) && @pset != "none"
   endparam
   bool param refract
     caption = "Refractions"
     default = false
   endparam
   float param rfi
     caption = "Refractive index"
     default = 1.33
     visible = @refract
   endparam
   float param refracval
     caption = "Refract value"
     default = 0.5
     visible = @refract
   endparam
   float param reflcorr
     caption = "Reflect correction"
     default = 1.0
     visible = @refract
   endparam
   color param backdrop
     caption = "Refract backdrop"
     default = rgba(0.5,0.5,0.5,1)
     visible = @refract
     hint = "Coloring for refraction rays that pass through all the \
             spheres. Try setting to the background color in the \
             outside tab."
   endparam
   float param blendval
     caption = "Backdrop blend"
     default = 0.5
     visible = @refract
   endparam
   float param tradj
     caption = "Refract color adj"
     default = 2
     min = 1
     visible = @refract
     hint = "Adjusts saturation and luminosity of refracted colors."
   endparam
   heading
     caption = "Sphere Textures"
   endheading
   TrapShape param f_traptexture
     caption = "Sphere Textures"
     default = DMJ_TrapShapeFlat
     expanded = false
     hint = "A trap shape that is used as a texture. Textures do not change \
             the shape of the trap but may change its coloring."
   endparam
   float param p_texturestrength
     caption = "Texture Amount"
     default = 0.0
     hint = "Sets the overall amount of texture to be used. Larger numbers \
            will increase the effect of the texture. A value of 0 will remove \
            the effects of the texture."
     visible = (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   param texflavor
     caption = "Texture type"
     default = 0
     enum = "Transformed" "Standard"
     visible = (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   bool param cent
     caption = "Center on sphere"
     default = true
     visible = (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   bool param sphmap
     caption = "Spherical mapping"
     default = false
     visible = (@f_traptexture != DMJ_TrapShapeFlat)
   endparam
   float param sphsize
     caption = "Map size"
     default = 0.5
     visible = @sphmap && (@f_traptexture != DMJ_TrapShapeFlat)
   endparam    
   heading
     caption = "Plane Textures"
   endheading
   heading
     text = "Floor Plane"
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endheading
   TrapShape param f_traptexture_plane1
     caption = "Plane Textures"
     default = DMJ_TrapShapeFlat
     expanded = false
     hint = "A trap shape that is used as a texture. Textures do not change \
             the shape of the trap but may change its coloring."
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   float param p_texturestrength_plane1
     caption = "Texture Amount"
     default = 0.0
     hint = "Sets the overall amount of texture to be used. Larger numbers \
            will increase the effect of the texture. A value of 0 will remove \
            the effects of the texture."
     visible = (@f_traptexture_plane1 != DMJ_TrapShapeFlat)
   endparam
   param texflavor_plane1
     caption = "Texture type"
     default = 0
     enum = "Transformed" "Standard"
     visible = (@f_traptexture_plane1 != DMJ_TrapShapeFlat)
   endparam
   heading
     text = "Back Plane"
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endheading
   TrapShape param f_traptexture_plane2
     caption = "Plane Textures"
     default = DMJ_TrapShapeFlat
     expanded = false
     hint = "A trap shape that is used as a texture. Textures do not change \
             the shape of the trap but may change its coloring."
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p_texturestrength_plane2
     caption = "Texture Amount"
     default = 0.0
     hint = "Sets the overall amount of texture to be used. Larger numbers \
            will increase the effect of the texture. A value of 0 will remove \
            the effects of the texture."
     visible = (@f_traptexture_plane2 != DMJ_TrapShapeFlat)
   endparam
   param texflavor_plane2
     caption = "Texture type"
     default = 0
     enum = "Transformed" "Standard"
     visible = (@f_traptexture_plane2 != DMJ_TrapShapeFlat)
   endparam
   heading
     text = "Left Plane"
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endheading
   TrapShape param f_traptexture_plane3
     caption = "Plane Textures"
     default = DMJ_TrapShapeFlat
     expanded = false
     hint = "A trap shape that is used as a texture. Textures do not change \
             the shape of the trap but may change its coloring."
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   float param p_texturestrength_plane3
     caption = "Texture Amount"
     default = 0.0
     hint = "Sets the overall amount of texture to be used. Larger numbers \
            will increase the effect of the texture. A value of 0 will remove \
            the effects of the texture."
     visible = (@f_traptexture_plane3 != DMJ_TrapShapeFlat)
   endparam
   param texflavor_plane3
     caption = "Texture type"
     default = 0
     enum = "Transformed" "Standard"
     visible = (@f_traptexture_plane3 != DMJ_TrapShapeFlat)
   endparam
   heading
     text = "Right Plane"
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endheading
   TrapShape param f_traptexture_plane4
     caption = "Plane Textures"
     default = DMJ_TrapShapeFlat
     expanded = false
     hint = "A trap shape that is used as a texture. Textures do not change \
             the shape of the trap but may change its coloring."
     visible = @pset == "right"|| @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top"  || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p_texturestrength_plane4
     caption = "Texture Amount"
     default = 0.0
     hint = "Sets the overall amount of texture to be used. Larger numbers \
            will increase the effect of the texture. A value of 0 will remove \
            the effects of the texture."
     visible = (@f_traptexture_plane4 != DMJ_TrapShapeFlat)
   endparam
   param texflavor_plane4
     caption = "Texture type"
     default = 0
     enum = "Transformed" "Standard"
     visible = (@f_traptexture_plane4 != DMJ_TrapShapeFlat)
   endparam
   heading
     text = "Top Plane"
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"  
   endheading
   TrapShape param f_traptexture_plane5
     caption = "Plane Textures"
     default = DMJ_TrapShapeFlat
     expanded = false
     hint = "A trap shape that is used as a texture. Textures do not change \
             the shape of the trap but may change its coloring."
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"  
   endparam
   float param p_texturestrength_plane5
     caption = "Texture Amount"
     default = 0.0
     hint = "Sets the overall amount of texture to be used. Larger numbers \
            will increase the effect of the texture. A value of 0 will remove \
            the effects of the texture."
     visible = (@f_traptexture_plane5 != DMJ_TrapShapeFlat)
   endparam
   param texflavor_plane5
     caption = "Texture type"
     default = 0
     enum = "Transformed" "Standard"
     visible = (@f_traptexture_plane5 != DMJ_TrapShapeFlat)
   endparam
   heading
     caption = "Patterns and Colors"
   endheading
   heading
     caption = "Spheres"
   endheading
   ColorTrap param f_trapcolor
     caption = "Sphere Colors"
     default = ColorTrapNoColor
     expanded = false
     hint = "A trap shape that is used as a color or pattern."
   endparam
   bool param centp
     caption = "Center on sphere"
     default = true
     visible = (@f_trapcolor != ColorTrapNoColor)
   endparam
   bool param sphmapp
     caption = "Spherical mapping"
     default = false
     visible = (@f_trapcolor != ColorTrapNoColor)
   endparam
   float param sphsizep
     caption = "Map size"
     default = 1.0
     visible = @sphmapp && (@f_trapcolor != ColorTrapNoColor)
   endparam
   heading
     caption = "Sphere Color Merge"
     visible = @f_trapcolor != ColorTrapNoColor
   endheading      
   DefaultColorMerge param f_colormerge
     caption = "Color Merge"
     default = DefaultColorMerge
     visible = @f_trapcolor != ColorTrapNoColor
   endparam
   param nmerge
     caption = "Merge order"
     default = 0
     enum = "Base on Top" "Base on Bottom"
     visible = @f_trapcolor != ColorTrapNoColor
   endparam
   float param opacity
     caption = "Merge Opacity"
     default = 1.0
     visible = @f_trapcolor != ColorTrapNoColor
   endparam
   heading
     caption = "Planes"
   endheading
   heading
     text = "Floor Plane"
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endheading
   bool param pper1
     caption = "Use perspective"
     default = false
     visible = ((@f_traptexture_plane1 != DMJ_TrapShapeFlat) || \
                (@f_trapcolor_plane1 != ColorTrapNoColor))&& \
                (@pset == "floor"  || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box")
   endparam  
   float param adjdif1
     caption = "Diffuse adjustment"
     default = 1.0
     visible = @pset == "floor"  || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   ColorTrap param f_trapcolor_plane1
     caption = "Plane Colors"
     default = ColorTrapNoColor
     expanded = false
     hint = "A trap shape that is used as a color or pattern."
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   heading
     caption = "Plane Color Merge"
     visible = @f_trapcolor_plane1 != ColorTrapNoColor
   endheading      
   DefaultColorMerge param f_colormerge_plane1
     caption = "Color Merge"
     default = DefaultColorMerge
     visible = @f_trapcolor_plane1 != ColorTrapNoColor
   endparam
   param nmerge_plane1
     caption = "Merge order"
     default = 0
     enum = "Base on Top" "Base on Bottom"
     visible = @f_trapcolor_plane1 != ColorTrapNoColor
   endparam
   float param opacity_plane1
     caption = "Merge Opacity"
     default = 0.5
     visible = @f_trapcolor_plane1 != ColorTrapNoColor
   endparam
   bool param tpfade1
     caption = "Use Distance Fade"
     default = false
     visible = @pset == "floor"  || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   bool param usepgrad1
     caption = "Use gradient"
     default = true
     visible = @pset == "floor"  || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   color param plambient1
     caption = "Distant color"
     default = rgba(0,0,0,1)
     visible = @pset == "floor"  || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   color param plplaincolor1
     caption = "Base Color"
     default = rgba(0.9,0.9,0.9,1)
     visible = !@usepgrad1 && (@pset == "floor"  || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box")
   endparam
   heading
     text = "Back Plane"
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endheading
   bool param pper2
     caption = "Use perspective"
     default = false
     visible = ((@f_traptexture_plane2 != DMJ_TrapShapeFlat) || \
                (@f_trapcolor_plane2 != ColorTrapNoColor))&& \
                (@pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box")
   endparam  
   float param adjdif2
     caption = "Diffuse adjustment"
     default = 1.0
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   ColorTrap param f_trapcolor_plane2
     caption = "Plane Colors"
     default = ColorTrapNoColor
     expanded = false
     hint = "A trap shape that is used as a color or pattern."
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   heading
     caption = "Plane Color Merge"
     visible = @f_trapcolor_plane2 != ColorTrapNoColor
   endheading      
   DefaultColorMerge param f_colormerge_plane2
     caption = "Color Merge"
     default = DefaultColorMerge
     visible = @f_trapcolor_plane2 != ColorTrapNoColor
   endparam
   param nmerge_plane2
     caption = "Merge order"
     default = 0
     enum = "Base on Top" "Base on Bottom"
     visible = @f_trapcolor_plane2 != ColorTrapNoColor
   endparam
   float param opacity_plane2
     caption = "Merge Opacity"
     default = 0.5
     visible = @f_trapcolor_plane2 != ColorTrapNoColor
   endparam
   bool param tpfade2
     caption = "Use Distance Fade"
     default = false
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   bool param usepgrad2
     caption = "Use gradient"
     default = true
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   color param plambient2
     caption = "Distant color"
     default = rgba(0,0,0,1)
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   color param plplaincolor2
     caption = "Base Color"
     default = rgba(0.9,0.9,0.9,1)
     visible = !@usepgrad2 && (@pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box")
   endparam
   heading
     text = "Left Plane"
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endheading
   bool param pper3
     caption = "Use perspective"
     default = false
     visible = ((@f_traptexture_plane3 != DMJ_TrapShapeFlat) || \
                (@f_trapcolor_plane3 != ColorTrapNoColor))&& \
                (@pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box")
   endparam  
   float param adjdif3
     caption = "Diffuse adjustment"
     default = 1.0
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   ColorTrap param f_trapcolor_plane3
     caption = "Plane Colors"
     default = ColorTrapNoColor
     expanded = false
     hint = "A trap shape that is used as a color or pattern."
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   heading
     caption = "Plane Color Merge"
     visible = @f_trapcolor_plane3 != ColorTrapNoColor
   endheading      
   DefaultColorMerge param f_colormerge_plane3
     caption = "Color Merge"
     default = DefaultColorMerge
     visible = @f_trapcolor_plane3 != ColorTrapNoColor
   endparam
   param nmerge_plane3
     caption = "Merge order"
     default = 0
     enum = "Base on Top" "Base on Bottom"
     visible = @f_trapcolor_plane3 != ColorTrapNoColor
   endparam
   float param opacity_plane3
     caption = "Merge Opacity"
     default = 0.5
     visible = @f_trapcolor_plane3 != ColorTrapNoColor
   endparam
   bool param tpfade3
     caption = "Use Distance Fade"
     default = false
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   bool param usepgrad3
     caption = "Use gradient"
     default = true
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   color param plambient3
     caption = "Distant color"
     default = rgba(0,0,0,1)
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   color param plplaincolor3
     caption = "Base Color"
     default = rgba(0.9,0.9,0.9,1)
     visible = !@usepgrad3 && (@pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box")
   endparam
   heading
     text = "Right Plane"
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endheading
   bool param pper4
     caption = "Use perspective"
     default = false
     visible = ((@f_traptexture_plane4 != DMJ_TrapShapeFlat) || \
                (@f_trapcolor_plane4 != ColorTrapNoColor))&& \
                (@pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box")
   endparam  
   float param adjdif4
     caption = "Diffuse adjustment"
     default = 1.0
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   ColorTrap param f_trapcolor_plane4
     caption = "Plane Colors"
     default = ColorTrapNoColor
     expanded = false
     hint = "A trap shape that is used as a color or pattern."
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   heading
     caption = "Plane Color Merge"
     visible = @f_trapcolor_plane4 != ColorTrapNoColor
   endheading      
   DefaultColorMerge param f_colormerge_plane4
     caption = "Color Merge"
     default = DefaultColorMerge
     visible = @f_trapcolor_plane4 != ColorTrapNoColor
   endparam
   param nmerge_plane4
     caption = "Merge order"
     default = 0
     enum = "Base on Top" "Base on Bottom"
     visible = @f_trapcolor_plane4 != ColorTrapNoColor
   endparam
   float param opacity_plane4
     caption = "Merge Opacity"
     default = 0.5
     visible = @f_trapcolor_plane4 != ColorTrapNoColor
   endparam
   bool param tpfade4
     caption = "Use Distance Fade"
     default = false
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   bool param usepgrad4
     caption = "Use gradient"
     default = true
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   color param plambient4
     caption = "Distant color"
     default = rgba(0,0,0,1)
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   color param plplaincolor4
     caption = "Base Color"
     default = rgba(0.9,0.9,0.9,1)
     visible = !@usepgrad4 && (@pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box")
   endparam
   heading
     text = "Top Plane"
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endheading
   bool param pper5
     caption = "Use perspective"
     default = false
     visible = ((@f_traptexture_plane5 != DMJ_TrapShapeFlat) || \
                (@f_trapcolor_plane5 != ColorTrapNoColor))&& \
                (@pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box")
   endparam  
   float param adjdif5
     caption = "Diffuse adjustment"
     default = 1.0
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   ColorTrap param f_trapcolor_plane5
     caption = "Plane Colors"
     default = ColorTrapNoColor
     expanded = false
     hint = "A trap shape that is used as a color or pattern."
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   heading
     caption = "Plane Color Merge"
     visible = @f_trapcolor_plane5 != ColorTrapNoColor
   endheading      
   DefaultColorMerge param f_colormerge_plane5
     caption = "Color Merge"
     default = DefaultColorMerge
     visible = @f_trapcolor_plane5 != ColorTrapNoColor
   endparam
   param nmerge_plane5
     caption = "Merge order"
     default = 0
     enum = "Base on Top" "Base on Bottom"
     visible = @f_trapcolor_plane5 != ColorTrapNoColor
   endparam
   float param opacity_plane5
     caption = "Merge Opacity"
     default = 0.5
     visible = @f_trapcolor_plane5 != ColorTrapNoColor
   endparam
   bool param tpfade5
     caption = "Use Distance Fade"
     default = false
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   bool param usepgrad5
     caption = "Use gradient"
     default = true
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   color param plambient5
     caption = "Distant color"
     default = rgba(0,0,0,1)
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   color param plplaincolor5
     caption = "Base Color"
     default = rgba(0.9,0.9,0.9,1)
     visible = !@usepgrad5 && (@pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box")
   endparam
 
 
   heading
     caption = "Sphere inversion parameters"
     expanded = false
   endheading
   bool param boundary
     caption = "Use boundaries"
     default = false
   endparam
   float param boundadj
     caption = "Boundary adj"
     default = 1.0
     visible = @boundary
   endparam
   bool param displaybound
     caption = "Display boundary"
     default = false
     visible = @boundary
   endparam
   InvertSphere param isph
     caption = "Inversion Type"
     default = InvertSphere
   endparam
   bool param showbase
     caption = "Show base spheres"
     default = true
     visible = @isph != InvertMobius
   endparam
   bool param slice
     caption = "Slice Gasket"
     default = false
     visible = @isph != InvertMobius
   endparam
   heading
     caption = "Slicing Plane"
     visible = @slice
   endheading
   float param sa
     caption = "X Direction"
     default = 0.0
     visible = @slice
   endparam
   float param sb
     caption = "Y Direction"
     default = -1.0
     visible = @slice
   endparam
   float param sc
     caption = "Z Direction"
     default = 0.5
     visible = @slice
   endparam
   float param pd
     caption = "Position"
     default = 0.01
     visible = @slice
   endparam
   heading
     caption = "Plane Parameters"
     expanded = false
   endheading
   PlaneArray param paar
     caption = "Plane array"
     default = PlaneArray
   endparam
   heading
     text = "Choose a set of plane objects"
   endheading
   heading
     text = "Ax + By + Cz + D = 0"
   endheading
   param pset
     caption = "Plane sets"
     default = 0
     enum = "none" "floor" "back" "left" "right" "top" "floor-back" \
            "floor-left" "floor-right" "floor-top" "back-left" "back-right" \
            "back-top" "left-right" "left-top" "right-top" "floor-back-left" \
            "floor-back-right" "floor-left-right" "back-left-right" \
            "floor-back-top" "floor-left-top" "back-left-top" \
            "floor-right-top" "back-right-top" "left-right-top" \
            "floor-back-left-right" "floor-back-left-top" \
            "floor-back-right-top" "floor-left-right-top" \
            "back-left-right-top" "open box"
   endparam
   heading
     text = "Floor parameters"
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endheading
   float param p1A
     caption = "Floor A"
     default = 0
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   float param p1B
     caption = "Floor B"
     default = -1
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   float param p1C
     caption = "Floor C"
     default = 0
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   float param p1D
     caption = "Floor D"
     default = 1
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   float param p1F
     caption = "Fade"
     default = 1
     visible = @pset == "floor" || @pset == "floor-back"  || @pset == "floor-left" \
            || @pset == "floor-right" || @pset == "floor-top" \
            || @pset == "floor-back-left"|| @pset == "floor-back-right"\
            || @pset == "floor-left-right" || @pset == "floor-back-top" \
            || @pset ==  "floor-left-top"|| @pset == "floor-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
            || @pset == "open box"
   endparam
   heading
     text = "Back parameters"
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endheading
   float param p2A
     caption = "Back A"
     default = 0
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p2B
     caption = "Back B"
     default = 1e-10
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p2C
     caption = "Back C"
     default = 1
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p2D
     caption = "Back D"
     default = 10
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p2F
     caption = "Fade"
     default = 1
     visible = @pset == "back" || @pset == "floor-back"\
            || @pset == "back-left" || @pset == "back-right" \
            || @pset == "back-top" || @pset == "floor-back-left"\
            || @pset == "floor-back-right" || @pset ==  "back-left-right" \
            || @pset == "floor-back-top" || @pset == "back-left-top" \
            || @pset == "back-right-top" || @pset == "floor-back-left-right" \
            || @pset == "floor-back-left-top" || @pset == "floor-back-right-top" \
            || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   heading
     text = "Left parameters"
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endheading
   float param p3A
     caption = "Left A"
     default = 1
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   float param p3B
     caption = "Left B"
     default = 0
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   float param p3C
     caption = "Left C"
     default = 0
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   float param p3D
     caption = "Left D"
     default = 1
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   float param p3F
     caption = "Fade"
     default = 1
     visible = @pset == "left" || @pset == "floor-left" || @pset == "back-left"\
            || @pset == "left-right" || @pset == "left-top" \
            || @pset == "floor-back-left" || @pset == "floor-left-right" \
            || @pset ==  "back-left-right" || @pset ==  "floor-left-top" \
            || @pset == "back-left-top" || @pset ==  "left-right-top" \
            || @pset == "floor-back-left-right" || @pset == "floor-back-left-top" \
            || @pset == "floor-left-right-top" || @pset == "back-left-right-top" \
            || @pset == "open box"
   endparam
   heading
     text = "Right parameters"
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endheading
   float param p4A
     caption = "Right A"
     default = 1
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p4B
     caption = "Right B"
     default = 0
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p4C
     caption = "Right C"
     default = 0
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p4D
     caption = "Right D"
     default = -1
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p4F
     caption = "Fade"
     default = 1
     visible = @pset == "right" || @pset == "floor-right" \
               || @pset == "back-right" || @pset == "left-right" \
               || @pset == "right-top" || @pset == "floor-back-right"\
               || @pset == "floor-left-right" || @pset ==  "back-left-right" \
               || @pset == "floor-right-top" || @pset == "back-right-top" \
               || @pset ==  "left-right-top" || @pset == "floor-back-left-right" \
               || @pset == "floor-back-right-top" || @pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   heading
     text = "Top parameters"
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endheading
   float param p5A
     caption = "Top A"
     default = 0
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p5B
     caption = "Top B"
     default = -1
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p5C
     caption = "Top C"
     default = 0
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p5D
     caption = "Top D"
     default = -1
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
   float param p5F
     caption = "Fade"
     default = 1
     visible = @pset == "top" || @pset == "floor-top" || @pset == "back-top" \
               || @pset == "left-top" || @pset == "right-top" \
               || @pset == "floor-back-top" || @pset ==  "floor-left-top" \
               || @pset == "back-left-top" || @pset == "floor-right-top" \
               || @pset == "back-right-top" || @pset ==  "left-right-top" \
               || @pset == "floor-back-left-top" \
               || @pset == "floor-back-right-top" ||@pset == "floor-left-right-top" \
               || @pset == "back-left-right-top" || @pset == "open box"
   endparam
 }
 


Constructor Summary
RaytraceSphere()
           
 
Method Summary
 boolean BoundXY(complex grid)
           
 void Init()
          Call Init() in the global section
 boolean Intersect(Vector origin, Vector ray, int regress, int rsi, float dif, float sbr, color scolor)
          Function to determine object intersections with rays The maximum recursion level is currently set to 10
 void RatytraceSphere(Generic pparent)
          import "reb.ulb"
 color Result()
          call result() in the final section
 
Methods inherited from class reb:RaytraceGeneric
ViewPoint
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

RaytraceSphere

public RaytraceSphere()
Method Detail

RatytraceSphere

public void RatytraceSphere(Generic pparent)
import "reb.ulb"


Init

public void Init()
Description copied from class: RaytraceGeneric
Call Init() in the global section

Overrides:
Init in class RaytraceGeneric

Intersect

public boolean Intersect(Vector origin,
                         Vector ray,
                         int regress,
                         int rsi,
                         float dif,
                         float sbr,
                         color scolor)
Function to determine object intersections with rays The maximum recursion level is currently set to 10

Overrides:
Intersect in class RaytraceGeneric
Parameters:
origin - = ray origin as a vector
ray - = ray as a vector
regress - = regression level
rsi - = object index - passed back from recursion
dif - = diffuse lighting parameter - passed back from recursion
sbr - = specular lighting paramer - passed back from recursion
scolor - = color of the intersected object Call Intersect() after viewpoint

BoundXY

public boolean BoundXY(complex grid)

Result

public color Result()
Description copied from class: RaytraceGeneric
call result() in the final section

Overrides:
Result in class RaytraceGeneric