int main (void) { Settings settings; settings.whole_area = Rectangle(Point2i(0, 0), Vector2i(800, 600)); settings.area = Rectangle(Point2i(0, 0), Vector2i(800, 600)); settings.max_thread_count = std::thread::hardware_concurrency(); settings.tile_size = Vector2i(100, 100); settings.max_sample_count = 1; settings.adaptive_sample_step = 10; CosineDebuggerEngine engine; ParallelRenderer renderer; RandomSuperSampling super_sampling(true); PerspectiveCamera camera( Point3(0.0, 0.75, -4.5), Vector3(0.0, 0.0, 1.0), Vector3(0.0, 1.0, 0.0), Rectangle(Point2i(0, 0), Vector2i(80, 60)).get_aspect_ratio(), M_PI/2.0f); ObjModel cow_model; BVH cow_bvh(new RoundRobinAxisSelector(), new CentreSplitStrategy(), 520, 8); Instance cow(&cow_bvh); cow_model.load("mdl/cow.obj"); cow_model.add_to_group(cow_bvh); cow_bvh.finish(); cow.rotate(Vector3(0.0f, 0.0f, 1.0f), M_PI/4.0f); cow.rotate(Vector3(0.0f, 1.0f, 0.0f), M_PI/2.0f); cow.rotate(Vector3(0.0f, 0.0f, 1.0f), M_PI/2.0f); cow.rotate(Vector3(0.0f, 1.0f, 0.0f), M_PI/3.5f); cow.translate(Vector3(-3.5f, -2.0f, 0.0f)); InfinitePlane plane(Point3(0.0f, -3.0f, 0.0f), Vector3(0.0f, 1.0f, 0.0f)); SimpleGroup scene; scene.add(&cow); scene.add(&plane); World world; world.scene = &scene; world.camera = &camera; Image image = renderer.render(world, settings, engine, super_sampling); image.write_png(std::string("cow.png")); return 0; }
void trynomapper(const char* filename) { static const float scale = 0.001f; Image img(400, 400); World world; SimpleGroup scene; world.scene = &scene; PerspectiveCamera cam(Point(278*scale, 273*scale, -800*scale), Vector(0, 0, 1), Vector(0, 1, 0), 0.686f, 0.686f); ImageTexture* whitetex = new ImageTexture("models/stones_diffuse.png"); ConstantTexture* redtex = new ConstantTexture(RGBColor(.7f,0.f,0.f)); ConstantTexture* greentex = new ConstantTexture(RGBColor(0.f,.7f,0.f)); ConstantTexture* blacktex = new ConstantTexture(RGBColor::rep(0.0f)); ConstantTexture* lightsrctex = new ConstantTexture(RGBColor::rep(1.0f)); LambertianMaterial white(blacktex, whitetex); LambertianMaterial green(blacktex, greentex); LambertianMaterial red(blacktex, redtex); //point light world.light.push_back(new PointLight(Point((278)*scale,429.99f*scale,(279.5f)*scale),RGBColor::rep(100000.0f*scale*scale))); world.light.push_back(new PointLight(Point(478*scale,229.99f*scale,(-59.5f)*scale),RGBColor::rep(150000.0f*scale*scale))); world.light.push_back(new PointLight(Point(490*scale,159.99f*scale,279.5f*scale),RGBColor(40000.0f*scale*scale,0,0))); world.light.push_back(new PointLight(Point(40*scale,159.99f*scale,249.5f*scale),RGBColor(5000.0f*scale*scale,30000.0f*scale*scale,5000.0f*scale*scale))); //floor scene.add(new Triangle(Point(000.f,000.f,000.f)*scale, Point(550.f,000.f,000.f)*scale, Point(000.f,000.f,560.f)*scale, nullptr, &white)); scene.add(new Triangle(Point(550.f,000.f,560.f)*scale, Point(550.f,000.f,000.f)*scale, Point(000.f,000.f,560.f)*scale, nullptr, &white)); //ceiling scene.add(new Triangle(Point(000.f,550.f,000.f)*scale, Point(550.f,550.f,000.f)*scale, Point(000.f,550.f,560.f)*scale, nullptr, &white)); scene.add(new Triangle(Point(550.f,550.f,560.f)*scale, Point(550.f,550.f,000.f)*scale, Point(000.f,550.f,560.f)*scale, nullptr, &white)); //back wall scene.add(new Triangle(Point(000.f,000.f,560.f)*scale, Point(550.f,000.f,560.f)*scale, Point(000.f,550.f,560.f)*scale, nullptr, &white)); scene.add(new Triangle(Point(550.f,550.f,560.f)*scale, Point(550.f,000.f,560.f)*scale, Point(000.f,550.f,560.f)*scale, nullptr, &white)); //right wall scene.add(new Triangle(Point(000.f,000.f,000.f)*scale, Point(000.f,000.f,560.f)*scale, Point(000.f,550.f,000.f)*scale, nullptr, &green)); scene.add(new Triangle(Point(000.f,550.f,560.f)*scale, Point(000.f,000.f,560.f)*scale, Point(000.f,550.f,000.f)*scale, nullptr, &green)); //left wall scene.add(new Triangle(Point(550.f,000.f,000.f)*scale, Point(550.f,000.f,560.f)*scale, Point(550.f,550.f,000.f)*scale, nullptr, &red)); scene.add(new Triangle(Point(550.f,550.f,560.f)*scale, Point(550.f,000.f,560.f)*scale, Point(550.f,550.f,000.f)*scale, nullptr, &red)); //sphere scene.add(new Sphere(Point(200.f,100.f,300.f)*scale, 150.f*scale, nullptr, &white)); RayTracingIntegrator integrator(&world); Renderer engine(&cam, &integrator); engine.render(img); img.writePNG(filename); }
void trymapper(const char* filename, CoordMapper* spheremapper1, CoordMapper* spheremapper2) { static const float scale = 0.001f; Image img(400, 400); World world; SimpleGroup scene; world.scene = &scene; PerspectiveCamera cam(Point(278*scale, 273*scale, -800*scale), Vector(0, 0, 1), Vector(0, 1, 0), 0.686f, 0.686f); CheckerboardTexture* redtex = new CheckerboardTexture(RGBColor(.7f,0.1f,0.1f), RGBColor(0.3f,0.1f,0.1f)); PerlinTexture* greentex = new PerlinTexture(RGBColor(0.f,.7f,0.f), RGBColor(0.0f,0.2f,0.4f)); greentex->addOctave(1.0f, 3.0f); greentex->addOctave(0.5f, 6.0f); greentex->addOctave(0.25f, 12.0f); ConstantTexture* blacktex = new ConstantTexture(RGBColor::rep(0.0f)); ConstantTexture* lightsrctex = new ConstantTexture(RGBColor::rep(1.0f)); ImageTexture* whitetex = new ImageTexture("models/stones_diffuse.png"); ImageTexture* clamptex = new ImageTexture("models/stones_diffuse.png", ImageTexture::CLAMP); ImageTexture* mirrtex = new ImageTexture("models/stones_diffuse.png", ImageTexture::MIRROR); LambertianMaterial white(blacktex, whitetex); LambertianMaterial clamp(blacktex, clamptex); LambertianMaterial mirror(blacktex, mirrtex); LambertianMaterial green(blacktex, greentex); LambertianMaterial red(blacktex, redtex); //point light world.light.push_back(new PointLight(Point((178)*scale,429.99f*scale,(279.5f)*scale),RGBColor::rep(100000.0f*scale*scale))); world.light.push_back(new PointLight(Point(478*scale,229.99f*scale,(-59.5f)*scale),RGBColor::rep(150000.0f*scale*scale))); world.light.push_back(new PointLight(Point(490*scale,159.99f*scale,279.5f*scale),RGBColor(40000.0f*scale*scale,0,0))); world.light.push_back(new PointLight(Point(40*scale,159.99f*scale,249.5f*scale),RGBColor(5000.0f*scale*scale,30000.0f*scale*scale,5000.0f*scale*scale))); TriangleMapper* bottomleft = new TriangleMapper(Point(0,0,0), Point(3,0,0), Point(0,3,0)); TriangleMapper* topright = new TriangleMapper(Point(3,3,0), Point(3,0,0), Point(0,3,0)); //floor scene.add(new Triangle(Point(000.f,000.f,000.f)*scale, Point(550.f,000.f,000.f)*scale, Point(000.f,000.f,560.f)*scale, bottomleft, &clamp)); scene.add(new Triangle(Point(550.f,000.f,560.f)*scale, Point(550.f,000.f,000.f)*scale, Point(000.f,000.f,560.f)*scale, topright, &clamp)); //ceiling scene.add(new Triangle(Point(000.f,550.f,000.f)*scale, Point(550.f,550.f,000.f)*scale, Point(000.f,550.f,560.f)*scale, bottomleft, &mirror)); scene.add(new Triangle(Point(550.f,550.f,560.f)*scale, Point(550.f,550.f,000.f)*scale, Point(000.f,550.f,560.f)*scale, topright, &mirror)); //back wall scene.add(new Triangle(Point(000.f,000.f,560.f)*scale, Point(550.f,000.f,560.f)*scale, Point(000.f,550.f,560.f)*scale, bottomleft, &white)); scene.add(new Triangle(Point(550.f,550.f,560.f)*scale, Point(550.f,000.f,560.f)*scale, Point(000.f,550.f,560.f)*scale, topright, &white)); //right wall scene.add(new Triangle(Point(000.f,000.f,000.f)*scale, Point(000.f,000.f,560.f)*scale, Point(000.f,550.f,000.f)*scale, bottomleft, &green)); scene.add(new Triangle(Point(000.f,550.f,560.f)*scale, Point(000.f,000.f,560.f)*scale, Point(000.f,550.f,000.f)*scale, topright, &green)); //left wall scene.add(new Triangle(Point(550.f,000.f,000.f)*scale, Point(550.f,000.f,560.f)*scale, Point(550.f,550.f,000.f)*scale, bottomleft, &red)); scene.add(new Triangle(Point(550.f,550.f,560.f)*scale, Point(550.f,000.f,560.f)*scale, Point(550.f,550.f,000.f)*scale, topright, &red)); //sphere scene.add(new Sphere(Point(400.f,450.f,300.f)*scale, 150.f*scale, spheremapper1, &white)); scene.add(new Sphere(Point(200.f,100.f,300.f)*scale, 150.f*scale, spheremapper2, &white)); RayTracingIntegrator integrator(&world); Renderer engine(&cam, &integrator); engine.render(img); img.writePNG(filename); }