#include "colors.inc"
#include "glass.inc"

#declare Eps = 1E-6;

#macro menger_level(C1, C2, Lev) 
    #if (Lev > 0) 
	#local dx = 0;
	#while (dx < 3) 
	    #local dy = 0;
	    #while (dy < 3) 
		#local dz = 0;
		#while (dz < 3) 

		    #if ((dx = 1) + (dy = 1) + (dz = 1) < 2)

			menger_level(<C1.x + (C2.x - C1.x)*dx/3,
				      C1.y + (C2.y - C1.y)*dy/3,
				      C1.z + (C2.z - C1.z)*dz/3>,
				     <C1.x + (C2.x - C1.x)*(dx+1)/3,
				      C1.y + (C2.y - C1.y)*(dy+1)/3,
				      C1.z + (C2.z - C1.z)*(dz+1)/3>,
				     Lev-1)

		    #end

		    #local dz = dz + 1;
		#end

		#local dy = dy + 1;
	    #end

	    #local dx = dx + 1;
	#end
    #else
	box {
	    C1 + Eps, C2 - Eps
	}
    #end

#end

union {
    menger_level(<-1, -1, -1>, <1, 1, 1>, 3)
    // texture { pigment { color rgb <1, 1, 1> }}
    texture {
	finish { F_Glass4 }
	pigment { color rgbf <0.8, 0.6, 0.6, 0.75> }
    }
    interior {
	ior 1.5
	caustics 1.0
    }

}

global_settings {
        assumed_gamma 1.0
        ambient_light rgb<0.5, 0.5, 0.5>
	max_trace_level 15
}

light_source {
    <2000, 3000, 1000>
    color White
}

    
camera {
        location <5, 4, 3>
        look_at <0, 0, 0>
	angle 40

}

plane {
    <0, 1, 0>, -1
    pigment {
	hexagon 
	pigment { color <1, 0.5, 0.5> }
	pigment { color <0.5, 1, 0.5> }
	pigment { color <0.5, 0.5, 1> }
	scale 0.1
    }
}
