added ability to pause / stop / restart raytracing.

main
Brett 2022-10-28 15:05:08 -04:00
parent 7b379f722d
commit 1e8914b4a5
53 changed files with 110 additions and 228 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/Step 3/cmake-build-debug/

View File

@ -1 +1 @@
,brett,laforge,28.10.2022 01:24,file:///home/brett/.config/libreoffice/4;
,brett,laforge,28.10.2022 15:02,file:///home/brett/.config/libreoffice/4;

View File

@ -1,108 +0,0 @@
{
"cmake" :
{
"generator" :
{
"multiConfig" : false,
"name" : "Ninja"
},
"paths" :
{
"cmake" : "/opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/bin/cmake",
"cpack" : "/opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/bin/cpack",
"ctest" : "/opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/bin/ctest",
"root" : "/opt/netbrains/clion/clion-2022.1.3/bin/cmake/linux/share/cmake-3.23"
},
"version" :
{
"isDirty" : false,
"major" : 3,
"minor" : 23,
"patch" : 2,
"string" : "3.23.2",
"suffix" : ""
}
},
"objects" :
[
{
"jsonFile" : "codemodel-v2-efb0d1357378cbd0a379.json",
"kind" : "codemodel",
"version" :
{
"major" : 2,
"minor" : 4
}
},
{
"jsonFile" : "cache-v2-5fdf2e49722c528a78eb.json",
"kind" : "cache",
"version" :
{
"major" : 2,
"minor" : 0
}
},
{
"jsonFile" : "cmakeFiles-v1-8856d3a45f872662a860.json",
"kind" : "cmakeFiles",
"version" :
{
"major" : 1,
"minor" : 0
}
},
{
"jsonFile" : "toolchains-v1-a68c232ca45b00aa6bba.json",
"kind" : "toolchains",
"version" :
{
"major" : 1,
"minor" : 0
}
}
],
"reply" :
{
"cache-v2" :
{
"jsonFile" : "cache-v2-5fdf2e49722c528a78eb.json",
"kind" : "cache",
"version" :
{
"major" : 2,
"minor" : 0
}
},
"cmakeFiles-v1" :
{
"jsonFile" : "cmakeFiles-v1-8856d3a45f872662a860.json",
"kind" : "cmakeFiles",
"version" :
{
"major" : 1,
"minor" : 0
}
},
"codemodel-v2" :
{
"jsonFile" : "codemodel-v2-efb0d1357378cbd0a379.json",
"kind" : "codemodel",
"version" :
{
"major" : 2,
"minor" : 4
}
},
"toolchains-v1" :
{
"jsonFile" : "toolchains-v1-a68c232ca45b00aa6bba.json",
"kind" : "toolchains",
"version" :
{
"major" : 1,
"minor" : 0
}
}
}
}

Binary file not shown.

View File

