Exemplo n.º 1
0
 private ShadingState(ShadingState previous, IntersectionState istate, Ray r, int i, int d)
 {
     this.r           = r;
     this.istate      = istate;
     this.i           = i;
     this.d           = d;
     this.instance    = istate.instance; // local copy
     this.primitiveID = istate.id;
     this.hitU        = istate.u;
     this.hitV        = istate.v;
     if (previous == null)
     {
         diffuseDepth    = 0;
         reflectionDepth = 0;
         refractionDepth = 0;
     }
     else
     {
         diffuseDepth    = previous.diffuseDepth;
         reflectionDepth = previous.reflectionDepth;
         refractionDepth = previous.refractionDepth;
         this.server     = previous.server;
         this.map        = previous.map;
         this.rx         = previous.rx;
         this.ry         = previous.ry;
         this.i         += previous.i;
         this.d         += previous.d;
     }
     behind        = false;
     cosND         = float.NaN;
     includeLights = includeSpecular = true;
     qmcD0I        = QMC.halton(this.d, this.i);
     qmcD1I        = QMC.halton(this.d + 1, this.i);
     result        = null;
 }
Exemplo n.º 2
0
 public CalculatePhotons(int start, int end, LightServer server, int seed, float[] histogram, float scale, PhotonStore map, object lockObj)
 {
     this.start     = start;
     this.end       = end;
     this.server    = server;
     this.seed      = seed;
     this.histogram = histogram;
     this.lockObj   = lockObj;
     this.scale     = scale;
     this.map       = map;
     this.lockObj   = lockObj;
 }
Exemplo n.º 3
0
        private ShadingState(ShadingState previous, IntersectionState istate, Ray r, int i, int d)
        {
            this.r      = r;
            this.istate = istate;
            this.i      = i;
            this.d      = d;
            time        = istate.time;
            instance    = istate.instance; // local copy
            primitiveID = istate.id;
            hitU        = istate.u;
            hitV        = istate.v;
            hitW        = istate.w;
            // get matrices for current time
            o2w = instance.getObjectToWorld(time);
            w2o = instance.getWorldToObject(time);

            if (previous == null)
            {
                diffuseDepth    = 0;
                reflectionDepth = 0;
                refractionDepth = 0;
            }
            else
            {
                diffuseDepth    = previous.diffuseDepth;
                reflectionDepth = previous.reflectionDepth;
                refractionDepth = previous.refractionDepth;
                server          = previous.server;
                map             = previous.map;
                rx      = previous.rx;
                ry      = previous.ry;
                this.i += previous.i;
                this.d += previous.d;
            }
            behind        = false;
            cosND         = float.NaN;
            includeLights = includeSpecular = true;
            qmcD0I        = QMC.halton(this.d, this.i);
            qmcD1I        = QMC.halton(this.d + 1, this.i);
            result        = null;
            bias          = 0.001f;
        }
Exemplo n.º 4
0
 public CalculatePhotons(int start, int end, LightServer server, int seed, float[] histogram, float scale, PhotonStore map, object lockObj)
 {
     this.start = start;
     this.end = end;
     this.server = server;
     this.seed = seed;
     this.histogram = histogram;
     this.lockObj = lockObj;
     this.scale = scale;
     this.map = map;
     this.lockObj = lockObj;
 }
Exemplo n.º 5
0
 public bool calculatePhotons(PhotonStore map, string type, int seed, Options options)
 {
     if (map == null)
         return true;
     if (lights.Length == 0)
     {
         UI.printError(UI.Module.LIGHT, "Unable to trace {0} photons, no lights in scene", type);
         return false;
     }
     float[] histogram = new float[lights.Length];
     histogram[0] = lights[0].getPower();
     for (int i = 1; i < lights.Length; i++)
         histogram[i] = histogram[i - 1] + lights[i].getPower();
     UI.printInfo(UI.Module.LIGHT, "Tracing {0} photons ...", type);
     map.prepare(options, scene.getBounds());
     int numEmittedPhotons = map.numEmit();
     if (numEmittedPhotons <= 0 || histogram[histogram.Length - 1] <= 0)
     {
         UI.printError(UI.Module.LIGHT, "Photon mapping enabled, but no {0} photons to emit", type);
         return false;
     }
     UI.taskStart("Tracing " + type + " photons", 0, numEmittedPhotons);
     Thread[] photonThreads = new Thread[scene.getThreads()];
     float scale = 1.0f / numEmittedPhotons;
     int delta = numEmittedPhotons / photonThreads.Length;
     photonCounter = 0;
     SunflowSharp.Systems.Timer photonTimer = new SunflowSharp.Systems.Timer();
     photonTimer.start();
     for (int i = 0; i < photonThreads.Length; i++)
     {
         int threadID = i;
         int start = threadID * delta;
         int end = (threadID == (photonThreads.Length - 1)) ? numEmittedPhotons : (threadID + 1) * delta;
         photonThreads[i] = new Thread(new ThreadStart(new CalculatePhotons(start, end, this, seed, histogram, scale, map, lockObj).Run));
         photonThreads[i].Priority = scene.getThreadPriority();
         photonThreads[i].Start();
     }
     for (int i = 0; i < photonThreads.Length; i++)
     {
         try
         {
             photonThreads[i].Join();
         }
         catch (Exception e)
         {
             UI.printError(UI.Module.LIGHT, "Photon thread {0} of {1} was interrupted", i + 1, photonThreads.Length);
             return false;
         }
     }
     if (UI.taskCanceled())
     {
         UI.taskStop(); // shut down task cleanly
         return false;
     }
     photonTimer.end();
     UI.taskStop();
     UI.printInfo(UI.Module.LIGHT, "Tracing time for {0} photons: {1}", type, photonTimer.ToString());
     map.init();
     return true;
 }
