Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // generate 8 points around this point, from a certain factor
- std::vector<Vec3Df> getPointsCircle(Vec3Df const point,
- int const dimensions,
- float const factor = 0.08f)
- {
- using namespace std;
- vector<Vec3Df> points;
- Vec3Df p0, p2;
- for (int dimLevel = 1; dimLevel < dimensions + 1; dimLevel++) {
- // set up the box
- for (int i = 0; i < 3; ++i)
- p0[i] = point[i] + (dimLevel * factor * -0.5f);
- p2[0] = point[0];
- p2[1] = point[1] + (dimLevel * factor * 0.5f);
- p2[2] = point[2] + (dimLevel * factor * 0.5f);
- BoundingBox triBoxed(p0, p2);
- // take the eight points around it and put them in a list
- Vec3Df A, B, C, D, E, F, G, H;
- triBoxed.allPoints(A, B, C, D, E, F, G, H);
- for (Vec3Df boxPoint : {
- A, B, C, D, E, F, G, H
- })
- points.push_back(boxPoint);
- }
- return points;
- }
- float hardShadow(Vec3Df& isctPoint,
- Vec3Df& normal)
- {
- using namespace std;
- float total = 0.f;
- isctPoint += .01f * normal;
- for (int i = 0; i < MyLightPositions.size(); i++) {
- Vec3Df tempLight = MyLightPositions[i];
- Vec3Df lightDir = getRay(isctPoint, tempLight);
- Vec3Df potentialIsct, n, color;
- float t, tMin = FLT_MAX;
- bool hitTriangle = rootNode.hit(&rootNode, isctPoint, lightDir, t,
- tMin, n, color, potentialIsct);
- if (!hitTriangle)
- return 1.f;
- }
- return 0.f;
- }
- float softShadow(Vec3Df& isctPoint,
- Vec3Df& normal)
- {
- using namespace std;
- float total = 0.f;
- int dimensions = 5;
- isctPoint += .01f * normal;
- for (int i = 0; i < MyLightPositions.size(); i++) {
- vector<Vec3Df> lightList = getPointsCircle(MyLightPositions[i], dimensions);
- // vector<Vec3Df> lightList = generateRandomPoints(MyLightPositions[i], 8);
- Vec3Df tempLight;
- for (int i = 0; i < lightList.size(); i++) {
- tempLight = lightList[i];
- Vec3Df lightDir = getRay(isctPoint, tempLight);
- float lightDist = lightDir.getLength();
- // see if there is anything in the way by comparing lengths
- Vec3Df potentialIsct, n, color;
- float t, tMin = FLT_MAX;
- bool hitTriangle = rootNode.hit(&rootNode, isctPoint, lightDir, t,
- tMin, n, color, potentialIsct);
- if (!hitTriangle)
- total += 1;
- }
- }
- float positions = MyLightPositions.size();
- float res = total / (dimensions * 8.f * positions);
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement