Beispiel #1
0
 private void parseLightserverBlock(SunflowAPI api)
 {
     p.checkNextToken("{");
     if (p.peekNextToken("shadows"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: shadows setting ignored");
         p.getNextbool();
     }
     if (p.peekNextToken("direct-samples"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: use samples keyword in area light definitions");
         numLightSamples = p.getNextInt();
     }
     if (p.peekNextToken("glossy-samples"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: use samples keyword in glossy shader definitions");
         p.getNextInt();
     }
     if (p.peekNextToken("max-depth"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: max-depth setting - use trace-depths block instead");
         int d = p.getNextInt();
         api.parameter("depths.diffuse", 1);
         api.parameter("depths.reflection", d - 1);
         api.parameter("depths.refraction", 0);
         api.options(SunflowAPI.DEFAULT_OPTIONS);
     }
     if (p.peekNextToken("global"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: global settings ignored - use photons block instead");
         p.getNextbool();
         p.getNextInt();
         p.getNextInt();
         p.getNextInt();
         p.getNextFloat();
     }
     if (p.peekNextToken("caustics"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: caustics settings ignored - use photons block instead");
         p.getNextbool();
         p.getNextInt();
         p.getNextFloat();
         p.getNextInt();
         p.getNextFloat();
     }
     if (p.peekNextToken("irr-cache"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: irradiance cache settings ignored - use gi block instead");
         p.getNextInt();
         p.getNextFloat();
         p.getNextFloat();
         p.getNextFloat();
     }
     p.checkNextToken("}");
 }
Beispiel #2
0
    public void SetupSunflow(SunflowAPI a)
    {
        a.parameter("threads", Environment.ProcessorCount);
        //          parameter ("threads", 1);
        a.options(SunflowAPI.DEFAULT_OPTIONS);
        //The render's resolution. 1920 by 1080 is full HD.
        int resolutionX = 3840;
        int resolutionY = 1920;

        //      resolutionX = 1920;
        //    resolutionY = 1920;

        resolutionX = 384 * 4;
        resolutionY = 192 * 4;
//		      int resolutionX = 3840;
//		      int resolutionY = 960;
        a.parameter("resolutionX", resolutionX);
        a.parameter("resolutionY", resolutionY);

        //The anti-aliasing. Negative is subsampling and positive is supersampling.
        a.parameter("aa.min", 1);
        a.parameter("aa.max", 2);

        //Number of samples.
        a.parameter("aa.samples", 1);

        //The contrast needed to increase anti-aliasing.
        a.parameter("aa.contrast", .016f);

        //Subpixel jitter.
        a.parameter("aa.jitter", true);

        //The filter.
        a.parameter("filter", "mitchell");
        a.options(SunflowAPI.DEFAULT_OPTIONS);



//				Point3 eye = new Point3(7.0f, -7.0f, -7.0f);
//				Point3 target = new Point3(0.0f, -7.0f, 0.0f);


        Point3  target = new Point3(7.0f, -7.0f, -7.0f);
        Point3  eye    = new Point3(-6.0f, -10.0f, 2.0f);
        Vector3 up     = new Vector3(0, 1, 0);

        a.parameter("transform", Matrix4.lookAt(eye, target, up));

        String name = "Camera";


        /*     thinlens camera */

        /*
         *      //Aspect Ratio.
         *      float aspect = ((float)resolutionX) / ((float)resolutionY);
         *      a.parameter("aspect", aspect);
         *      a.camera(name, "thinlens");
         */

        /* 360 3D VR camera */

        /*
         *
         *      a.parameter("lens.eyegap", 0.5f);
         * //		a.camera(name, "spherical3d");
         *
         *      a.camera(name, "spherical1803d");
         *
         *
         */
        a.parameter("lens.eyegap", 0.1f);
        a.camera(name, "vr180fisheye");


        a.parameter("camera", name);
        a.options(SunflowAPI.DEFAULT_OPTIONS);

        //Trace depths. Higher numbers look better.
        a.parameter("depths.diffuse", 3);
        a.parameter("depths.reflection", 2);
        a.parameter("depths.refraction", 2);
        a.options(SunflowAPI.DEFAULT_OPTIONS);

        //Setting up the shader for the ground.
        a.parameter("diffuse", null, 0.4f, 0.4f, 0.4f);
        a.parameter("shiny", .1f);
        a.shader("ground", "shiny_diffuse");
        a.options(SunflowAPI.DEFAULT_OPTIONS);

        //Setting up the shader for the big metal sphere.
        a.parameter("diffuse", null, 0.3f, 0.3f, 0.3f);
        a.parameter("shiny", .95f);
        a.shader("metal", "shiny_diffuse");
        a.options(SunflowAPI.DEFAULT_OPTIONS);


        //Setting up the shader for the cube of spheres.
        a.parameter("diffuse", null, 1.0f, 0.0f, 0.0f);
        a.shader("sps", "diffuse");
        a.options(SunflowAPI.DEFAULT_OPTIONS);

        //Instancing the floor.
        a.parameter("center", new Point3(0, -14.2f, 0));
        a.parameter("normal", new Vector3(0, 1, 0));
        a.geometry("floor", "plane");
        a.parameter("shaders", "ground");
        a.instance("FloorInstance", "floor");
        a.options(SunflowAPI.DEFAULT_OPTIONS);

        //Creating the lighting system with the sun and sky.
        a.parameter("up", new Vector3(0, 1, 0));
        a.parameter("east", new Vector3(1, 0, 0));
        //            double sunRad = (Math.PI * 1.05);
        //          a.parameter("sundir", new Vector3((float)Math.Cos(sunRad), (float)Math.Sin(sunRad), (float)(.5 * Math.Sin(sunRad))).normalize());
        a.parameter("sundir", new Vector3(0.8f, 0.8f, 0.5f).normalize());
        a.parameter("turbidity", 4f);
        a.parameter("samples", 128);
        a.light("sunsky", "sunsky");
        a.options(SunflowAPI.DEFAULT_OPTIONS);
    }
Beispiel #3
0
 public override bool parse(Stream stream, SunflowAPI api)
 {
     //string localDir = Path.GetFullPath(filename);
     numLightSamples = 1;
     Timer timer = new Timer();
     timer.start();
     UI.printInfo(UI.Module.API, "Parsing stream ...");
     try
     {
         p = new Systems.Parser(stream);
         while (true)
         {
             string token = p.getNextToken();
             if (token == null)
                 break;
             if (token == "image")
             {
                 UI.printInfo(UI.Module.API, "Reading image settings ...");
                 parseImageBlock(api);
             }
             else if (token == "background")
             {
                 UI.printInfo(UI.Module.API, "Reading background ...");
                 parseBackgroundBlock(api);
             }
             else if (token == "accel")
             {
                 UI.printInfo(UI.Module.API, "Reading accelerator type ...");
                 p.getNextToken();
                 UI.printWarning(UI.Module.API, "Setting accelerator type is not recommended - ignoring");
             }
             else if (token == "filter")
             {
                 UI.printInfo(UI.Module.API, "Reading image filter type ...");
                 parseFilter(api);
             }
             else if (token == "bucket")
             {
                 UI.printInfo(UI.Module.API, "Reading bucket settings ...");
                 api.parameter("bucket.size", p.getNextInt());
                 api.parameter("bucket.order", p.getNextToken());
                 api.options(SunflowAPI.DEFAULT_OPTIONS);
             }
             else if (token == "photons")
             {
                 UI.printInfo(UI.Module.API, "Reading photon settings ...");
                 parsePhotonBlock(api);
             }
             else if (token == "gi")
             {
                 UI.printInfo(UI.Module.API, "Reading global illumination settings ...");
                 parseGIBlock(api);
             }
             else if (token == "lightserver")
             {
                 UI.printInfo(UI.Module.API, "Reading light server settings ...");
                 parseLightserverBlock(api);
             }
             else if (token == "trace-depths")
             {
                 UI.printInfo(UI.Module.API, "Reading trace depths ...");
                 parseTraceBlock(api);
             }
             else if (token == "camera")
             {
                 parseCamera(api);
             }
             else if (token == "shader")
             {
                 if (!parseShader(api))
                     return false;
             }
             else if (token == "modifier")
             {
                 if (!parseModifier(api))
                     return false;
             }
             else if (token == "override")
             {
                 api.shaderOverride(p.getNextToken(), p.getNextbool());
             }
             else if (token == "object")
             {
                 parseObjectBlock(api);
             }
             else if (token == "instance")
             {
                 parseInstanceBlock(api);
             }
             else if (token == "light")
             {
                 parseLightBlock(api);
             }
             else if (token == "texturepath")
             {
                 string path = p.getNextToken();
                 //if (!new File(path).isAbsolute())
                 //    path = localDir + File.separator + path;
                 api.addTextureSearchPath(Path.GetFullPath(path));
             }
             else if (token == "includepath")
             {
                 string path = p.getNextToken();
                 //if (!new File(path).isAbsolute())
                 //    path = localDir + File.separator + path;
                 api.addIncludeSearchPath(Path.GetFullPath(path));
             }
             else if (token == "include")
             {
                 string file = p.getNextToken();
                 UI.printInfo(UI.Module.API, "Including: \"{0}\" ...", file);
                 api.parse(file);
             }
             else
                 UI.printWarning(UI.Module.API, "Unrecognized token {0}", token);
         }
         p.close();
     }
     catch (Exception e)
     {
         UI.printError(UI.Module.API, "{0}", e);
         return false;
     }
     timer.end();
     UI.printInfo(UI.Module.API, "Done parsing.");
     UI.printInfo(UI.Module.API, "Parsing time: {0}", timer.ToString());
     return true;
 }
Beispiel #4
0
 private void parseImageBlock(SunflowAPI api)
 {
     p.checkNextToken("{");
     if (p.peekNextToken("resolution"))
     {
         api.parameter("resolutionX", p.getNextInt());
         api.parameter("resolutionY", p.getNextInt());
     }
     if (p.peekNextToken("aa"))
     {
         api.parameter("aa.min", p.getNextInt());
         api.parameter("aa.max", p.getNextInt());
     }
     if (p.peekNextToken("samples"))
         api.parameter("aa.samples", p.getNextInt());
     if (p.peekNextToken("contrast"))
         api.parameter("aa.contrast", p.getNextFloat());
     if (p.peekNextToken("filter"))
         api.parameter("filter", p.getNextToken());
     if (p.peekNextToken("jitter"))
         api.parameter("aa.jitter", p.getNextbool());
     if (p.peekNextToken("show-aa"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: show-aa ignored");
         p.getNextbool();
     }
     if (p.peekNextToken("output"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: output statement ignored");
         p.getNextToken();
     }
     api.options(SunflowAPI.DEFAULT_OPTIONS);
     p.checkNextToken("}");
 }
Beispiel #5
0
 private void parseGIBlock(SunflowAPI api)
 {
     p.checkNextToken("{");
     p.checkNextToken("type");
     if (p.peekNextToken("irr-cache"))
     {
         api.parameter("gi.engine", "irr-cache");
         p.checkNextToken("samples");
         api.parameter("gi.irr-cache.samples", p.getNextInt());
         p.checkNextToken("tolerance");
         api.parameter("gi.irr-cache.tolerance", p.getNextFloat());
         p.checkNextToken("spacing");
         api.parameter("gi.irr-cache.min_spacing", p.getNextFloat());
         api.parameter("gi.irr-cache.max_spacing", p.getNextFloat());
         // parse global photon map info
         if (p.peekNextToken("global"))
         {
             api.parameter("gi.irr-cache.gmap.emit", p.getNextInt());
             api.parameter("gi.irr-cache.gmap", p.getNextToken());
             api.parameter("gi.irr-cache.gmap.gather", p.getNextInt());
             api.parameter("gi.irr-cache.gmap.radius", p.getNextFloat());
         }
     }
     else if (p.peekNextToken("path"))
     {
         api.parameter("gi.engine", "path");
         p.checkNextToken("samples");
         api.parameter("gi.path.samples", p.getNextInt());
         if (p.peekNextToken("bounces"))
         {
             UI.printWarning(UI.Module.API, "Deprecated setting: bounces - use diffuse trace depth instead");
             p.getNextInt();
         }
     }
     else if (p.peekNextToken("fake"))
     {
         api.parameter("gi.engine", "fake");
         p.checkNextToken("up");
         api.parameter("gi.fake.up", parseVector());
         p.checkNextToken("sky");
         api.parameter("gi.fake.sky", parseColor());
         p.checkNextToken("ground");
         api.parameter("gi.fake.ground", parseColor());
     }
     else if (p.peekNextToken("igi"))
     {
         api.parameter("gi.engine", "igi");
         p.checkNextToken("samples");
         api.parameter("gi.igi.samples", p.getNextInt());
         p.checkNextToken("sets");
         api.parameter("gi.igi.sets", p.getNextInt());
         if (!p.peekNextToken("b"))
             p.checkNextToken("c");
         api.parameter("gi.igi.c", p.getNextFloat());
         p.checkNextToken("bias-samples");
         api.parameter("gi.igi.bias_samples", p.getNextInt());
     }
     else if (p.peekNextToken("ambocc"))
     {
         api.parameter("gi.engine", "ambocc");
         p.checkNextToken("bright");
         api.parameter("gi.ambocc.bright", parseColor());
         p.checkNextToken("dark");
         api.parameter("gi.ambocc.dark", parseColor());
         p.checkNextToken("samples");
         api.parameter("gi.ambocc.samples", p.getNextInt());
         if (p.peekNextToken("maxdist"))
             api.parameter("gi.ambocc.maxdist", p.getNextFloat());
     }
     else if (p.peekNextToken("none") || p.peekNextToken("null"))
     {
         // disable GI
         api.parameter("gi.engine", "none");
     }
     else
         UI.printWarning(UI.Module.API, "Unrecognized gi engine type \"{0}\" - ignoring", p.getNextToken());
     api.options(SunflowAPI.DEFAULT_OPTIONS);
     p.checkNextToken("}");
 }
Beispiel #6
0
 private void parseFilter(SunflowAPI api)
 {
     UI.printWarning(UI.Module.API, "Deprecated keyword \"filter\" - set this option in the image block");
     string name = p.getNextToken();
     api.parameter("filter", name);
     api.options(SunflowAPI.DEFAULT_OPTIONS);
     bool hasSizeParams = name == "box" || name == "gaussian" || name == "blackman-harris" || name == "sinc" || name == "triangle";
     if (hasSizeParams)
     {
         p.getNextFloat();
         p.getNextFloat();
     }
 }
Beispiel #7
0
 private void parseCamera(SunflowAPI api)
 {
     p.checkNextToken("{");
     p.checkNextToken("type");
     string type = p.getNextToken();
     UI.printInfo(UI.Module.API, "Reading %s camera ...", type);
     parseCameraTransform(api);
     string name = api.getUniqueName("camera");
     if (type == "pinhole")
     {
         p.checkNextToken("fov");
         api.parameter("fov", p.getNextFloat());
         p.checkNextToken("aspect");
         api.parameter("aspect", p.getNextFloat());
         api.camera(name, new PinholeLens());
     }
     else if (type == "thinlens")
     {
         p.checkNextToken("fov");
         api.parameter("fov", p.getNextFloat());
         p.checkNextToken("aspect");
         api.parameter("aspect", p.getNextFloat());
         p.checkNextToken("fdist");
         api.parameter("focus.distance", p.getNextFloat());
         p.checkNextToken("lensr");
         api.parameter("lens.radius", p.getNextFloat());
         if (p.peekNextToken("sides"))
             api.parameter("lens.sides", p.getNextInt());
         if (p.peekNextToken("rotation"))
             api.parameter("lens.rotation", p.getNextFloat());
         api.camera(name, new ThinLens());
     }
     else if (type == "spherical")
     {
         // no extra arguments
         api.camera(name, new SphericalLens());
     }
     else if (type == "fisheye")
     {
         // no extra arguments
         api.camera(name, new FisheyeLens());
     }
     else
     {
         UI.printWarning(UI.Module.API, "Unrecognized camera type: {0}", p.getNextToken());
         p.checkNextToken("}");
         return;
     }
     p.checkNextToken("}");
     if (name != null)
     {
         api.parameter("camera", name);
         api.options(SunflowAPI.DEFAULT_OPTIONS);
     }
 }
Beispiel #8
0
 private void parseTraceBlock(SunflowAPI api)
 {
     p.checkNextToken("{");
     if (p.peekNextToken("diff"))
         api.parameter("depths.diffuse", p.getNextInt());
     if (p.peekNextToken("refl"))
         api.parameter("depths.reflection", p.getNextInt());
     if (p.peekNextToken("refr"))
         api.parameter("depths.refraction", p.getNextInt());
     p.checkNextToken("}");
     api.options(SunflowAPI.DEFAULT_OPTIONS);
 }
Beispiel #9
0
 private void parsePhotonBlock(SunflowAPI api)
 {
     int numEmit = 0;
     bool globalEmit = false;
     p.checkNextToken("{");
     if (p.peekNextToken("emit"))
     {
         UI.printWarning(UI.Module.API, "Shared photon emit values are deprectated - specify number of photons to emit per map");
         numEmit = p.getNextInt();
         globalEmit = true;
     }
     if (p.peekNextToken("global"))
     {
         UI.printWarning(UI.Module.API, "Global photon map setting belonds inside the gi block - ignoring");
         if (!globalEmit)
             p.getNextInt();
         p.getNextToken();
         p.getNextInt();
         p.getNextFloat();
     }
     p.checkNextToken("caustics");
     if (!globalEmit)
         numEmit = p.getNextInt();
     api.parameter("caustics.emit", numEmit);
     api.parameter("caustics", p.getNextToken());
     api.parameter("caustics.gather", p.getNextInt());
     api.parameter("caustics.radius", p.getNextFloat());
     api.options(SunflowAPI.DEFAULT_OPTIONS);
     p.checkNextToken("}");
 }