Exemplo n.º 1
0
 private void build()
 {
     lock (lockObj)
     {
         // double check flag
         if (builtAccel != 0)
         {
             return;
         }
         if (primitives != null)
         {
             int n = primitives.getNumPrimitives();
             if (n >= 1000)
             {
                 UI.printInfo(UI.Module.GEOM, "Building acceleration structure for {0} primitives ...", n);
             }
             accel = AccelerationStructureFactory.create(acceltype, n, true);
             accel.build(primitives);
         }
         else
         {
             // create an empty accelerator to avoid having to check for null
             // pointers in the intersect method
             accel = new NullAccelerator();
         }
         builtAccel = 1;
     }
 }
Exemplo n.º 2
0
 /**
  * Create a geometry from the specified primitive aggregate. The
  * acceleration structure for this object will be built on demand.
  *
  * @param primitives primitive list object
  */
 public Geometry(PrimitiveList primitives)
 {
     tesselatable    = null;
     this.primitives = primitives;
     accel           = null;
     builtAccel      = 0;
     builtTess       = 1; // already tesselated
 }
Exemplo n.º 3
0
 /**
  * Create a geometry from the specified primitive aggregate. The
  * acceleration structure for this object will be built on demand.
  *
  * @param primitives primitive list object
  */
 public Geometry(PrimitiveList primitives)
 {
     tesselatable = null;
     this.primitives = primitives;
     accel = null;
     builtAccel = 0;
     builtTess = 1; // already tesselated
 }
Exemplo n.º 4
0
 /**
  * Create a geometry from the specified tesselatable object. The actual
  * renderable primitives will be generated on demand.
  *
  * @param tesselatable tesselation object
  */
 public Geometry(ITesselatable tesselatable)
 {
     this.tesselatable = tesselatable;
     primitives        = null;
     accel             = null;
     builtAccel        = 0;
     builtTess         = 0;
     acceltype         = null;
 }
Exemplo n.º 5
0
 /**
  * Create a geometry from the specified tesselatable object. The actual
  * renderable primitives will be generated on demand.
  *
  * @param tesselatable tesselation object
  */
 public Geometry(ITesselatable tesselatable)
 {
     this.tesselatable = tesselatable;
     primitives = null;
     accel = null;
     builtAccel = 0;
     builtTess = 0;
     acceltype = null;
 }
        public static AccelerationStructure create(string name, int n, bool primitives)
        {
            if (name == null || name == "auto")
            {
                if (primitives)
                {
                    if (n > 20000000)
                    {
                        name = "uniformgrid";
                    }
                    else if (n > 2000000)
                    {
                        name = "bih";
                    }
                    else if (n > 2)
                    {
                        name = "kdtree";
                    }
                    else
                    {
                        name = "null";
                    }
                }
                else
                {
                    if (n > 2)
                    {
                        name = "bih";
                    }
                    else
                    {
                        name = "null";
                    }
                }
            }
            AccelerationStructure accel = PluginRegistry.accelPlugins.createObject(name);

            if (accel == null)
            {
                UI.printWarning(UI.Module.ACCEL, "Unrecognized intersection accelerator \"{0}\" - using auto", name);
                return(create(null, n, primitives));
            }
            if (name != "null")
            {
                UI.printInfo(UI.Module.ACCEL, "Building {0} acceleration structure...", name);
            }
            return(accel);
        }
Exemplo n.º 7
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     acceltype = pl.getstring("accel", acceltype);
     // clear up old tesselation if it exists
     if (tesselatable != null)
     {
         primitives = null;
         builtTess  = 0;
     }
     // clear acceleration structure so it will be rebuilt
     accel      = null;
     builtAccel = 0;
     if (tesselatable != null)
     {
         return(tesselatable.Update(pl, api));
     }
     // update primitives
     return(primitives.Update(pl, api));
 }
Exemplo n.º 8
0
        /**
         * Creates an empty scene.
         */
        public Scene()
        {
            lightServer = new LightServer(this);
            instanceList = new InstanceList();
            infiniteInstanceList = new InstanceList();
            acceltype = "auto";

            bakingViewDependent = false;
            bakingInstance = null;
            bakingPrimitives = null;
            bakingAccel = null;

            camera = null;
            imageWidth = 640;
            imageHeight = 480;
            threads = 0;
            lowPriority = true;

            rebuildAccel = true;
        }
Exemplo n.º 9
0
        /**
         * Creates an empty scene.
         */
        public Scene()
        {
            lightServer          = new LightServer(this);
            instanceList         = new InstanceList();
            infiniteInstanceList = new InstanceList();
            acceltype            = "auto";

            bakingViewDependent = false;
            bakingInstance      = null;
            bakingPrimitives    = null;
            bakingAccel         = null;

            camera      = null;
            imageWidth  = 640;
            imageHeight = 480;
            threads     = 0;
            lowPriority = true;

            rebuildAccel = true;
        }
