#include #include #include #include #include #include #include "scene.hpp" #include "camera.hpp" #include #include #include #include using std::printf; void errorFunction(void* userPtr, enum RTCError error, const char* str){ printf("error %d: %s\n", error, str); } RTCDevice initializeDevice(){ RTCDevice device = rtcNewDevice("threads=24,user_threads=24"); if (!device) printf("error %d: cannot create device\n", rtcGetDeviceError(NULL)); rtcSetDeviceErrorFunction(device, errorFunction, NULL); return device; } int main(){ using std::cos; using std::sin; using namespace Eigen; RTCDevice dev = initializeDevice(); scene scene(dev); objl::Loader ajax; objl::Loader quad; ajax.LoadFile("ajax.obj"); quad.LoadFile("quad.obj"); objl::Mesh ajax_mesh = ajax.LoadedMeshes[0]; objl::Mesh quad_mesh = quad.LoadedMeshes[0]; Matrix4f trf; std::uniform_real_distribution angles(0, 2 * M_PI); std::uniform_real_distribution o1(0, 1); xoshiro_256 gangles(42); for(float ax = -10;ax < 10;ax += 5){ for(float ay = -10;ay < 10;ay += 5){ float angle = angles(gangles); trf << cos(angle),0,-sin(angle),ax, 0,1.6,0,0, sin(angle),0,cos(angle),ay, 0,0,0,1; scene.add_object(ajax_mesh, trf, false); scene.added_objects.back()->mat.tex = std::make_unique(Color(o1(gangles), o1(gangles), o1(gangles))); scene.added_objects.back()->mat.m_bsdf = std::make_unique(0.8); } } trf << 40,0,0,0, 0,1,0,-1.6, 0,0,40,0, 0,0,0,1; scene.add_object(quad_mesh, trf, false); //scene.add_sphere(Vector3f(-1.5,0,0),0.5, true); scene.pointlight.push_back(pointlight{Eigen::Vector3f(2,0,0), Eigen::Vector3f(1,1,0)}); scene.pointlight.push_back(pointlight{Eigen::Vector3f(2,0,2), Eigen::Vector3f(0,1,1)}); scene.build(); camera cam(Vector3f(0, 0.6 * 5, 2.4 * 5),Vector3f(0,0,0), Vector3f(0,1,0)); sampler simp; size_t n = 1000; auto t1 = nanoTime(); auto x = cam.get_image(scene, n, simp); auto t2 = nanoTime(); std::cout << (t2 - t1) / 1000 / 1000.0 << " miliseconds\n"; std::vector lodepng_image(x.size() * 4); for(size_t i = 0;i < x.size();i++){ lodepng_image[i * 4] = (unsigned char)(std::min(x[x.size() - i - 1].x() * 256,255.f)); lodepng_image[i * 4 + 1] = (unsigned char)(std::min(x[x.size() - i - 1].y() * 256,255.f)); lodepng_image[i * 4 + 2] = (unsigned char)(std::min(x[x.size() - i - 1].z() * 256,255.f)); lodepng_image[i * 4 + 3] = 255; } lodepng::encode("bild.png", lodepng_image, n, n); //drawbmp("bild.bmp", x, n, n); //std::cout << (rayhit.ray.tfar) << "\n"; //std::cout << (rayhit.hit.Ng_x) << "\n"; return 0; }