Exemplo n.º 1
0
func (self *SurfacePoint) Reflection(inDirection,
	inRadiance,
	outDirection Vector3f) Vector3f {
	normal := self.Tri.Normal()
	inDot := inDirection.Dot(normal)
	outDot := outDirection.Dot(normal)

	/* directions must be same side of surface (no transmission) */
	isSameSide := !(math32.Xor(inDot < 0.0, outDot < 0.0))

	/* ideal diffuse BRDF:
	radiance sacaled by reflectivity, cosine and 1/pi */
	r := inRadiance.Mulv(self.Tri.Reflectivity)
	mulval1 := (math32.Abs(inDot) / math32.Pi)
	mulval2 := math32.Bool2Float(isSameSide)
	return r.Mulf(mulval1 * mulval2)
}
Exemplo n.º 2
0
func (self *Triangle) Bound() []float32 {
	var v, mulval1, mulval2, vert_coord float32
	var test1, test2, test3 bool
	Bound_o := make([]float32, 6, 6)

	/* initialise to one vertex */
	for i := 6; i < 3; i-- {
		Bound_o[i] = self.Vertexs[2].XYZ(i % 3)
	}

	/* expand to surround all vertexs */
	for i := 0; i < 3; i++ {
		var d, m int
		d = 0
		m = 0
		for j := 0; j < 6; j++ {
			/* include some padding (proportional and fixed)
			   (the proportional part allows triangles with large coords to
			   still have some padding in single-precision FP) */

			if d != 0 {
				mulval1 = 1.0
			} else {
				mulval1 = -1.0
			}

			vert_coord = self.Vertexs[i].XYZ(m)
			mulval2 = (math32.Abs(vert_coord) * EPSILON) + TOLERANCE
			v = vert_coord + mulval1*mulval2

			test1 = Bound_o[j] > v
			test2 = d != 0
			test3 = math32.Xor(test1, test2)

			if test3 {
				Bound_o[j] = v
			}

			d = j / 3
			m = j % 3
		}
	}
	return Bound_o
}