@ -1,39 +1,23 @@
# ninja log v5
3 2328 1666645817680080118 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o dc4b23b5e01a8208
2 1997 1666645817348070656 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o cf522ea42b0f8fd3
2 1801 1666673054479669816 CMakeFiles/Step_3.dir/src/engine/world.cpp.o fa088ebdd4dea6cb
2 1620 1666983166449949656 CMakeFiles/Step_3.dir/src/engine/world.cpp.o fa088ebdd4dea6cb
1 979 1666648980885505392 CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o d5972a669671ede
1 1508 1666673054183662428 CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o 4ca9d05ad8f3d295
1 816 1666648980721500521 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 3e7c95bef1d0ddaa
1 1234 1666981302357304642 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 3e7c95bef1d0ddaa
2 1991 1666645817344070539 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 12778f168a75833b
2 2207 1666645817560076697 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o f8031520e846a554
2 3803 1666645819156122183 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o f152a6b2309aba93
1809 1966 1666673610818173691 Step_3 48736482bab78a22
4 2331 1666645817684080231 CMakeFiles/Step_3.dir/src/graphics/shader.cpp.o 89b6559e07a1508c
1 1809 1666673610662169502 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 39bc1042baf06dcd
1 16 1666549780060504850 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 10752ac78f398bdb
3 3104 1666645818456102230 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o 707f99c685c75a0f
1 787 1666549780832519379 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o 53ce7d6ed877d888
3 3490 1666645818844113291 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o d81abd5f968f8f53
2 2186 1666673054863679392 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 9281ecbfd964c525
1 1178 1666549740059765852 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o e9e3fe6fe9a4de66
4 41 1666933458043351230 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 10752ac78f398bdb
3 375 1666933458379361395 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o 45a2ee53269bffeb
3 679 1666933458683370593 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 35f01a0bb2fddead
1 1503 1666933459507395524 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 3e7c95bef1d0ddaa
3 2280 1666933460283419002 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 67f44a482b45cec6
2 2283 1666933460283419002 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o f8031520e846a554
3 2372 1666933460375421785 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o 53ce7d6ed877d888
2 2386 1666933460387422148 CMakeFiles/Step_3.dir/src/engine/world.cpp.o fa088ebdd4dea6cb
2 2922 1666933460923438365 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 39bc1042baf06dcd
2 3235 1666933461235447804 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 9281ecbfd964c525
2 3245 1666933461243448045 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o c67f39c07aae8f1c
3245 3612 1666933461611459180 Step_3 50a8b57262a84bea
2 3803 1666645819156122183 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o f152a6b2309aba93
2088 2309 1666983564938369031 Step_3 50a8b57262a84bea
1 345 1666981453797536430 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 35f01a0bb2fddead
4 2331 1666645817684080231 CMakeFiles/Step_3.dir/src/graphics/shader.cpp.o 89b6559e07a1508c
1 1849 1666983376724092088 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 39bc1042baf06dcd
4 41 1666933458043351230 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 10752ac78f398bdb
3 3104 1666645818456102230 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o 707f99c685c75a0f
1 1429 1666983376304079808 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o 53ce7d6ed877d888
3 3490 1666645818844113291 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o d81abd5f968f8f53
2 2699 1666981303821348302 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o c67f39c07aae8f1c
3 375 1666933458379361395 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o 45a2ee53269bffeb
1 1377 1666934125123463514 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 67f44a482b45cec6
1 2062 1666934125803483973 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 9281ecbfd964c525
2062 2233 1666934125975489144 Step_3 50a8b57262a84bea
2 337 1666934180077116398 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 35f01a0bb2fddead
337 554 1666934180289122774 Step_3 50a8b57262a84bea
1 332 1666934229626606442 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 35f01a0bb2fddead
1 1373 1666934230666637715 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o 53ce7d6ed877d888
1373 1539 1666934230830642646 Step_3 50a8b57262a84bea
1 2088 1666983564718361404 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 9281ecbfd964c525
1 1178 1666549740059765852 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o e9e3fe6fe9a4de66

Binary file not shown.

View File

@ -1,3 +1,3 @@
Start testing: Oct 28 01:17 EDT
Start testing: Oct 28 14:59 EDT
----------------------------------------------------------
End testing: Oct 28 01:17 EDT
End testing: Oct 28 14:59 EDT

View File

@ -8,3 +8,8 @@ Pos=650,20
Size=550,680
Collapsed=0
[Window][Debug]
Pos=72,82
Size=74,100
Collapsed=0

View File

