Example #1
0
 public void init(string name, SunflowAPI api)
 {
     api.light(name, this);
     api.geometry(name + ".geo", new Sphere());
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.parameter("transform", Matrix4.translation(center.x, center.y, center.z).multiply(Matrix4.scale(radius)));
     api.instance(name + ".instance", name + ".geo");
 }
Example #2
0
 public void init(string name, SunflowAPI api)
 {
     // register this object with the api properly
     api.geometry(name, this);
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.instance(name + ".instance", name);
     api.light(name + ".light", this);
 }
Example #3
0
 public void init(string name, SunflowAPI api)
 {
     api.geometry(name, this);
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.instance(name + ".instance", name);
     for (int i = 0, j = 0; i < triangles.Length; i += 3, j++)
     {
         TriangleLight t = new TriangleLight(j, this);
         string lname = string.Format("%s.light[%d]", name, j);
         api.light(lname, t);
     }
 }
Example #4
0
 public void init(string name, SunflowAPI api)
 {
     api.geometry(name, this);
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.instance(name + ".instance", name);
     for (int i = 0, j = 0; i < triangles.Length; i += 3, j++)
     {
         TriangleLight t     = new TriangleLight(j, this);
         string        lname = string.Format("%s.light[%d]", name, j);
         api.light(lname, t);
     }
 }
Example #5
0
 public void init(string name, SunflowAPI api)
 {
     // register this object with the api properly
     api.geometry(name, this);
     if (api.lookupGeometry(name) == null)
     {
         // quit if we don't see our geometry in here (error message
         // will have already been printed)
         return;
     }
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.instance(name + ".instance", name);
     api.light(name + ".light", this);
 }
Example #6
0
 public void init(string name, SunflowAPI api)
 {
     // register this object with the api properly
     api.geometry(name, this);
     if (api.lookupGeometry(name) == null)
     {
         // quit if we don't see our geometry in here (error message
         // will have already been printed)
         return;
     }
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.instance(name + ".instance", name);
     api.light(name + ".light", this);
 }
Example #7
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);
    }
Example #8
0
 public void init(string name, SunflowAPI api)
 {
     // register this object with the api properly
     api.geometry(name, this);
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.instance(name + ".instance", name);
     api.light(name + ".light", this);
 }
Example #9
0
 public void init(string name, SunflowAPI api)
 {
     api.light(name, this);
     api.geometry(name + ".geo", new Sphere());
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.parameter("transform", Matrix4.translation(center.x, center.y, center.z).multiply(Matrix4.scale(radius)));
     api.instance(name + ".instance", name + ".geo");
 }
Example #10
0
 private void parseBackgroundBlock(SunflowAPI api)
 {
     p.checkNextToken("{");
     p.checkNextToken("color");
     api.parameter("color", parseColor());
     api.shader("background.shader", new ConstantShader());
     api.geometry("background", new Background());
     api.parameter("shaders", "background.shader");
     api.instance("background.instance", "background");
     p.checkNextToken("}");
 }