Exemplo n.º 10
0
 private void build()
 {
     lock (lockObj)
     {
         // double check flag
         if (builtAccel != 0)
             return;
         if (primitives != null)
         {
             int n = primitives.getNumPrimitives();
             if (n >= 1000)
                 UI.printInfo(UI.Module.GEOM, "Building acceleration structure for {0} primitives ...", n);
             accel = AccelerationStructureFactory.create(acceltype, n, true);
             accel.build(primitives);
         }
         else
         {
             // create an empty accelerator to avoid having to check for null
             // pointers in the intersect method
             accel = new NullAccelerator();
         }
         builtAccel = 1;
     }
 }
Exemplo n.º 11
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     acceltype = pl.getstring("accel", acceltype);
     // clear up old tesselation if it exists
     if (tesselatable != null)
     {
         primitives = null;
         builtTess = 0;
     }
     // clear acceleration structure so it will be rebuilt
     accel = null;
     builtAccel = 0;
     if (tesselatable != null)
         return tesselatable.update(pl, api);
     // update primitives
     return primitives.update(pl, api);
 }
Exemplo n.º 12
0
 /// <summary> Intersect the <see cref="Scene"/> with a <paramref name="ray"/> </summary>
 /// <param name="ray">The <see cref="Ray"/> to intersect the <see cref="Scene"/> with</param>
 /// <returns>Whether the <paramref name="ray"/> intersects something in the <see cref="Scene"/></returns>
 public bool IntersectBool(Ray ray)
 {
     return(AccelerationStructure.IntersectBool(ray));
 }
Exemplo n.º 13
0
 /// <summary> Intersect the <see cref="Scene"/> with a <paramref name="ray"/> </summary>
 /// <param name="ray">The <see cref="Ray"/> to intersect the <see cref="Scene"/> with</param>
 /// <returns>The <see cref="Intersection"/> if there is any</returns>
 public Intersection?Intersect(Ray ray)
 {
     return(AccelerationStructure.Intersect(ray));
 }
Exemplo n.º 14
0
        /**
         * Render the scene using the specified options, image sampler and display.
         *
         * @param options rendering options object
         * @param sampler image sampler
         * @param display display to send the image to, a default display will
         *            be created if <code>null</code>
         */
        public void render(Options options, ImageSampler sampler, IDisplay display)
        {
            if (display == null)
                display = null;// new FrameDisplay();

            if (bakingInstance != null)
            {
                UI.printDetailed(UI.Module.SCENE, "Creating primitives for lightmapping ...");
                bakingPrimitives = bakingInstance.getBakingPrimitives();
                if (bakingPrimitives == null)
                {
                    UI.printError(UI.Module.SCENE, "Lightmap baking is not supported for the given instance.");
                    return;
                }
                int n = bakingPrimitives.getNumPrimitives();
                UI.printInfo(UI.Module.SCENE, "Building acceleration structure for lightmapping ({0} num primitives) ...", n);
                bakingAccel = AccelerationStructureFactory.create("auto", n, true);
                bakingAccel.build(bakingPrimitives);
            }
            else
            {
                bakingPrimitives = null;
                bakingAccel = null;
            }
            bakingViewDependent = options.getbool("baking.viewdep", bakingViewDependent);

            if ((bakingInstance != null && bakingViewDependent && camera == null) || (bakingInstance == null && camera == null))
            {
                UI.printError(UI.Module.SCENE, "No camera found");
                return;
            }

            // read from options
            threads = options.getInt("threads", 0);
            lowPriority = options.getbool("threads.lowPriority", true);
            imageWidth = options.getInt("resolutionX", 640);
            imageHeight = options.getInt("resolutionY", 480);
            // limit resolution to 16k
            imageWidth = MathUtils.clamp(imageWidth, 1, 1 << 14);
            imageHeight = MathUtils.clamp(imageHeight, 1, 1 << 14);

            // get acceleration structure info
            // count scene primitives
            long numPrimitives = 0;
            for (int i = 0; i < instanceList.getNumPrimitives(); i++)
                numPrimitives += instanceList.getNumPrimitives(i);
            UI.printInfo(UI.Module.SCENE, "Scene stats:");
            UI.printInfo(UI.Module.SCENE, "  * Infinite instances:  {0}", infiniteInstanceList.getNumPrimitives());
            UI.printInfo(UI.Module.SCENE, "  * Instances:           {0}", instanceList.getNumPrimitives());
            UI.printInfo(UI.Module.SCENE, "  * Primitives:          {0}", numPrimitives);
            string accelName = options.getstring("accel", null);
            if (accelName != null)
            {
                rebuildAccel = rebuildAccel || acceltype != accelName;
                acceltype = accelName;
            }
            UI.printInfo(UI.Module.SCENE, "  * Instance accel:      {0}", acceltype);
            if (rebuildAccel)
            {
                intAccel = AccelerationStructureFactory.create(acceltype, instanceList.getNumPrimitives(), false);
                intAccel.build(instanceList);
                rebuildAccel = false;
            }
            UI.printInfo(UI.Module.SCENE, "  * Scene bounds:        {0}", getBounds());
            UI.printInfo(UI.Module.SCENE, "  * Scene center:        {0}", getBounds().getCenter());
            UI.printInfo(UI.Module.SCENE, "  * Scene diameter:      {0}", getBounds().getExtents().Length());
            UI.printInfo(UI.Module.SCENE, "  * Lightmap bake:       {0}", bakingInstance != null ? (bakingViewDependent ? "view" : "ortho") : "off");
            if (sampler == null)
                return;
            if (!lightServer.build(options))
                return;
            // render
            UI.printInfo(UI.Module.SCENE, "Rendering ...");
            sampler.prepare(options, this, imageWidth, imageHeight);
            sampler.render(display);
            lightServer.showStats();
            // discard baking tesselation/accel structure
            bakingPrimitives = null;
            bakingAccel = null;
            UI.printInfo(UI.Module.SCENE, "Done.");
        }
