Esempio n. 1
0
            public void Run()
            {
                ByteUtil.InitByteUtil();
                IntersectionState istate = new IntersectionState();

                for (int i = start; i < end; i++)
                {
                    lock (lockObj)
                    {
                        UI.taskUpdate(server.photonCounter);
                        server.photonCounter++;
                        if (UI.taskCanceled())
                        {
                            return;
                        }
                    }

                    int qmcI = i + seed;

                    double rand = QMC.halton(0, qmcI) * histogram[histogram.Length - 1];
                    int    j    = 0;
                    while (rand >= histogram[j] && j < histogram.Length)
                    {
                        j++;
                    }
                    // make sure we didn't pick a zero-probability light
                    if (j == histogram.Length)
                    {
                        continue;
                    }

                    double  randX1 = (j == 0) ? rand / histogram[0] : (rand - histogram[j]) / (histogram[j] - histogram[j - 1]);
                    double  randY1 = QMC.halton(1, qmcI);
                    double  randX2 = QMC.halton(2, qmcI);
                    double  randY2 = QMC.halton(3, qmcI);
                    Point3  pt     = new Point3();
                    Vector3 dir    = new Vector3();
                    Color   power  = new Color();
                    server.lights[j].getPhoton(randX1, randY1, randX2, randY2, pt, dir, power);
                    power.mul(scale);
                    Ray r = new Ray(pt, dir);
                    server.scene.trace(r, istate);
                    if (istate.hit())
                    {
                        server.shadePhoton(ShadingState.createPhotonState(r, istate, qmcI, map, server), power);
                    }
                }
            }