Esempio n. 1
0
 private void parseBackgroundBlock(SunflowAPI api)
 {
     p.checkNextToken("{");
     p.checkNextToken("color");
     api.parameter("color", null, parseColor().getRGB());
     api.shader("background.shader", "constant");
     api.geometry("background", "background");
     api.parameter("shaders", "background.shader");
     api.instance("background.instance", "background");
     p.checkNextToken("}");
 }
Esempio n. 2
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",  null, parseColor().getRGB());
             api.shader(name, "diffuse");
         }
         else if (p.peekNextToken("texture"))
         {
             api.parameter("texture", p.getNextToken());
             api.shader(name, "textured_diffuse");
         }
         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", null, parseColor().getRGB());
         }
         p.checkNextToken("spec");
     api.parameter("specular", null, parseColor().getRGB());
         api.parameter("power", p.getNextFloat());
         if (p.peekNextToken("samples"))
             api.parameter("samples", p.getNextInt());
         if (tex != null)
             api.shader(name, "textured_phong");
         else
             api.shader(name, "phong");
     }
     else if (p.peekNextToken("amb-occ") || p.peekNextToken("amb-occ2"))
     {
         string tex = null;
         if (p.peekNextToken("diff") || p.peekNextToken("bright"))
       api.parameter("bright", null, parseColor().getRGB());
         else if (p.peekNextToken("texture"))
             api.parameter("texture", tex = p.getNextToken());
         if (p.peekNextToken("dark"))
         {
       api.parameter("dark", null, parseColor().getRGB());
             p.checkNextToken("samples");
             api.parameter("samples", p.getNextInt());
             p.checkNextToken("dist");
             api.parameter("maxdist", p.getNextFloat());
         }
         if (tex == null)
             api.shader(name, "ambient_occlusion");
         else
       api.shader(name, "textured_ambient_occlusion");
     }
     else if (p.peekNextToken("mirror"))
     {
         p.checkNextToken("refl");
     api.parameter("color", null, parseColor().getRGB());
         api.shader(name, "mirror");
     }
     else if (p.peekNextToken("glass"))
     {
         p.checkNextToken("eta");
         api.parameter("eta", p.getNextFloat());
         p.checkNextToken("color");
     api.parameter("color", null, parseColor().getRGB());
     if (p.peekNextToken("absorption.distance") || p.peekNextToken("absorbtion.distance"))
       api.parameter("absorption.distance", p.getNextFloat());
     if (p.peekNextToken("absorption.color") || p.peekNextToken("absorbtion.color"))
       api.parameter("absorption.color", null, parseColor().getRGB());
         api.shader(name, "glass");
     }
     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", null,  parseColor().getRGB());
         }
         p.checkNextToken("refl");
         api.parameter("shiny", p.getNextFloat());
         if (tex == null)
             api.shader(name, "shiny_diffuse");
         else
       api.shader(name, "textured_shiny_diffuse");
     }
     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", null,  parseColor().getRGB());
         }
         p.checkNextToken("spec");
         api.parameter("specular", null,  parseColor().getRGB());
         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, "textured_ward");
         else
             api.shader(name, "ward");
     }
     else if (p.peekNextToken("view-caustics"))
     {
         api.shader(name, "view_caustics");
     }
     else if (p.peekNextToken("view-irradiance"))
     {
     api.shader(name, "view_irradiance");
     }
     else if (p.peekNextToken("view-global"))
     {
     api.shader(name, "view_global");
     }
     else if (p.peekNextToken("constant"))
     {
         // backwards compatibility -- peek only
         p.peekNextToken("color");
         api.parameter("color", null,  parseColor().getRGB());
         api.shader(name, "constant");
     }
     else if (p.peekNextToken("csharp"))
     {
     String typename = p.peekNextToken("typename") ? p.getNextToken() : PluginRegistry.shaderPlugins.generateUniqueName("janino_shader");
     if (!PluginRegistry.shaderPlugins.registerPlugin(typename, p.getNextCodeBlock()))
       return false;
     api.shader(name, typename);
     }
     else if (p.peekNextToken("id"))
     {
         api.shader(name, "show_instance_id");
     }
     else if (p.peekNextToken("uber"))
     {
         if (p.peekNextToken("diff"))
             api.parameter("diffuse", null,  parseColor().getRGB());
         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", null,  parseColor().getRGB());
         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, "uber");
     }
     else
         UI.printWarning(UI.Module.API, "Unrecognized shader type: {0}", p.getNextToken());
     p.checkNextToken("}");
     return true;
 }