Пример #1
0
COLOR_T illuminate (SCENE_T scene, RAY_T ray, VP_T int_pt, VP_T normal, int object) {
   COLOR_T color;
   COLOR_T input_color = scene.objs[object].color;

   if(scene.objs[object].checkerboard) {
      if(((int)floor(int_pt.x) + (int)floor(int_pt.y) + (int)floor(int_pt.z)) & 1) {
         input_color = scene.objs[object].color2;
      }
   }

   //ambient
   color.R = 0.1 * scene.objs[object].color.R;
   color.G = 0.1 * scene.objs[object].color.G;
   color.B = 0.1 * scene.objs[object].color.B;

   if(!test_shadow(scene, int_pt, normal, object)) {
      //diffuse
      VP_T L = vec_subtract(scene.light.location, int_pt);
      double dL = vec_len(L);
      L = vec_normalize(L);
      double dot_L = vec_dot(normal, L);
      
      double c1 = 0.002,
             c2 = 0.02,
             c3 = 0.2;
      double light_atten = 1.0 / (c1 * dL * dL +
                                c2 * dL + c3);
      if (dot_L > 0) {
         color.R += dot_L * input_color.R * light_atten;
         color.G += dot_L * input_color.G * light_atten;
         color.B += dot_L * input_color.B * light_atten;

         //specular
         VP_T R;
         R.x = L.x - 2 * dot_L * normal.x;
         R.y = L.y - 2 * dot_L * normal.y;
         R.z = L.z - 2 * dot_L * normal.z;
         R = vec_normalize(R);
         double dot_R = vec_dot(R, ray.direction);

         if (dot_R > 0) {
            color.R += pow(dot_R, 100);
            color.G += pow(dot_R, 100);
            color.B += pow(dot_R, 100);
         }
      }
   }
   return color;
}
Пример #2
0
int
main (int argc, const char *argv[])
{
    getargs (argc, argv);

    texsys = TextureSystem::create ();
    std::cerr << "Created texture system\n";
    texsys->attribute ("statistics:level", 2);
    texsys->attribute ("autotile", autotile);
    texsys->attribute ("automip", (int)automip);
    if (cachesize >= 0)
        texsys->attribute ("max_memory_MB", cachesize);
    if (maxfiles >= 0)
        texsys->attribute ("max_open_files", maxfiles);
    if (searchpath.length())
        texsys->attribute ("searchpath", searchpath);
    if (nountiled)
        texsys->attribute ("accept_untiled", 0);
    if (nounmipped)
        texsys->attribute ("accept_unmipped", 0);
    texsys->attribute ("gray_to_rgb", gray_to_rgb);

    if (test_construction) {
        Timer t;
        for (int i = 0;  i < 1000000000;  ++i) {
            TextureOpt opt;
            dummyptr = &opt;  // This forces the optimizer to keep the loop
        }
        std::cout << "TextureOpt construction: " << t() << " ns\n";
        TextureOpt canonical, copy;
        t.reset();
        t.start();
        for (int i = 0;  i < 1000000000;  ++i) {
            memcpy (&copy, &canonical, sizeof(TextureOpt));
            dummyptr = &copy;  // This forces the optimizer to keep the loop
        }
        std::cout << "TextureOpt memcpy: " << t() << " ns\n";
    }

    if (iters > 0) {
        ustring filename (filenames[0]);
        test_gettextureinfo (filename);
        const char *texturetype = "Plain Texture";
        texsys->get_texture_info (filename, 0, ustring("texturetype"),
                                  TypeDesc::STRING, &texturetype);
        if (! strcmp (texturetype, "Plain Texture")) {
            test_plain_texture ();
        }
        if (! strcmp (texturetype, "Volume Texture")) {
            test_texture3d (filename);
        }
        if (! strcmp (texturetype, "Shadow")) {
            test_shadow (filename);
        }
        if (! strcmp (texturetype, "Environment")) {
            test_environment (filename);
        }
        test_getimagespec_gettexels (filename);
    }
    
    std::cout << "Memory use: "
              << Strutil::memformat (Sysutil::memory_used(true)) << "\n";
    TextureSystem::destroy (texsys);

    std::cout << "\nustrings: " << ustring::getstats(false) << "\n\n";
    return 0;
}