@ -1,74 +1,23 @@
# ninja log v5
2 1891 1666585888837654600 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o f6dab204e07e8dcf
1 2520 1666585889465673262 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o 7798aba97da63e31
1 1495 1666811808546009862 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
1 1301 1666981149056733417 CMakeFiles/Step_3.dir/src/engine/world.cpp.o 6470df278966c4
1 893 1666647453395941912 CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o d86a254d2bce8f74
1 1869 1666672425433732155 CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o 1c68ba16e6b4d09b
1 695 1666713001349370106 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511
1 741 1666980538714543808 CMakeFiles/Step_3.dir/src/engine/globals.cpp.o 4ef77d2224f86511
1 775 1666586379624689616 CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o 39e9f435096d066b
1 1524 1666811808578010855 CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o 164394d360c43072
1 6680 1666585893625796878 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o 55e7538fd27b47be
942 1008 1666906598573057126 Step_3 ee9dec69e3f6bf3f
2 584 1666811807637981741 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 6aef9db88eb3d76d
1438 1505 1666981290476950363 Step_3 8e1012bfab9235e9
2 352 1666934238066860228 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 6aef9db88eb3d76d
2 1091 1666586379944699493 CMakeFiles/Step_3.dir/src/graphics/shader.cpp.o 25fdf04995cdd7fe
1 1903 1666811808954022498 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
1 1438 1666981290408948337 CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o 11f0e227e9fda9ca
1 17 1666723625180468244 CMakeFiles/Step_3.dir/src/graphics/input.cpp.o 510001b0955ab019
1 3563 1666585915222438568 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o f89fa3d7b779872a
1 4522 1666585908106227137 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o 84017388bc7af144
1 1044 1666932872509514079 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
2 5345 1666932848160764512 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
2 1110 1666981148864727693 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
2 4819 1666981152572838255 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
4 176 1666717766117955862 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o 1b5f0fbe3cf8ce4e
2 2111 1666932844928664944 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
1 1350 1666485932124409891 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o 1007c86c207ac940
1 1136 1666932885281906922 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b
1136 1262 1666932885409910857 Step_3 8e1012bfab9235e9
1 1945 1666932902142425147 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
1945 2026 1666932902222427605 Step_3 8e1012bfab9235e9
1 1186 1666933048802917622 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b
1 2005 1666933049618942550 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
2005 2095 1666933049706945238 Step_3 8e1012bfab9235e9
1 1010 1666933189599209225 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1010 1099 1666933189687211902 Step_3 8e1012bfab9235e9
1 1072 1666933209963828560 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1072 1162 1666933210051831235 Step_3 8e1012bfab9235e9
2 1059 1666933232468512604 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1059 1136 1666933232544514913 Step_3 8e1012bfab9235e9
1 1058 1666933241016772340 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1059 1167 1666933241120775497 Step_3 8e1012bfab9235e9
2 1140 1666933307906803018 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b
1140 1223 1666933307990805565 Step_3 8e1012bfab9235e9
2 1256 1666933490872344229 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b
1256 1368 1666933490980347497 Step_3 8e1012bfab9235e9
1 1749 1666933952202259726 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
1749 1808 1666933952262261532 Step_3 8e1012bfab9235e9
1 995 1666934083498211266 CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o 2553d57dba16057b
1 1767 1666934084270234493 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
1767 1831 1666934084330236300 Step_3 8e1012bfab9235e9
2 352 1666934238066860228 CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o 6aef9db88eb3d76d
2 979 1666934238694879112 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1 1916 1666934239630907257 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
1916 1979 1666934239694909183 Step_3 8e1012bfab9235e9
2 1132 1666973684372901616 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
1 1928 1666973685168926327 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
1 4712 1666973687953012743 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
4712 4813 1666973688053015848 Step_3 8e1012bfab9235e9
1 972 1666973802264549771 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
972 1039 1666973802332551868 Step_3 8e1012bfab9235e9
1 957 1666973853034114376 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
957 1024 1666973853098116348 Step_3 8e1012bfab9235e9
1 957 1666974027615470803 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
957 1026 1666974027683472884 Step_3 8e1012bfab9235e9
1 958 1666974062028522979 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
958 1026 1666974062096525059 Step_3 8e1012bfab9235e9
1 971 1666974109329967557 CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o ce988de97a5cb51d
971 1037 1666974109393969509 Step_3 8e1012bfab9235e9
1 4589 1666974300435787409 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
4589 4657 1666974300503789473 Step_3 8e1012bfab9235e9
1 4563 1666974526658651253 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
4563 4626 1666974526722653192 Step_3 8e1012bfab9235e9
1 4557 1666974781086349492 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
4557 4626 1666974781154351547 Step_3 8e1012bfab9235e9
1 5008 1666974850596449938 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
5008 5075 1666974850664451993 Step_3 8e1012bfab9235e9
1 4945 1666974914782388699 CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o 330ad35a6abf06c3
4945 5009 1666974914846390631 Step_3 8e1012bfab9235e9
1 1924 1666981149676751903 CMakeFiles/Step_3.dir/src/engine/main.cpp.o 641dce3f86933e2e
1 1350 1666485932124409891 CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o 1007c86c207ac940

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 KiB

Binary file not shown.

View File

@ -1,3 +1,3 @@
Start testing: Oct 28 12:41 EDT
Start testing: Oct 28 15:02 EDT
----------------------------------------------------------
End testing: Oct 28 12:41 EDT
End testing: Oct 28 15:02 EDT

View File

@ -4,7 +4,12 @@ Size=95,60
Collapsed=0
[Window][Dear ImGui Demo]
Pos=874,4
Pos=952,11
Size=550,680
Collapsed=1
[Window][Debug]
Pos=60,60
Size=74,100
Collapsed=0

View File

@ -72,18 +72,14 @@ namespace Raytracing {
class Raycaster {
private:
const int maxBounceDepth = 50;
// 50 seems to be the magic number for the point of diminishing returns
// 100 looks like 50 but slightly clearer
// 25 is noisy
// 1 is VERY noisy.
const int raysPerPixel = 50;
int maxBounceDepth = 50;
int raysPerPixel = 50;
Camera& camera;
Image& image;
World& world;
std::vector<std::thread*> executors;
std::vector<std::unique_ptr<std::thread>> executors {};
// is the raytracer still running?
bool stillRunning = true;
unsigned int finishedThreads = 0;
@ -91,10 +87,18 @@ namespace Raytracing {
// yes this is actually the only sync we need between the threads
// and compared to the actual runtime of the raytracing it's very small!
std::mutex queueSync;
std::queue<std::vector<int>>* unprocessedQuads = new std::queue<std::vector<int>>();
std::queue<std::vector<int>>* unprocessedQuads = nullptr;
Vec4 raycast(const Ray& ray);
public:
inline void updateRayInfo(int maxBounce, int perPixel){
raysPerPixel = perPixel;
maxBounceDepth = maxBounce;
}
inline void resetRayInfo(){
raysPerPixel = 50;
maxBounceDepth = 50;
}
inline static Vec4 randomUnitVector() {
// there are two methods to generating a random unit sphere
// one which is fast and approximate:
@ -117,18 +121,22 @@ namespace Raytracing {
void runMulti(unsigned int t);
[[nodiscard]] inline bool areThreadsStillRunning() const {return finishedThreads == executors.size();}
inline void join(){
for (auto* p : executors)
for (auto& p : executors)
p->join();
}
~Raycaster() {
for (auto* p : executors){
void deleteThreads(){
for (auto& p : executors){
// wait for all threads to exit before trying to delete them.
try {
if (p->joinable())
p->join();
} catch (std::exception& e){}
delete(p);
}
// since executors contains the only reference to the unique_ptr it will be deleted automatically
executors.clear();
}
~Raycaster() {
deleteThreads();
delete(unprocessedQuads);
}
};

View File

@ -75,7 +75,7 @@ class VAO {
VAO(VAO &&) noexcept = delete; // Disable move constructor.
VAO& operator=(VAO &&) noexcept = delete; // Disable Move Assignment
VAO(const std::vector<Raytracing::Triangle> &triangles);
explicit VAO(const std::vector<Raytracing::Triangle> &triangles);
VAO(const std::vector<float>& verts, const std::vector<float>& uvs, const std::vector<unsigned int>& indices);
void bind() const;

View File

@ -6,6 +6,8 @@
#include "engine/util/debug.h"
bool* haltExecution;
bool* pauseRaytracing;
bool* haltRaytracing;
namespace Raytracing {
std::unordered_map<std::string, profiler*> profiles;

View File

@ -27,6 +27,8 @@
using namespace Raytracing;
extern bool* haltExecution;
extern bool* pauseRaytracing;
extern bool* haltRaytracing;
int main(int argc, char** args) {
// since this is linux only we can easily set our process priority to be high with a syscall
@ -77,7 +79,11 @@ int main(int argc, char** args) {
// yes this is a very stupid and bad way of doing this.
haltExecution = new bool;
pauseRaytracing = new bool;
haltRaytracing = new bool;
*haltExecution = false;
*pauseRaytracing = false;
*haltRaytracing = false;
if (signal(SIGTERM, [] (int sig) -> void {
ilog<<"Computations complete.\nHalting now...\n";
*haltExecution = true;
@ -137,15 +143,25 @@ int main(int argc, char** args) {
window.runUpdates([&window, &mainImage, &shader, &raycaster, &parser]() -> void {
if (*haltExecution){window.closeWindow();}
ImGui::Begin("Debug");
if (ImGui::Button("Start") && !started){
started = true;
*haltRaytracing = false;
ilog << "Running raycaster!\n";
if(parser.hasOption("--multi")) {
raycaster.runMulti(std::max(std::stoi(parser.getOptionValue("-t")), std::stoi(parser.getOptionValue("--threads"))));
} else { // we don't actually have to check for --single since it's implied to be default true.
raycaster.runSingle();
}
started = true;
}
if (ImGui::Checkbox("Pause", pauseRaytracing)){}
if (ImGui::Button("Stop") && started){
*haltRaytracing = true;
started = false;
raycaster.deleteThreads();
}
ImGui::End();
shader.use();
mainImage.updateImage();
@ -192,7 +208,12 @@ int main(int argc, char** args) {
imageOutput.write(parser.getOptionValue("--output") + timeString.str(), parser.getOptionValue("--format"));
delete(haltExecution);
delete(haltRaytracing);
delete(pauseRaytracing);
deleteQuad();
for (auto& p : Raytracing::profiles)
delete(p.second);
return 0;
}

View File

@ -9,6 +9,8 @@
#include <engine/util/debug.h>
extern bool* haltExecution;
extern bool* pauseRaytracing;
extern bool* haltRaytracing;
namespace Raytracing {
@ -46,8 +48,10 @@ namespace Raytracing {
Ray localRay = ray;
Vec4 color {1.0, 1.0, 1.0};
for (int CURRENT_BOUNCE = 0; CURRENT_BOUNCE < maxBounceDepth; CURRENT_BOUNCE++){
if (*haltExecution)
if (*haltExecution || *haltRaytracing)
return color;
while (*pauseRaytracing) // sleep for 1/60th of a second, or about 1 frame.
std::this_thread::sleep_for(std::chrono::milliseconds(16));
auto hit = world.checkIfHit(localRay, 0.001, infinity);
if (hit.first.hit) {
auto object = hit.second;
@ -91,7 +95,7 @@ namespace Raytracing {
}
void Raycaster::runSingle() {
executors.push_back(new std::thread([this]() -> void {
executors.push_back(std::make_unique<std::thread>([this]() -> void {
profiler::start("Raytracer Results", "Single Thread");
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); j++) {
@ -104,8 +108,10 @@ namespace Raytracing {
PRECISION_TYPE sf = 1.0 / raysPerPixel;
// apply pixel color with gamma correction
image.setPixelColor(i, j, {std::sqrt(sf * color.r()), std::sqrt(sf * color.g()), std::sqrt(sf * color.b())});
if (*haltExecution)
if (*haltExecution || *haltRaytracing)
return;
while (*pauseRaytracing) // sleep for 1/60th of a second, or about 1 frame.
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
}
profiler::end("Raytracer Results", "Single Thread");
@ -120,12 +126,16 @@ namespace Raytracing {
// matching the 16 threads.
if (t == 0)
t = system_threads;
ilog << "Starting multithreaded raytracer with " << t << " threads!\n";
int divs = int(std::log(t) / std::log(2));
// now double the divs, splitting each quadrant into 4 sub-quadrants which we can queue
// the reason to do this is that some of them will finish before others, and the now free threads can keep working
// do it without a queue like this leads to a single thread critical path and isn't optimally efficient.
divs *= 4; // 2 because two axis getting split makes 4 sub-quadrants, but I tested 4, and it was faster by two seconds, so I'm keeping 4.
delete(unprocessedQuads);
unprocessedQuads = new std::queue<std::vector<int>>();
for (int dx = 0; dx < divs; dx++) {
for (int dy = 0; dy < divs; dy++) {
// sending functions wasn't working. (fixed, however it feels janky sending lambda functions w/ captures)
@ -139,7 +149,7 @@ namespace Raytracing {
}
for (int i = 0; i < t; i++) {
executors.push_back(new std::thread([this, i, divs, t]() -> void {
executors.push_back(std::make_unique<std::thread>([this, i, divs, t]() -> void {
// run through all the quadrants
std::stringstream str;
str << "Threading of #";
@ -172,8 +182,12 @@ namespace Raytracing {
PRECISION_TYPE sf = 1.0 / raysPerPixel;
// apply pixel color with gamma correction
image.setPixelColor(x, y, {std::sqrt(sf * color.r()), std::sqrt(sf * color.g()), std::sqrt(sf * color.b())});
if (*haltExecution)
if (*haltExecution || *haltRaytracing) {
tlog << "Halting raytracing! " << *haltExecution << " " << *haltRaytracing << " " << i << "\n";
return;
}
while (*pauseRaytracing) // sleep for 1/60th of a second, or about 1 frame.
std::this_thread::sleep_for(std::chrono::milliseconds(16));
} catch (std::exception& error) {
flog << "Possibly fatal error in the multithreaded raytracer!\n";
flog << error.what() << "\n";
@ -182,6 +196,7 @@ namespace Raytracing {
}
j++;
}
tlog << "ex threead " << i << "\n";
finishedThreads++;
profiler::end("Raytracer Results", str.str());
}));

View File

@ -274,7 +274,7 @@ unsigned char *Texture::loadTexture(const std::string& path) {
return dta;
}
Texture::~Texture() {
tlog << "Deleting Texture {" << textureID << "}";
tlog << "Deleting Texture {" << textureID << "}\n";
glDeleteTextures(1, &textureID);
data = nullptr;
}

View File

@ -168,7 +168,8 @@ namespace Raytracing {
GLX_CONTEXT_MAJOR_VERSION_ARB, 4,
// OpenGL minor version,
GLX_CONTEXT_MINOR_VERSION_ARB, 5,
// I don't remember what this does, but I know GLFW recommends that forward compatability be set true,
// I don't remember what this does, but I know GLFW recommends that forward compatability be set true, (Pretty sure it's only an issue
// on MacOS but I've always included this in all my projects so :shrug:
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
// Core profile for better Renderdoc compatibility + I don't need non core extensions
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
@ -316,6 +317,7 @@ namespace Raytracing {
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
XFree(visualInfo);
glXMakeCurrent(display, None, NULL);
glXDestroyContext(display, glContext);
XDestroyWindow(display, window);

View File

@ -223,8 +223,6 @@ void ImGui_ImplGlfw_UpdateKeyModifiers(int mods)
}
void ImGui_ImplGlfw_MouseButtonCallback(unsigned int button, bool press, int mods) {
ImGui_ImplGlfw_UpdateKeyModifiers(mods);
ImGuiIO& io = ImGui::GetIO();
if (button < ImGuiMouseButton_COUNT)
io.AddMouseButtonEvent((int)button, press);