public Vector GetSamplePoint(Sampler random) { // get two randoms float sqr1 = (float)Math.Sqrt(random.GetNextSample()); float r2 = (float)random.GetNextSample(); // make barycentric coords float a = 1.0f - sqr1; float b = (1.0f - r2) * sqr1; // make position from barycentrics // calculate interpolation by using two edges as axes scaled by the // barycentrics return edge1 * a + edge2 * b + verts[0]; }
public void GetEmitter(Sampler random, out Vector position, out Triangle triangle) { if (emitters.Count != 0) { // select emitter // not using lower bits, by treating the random as fixed-point i.f bits int index = ((((int)(int.MaxValue*random.GetNextSample()) & ((1 << MAX_EMITTERS_P) - 1)) * emitters.Count) >> MAX_EMITTERS_P); // get position on triangle position = emitters[index].GetSamplePoint(random); triangle = emitters[index]; } else { position = Vector.ZERO; triangle = null; } }