コード例 #1
0
        public static void Test()
        {
            var b = ThreadPool.SetMaxThreads(System.Environment.ProcessorCount, System.Environment.ProcessorCount);
            //Debug.Log(b);

            int nx = 1280;
            int ny = 720;
            int ns = 128;

            myThreadCount = nx * ny;

            Vector3             lookfrom      = new Vector3(13, 3, 3);
            Vector3             lookat        = new Vector3(0, 0, 0);
            float               dist_to_focus = 10;
            float               aperture      = 0.1f;
            Vector3             up            = new Vector3(0, 1, 0);
            MotionBlurRayCamera camera        = new MotionBlurRayCamera(lookfrom, lookat, up, 20,
                                                                        (float)(nx) / (float)(ny), aperture, dist_to_focus);

            HitList list = new HitList();

            RandomScene(ref list);
            Texture2D tex = ImageHelper.CreateImg(nx, ny);

            Vector3[,] imgBin = new Vector3[nx, ny];

            ManualResetEvent resetEvent = new ManualResetEvent(false);

            for (int j = ny - 1; j >= 0; --j)
            {
                for (int i = 0; i < nx; ++i)
                {
                    var param = new Param();
                    param.world      = list;
                    param.camera     = camera;
                    param.pos_x      = i;
                    param.pos_y      = j;
                    param.img_width  = nx;
                    param.img_height = ny;
                    param.times      = ns;
                    param.img        = imgBin;
                    param.mre        = resetEvent;
                    param.seed       = new System.Random();

                    while (!ThreadPool.QueueUserWorkItem(ThreadRayMain, param))
                    {
                        Debug.Log("wait ");
                        Thread.Sleep(500);
                    }
                }
            }
            resetEvent.WaitOne();

            for (int j = ny - 1; j >= 0; --j)
            {
                for (int i = 0; i < nx; ++i)
                {
                    ImageHelper.SetPixel(tex, i, j, imgBin[i, j]);
                }
            }
            ImageHelper.SaveImg(tex, "Img/chapter12.png");
            Debug.Log("Chapter 12 done");
        }