Exemplo n.º 15
0
        /**
         * Render the scene using the specified options, image sampler and display.
         *
         * @param options rendering options object
         * @param sampler image sampler
         * @param display display to send the image to, a default display will
         *            be created if <code>null</code>
         */
        public void render(Options options, ImageSampler sampler, IDisplay display)
        {
            stats.reset();
            if (display == null)
            {
                display = null;// new FrameDisplay();
            }
            if (bakingInstance != null)
            {
                UI.printDetailed(UI.Module.SCENE, "Creating primitives for lightmapping ...");
                bakingPrimitives = bakingInstance.getBakingPrimitives();
                if (bakingPrimitives == null)
                {
                    UI.printError(UI.Module.SCENE, "Lightmap baking is not supported for the given instance.");
                    return;
                }
                int n = bakingPrimitives.getNumPrimitives();
                UI.printInfo(UI.Module.SCENE, "Building acceleration structure for lightmapping ({0} num primitives) ...", n);
                bakingAccel = AccelerationStructureFactory.create("auto", n, true);
                bakingAccel.build(bakingPrimitives);
            }
            else
            {
                bakingPrimitives = null;
                bakingAccel      = null;
            }
            bakingViewDependent = options.getbool("baking.viewdep", bakingViewDependent);

            if ((bakingInstance != null && bakingViewDependent && camera == null) || (bakingInstance == null && camera == null))
            {
                UI.printError(UI.Module.SCENE, "No camera found");
                return;
            }

            // read from options
            threads     = options.getInt("threads", 0);
            lowPriority = options.getbool("threads.lowPriority", true);
            imageWidth  = options.getInt("resolutionX", 640);
            imageHeight = options.getInt("resolutionY", 480);
            // limit resolution to 16k
            imageWidth  = MathUtils.clamp(imageWidth, 1, 1 << 14);
            imageHeight = MathUtils.clamp(imageHeight, 1, 1 << 14);

            // prepare lights
            createAreaLightInstances();

            // get acceleration structure info
            // count scene primitives
            long numPrimitives = 0;

            for (int i = 0; i < instanceList.getNumPrimitives(); i++)
            {
                numPrimitives += instanceList.getNumPrimitives(i);
            }
            UI.printInfo(UI.Module.SCENE, "Scene stats:");
            UI.printInfo(UI.Module.SCENE, "  * Infinite instances:  {0}", infiniteInstanceList.getNumPrimitives());
            UI.printInfo(UI.Module.SCENE, "  * Instances:           {0}", instanceList.getNumPrimitives());
            UI.printInfo(UI.Module.SCENE, "  * Primitives:          {0}", numPrimitives);
            string accelName = options.getstring("accel", null);

            if (accelName != null)
            {
                rebuildAccel = rebuildAccel || acceltype != accelName;
                acceltype    = accelName;
            }
            UI.printInfo(UI.Module.SCENE, "  * Instance accel:      {0}", acceltype);
            if (rebuildAccel)
            {
                intAccel = AccelerationStructureFactory.create(acceltype, instanceList.getNumPrimitives(), false);
                intAccel.build(instanceList);
                rebuildAccel = false;
            }
            UI.printInfo(UI.Module.SCENE, "  * Scene bounds:        {0}", getBounds());
            UI.printInfo(UI.Module.SCENE, "  * Scene center:        {0}", getBounds().getCenter());
            UI.printInfo(UI.Module.SCENE, "  * Scene diameter:      {0}", getBounds().getExtents().Length());
            UI.printInfo(UI.Module.SCENE, "  * Lightmap bake:       {0}", bakingInstance != null ? (bakingViewDependent ? "view" : "ortho") : "off");
            if (sampler == null)
            {
                return;
            }
            if (!lightServer.build(options))
            {
                return;
            }
            // render
            UI.printInfo(UI.Module.SCENE, "Rendering ...");
            stats.setResolution(imageWidth, imageHeight);
            sampler.prepare(options, this, imageWidth, imageHeight);
            sampler.render(display);
            // show statistics
            stats.displayStats();
            lightServer.showStats();
            // discard area lights
            removeAreaLightInstances();

            // discard baking tesselation/accel structure
            bakingPrimitives = null;
            bakingAccel      = null;
            UI.printInfo(UI.Module.SCENE, "Done.");
        }