diffuse fixes
parent
7017835cfa
commit
87395a9315
Binary file not shown.
|
@ -24,3 +24,9 @@
|
||||||
1 762 1665980918014947659 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
|
1 762 1665980918014947659 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
|
||||||
1 792 1665980918042948384 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
1 792 1665980918042948384 CMakeFiles/Step_2.dir/src/main.cpp.o 2fb1ddffcef25127
|
||||||
792 853 1665980918102949937 Step_2 513d6b5f7b82bcb
|
792 853 1665980918102949937 Step_2 513d6b5f7b82bcb
|
||||||
|
0 1054 1666014553412325352 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
|
||||||
|
1054 1110 1666014553468326760 Step_2 513d6b5f7b82bcb
|
||||||
|
1 769 1666014587269182037 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
|
||||||
|
769 823 1666014587321183357 Step_2 513d6b5f7b82bcb
|
||||||
|
0 764 1666014713416442097 CMakeFiles/Step_2.dir/src/raytracing.cpp.o cfda37b51895cd7e
|
||||||
|
764 819 1666014713468443463 Step_2 513d6b5f7b82bcb
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,3 @@
|
||||||
Start testing: Oct 17 00:29 EDT
|
Start testing: Oct 17 09:51 EDT
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
End testing: Oct 17 00:29 EDT
|
End testing: Oct 17 09:51 EDT
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 93 KiB |
|
@ -70,7 +70,7 @@ namespace Raytracing {
|
||||||
World& world;
|
World& world;
|
||||||
Random rnd{-1, 1};
|
Random rnd{-1, 1};
|
||||||
|
|
||||||
vec4 randomInSphere() {
|
vec4 randomUnitVector() {
|
||||||
// there are two methods to generating a random unit sphere
|
// there are two methods to generating a random unit sphere
|
||||||
// one which is fast and approximate:
|
// one which is fast and approximate:
|
||||||
//auto v = vec4(rnd.getDouble(), rnd.getDouble(), rnd.getDouble());
|
//auto v = vec4(rnd.getDouble(), rnd.getDouble(), rnd.getDouble());
|
||||||
|
@ -85,6 +85,14 @@ namespace Raytracing {
|
||||||
// the second creates better results but is 18% slower (better defined shadows)
|
// the second creates better results but is 18% slower (better defined shadows)
|
||||||
// likely due to not over generating unit vectors biased towards the corners
|
// likely due to not over generating unit vectors biased towards the corners
|
||||||
}
|
}
|
||||||
|
// unused but provides another method of diffuse rendering
|
||||||
|
vec4 randomUnitHemisphere(const vec4& normal){
|
||||||
|
vec4 v = randomUnitVector().normalize();
|
||||||
|
if (vec4::dot(v, normal) > 0.0)
|
||||||
|
return v;
|
||||||
|
else
|
||||||
|
return -v;
|
||||||
|
}
|
||||||
|
|
||||||
vec4 raycast(const Ray& ray, int depth);
|
vec4 raycast(const Ray& ray, int depth);
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -43,7 +43,7 @@ int main(int argc, char** args) {
|
||||||
// not perfect (contains duplicates) but good enough.
|
// not perfect (contains duplicates) but good enough.
|
||||||
parser.printAllInInfo();
|
parser.printAllInInfo();
|
||||||
|
|
||||||
Raytracing::Image image(256, 256);
|
Raytracing::Image image(445, 256);
|
||||||
|
|
||||||
Raytracing::Camera camera(90, image);
|
Raytracing::Camera camera(90, image);
|
||||||
//camera.lookAt(Raytracing::vec4(0,1,0), Raytracing::vec4(0, 0, -1), Raytracing::vec4(0, 1, 0));
|
//camera.lookAt(Raytracing::vec4(0,1,0), Raytracing::vec4(0, 0, -1), Raytracing::vec4(0, 1, 0));
|
||||||
|
|
|
@ -38,8 +38,6 @@ namespace Raytracing {
|
||||||
// TODO: profile for speed;
|
// TODO: profile for speed;
|
||||||
for (int s = 0; s < raysPerPixel; s++){
|
for (int s = 0; s < raysPerPixel; s++){
|
||||||
// simulate anti aliasing by generating rays with very slight random directions
|
// simulate anti aliasing by generating rays with very slight random directions
|
||||||
// TODO: this should be updated with a [-1, 1] generator as this currently only produces [0, 1]
|
|
||||||
// and therefore lacks true aliasing
|
|
||||||
color = color + raycast(camera.projectRay(i + rnd.getDouble(), j + rnd.getDouble()), 0);
|
color = color + raycast(camera.projectRay(i + rnd.getDouble(), j + rnd.getDouble()), 0);
|
||||||
}
|
}
|
||||||
PRECISION_TYPE sf = 1.0 / raysPerPixel;
|
PRECISION_TYPE sf = 1.0 / raysPerPixel;
|
||||||
|
@ -57,10 +55,10 @@ namespace Raytracing {
|
||||||
|
|
||||||
if (hit.hit) {
|
if (hit.hit) {
|
||||||
// randomly cast our bounce rays to simulate diffuse lighting
|
// randomly cast our bounce rays to simulate diffuse lighting
|
||||||
vec4 newRay = hit.hitPoint + hit.normal + randomInSphere();
|
vec4 newRay = hit.normal + randomUnitVector().normalize();
|
||||||
// recursion is the only good way to do this
|
// recursion is the only good way to do this
|
||||||
// TODO: maybe without the recursion, clang tidy is annoying me.
|
// TODO: maybe without the recursion, clang tidy is annoying me.
|
||||||
return 0.5* raycast({hit.hitPoint, newRay - hit.hitPoint}, depth + 1);
|
return 0.5* raycast({hit.hitPoint, newRay}, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 dir = ray.getDirection().normalize();
|
vec4 dir = ray.getDirection().normalize();
|
||||||
|
|
Loading…
Reference in New Issue