Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- importer(main_scene);
- // Construct of type: unsigned int geomID = rtcNewTriangleMesh(main_scene, numTriangles, numVertices, 1);
- //unsigned int geomID = rtcNewTriangleMesh(new_scene, size_t(num_of_faces), size_t(num_of_vertices), 1);
- // Commit changes
- rtcCommit(main_scene);
- // Raytrace
- float x, y, z;
- x = 3;
- y = 3;
- z = 3;
- glm::vec3 camera_pos(x, y, z);
- glm::vec3 dx(-y, x, 0);
- glm::vec3 dy = glm::cross(dx, camera_pos);
- glm::vec3 camera_dir = -camera_pos;
- //---------------
- glm::vec3 light(1, 3, 2);
- //----------------
- dx = glm::normalize(dx);
- dy = glm::normalize(dy);
- float fov = 0.001;
- auto len = glm::length(camera_dir);
- dx *= len * fov;
- dy *= len * fov;
- // OUTPUT:
- const int H = 1000;
- const int W = 1000;
- std::ofstream out("out.ppm");
- out << "P3\n" << W << ' ' << H << ' ' << "255\n";
- for (int y = 0; y < H; ++y) {
- for (int x = 0; x < W; ++x) {
- RTCRay ray;
- float i = x - W/2.0 + 0.5;
- float j = y - H/2.0 + 0.5;
- auto direction = camera_dir + j * dx + i * dy;
- memcpy(ray.org, &camera_pos, sizeof(camera_pos)); //ray.org = camera_pos;
- memcpy(ray.dir, &direction, sizeof(direction)); //ray.dir = camera_dir;
- ray.tnear = 0.00001f;
- ray.tfar = 100000000.0f;
- ray.geomID = RTC_INVALID_GEOMETRY_ID;
- rtcIntersect(main_scene, ray);
- //-----
- glm::vec3 norm(ray.Ng[0], ray.Ng[1], ray.Ng[2]);
- if (norm.x*norm.x + norm.y*norm.y + norm.z*norm.z != 0) {
- norm = glm::normalize(norm);
- norm = -norm;
- }
- auto worldLight = 0.25f;
- auto intensity = -glm::dot(norm, light);
- intensity = glm::clamp(intensity, 0.0f, 1.0f);
- auto white = glm::vec3(255.0f, 255.0f, 255.0f);
- auto color = white * (worldLight + intensity) / (worldLight + 1.0f);
- color = glm::clamp(color, 0, 255);
- auto depthmap = white * ray.tfar;
- if (ray.geomID == RTC_INVALID_GEOMETRY_ID) {
- depthmap.x = 0;
- depthmap.y = 0;
- depthmap.z = 0;
- }
- if (ray.geomID != RTC_INVALID_GEOMETRY_ID) {
- //out << 255 << " " << 255 << " " << 255 << "\n";
- out << color.x << " " << color.y << " " << color.z << "\n";
- std::cout << color.x << " " << color.y << " " << color.z << " ";
- //out << depthmap.x << ' ' << depthmap.y << ' ' << depthmap.z << '\n';
- }
- else { out << 0 << " " << 0 << " " << 0 << "\n"; }
- }
- std::cout << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment