AVasK

rtc

Nov 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. for (int y = 0; y < H; ++y) {
  2. for (int x = 0; x < W; ++x) {
  3. RTCRay ray;
  4. float j = x - W/2.0 + 0.5;
  5. float i = y - H/2.0 + 0.5;
  6.  
  7. auto direction = camera_dir + j * dx + i * dy;
  8. memcpy(ray.org, &camera_pos, sizeof(camera_pos)); //ray.org = camera_pos;
  9. memcpy(ray.dir, &direction, sizeof(direction)); //ray.dir = camera_dir;
  10. ray.tnear = 0.00001f;
  11. ray.tfar = 100000000.0f;
  12. ray.geomID = RTC_INVALID_GEOMETRY_ID;
  13. rtcIntersect(main_scene, ray);
  14.  
  15. if (ray.geomID != RTC_INVALID_GEOMETRY_ID) {
  16. glm::vec3 norm(ray.Ng[0], ray.Ng[1], ray.Ng[2]);
  17. norm = glm::normalize(norm);
  18. norm = -norm;
  19. auto worldLight = 0.5f;
  20. auto intensity = -glm::dot(norm, light);
  21. intensity = glm::clamp(intensity, 0.0f, 1.0f);
  22. auto white = glm::vec3(255.0f, 255.0f, 255.0f);
  23. auto color = white * (worldLight + intensity) / (worldLight + 1.0f);
  24.  
  25. //out << 255 << " " << 255 << " " << 255 << "\n";
  26. out << (int)color.x << " " << (int)color.y << " " << (int)color.z << "\n";
  27. //std::cout << color.x << " " << color.y << " " << color.z << " ";
  28.  
  29. //out << depthmap.x << ' ' << depthmap.y << ' ' << depthmap.z << '\n';
  30. }
  31. else { out << 0 << " " << 130 << " " << 200 << "\n"; }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment