Exemplo n.º 1
0
            public Sample GetNextSample(FastRandom rnd)
            {
                curX++;
                if (curX >= Width)
                {
                    curY++;
                    curX = 0;
                    if (curY >= Height)
                    {
                        curY = 0;
                        CurrentPass++;
                    }
                }
                var data = (new float[sampleDepth]).Select(item => rnd.NextFloat()).ToArray();

                return new Sample()
                    {
                        ImageX = curX,
                        ImageY = Height - curY - 1,
                        Data = data
                    };
            }
Exemplo n.º 2
0
        private static void Hashtest()
        {
            float worldSize = 100f;
            AABB hpbbox = new AABB(new Point(-worldSize), new Point(worldSize));
            int pointsCount = 1000000;

            var rnd = new FastRandom();
            HashMap map = new HashMap();
            List<Photon> pt = new List<Photon>();
            for (int i = 0; i < pointsCount; i++)
            {
                var hitPoint = new Point(worldSize * rnd.NextFloatNeg(), worldSize * rnd.NextFloatNeg(),
                                         worldSize * rnd.NextFloatNeg());
                if (!hpbbox.Inside(hitPoint))
                {
                    Console.WriteLine("Generated invalid point");
                    continue;
                }

                Vector dir = new Vector(worldSize * rnd.NextFloatNeg(), worldSize * rnd.NextFloatNeg(), worldSize * rnd.NextFloatNeg());
                RgbSpectrum spec = new RgbSpectrum(rnd.NextFloat(), rnd.NextFloat(), rnd.NextFloat());

                pt.Add(new Photon(ref hitPoint, ref dir, ref spec));
            }

            map.Construct(pt.ToArray());

            var qp = new Point(1f);

            var query = map.Query(ref qp, 2f);
            foreach (var photon in query)
            {
                Console.WriteLine(photon);
            }

            Console.WriteLine("Bounding box size {0}, Points {1}", worldSize, pointsCount);

            return;
        }