Exemplo n.º 6
0
        public static ShadingState createPhotonState(Ray r, IntersectionState istate, int i, PhotonStore map, LightServer server)
        {
            ShadingState s = new ShadingState(null, istate, r, i, 4);

            s.server = server;
            s.map    = map;
            return(s);
        }
Exemplo n.º 7
0
        public bool calculatePhotons(PhotonStore map, string type, int seed)
        {
            if (map == null)
            {
                return(true);
            }
            if (lights.Length == 0)
            {
                UI.printError(UI.Module.LIGHT, "Unable to trace {0} photons, no lights in scene", type);
                return(false);
            }
            float[] histogram = new float[lights.Length];
            histogram[0] = lights[0].getPower();
            for (int i = 1; i < lights.Length; i++)
            {
                histogram[i] = histogram[i - 1] + lights[i].getPower();
            }
            UI.printInfo(UI.Module.LIGHT, "Tracing %s photons ...", type);
            int numEmittedPhotons = map.numEmit();

            if (numEmittedPhotons <= 0 || histogram[histogram.Length - 1] <= 0)
            {
                UI.printError(UI.Module.LIGHT, "Photon mapping enabled, but no {0} photons to emit", type);
                return(false);
            }
            map.prepare(scene.getBounds());
            UI.taskStart("Tracing " + type + " photons", 0, numEmittedPhotons);
            Thread[] photonThreads = new Thread[scene.getThreads()];
            float    scale         = 1.0f / numEmittedPhotons;
            int      delta         = numEmittedPhotons / photonThreads.Length;

            photonCounter = 0;
            SunflowSharp.Systems.Timer photonTimer = new SunflowSharp.Systems.Timer();
            photonTimer.start();
            for (int i = 0; i < photonThreads.Length; i++)
            {
                int threadID = i;
                int start    = threadID * delta;
                int end      = (threadID == (photonThreads.Length - 1)) ? numEmittedPhotons : (threadID + 1) * delta;
                photonThreads[i]          = new Thread(new ThreadStart(new CalculatePhotons(start, end, this, seed, histogram, scale, map, lockObj).Run));
                photonThreads[i].Priority = scene.getThreadPriority();
                photonThreads[i].Start();
            }
            for (int i = 0; i < photonThreads.Length; i++)
            {
                try
                {
                    photonThreads[i].Join();
                }
                catch (Exception e)
                {
                    UI.printError(UI.Module.LIGHT, "Photon thread {0} of {1} was interrupted", i + 1, photonThreads.Length);
                    return(false);
                }
            }
            if (UI.taskCanceled())
            {
                UI.taskStop(); // shut down task cleanly
                return(false);
            }
            photonTimer.end();
            UI.taskStop();
            UI.printInfo(UI.Module.LIGHT, "Tracing time for {0} photons: {1}", type, photonTimer.ToString());
            map.init();
            return(true);
        }
Exemplo n.º 8
0
 /**
  * Create a photon map as prescribed by the given {@link PhotonStore}.
  *
  * @param map object that will recieve shot photons
  * @param type type of photons being shot
  * @param seed QMC seed parameter
  * @return <code>true</code> upon success
  */
 public bool calculatePhotons(PhotonStore map, string type, int seed)
 {
     return lightServer.calculatePhotons(map, type, seed);
 }
Exemplo n.º 9
0
 /**
  * Create a photon map as prescribed by the given {@link PhotonStore}.
  *
  * @param map object that will recieve shot photons
  * @param type type of photons being shot
  * @param seed QMC seed parameter
  * @return <code>true</code> upon success
  */
 public bool calculatePhotons(PhotonStore map, string type, int seed, Options options)
 {
     return(lightServer.calculatePhotons(map, type, seed, options));
 }