Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1.  
  2. // generate 8 points around this point, from a certain factor
  3. std::vector<Vec3Df> getPointsCircle(Vec3Df const point,
  4. int const dimensions,
  5. float const factor = 0.08f)
  6. {
  7. using namespace std;
  8.  
  9. vector<Vec3Df> points;
  10. Vec3Df p0, p2;
  11.  
  12. for (int dimLevel = 1; dimLevel < dimensions + 1; dimLevel++) {
  13. // set up the box
  14. for (int i = 0; i < 3; ++i)
  15. p0[i] = point[i] + (dimLevel * factor * -0.5f);
  16.  
  17. p2[0] = point[0];
  18. p2[1] = point[1] + (dimLevel * factor * 0.5f);
  19. p2[2] = point[2] + (dimLevel * factor * 0.5f);
  20.  
  21. BoundingBox triBoxed(p0, p2);
  22.  
  23. // take the eight points around it and put them in a list
  24. Vec3Df A, B, C, D, E, F, G, H;
  25. triBoxed.allPoints(A, B, C, D, E, F, G, H);
  26.  
  27. for (Vec3Df boxPoint : {
  28. A, B, C, D, E, F, G, H
  29. })
  30. points.push_back(boxPoint);
  31. }
  32.  
  33. return points;
  34. }
  35.  
  36. float hardShadow(Vec3Df& isctPoint,
  37. Vec3Df& normal)
  38. {
  39. using namespace std;
  40.  
  41. float total = 0.f;
  42.  
  43. isctPoint += .01f * normal;
  44.  
  45. for (int i = 0; i < MyLightPositions.size(); i++) {
  46.  
  47. Vec3Df tempLight = MyLightPositions[i];
  48. Vec3Df lightDir = getRay(isctPoint, tempLight);
  49.  
  50. Vec3Df potentialIsct, n, color;
  51. float t, tMin = FLT_MAX;
  52. bool hitTriangle = rootNode.hit(&rootNode, isctPoint, lightDir, t,
  53. tMin, n, color, potentialIsct);
  54.  
  55. if (!hitTriangle)
  56. return 1.f;
  57. }
  58.  
  59. return 0.f;
  60. }
  61.  
  62. float softShadow(Vec3Df& isctPoint,
  63. Vec3Df& normal)
  64. {
  65. using namespace std;
  66.  
  67. float total = 0.f;
  68.  
  69. int dimensions = 5;
  70.  
  71. isctPoint += .01f * normal;
  72.  
  73. for (int i = 0; i < MyLightPositions.size(); i++) {
  74.  
  75. vector<Vec3Df> lightList = getPointsCircle(MyLightPositions[i], dimensions);
  76. // vector<Vec3Df> lightList = generateRandomPoints(MyLightPositions[i], 8);
  77. Vec3Df tempLight;
  78.  
  79. for (int i = 0; i < lightList.size(); i++) {
  80. tempLight = lightList[i];
  81. Vec3Df lightDir = getRay(isctPoint, tempLight);
  82. float lightDist = lightDir.getLength();
  83.  
  84. // see if there is anything in the way by comparing lengths
  85. Vec3Df potentialIsct, n, color;
  86. float t, tMin = FLT_MAX;
  87. bool hitTriangle = rootNode.hit(&rootNode, isctPoint, lightDir, t,
  88. tMin, n, color, potentialIsct);
  89.  
  90. if (!hitTriangle)
  91. total += 1;
  92. }
  93. }
  94. float positions = MyLightPositions.size();
  95. float res = total / (dimensions * 8.f * positions);
  96. return res;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement