Ejemplo n.º 1
0
func MakeViewRay(u, v, k float64) geometry.Ray {
	//var d1 float64 = math.Sqrt(1/(2+4*sinθ2))
	// = math.Sqrt(5/14)
	const d1 float64 = 0.5976143046671968
	//var d2 float64 = -2*sinθ*d1
	const d2 float64 = -2 * sinθ * d1
	// = -math.Sqrt(2/7)
	d := geometry.MakeVector(d1, d2, d1)

	bu := geometry.MakeVector(1.0/math.Sqrt(2), 0, -1.0/math.Sqrt(2))
	var bv1 float64 = math.Sqrt(1.0 / 7.0) //math.Sqrt(1/(2 + 1/sinθ2))
	var bv2 float64 = math.Sqrt(5.0 / 7.0) //bv1/sinθ
	bv := geometry.MakeVector(bv1, bv2, bv1)

	//fmt.Println(bu.Dot(d), bv.Dot(d), bu.Dot(bv))

	o := (bu.Mul(u)).Add(bv.Mul(v)).Add(d.Mul(k))

	return geometry.MakeRay(o, d)
}
Ejemplo n.º 2
0
func calculateColour(r geometry.Ray,
	depth float64,
	scene geometry.Object,
	object geometry.Object,
	mat geometry.Material,
	recursionLimit uint) (colour geometry.Vector) {

	colour = mat.BaseColour.Mul(mat.CBase)

	if mat.CReflectance != 0 && recursionLimit != 0 {
		//calculate normal
		normal := object.Normal(r, depth)
		dir_proj := normal.Mul(normal.Dot(r.GetDirectionVector()))
		reflectedDirection := dir_proj.Mul(2).Sub(r.GetDirectionVector())

		incidence := r.Point(depth)
		reflectedRay := geometry.MakeRay(incidence.Add(reflectedDirection.Mul(0.01)), reflectedDirection) //add a small amount so that it doesn't intersect the mirror
		_, reflectedColour := castRay(reflectedRay, scene, recursionLimit-1)
		colour = colour.Add(reflectedColour.Mul(mat.CReflectance))
	}
	return
}