Esempio n. 1
0
        public override SampledSpectrum Sample(ref Vector3 point, Scene scene, out Vector3 incomingVector,
                                               out VisibilityTester visibilityTester)
        {
            var r1 = StaticRandom.NextFloat() * 2 - 1;
            var r2 = StaticRandom.NextFloat() * 2 - 1;
            var pointInDiskLocal = new Vector3(r1 * _radius, 0, r2 * _radius);
            var pointInDiskWorld = ObjectToWorld.TransformPoint(ref pointInDiskLocal);

            incomingVector = point - pointInDiskWorld;
            var cosangle = Vector3.Dot(incomingVector.Normalized(), _normal);

            visibilityTester = new VisibilityTester(pointInDiskWorld, point, scene);
            return(Spectrum * cosangle / incomingVector.Length);
        }
 /// <summary>
 ///     Get the samples
 /// </summary>
 /// <returns></returns>
 public override IEnumerable <Sample> Samples()
 {
     for (var y = 0f; y < Screen.Height; ++y)
     {
         for (var x = 0f; x < Screen.Width; ++x)
         {
             for (var i = 0; i < NumberOfSamples; ++i)
             {
                 yield return(new Sample(MathHelper.Clamp(x + StaticRandom.NextFloat(), 0, Screen.Width - 1),
                                         MathHelper.Clamp(y + StaticRandom.NextFloat(), 0, Screen.Height - 1)));
             }
         }
     }
 }
 public TestMaterial(float?reflectiveness = null, SampledSpectrum spectrum = null)
 {
     _reflectiveness = reflectiveness ?? StaticRandom.NextFloat();
     _spectrum       = spectrum ?? SampledSpectrum.Random() * 0.3f;
 }