Exemplo n.º 3
0
        private static void TestDirections(FastRandom rnd)
        {
            int dirCount = 80;
            var directions = new List<Vector>(dirCount);

            for (int i = 0; i < dirCount; i++)
            {
                var dir = new Vector(1f - 2f * rnd.NextFloat(), 1f - 2f * rnd.NextFloat(), 1f - 2f * rnd.NextFloat());
                directions.Add(dir);
            }
            directions.Sort((a, b) => Geometry.ClassifyDirection(ref a).CompareTo(Geometry.ClassifyDirection(ref b)));

            for (int index = 0; index < directions.Count; index++)
            {
                var dir = directions[index];
                Console.WriteLine("Vector {0}  Classification {1}", dir, Geometry.ClassifyDirection(ref dir));
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {

            int itemCount = 1000;
            int iters = 100000;
            Random rand = new Random();
            int[] ints = Enumerable.Range(0, itemCount).Select(cc => rand.Next()).ToArray();
            HashSet<int> hs = new HashSet<int>(ints);
            List<int> lst = ints.ToList();
            bool contains = false;
            string result = string.Empty;
            result = PerformanceMeasurementController.Test(delegate
            {
                var index = rand.Next(0, itemCount - 1);
                contains = hs.Contains(index) != true;
            }, "HashSet search\r\n", iters);
            Console.WriteLine("Time "+result);

            result = PerformanceMeasurementController.Test(delegate
            {
                var index = rand.Next(0, itemCount - 1);
                contains = lst.BinarySearch(index) > 0;
            }, "List search\r\n", iters);
            Console.WriteLine("Time " + result);

            result = PerformanceMeasurementController.Test(delegate
            {
                var index = rand.Next(0, itemCount - 1);
                for (int j = 0; j < itemCount; j++)
                {
                    if (ints[j] == index)
                    {
                        contains = true;
                        break;
                    }
                }
            }, "Array enum search\r\n", iters);
            Console.WriteLine("Time " + result);

            return;

            IRandomProvider rp = new BaseQMCSequence();
            int i = 100;
            while (i!=0)
            {
                Console.WriteLine("{0}  {1:F6},  {2:F6},  {3:F6},  {4:F6}", i, rp.NextFloat(),rp.NextFloat(),rp.NextFloat(),rp.NextFloat());
                i--;
            }
            Console.WriteLine(rp.GetType().Name);
            return;
            /*
            RgbSpectrum c1 = new RgbSpectrum(0.5f, 0.7f, 1.55f);
            RgbSpectrum c2 = new RgbSpectrum(1.5f, 0.4f, 11f);
            RgbSpectrum c3 = new RgbSpectrum(0);

            
            SSE.MaddSse(ref c1, ref c2, 4f, ref c3);

            Console.WriteLine("SSE Version - {0}", c3);
            Console.WriteLine("CPU Version - {0}", (c1+c2)*4f);



            return;
            */

            v1();
            v1();
            v1();

            var res = new SampledSpectrum(1.9f);
            var rs = new SampledSpectrum(1.9f);

            var rgb_1 = ColorFactory.SSEToRgb(ref res);
            var rgb_2 = res.ToRgb();

            Console.WriteLine("SSE:{0} / Norm {1}", rgb_1, rgb_2);

            SSE.ClampSSE(ref res, ref rs);
            var maxIterations = 5;
            var testIterations = 1;
            var iterations = 100000000;
            var rnd = new FastRandom();

            var s1 = new SampledSpectrum(rnd.NextFloat());
            var s2 = new SampledSpectrum(rnd.NextFloat());
            var s3 = SampledSpectrum.UnitSpectrum();
            RgbSpectrum r3;
            float rx = 0f;
            float[][] rgb = Enumerable.Repeat(new[] {rnd.NextFloat(), rnd.NextFloat(), rnd.NextFloat()}, 1000).ToArray();

            var testActions = new[]
                {
                    //new Tuple<string, Action>("Spectral mul cpu", () =>
                    //{
                    //    s3 = s1*s2;
                    //}),

                    //new Tuple<string, Action>("Spectral mul sse", () =>
                    //{
                    //    SSE.MulSSE(ref s1, ref s2, ref s3);
                    //}),

                    new Tuple<string, Action>("Dot SSE", () =>
                    {
                        rx = SSE.Dot(ref s1, ref s2);
                    }),

                    new Tuple<string, Action>("Dot avx", () =>
                    {
                        rx = AVX.Dot(ref s1, ref s2);
                    }),

                    /*
                    new Tuple<string, Action>("to Rgb  cpu", () =>
                    {
                        r3 = s1.ToRgb();
                    }),

                    new Tuple<string, Action>("to Rgb  sse", () =>
                    {
                        r3 = ColorFactory.SSEToRgb(ref s1);
                    }),*/

                    //new Tuple<string, Action>("Rgb madd cpu", () =>
                    //{
                    //    var r1 = new RgbSpectrum(rnd.NextFloat());
                    //    var r2 = new RgbSpectrum(rnd.NextFloat());
                    //    var r4 = new RgbSpectrum(rnd.NextFloat());

                    //    r3 = (r1 + r2+r4+r1) * (1f / 3f);

                    //    //SSE.MaddSse(ref r1, ref c2, 4f, ref c3);

                    //}), 

                    //new Tuple<string, Action>("Rgb madd sse", () =>
                    //{
                    //    var r1 = new RgbSpectrum(rnd.NextFloat());
                    //    var r2 = new RgbSpectrum(rnd.NextFloat());
                    //    var r4 = new RgbSpectrum(rnd.NextFloat());


                    //    SSE.AverageSSE(ref r1, ref r2, ref r4,ref r1, ref r3);

                    //}), 

                    /*
                    new Tuple<string, Action>    (" SSE to rgb ", () =>
                        {
                            foreach (var f in rgb)
                            {
                                ColorFactory.SSEFromRgb(f, SpectrumType.Illuminant);
                                
                            }
                        }),
                         new Tuple<string, Action>    (" AVX to rgb ", () =>
                        {
                            foreach (var f in rgb)
                            {
                                ColorFactory.AVXFromRgb(f, SpectrumType.Illuminant);
                            }
                        }),
                        new Tuple<string, Action>(" CPU to rgb ", () =>
                        {
                            foreach (var f in rgb)
                            {
                                ColorFactory.BaseFromRgb(f, SpectrumType.Illuminant);

                            }
                        }),
                     */ 
/*

                          new Tuple<string, Action>    (" Normal sqrt ", () =>
                        {
                            for (int i = 0; i < 4; i++)
                            {
                                var f = rnd.NextFloat();
                                res[0] = MathLab.Sqrt(f);
                            }
                        }),
                        new Tuple<string, Action>(" SSE sqrt    ", () =>
                        {
                            SSE. VSqrt();
                        }),*/
                        /*
                    new Tuple<string, Action>("Current NextFloat :",  () =>
                        {
                            var rnd = new FastRandom();
                            rnd.NextFloat();
                            for (var i = 0; i < iterations; i++)
                            {
                                rnd.NextFloat();
                            }
                        }),
                    new Tuple<string, Action>("Halton : ",  () =>
                        {
                            var qmc = new HaltonSequence();
                            for (var i = 0; i < iterations; i++)
                            {
                                //rnd.NextDouble();
                                qmc.NextFloat();
                            }
                        }),
                    new Tuple<string, Action>("VanDerCorrupt : ",  () =>
                        {
                            var qmc = new BaseQMCSequence();
                            for (var i = 0; i < iterations; i++)
                            {
                                //rnd.NextDouble();
                                qmc.NextFloat();
                            }
                        }),*/

                };
        @test:

            Console.WriteLine("Converting 1000 float triplets to SampledSpectrum");
            Console.WriteLine("Running test for {0} iterations per test . {1} test iteration", iterations, testIterations);
            //TestExpressions();
            foreach (var testAction in testActions)
            {
                Tuple<string, Action> action = testAction;
                Console.WriteLine(PerformanceMeasurementController.Test(() => action.Item2(), 8,testAction.Item1, iterations));
            }
            testIterations++;
            if (testIterations > maxIterations)
                return;
            goto @test;


            /*
            QualitySettingsInfo qs = new QualitySettingsInfo() { SamplesPerPixel = 32, ShadowRaysPerLight = 1, TextureSamplingQuality = TextureSamplingQuality.Linear, SuperSamplingSize = 1 };
            OutputSettingsInfo os = new OutputSettingsInfo() { FilePath = @"G:\Git", Width = 640, Height = 480, GammaCorrection = true, BitsPerPixel = 32, ToneMap = false, ToneMapValue = 1.5f };

            var qs_s = SerializationService.Serialize(qs, typeof(QualitySettingsInfo), typeof(TextureSamplingQuality));
            var os_s = SerializationService.Serialize(os, typeof(OutputSettingsInfo));
            Console.WriteLine(qs_s);
            Console.WriteLine(os_s);*/

            /*
            var f = new [] {0.25f, 0.15f, 0.15f, 0.45f};
            float[] cdf = new float[f.Length+1];
            float c;
            MC.ComputeStep1dCDF(f, 4, cdf, out c);
            Console.WriteLine();
            return;
           */
            //CreateFrame(@"F:\Dev\Frames\RDF\", "cornell_service", @"F:\Dev\Scenes\OasisCornell\");
            //CreateFrame(@"F:\Dev\Frames\RDF\", "decostreet", @"F:\3D\Models\decostreet\");
            //            CreateFrame(@"F:\Dev\Frames\RDF\", "tmp", @"F:\3D\Models\decostreet\");
            /*
            GlobalConfiguration.Instance.OpenConfig(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Global.Config.xml");
            GlobalConfiguration.Instance.Add("TextureFindPaths", new string[3] { @"C:\Dev\", @"F:\3d\HDRi\", @"F:\3d\Textures\" });
            GlobalConfiguration.Instance.SaveConfig(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Global.Config.xml");


            //CreateFrame(@"F:\Dev\Frames\CompressedDataFrames\DecoStreet\", "decostreet", @"F:\Dev\Frames\CompressedDataFrames\DecoStreet\");
            return;
            //
            //CreateFrame(@"F:\Dev\Frames\RDF\", "cornell_service");
            using (var frame = ArchiveFrameService.OpenArchive(@"F:\Dev\Frames\CompressedDataFrames\OasisCornell\OasisCornell.cdf",
                                                @"F:\Temp\RayDenTemp\OasisCornell"))
                Console.WriteLine("Frame opened {0}", frame.Frame.FrameName);
             * */
        }
Exemplo n.º 5
0
        public static RgbSpectrum EstimateDirect(ref Vector wo, IAccellerationStructure intersector, SceneGeometryInfo scene, ILight light, IntersectionInfo isect, SurfaceBsdf bsdf, FastRandom rnd)
        {
            RgbSpectrum Ld = new RgbSpectrum();
            Vector wi;
            float lightPdf, bsdfPdf;
            RayInfo shadowRay;
            RgbSpectrum Li = light.Sample(ref isect.GeometryInfo.HitPoint, ref isect.GeometryInfo.GeoNormal, rnd.NextFloat(), rnd.NextFloat(), rnd.NextFloat(),
                                          out shadowRay, out lightPdf);
            if (lightPdf > 0f && !Li.IsBlack())
            {
                wi = -shadowRay.Dir;
                RgbSpectrum f ;
                bsdf.f(ref wo, ref wi, ref isect.GeometryInfo.GeoNormal, ref Ld, out f);
                if (!f.IsBlack() && !intersector.Intersect(shadowRay))
                {
                    // Add light's contribution to reflected radiance
                    //Li *= visibility.Transmittance(scene, renderer, NULL, rng, arena);
                    if (light.IsDelta)
                        Ld += f * Li * (Vector.AbsDot(ref wi, ref isect.GeometryInfo.GeoNormal) / lightPdf);
                    else
                    {
                        bsdfPdf = bsdf.Pdf(ref wo, ref wi, BxDFTypes.BSDF_ALL_TYPES);
                        float weight = MC.PowerHeuristic(1, lightPdf, 1, bsdfPdf);
                        Ld += f * Li * (Vector.AbsDot(ref wi, ref isect.GeometryInfo.GeoNormal) * weight / lightPdf);
                    }
                }
            }
            if (!light.IsDelta)
            {
                //float bsdfPdf;
                bool spb;
                BsdfSampleData result;
                bsdf.Sample_f(ref wo, ref isect.GeometryInfo.GeoNormal, ref isect.GeometryInfo.ShadingNormal, ref Ld, rnd.NextFloat(),
                                              rnd.NextFloat(), rnd.NextFloat(), ref isect.TextureData, out result);
                bsdfPdf = result.Pdf;
                if (!result.F.IsBlack() && result.Pdf > 0f)
                {
                    if (lightPdf > 0f)
                    {
                        float weight = MC.PowerHeuristic(1, bsdfPdf, 1, lightPdf);
                        IntersectionInfo lightIsect;
                        RgbSpectrum li = new RgbSpectrum();
                        var ray = new RayInfo(isect.GeometryInfo.HitPoint, result.Wi, 1e-4f, 1e+4f);
                        if (intersector.Intersect(ray, out lightIsect))
                        {
                            if (light is TriangleLight && lightIsect.PrimitiveId.Equals(((TriangleLight)light).Owner.Id))
                                li = light.Le(-result.Wi);
                        }
                        else
                            li = light.Le(ray.Dir);
                        if (!li.IsBlack())
                        {
                            //Li *= scene->Transmittance(ray);
                            Ld += result.F * li * Vector.AbsDot(ref result.Wi, ref isect.GeometryInfo.GeoNormal) * weight / bsdfPdf;
                        }
                    }
                }
            }
            /*

            if (!light->IsDeltaLight()) {
		BxDFType flags = BxDFType(BSDF_ALL & ~BSDF_SPECULAR);
		Spectrum f = bsdf->Sample_f(wo, &wi,
			bs1, bs2, bcs, &bsdfPdf, flags);
		if (!f.Black() && bsdfPdf > 0.) {
			lightPdf = light->Pdf(p, n, wi);
			if (lightPdf > 0.) {
				// Add light contribution from BSDF sampling
				float weight = PowerHeuristic(1, bsdfPdf, 1, lightPdf);
				Intersection lightIsect;
				Spectrum Li(0.f);
				RayDifferential ray(p, wi);
				if (scene->Intersect(ray, &lightIsect)) {
					if (lightIsect.primitive->GetAreaLight() == light)
						Li = lightIsect.Le(-wi);
				}
				else
					Li = light->Le(ray);
				if (!Li.Black()) {
					Li *= scene->Transmittance(ray);
					Ld += f * Li * AbsDot(wi, n) * weight / bsdfPdf;
				}
			}
		}
	} 
             */
            return Ld;
        }