Example #11
0
 private bool parseShader(SunflowAPI api)
 {
     p.checkNextToken("{");
     p.checkNextToken("name");
     string name = p.getNextToken();
     UI.printInfo(UI.Module.API, "Reading shader: {0} ...", name);
     p.checkNextToken("type");
     if (p.peekNextToken("diffuse"))
     {
         if (p.peekNextToken("diff"))
         {
             api.parameter("diffuse", parseColor());
             api.shader(name, new DiffuseShader());
         }
         else if (p.peekNextToken("texture"))
         {
             api.parameter("texture", p.getNextToken());
             api.shader(name, new TexturedDiffuseShader());
         }
         else
             UI.printWarning(UI.Module.API, "Unrecognized option in diffuse shader block: {0}", p.getNextToken());
     }
     else if (p.peekNextToken("phong"))
     {
         string tex = null;
         if (p.peekNextToken("texture"))
             api.parameter("texture", tex = p.getNextToken());
         else
         {
             p.checkNextToken("diff");
             api.parameter("diffuse", parseColor());
         }
         p.checkNextToken("spec");
         api.parameter("specular", parseColor());
         api.parameter("power", p.getNextFloat());
         if (p.peekNextToken("samples"))
             api.parameter("samples", p.getNextInt());
         if (tex != null)
             api.shader(name, new TexturedPhongShader());
         else
             api.shader(name, new PhongShader());
     }
     else if (p.peekNextToken("amb-occ") || p.peekNextToken("amb-occ2"))
     {
         string tex = null;
         if (p.peekNextToken("diff") || p.peekNextToken("bright"))
             api.parameter("bright", parseColor());
         else if (p.peekNextToken("texture"))
             api.parameter("texture", tex = p.getNextToken());
         if (p.peekNextToken("dark"))
         {
             api.parameter("dark", parseColor());
             p.checkNextToken("samples");
             api.parameter("samples", p.getNextInt());
             p.checkNextToken("dist");
             api.parameter("maxdist", p.getNextFloat());
         }
         if (tex == null)
             api.shader(name, new AmbientOcclusionShader());
         else
             api.shader(name, new TexturedAmbientOcclusionShader());
     }
     else if (p.peekNextToken("mirror"))
     {
         p.checkNextToken("refl");
         api.parameter("color", parseColor());
         api.shader(name, new MirrorShader());
     }
     else if (p.peekNextToken("glass"))
     {
         p.checkNextToken("eta");
         api.parameter("eta", p.getNextFloat());
         p.checkNextToken("color");
         api.parameter("color", parseColor());
         if (p.peekNextToken("absorbtion.distance"))
             api.parameter("absorbtion.distance", p.getNextFloat());
         if (p.peekNextToken("absorbtion.color"))
             api.parameter("absorbtion.color", parseColor());
         api.shader(name, new GlassShader());
     }
     else if (p.peekNextToken("shiny"))
     {
         string tex = null;
         if (p.peekNextToken("texture"))
             api.parameter("texture", tex = p.getNextToken());
         else
         {
             p.checkNextToken("diff");
             api.parameter("diffuse", parseColor());
         }
         p.checkNextToken("refl");
         api.parameter("shiny", p.getNextFloat());
         if (tex == null)
             api.shader(name, new ShinyDiffuseShader());
         else
             api.shader(name, new TexturedShinyDiffuseShader());
     }
     else if (p.peekNextToken("ward"))
     {
         string tex = null;
         if (p.peekNextToken("texture"))
             api.parameter("texture", tex = p.getNextToken());
         else
         {
             p.checkNextToken("diff");
             api.parameter("diffuse", parseColor());
         }
         p.checkNextToken("spec");
         api.parameter("specular", parseColor());
         p.checkNextToken("rough");
         api.parameter("roughnessX", p.getNextFloat());
         api.parameter("roughnessY", p.getNextFloat());
         if (p.peekNextToken("samples"))
             api.parameter("samples", p.getNextInt());
         if (tex != null)
             api.shader(name, new TexturedWardShader());
         else
             api.shader(name, new AnisotropicWardShader());
     }
     else if (p.peekNextToken("view-caustics"))
     {
         api.shader(name, new ViewCausticsShader());
     }
     else if (p.peekNextToken("view-irradiance"))
     {
         api.shader(name, new ViewIrradianceShader());
     }
     else if (p.peekNextToken("view-global"))
     {
         api.shader(name, new ViewGlobalPhotonsShader());
     }
     else if (p.peekNextToken("constant"))
     {
         // backwards compatibility -- peek only
         p.peekNextToken("color");
         api.parameter("color", parseColor());
         api.shader(name, new ConstantShader());
     }
     else if (p.peekNextToken("janino"))
     {
         string code = p.getNextCodeBlock();
         try
         {
             IShader shader = null;//fixme:(Shader) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, new stringReader(code)), Shader.class, ClassLoader.getSystemClassLoader());
             api.shader(name, shader);
         }
         catch (Exception e)
         {
             UI.printDetailed(UI.Module.API, "Compiling: {0}", code);
             UI.printError(UI.Module.API, "{0}", e);
             return false;
         }
     }
     else if (p.peekNextToken("id"))
     {
         api.shader(name, new IDShader());
     }
     else if (p.peekNextToken("uber"))
     {
         if (p.peekNextToken("diff"))
             api.parameter("diffuse", parseColor());
         if (p.peekNextToken("diff.texture"))
             api.parameter("diffuse.texture", p.getNextToken());
         if (p.peekNextToken("diff.blend"))
             api.parameter("diffuse.blend", p.getNextFloat());
         if (p.peekNextToken("refl") || p.peekNextToken("spec"))
             api.parameter("specular", parseColor());
         if (p.peekNextToken("texture"))
         {
             // deprecated
             UI.printWarning(UI.Module.API, "Deprecated uber shader parameter \"texture\" - please use \"diffuse.texture\" and \"diffuse.blend\" instead");
             api.parameter("diffuse.texture", p.getNextToken());
             api.parameter("diffuse.blend", p.getNextFloat());
         }
         if (p.peekNextToken("spec.texture"))
             api.parameter("specular.texture", p.getNextToken());
         if (p.peekNextToken("spec.blend"))
             api.parameter("specular.blend", p.getNextFloat());
         if (p.peekNextToken("glossy"))
             api.parameter("glossyness", p.getNextFloat());
         if (p.peekNextToken("samples"))
             api.parameter("samples", p.getNextInt());
         api.shader(name, new UberShader());
     }
     else
         UI.printWarning(UI.Module.API, "Unrecognized shader type: {0}", p.getNextToken());
     p.checkNextToken("}");
     return true;
 }