# mi2 format

verbose on

$include <physics.mi>

# --- Camera ---

camera "cam"
        output "tif" "demo.tif"
        focal 50.000000
        aperture 42.0 
        aspect 1.0 
        resolution 500 500
end camera



# --- Options ---

options "opt"
        globillum on 

	# globillum accuracy 3000 2.0
	# globillum accuracy 2000 1.0   # --- without fog
	globillum accuracy 1500 1.0   # --- with fog
	# globillum accuracy 200 1.0

	# photonvol accuracy 300 1.0
	# photonvol accuracy 200 2.0
	# photonvol accuracy 100 0.5   # --- for homogeneous fog
	photonvol accuracy 50 0.5   # --- for nonhomogeneous fog

	object space
	shadow on 
        samples -2 2 
        contrast 0.1 0.1 0.1 1.0
        trace depth 7 7 7 
        face both
        trace on
        desaturate off
        dither on
end options



# --- Light source ---

light "arealight" visible 
        "physical_light" (
                "color"  1000. 1000. 1000.       # energy [W] for direct illum
        )
        origin  0.0 4.999 -20.0
        rectangle  0.5 0.0 0.0  0.0 0.0 0.5   10 10
        energy   1000. 1000. 1000.       # energy [W] for indirect illum
        globillum photons   200000       # number of photons shot
end light

instance "arealight-i" "arealight" end instance



# --- Materials ---

material "diffusewhite"  opaque
        "dgs_material" (
           	"diffuse"       0.8 0.8 0.8,
           	"lights" ["arealight-i"]
        )
        photon "dgs_material_photon" ()
end material

material "diffusered"  opaque
        "dgs_material" (
           	"diffuse"       0.8 0.0 0.0,
           	"lights" ["arealight-i"]
        )
        photon "dgs_material_photon" ()
end material

material "diffuseblue"  opaque
        "dgs_material" (
           	"diffuse"       0.0 0.0 0.8,
           	"lights" ["arealight-i"]
        )
        photon "dgs_material_photon" ()
end material

material "mirror"  opaque    # ideal mirror: specular reflection
        "dgs_material" (
        	"specular"      1.0 1.0 1.0,
        	"lights" ["arealight-i"]
        )
        photon "dgs_material_photon" ()
        shadow "dgs_material" ()
end material

material "glass"  opaque    # clear glass: specular reflection and refraction
        "dielectric_material" (
	   	"ior" 1.75,   # dense flint glass
	   	"col" 0.990 0.990 0.995,
        ) 
        photon "dielectric_material_photon" ()
        #shadow "dgs_material" ()  
	shadow "dielectric_material" () 
end material

material "volsurf"          # for transparent front and back walls of box plus
			    # in front of light source: surface of volume
        "transmat" ()
        photon "transmat_photon" ()
        shadow "transmat" ()

	volume "parti_volume" (
		"mode" 0,   # smoke everywhere in volume
		# "mode" 1,   # smoke below 'height'
		"scatter" 0.05 0.05 0.05, 
		"extinction" 0.05,
		"r" 1.0,    # one lobe for anisotropic scattering
		"g1" 0.8,   # anisotropic (directional) scattering: 0.8
  		"nonuniform" 0.9,  # homogeneous: 0.0, nonhomogeneous: 0.9 
		# "height" -2.5,   # used with mode 1 only 
		"min_step_len" 0.13,
		"max_step_len" 1.0,
		"light_dist" 2.0,
           	"lights" ["arealight-i"]
	)
	photonvol "parti_volume_photon" (
		"mode" 0,   # smoke everywhere in volume
		# "mode" 1,   # smoke below 'height'
		"scatter" 0.05 0.05 0.05, 
		"extinction" 0.05,
		"r" 1.0,    # one lobe for anisotropic scattering
		"g1" 0.8,   # anisotropic (directional) scattering: 0.8
  		"nonuniform" 0.9,  # homogeneous: 0.0, nonhomogeneous: 0.9
		# "height" -2.5,   # used with mode 1 only 
		"min_step_len" 0.13,
		"max_step_len" 1.0,
	)

end material



# --- Light cover ---

object "lightcover" visible trace tag 10   # No shadow !
	group _mesh
		1.0	4.998	-19.0
		1.0	4.998	-21.0
		-1.0	4.998	-21.0
		-1.0	4.998	-19.0

		v 0
		v 1
		v 2
		v 3

		p "volsurf"	0 1 2 3
	end group
end object



# --- Left red wall ---

object "box_face1" visible trace tag 1
	group _mesh
		-5.0	5.0	-25.0
		-5.0	5.0	-15.0
		-5.0	-5.0	-15.0
		-5.0	-5.0	-25.0

		v 0
		v 1
		v 2
		v 3

		p "diffusered"	0 1 2 3
	end group
end object



# --- Right blue wall ---

object "box_face2" visible trace tag 2
	group _mesh
		5.0	5.0	-25.0
		5.0	5.0	-15.0
		5.0 	-5.0	-15.0
		5.0	-5.0	-25.0

		v 0
		v 1
		v 2
		v 3

		p "diffuseblue"	 0 1 2 3
	end group
end object



# --- Back wall ---

object "box_face3" visible trace tag 3
	group _mesh
		-5.0	-5.0	-25.0
		5.0	-5.0	-25.0
		5.0	5.0	-25.0
		-5.0	5.0	-25.0

		v 0
		v 1
		v 2
		v 3

		p "volsurf"	0 1 2 3
		# p "diffusewhite"	0 1 2 3
	end group
end object



# --- Front wall ---

object "box_face4" visible trace tag 4
	group _mesh
		-5.0	-5.0	-15.0
		5.0	-5.0	-15.0
		5.0	5.0	-15.0
		-5.0	5.0	-15.0

		v 0
		v 1
		v 2
		v 3

		p "volsurf"	0 1 2 3
	end group
end object



# --- Ceiling ---

object "box_face5" visible trace tag 5
	group _mesh
		5.0	5.0	-15.0
		5.0	5.0	-25.0
		-5.0	5.0	-25.0
		-5.0	5.0	-15.0

		v 0
		v 1
		v 2
		v 3

		p "diffusewhite"	0 1 2 3
	end group
end object



# --- Floor ---

object "box_face6" visible trace tag 6
	group _mesh
		5.0	-5.0	-15.0
		5.0	-5.0	-25.0
	 	-5.0	-5.0	-25.0
		-5.0	-5.0	-15.0

		v 0
		v 1
		v 2
		v 3

		p "diffusewhite"	0 1 2 3
	end group
end object



# --- Sphere ---


# Unit sphere at origin

object "unitsphere" visible shadow trace

	# bases of surfaces
	basis "ratio_bez2" rational bezier 2

	group
		# points of surfaces
		0.0 0.0 -1.0

		1.0 0.0 -1.0
		1.0 1.0 -1.0
		0.0 1.0 -1.0
		-1.0 1.0 -1.0
		-1.0 0.0 -1.0
		-1.0 -1.0 -1.0
		0.0 -1.0 -1.0
		1.0 -1.0 -1.0

		1.0 0.0 0.0
		1.0 1.0 0.0
		0.0 1.0 0.0
		-1.0 1.0 0.0
		-1.0 0.0 0.0
		-1.0 -1.0 0.0
		0.0 -1.0 0.0
		1.0 -1.0 0.0

		1.0 0.0 1.0
		1.0 1.0 1.0
		0.0 1.0 1.0
		-1.0 1.0 1.0
		-1.0 0.0 1.0
		-1.0 -1.0 1.0
		0.0 -1.0 1.0
		1.0 -1.0 1.0

		0.0 0.0 1.0

		# vectors
		v 0
		v 1	v 2	v 3	v 4
		v 5	v 6	v 7	v 8
		v 9	v 10	v 11	v 12
		v 13	v 14	v 15	v 16
		v 17	v 18	v 19	v 20
		v 21	v 22	v 23	v 24
		v 25

		# the surface
		surface "surf" ""

		"ratio_bez2" 0.000000 1.000000
		0.0 0.25 0.5 0.75 1.0

		"ratio_bez2" 0.000000 1.000000
		0.0 0.5	1.0

		0
		0
		0 w 2.0
		0
		0
		0
		0 w 2.0
		0
		0

		1
		2
		3 w 2.0
		4
		5
		6
		7 w 2.0
		8
		1

		9 w 2.0
		10 w 2.0
		11 w 4.0
		12 w 2.0
		13 w 2.0
		14 w 2.0
		15 w 4.0
		16 w 2.0
		9 w 2.0

		17
		18
		19 w 2.0
		20
		21
		22
		23 w 2.0
		24
		17

		25
		25
		25 w 2.0
		25
		25
		25
		25 w 2.0
		25
		25

		derivative
		approximate surface parametric 14.0 14.0 "surf"
	end group

end object


# --- Instancing and rendering ---

instance "cam-i" "cam" end instance

instance "lightcover-i" "lightcover" end instance
instance "box_face1-i" "box_face1" end instance
instance "box_face2-i" "box_face2" end instance
instance "box_face3-i" "box_face3" end instance
instance "box_face4-i" "box_face4" end instance
instance "box_face5-i" "box_face5" end instance
instance "box_face6-i" "box_face6" end instance

instance "sphere-1" "unitsphere"   # front sphere (glass)
	transform
	 	0.6  0   0  0 
		 0  0.6  0  0
		 0   0  0.6 0
		 1  0.2 11  1
        material "glass"
end instance

instance "sphere-2" "unitsphere"    # back sphere (mirror)
	transform
		0.6  0   0  0 
		 0  0.6  0  0
		 0   0  0.6 0
		-1   2  13  1
	material "mirror"
end instance

instgroup "all"
	"cam-i"
	"arealight-i"
	"lightcover-i"
        "box_face1-i" "box_face2-i" "box_face3-i" 
	"box_face4-i" "box_face5-i" "box_face6-i"
	"sphere-1" "sphere-2" 
end instgroup

render "all" "cam-i" "opt"
