public void ZeroRadius() { var random = new Random(123456); var d = new SphereDistribution { OuterRadius = 0 }; Assert.AreEqual(new Vector3F(), d.Next(random)); Assert.AreEqual(new Vector3F(), d.Next(random)); Assert.AreEqual(new Vector3F(), d.Next(random)); }
public void ZeroRadius() { var random = new Random(123456); var d = new SphereDistribution { OuterRadius = 0 }; Assert.AreEqual(new Vector3F(), d.Next(random)); Assert.AreEqual(new Vector3F(), d.Next(random)); Assert.AreEqual(new Vector3F(), d.Next(random)); }
public void Values() { var random = new Random(123456); var d = new SphereDistribution(); for (int i = 0; i < 100; i++) { d.InnerRadius = RandomHelper.Random.NextFloat(0, 100); d.OuterRadius = RandomHelper.Random.NextFloat(0, 100); var value = d.Next(random); var radius = value.Length; Assert.IsTrue(d.InnerRadius < radius && radius < d.OuterRadius || d.OuterRadius < radius && radius < d.InnerRadius); } }
public void Values() { var random = new Random(123456); var d = new SphereDistribution(); for (int i = 0; i < 100; i++) { d.InnerRadius = RandomHelper.Random.NextFloat(0, 100); d.OuterRadius = RandomHelper.Random.NextFloat(0, 100); var value = d.Next(random); var radius = value.Length; Assert.IsTrue(d.InnerRadius < radius && radius < d.OuterRadius || d.OuterRadius < radius && radius < d.InnerRadius); } }
public Vector3F GetAmbientLight(int numberOfSamples) { var random = new Random(1234567); var sphereDistribution = new SphereDistribution { Center = Vector3F.Zero, InnerRadius = 1, OuterRadius = 1, }; Vector3F ambient = new Vector3F(); for (int i = numberOfSamples - 1; i >= 0; i--) { Vector3F sampleDirection = sphereDistribution.Next(random); if (sampleDirection.Y < 0) { sampleDirection.Y *= -1; } Vector3F transmittance; Vector3F colorR, colorM; ComputeScattering(sampleDirection, true, out transmittance, out colorR, out colorM); Debug.Assert(sampleDirection.IsNumericallyNormalized); Vector3F sample = colorR + colorM + GetBaseColor(sampleDirection); if (sample.IsNaN) { numberOfSamples--; // Ignore sample. } else { ambient += sample; } } ambient /= numberOfSamples; // We have added up luminance, now we have to multiply by the solid angle // of the hemisphere to get illuminance. return(ambient * ConstantsF.TwoPi); }
public Vector3F GetAmbientLight(int numberOfSamples) { var random = new Random(1234567); var sphereDistribution = new SphereDistribution { Center = Vector3F.Zero, InnerRadius = 1, OuterRadius = 1, }; Vector3F ambient = new Vector3F(); for (int i = numberOfSamples - 1; i >= 0; i--) { Vector3F sampleDirection = sphereDistribution.Next(random); if (sampleDirection.Y < 0) sampleDirection.Y *= -1; Vector3F transmittance; Vector3F colorR, colorM; ComputeScattering(sampleDirection, true, out transmittance, out colorR, out colorM); Debug.Assert(sampleDirection.IsNumericallyNormalized); Vector3F sample = colorR + colorM + GetBaseColor(sampleDirection); if (sample.IsNaN) numberOfSamples--; // Ignore sample. else ambient += sample; } ambient /= numberOfSamples; // We have added up luminance, now we have to multiply by the solid angle // of the hemisphere to get illuminance. return ambient * ConstantsF.TwoPi; }