From fa087a8c55324690f86eec40c70999279704c63f Mon Sep 17 00:00:00 2001 From: "Andrew M. Zhang" Date: Tue, 22 May 2018 23:50:55 -0700 Subject: [PATCH 1/3] Create README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..e8aa3c2 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Metaball/Spheres Raytracer + +Renders metaballs and spheres. Uses C++. No external libraries (as of yet). Project is still being improved on. This is also an excuse for me to learn more C++. + +## Current Features and Methods + +Renders metaballs and spheres using ray marching and raytracing, respectively. Metaball rendering is done by first checking if a ray will enter a proper bounding sphere, before inching a ray through the bounding sphere to determine where the isosurface lies. This task is parallelized with OpenMP. + +To create an interesting animation, metaballs are connected to each other with springs with various k values. We let the physics dictate the movement of the metaballs (each with a mass of 1kg) between frames. See video below: + +[![Metaball Minute Youtube Video](https://img.youtube.com/vi/dfxTMVnEfB0/0.jpg)](https://www.youtube.com/watch?v=dfxTMVnEfB0) + + + +## Todo: + +- [ ] Finish writing this README... +- [ ] Multi-node cluster computing. Current metaball rendering takes a bit too long (4 cores ~ 6 sec), rendering frames are parallizable, however From 396725e29d544233305cf3dd5ad9000a609c75eb Mon Sep 17 00:00:00 2001 From: "Andrew M. Zhang" Date: Sun, 27 May 2018 09:39:36 -0700 Subject: [PATCH 2/3] Added config command line arg --- .idea/blinn.iml | 2 ++ .idea/misc.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ src/main.cpp | 9 ++++++--- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .idea/blinn.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml diff --git a/.idea/blinn.iml b/.idea/blinn.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/blinn.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8822db8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..104b860 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 020be73..fcc935c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,14 +8,17 @@ using namespace std; -int main() { +int main(int argc, char **argv) { debug("Debug Mode ON!"); - config conf("C:\\Users\\andrewmzhang\\CLionProjects\\blinn\\src\\config.txt"); + if (argc != 2) { + throw std::runtime_error("Wrong number of arguments"); + } - tracer t(&conf); + config conf(argv[1]); + tracer t(&conf); blobsys sys(&conf); From 4de2db19bc0d7f55b8779e84e7e3840d78372aae Mon Sep 17 00:00:00 2001 From: "Andrew M. Zhang" Date: Sun, 27 May 2018 09:46:57 -0700 Subject: [PATCH 3/3] Moved arguments around --- CMakeLists.txt | 38 ++++---- src/.exrc | 21 ----- src/{ => basics}/color.cpp | 2 +- src/{ => basics}/color.h | 0 src/{ => basics}/geometry.cpp | 0 src/{ => basics}/geometry.h | 0 src/{ => basics}/point.cpp | 2 +- src/{ => basics}/point.h | 0 src/{ => basics}/ray.cpp | 3 - src/{ => basics}/ray.h | 0 src/{ => basics}/square.cpp | 1 - src/{ => basics}/square.h | 0 src/config.cpp | 150 ------------------------------- src/config.h | 68 -------------- src/dbg.h | 37 -------- src/main.cpp | 8 +- src/{ => physics}/blobsys.cpp | 0 src/{ => physics}/blobsys.h | 6 +- src/{ => renderables}/sphere.cpp | 2 +- src/{ => renderables}/sphere.h | 8 +- src/{ => rendersys}/render.cpp | 4 +- src/{ => rendersys}/render.h | 2 +- src/{ => rendersys}/scene.cpp | 0 src/{ => rendersys}/scene.h | 4 +- src/{ => rendersys}/tracer.cpp | 2 +- src/{ => rendersys}/tracer.h | 10 +-- 26 files changed, 44 insertions(+), 324 deletions(-) delete mode 100644 src/.exrc rename src/{ => basics}/color.cpp (98%) rename src/{ => basics}/color.h (100%) rename src/{ => basics}/geometry.cpp (100%) rename src/{ => basics}/geometry.h (100%) rename src/{ => basics}/point.cpp (98%) rename src/{ => basics}/point.h (100%) rename src/{ => basics}/ray.cpp (94%) rename src/{ => basics}/ray.h (100%) rename src/{ => basics}/square.cpp (96%) rename src/{ => basics}/square.h (100%) delete mode 100644 src/config.cpp delete mode 100644 src/config.h delete mode 100644 src/dbg.h rename src/{ => physics}/blobsys.cpp (100%) rename src/{ => physics}/blobsys.h (86%) rename src/{ => renderables}/sphere.cpp (99%) rename src/{ => renderables}/sphere.h (89%) rename src/{ => rendersys}/render.cpp (99%) rename src/{ => rendersys}/render.h (97%) rename src/{ => rendersys}/scene.cpp (100%) rename src/{ => rendersys}/scene.h (91%) rename src/{ => rendersys}/tracer.cpp (99%) rename src/{ => rendersys}/tracer.h (79%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ad35a1..cd16005 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,24 +15,24 @@ include_directories(src) include_directories(include) add_executable(blinn - src/color.cpp - src/color.h - src/dbg.h - src/geometry.cpp - src/geometry.h + src/basics/color.cpp + src/basics/color.h + src/utils/dbg.h + src/basics/geometry.cpp + src/basics/geometry.h src/main.cpp - src/point.cpp - src/point.h - src/ray.cpp - src/ray.h - src/render.cpp - src/render.h - src/sphere.cpp - src/sphere.h - src/square.cpp - src/square.h - src/blobsys.cpp - src/blobsys.h + src/basics/point.cpp + src/basics/point.h + src/basics/ray.cpp + src/basics/ray.h + src/rendersys/render.cpp + src/rendersys/render.h + src/renderables/sphere.cpp + src/renderables/sphere.h + src/basics/square.cpp + src/basics/square.h + src/physics/blobsys.cpp + src/physics/blobsys.h #src/test.cpp - src/tracer.cpp - src/tracer.h src/config.cpp src/config.h src/scene.cpp src/scene.h) + src/rendersys/tracer.cpp + src/rendersys/tracer.h src/utils/config.cpp src/utils/config.h src/rendersys/scene.cpp src/rendersys/scene.h) diff --git a/src/.exrc b/src/.exrc deleted file mode 100644 index b990b25..0000000 --- a/src/.exrc +++ /dev/null @@ -1,21 +0,0 @@ -if &cp | set nocp | endif -let s:cpo_save=&cpo -set cpo&vim -vmap gx NetrwBrowseXVis -nmap gx NetrwBrowseX -vnoremap NetrwBrowseXVis :call netrw#BrowseXVis() -nnoremap NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '')),netrw#CheckIfRemote()) -let &cpo=s:cpo_save -unlet s:cpo_save -set backspace=indent,eol,start -set expandtab -set fileencodings=ucs-bom,utf-8,default,latin1 -set helplang=en -set nomodeline -set printoptions=paper:letter -set ruler -set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after -set shiftwidth=4 -set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc -set tabstop=4 -" vim: set ft=vim : diff --git a/src/color.cpp b/src/basics/color.cpp similarity index 98% rename from src/color.cpp rename to src/basics/color.cpp index 591ce8e..466a763 100644 --- a/src/color.cpp +++ b/src/basics/color.cpp @@ -1,6 +1,6 @@ #include #include "color.h" -#include "dbg.h" +#include "utils/dbg.h" using namespace std; diff --git a/src/color.h b/src/basics/color.h similarity index 100% rename from src/color.h rename to src/basics/color.h diff --git a/src/geometry.cpp b/src/basics/geometry.cpp similarity index 100% rename from src/geometry.cpp rename to src/basics/geometry.cpp diff --git a/src/geometry.h b/src/basics/geometry.h similarity index 100% rename from src/geometry.h rename to src/basics/geometry.h diff --git a/src/point.cpp b/src/basics/point.cpp similarity index 98% rename from src/point.cpp rename to src/basics/point.cpp index 4a7e870..8d50e07 100644 --- a/src/point.cpp +++ b/src/basics/point.cpp @@ -1,6 +1,6 @@ -#include +#include #include "ray.h" diff --git a/src/point.h b/src/basics/point.h similarity index 100% rename from src/point.h rename to src/basics/point.h diff --git a/src/ray.cpp b/src/basics/ray.cpp similarity index 94% rename from src/ray.cpp rename to src/basics/ray.cpp index eaf0050..3778d9a 100644 --- a/src/ray.cpp +++ b/src/basics/ray.cpp @@ -1,8 +1,5 @@ #include "ray.h" -#include "point.h" #include -#include -#include using namespace std; diff --git a/src/ray.h b/src/basics/ray.h similarity index 100% rename from src/ray.h rename to src/basics/ray.h diff --git a/src/square.cpp b/src/basics/square.cpp similarity index 96% rename from src/square.cpp rename to src/basics/square.cpp index fab6259..74726a2 100644 --- a/src/square.cpp +++ b/src/basics/square.cpp @@ -1,6 +1,5 @@ #include "color.h" #include "square.h" -#include "point.h" square::square() { this->x = 0; diff --git a/src/square.h b/src/basics/square.h similarity index 100% rename from src/square.h rename to src/basics/square.h diff --git a/src/config.cpp b/src/config.cpp deleted file mode 100644 index 6569f58..0000000 --- a/src/config.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// -// Created by camus on 5/19/18. Format borrowed from Joao Carreira's Cirrus project. -// - -#include "config.h" -#include "dbg.h" - -#include - - -config::config(const std::string &path) : path(path) { - - - std::ifstream fin(path.c_str(), std::ifstream::in); - - if (!fin) { - throw std::runtime_error("Error opening config file: " + path); - } - - std::string line; - while (getline(fin, line)) { - parse_line(line); - } - - -} - - -void config::parse_line(const std::string &line) { - - std::istringstream iss(line); - - std::string s; - - iss >> s; - - log_info("Parsing line: %s", s.c_str()); - - if (s == "num_spheres:") { - iss >> num_spheres; - } else if (s == "sphere:") { - double x; - double y; - double z; - double rad; - - int r; - int g; - int b; - - if (spheres.size() == num_spheres && num_spheres > 0) { - throw std::runtime_error( - std::string("num spheres and list spheres mismatch")); - } - - iss >> x >> y >> z >> rad >> r >> g >> b; - - auto *sp = new sphere(x, y, z, rad); - sp->set_color(r, g, b); - spheres.push_back(sp); - - - } else if (s == "spring:") { - uint32_t start; - uint32_t end; - double k; - iss >> start >> end >> k; - auto pair = std::make_tuple((uint8_t) start, (uint8_t) end, k); - springs.push_back(std::move(pair)); - - - } else if (s == "interval:") { - iss >> intv; - } else if (s == "num_frames:") { - iss >> this->start_frame >> this->end_frame; - } else if (s == "background:") { - int r, g, b; - iss >> r >> g >> b; - background.set_rgb(r, g, b); - } else if (s == "size:") { - - iss >> width >> height; - log_info("size: %d %d", width, height); - - } else if (s == "light:") { - - double x, y, z, i; - - iss >> x >> y >> z >> i; - - light.first.set_x(x); - light.first.set_y(y); - light.first.set_z(z); - light.second = i; - - - } else { - throw std::runtime_error(std::string("No such thing as: ") + s); - } - -/* - if (iss.fail()) { - throw std::runtime_error("Error parsing configuration file"); - } -*/ - - -} - -double config::get_intv() const { - return intv; -} - -uint32_t config::get_num_spheres() const { - return num_spheres; -} - -uint32_t config::get_end_frame() const { - return end_frame; -} - -uint32_t config::get_start_frame() const { - return start_frame; -} - -const std::vector &config::get_spheres() const { - return spheres; -} - -const std::vector> &config::get_springs() const { - return springs; -} - -const color &config::get_background() const { - return background; -} - -uint32_t config::get_width() const { - return width; -} - -uint32_t config::get_height() const { - return height; -} - -std::pair config::get_light() const { - - return light; - -}; diff --git a/src/config.h b/src/config.h deleted file mode 100644 index 8f9f15c..0000000 --- a/src/config.h +++ /dev/null @@ -1,68 +0,0 @@ -// -// Created by camus on 5/19/18. -// - -#ifndef BLINN_CONFIG_H -#define BLINN_CONFIG_H - - -#include -#include -#include "color.h" -#include "sphere.h" - -class config { - - -public: - config(const std::string &path); - - void parse_line(const std::string &line); - - uint32_t get_end_frame() const; - - uint32_t get_start_frame() const; - - double get_intv() const; - - uint32_t get_num_spheres() const; - - const std::vector &get_spheres() const; - - const std::vector> &get_springs() const; - - const color &get_background() const; - - uint32_t get_width() const; - - uint32_t get_height() const; - - std::pair get_light() const; - - - - -private: - std::string path; - - uint32_t width; - uint32_t height; - - uint32_t start_frame; - uint32_t end_frame; - - - double intv; - uint32_t num_spheres; - std::vector spheres; - - std::vector> springs; - color background; - - std::pair light; - - -}; - - -#endif //BLINN_CONFIG_H diff --git a/src/dbg.h b/src/dbg.h deleted file mode 100644 index 7b73272..0000000 --- a/src/dbg.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __dbg_h__ -#define __dbg_h__ - -#include -#include -#include -#include - -#define ANSI_COLOR_RED "\x1b[31m" -#define ANSI_COLOR_GREEN "\x1b[32m" -#define ANSI_COLOR_YELLOW "\x1b[33m" -#define ANSI_COLOR_CYAN "\x1b[36m" -#define ANSI_COLOR_RESET "\x1b[0m" - -#ifdef NDEBUG -#define debug(M, ...) -#else -#define debug(M, ...) fprintf(stderr, ANSI_COLOR_CYAN "[DEBUG]" ANSI_COLOR_RESET " %s:%d:%s: " M "\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) -#endif - -#define clean_errno() (errno == 0 ? "None" : strerror(errno)) - -#define log_err(M, ...) fprintf(stderr, ANSI_COLOR_RED "[ERROR]" ANSI_COLOR_RESET " (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__) - -#define log_warn(M, ...) fprintf(stderr, ANSI_COLOR_YELLOW "[WARN]" ANSI_COLOR_RESET " (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__) - -#define log_info(M, ...) fprintf(stderr, ANSI_COLOR_GREEN "[INFO]" ANSI_COLOR_RESET " (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__) - -#define check(A, M, ...) if (!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; } - -#define sentinel(M, ...) { log_err(M, ##__VA_ARGS__); errno=0; goto error; } - -#define check_mem(A) check((A), "Out of memory.") - -#define check_debug(A, M, ...) if (!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; } - -#endif diff --git a/src/main.cpp b/src/main.cpp index fcc935c..a50cf33 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,10 @@ #include #include -#include "dbg.h" -#include "sphere.h" -#include "tracer.h" -#include "blobsys.h" +#include "utils/dbg.h" +#include "renderables/sphere.h" +#include "rendersys/tracer.h" +#include "physics/blobsys.h" using namespace std; diff --git a/src/blobsys.cpp b/src/physics/blobsys.cpp similarity index 100% rename from src/blobsys.cpp rename to src/physics/blobsys.cpp diff --git a/src/blobsys.h b/src/physics/blobsys.h similarity index 86% rename from src/blobsys.h rename to src/physics/blobsys.h index 4baecee..2570595 100644 --- a/src/blobsys.h +++ b/src/physics/blobsys.h @@ -3,9 +3,9 @@ #define __system__ #include #include -#include "sphere.h" -#include "config.h" -#include "scene.h" +#include "renderables/sphere.h" +#include "utils/config.h" +#include "rendersys/scene.h" class blobsys { diff --git a/src/sphere.cpp b/src/renderables/sphere.cpp similarity index 99% rename from src/sphere.cpp rename to src/renderables/sphere.cpp index beecf35..37503b9 100644 --- a/src/sphere.cpp +++ b/src/renderables/sphere.cpp @@ -1,6 +1,6 @@ #include "sphere.h" #include -#include "dbg.h" +#include "utils/dbg.h" bool sphere::intersection(ray *r, double *t) { diff --git a/src/sphere.h b/src/renderables/sphere.h similarity index 89% rename from src/sphere.h rename to src/renderables/sphere.h index e858f5c..32227c5 100644 --- a/src/sphere.h +++ b/src/renderables/sphere.h @@ -2,10 +2,10 @@ #define __sphere_h__ #include -#include "point.h" -#include "ray.h" -#include "geometry.h" -#include "color.h" +#include "basics/point.h" +#include "basics/ray.h" +#include "basics/geometry.h" +#include "basics/color.h" class sphere: public geometry { diff --git a/src/render.cpp b/src/rendersys/render.cpp similarity index 99% rename from src/render.cpp rename to src/rendersys/render.cpp index 98f13ee..12abae8 100644 --- a/src/render.cpp +++ b/src/rendersys/render.cpp @@ -1,8 +1,8 @@ -#include "color.h" +#include "basics/color.h" #include #include #include "render.h" -#include "dbg.h" +#include "utils/dbg.h" using namespace std; diff --git a/src/render.h b/src/rendersys/render.h similarity index 97% rename from src/render.h rename to src/rendersys/render.h index 2a80d67..d0f0869 100644 --- a/src/render.h +++ b/src/rendersys/render.h @@ -7,7 +7,7 @@ #ifndef __render_h__ #define __render_h__ -#include "color.h" +#include "basics/color.h" #include diff --git a/src/scene.cpp b/src/rendersys/scene.cpp similarity index 100% rename from src/scene.cpp rename to src/rendersys/scene.cpp diff --git a/src/scene.h b/src/rendersys/scene.h similarity index 91% rename from src/scene.h rename to src/rendersys/scene.h index d73fd1c..d6cff30 100644 --- a/src/scene.h +++ b/src/rendersys/scene.h @@ -7,8 +7,8 @@ #include -#include "sphere.h" -#include "config.h" +#include "renderables/sphere.h" +#include "utils/config.h" class scene { diff --git a/src/tracer.cpp b/src/rendersys/tracer.cpp similarity index 99% rename from src/tracer.cpp rename to src/rendersys/tracer.cpp index 66891c0..908eca2 100644 --- a/src/tracer.cpp +++ b/src/rendersys/tracer.cpp @@ -1,5 +1,5 @@ #include "cmath" -#include "dbg.h" +#include "utils/dbg.h" #include "tracer.h" #include "render.h" #include diff --git a/src/tracer.h b/src/rendersys/tracer.h similarity index 79% rename from src/tracer.h rename to src/rendersys/tracer.h index 1e88266..6002f70 100644 --- a/src/tracer.h +++ b/src/rendersys/tracer.h @@ -2,12 +2,12 @@ #define __tracer_h__ -#include "square.h" -#include "geometry.h" +#include "basics/square.h" +#include "basics/geometry.h" #include -#include "ray.h" -#include "sphere.h" -#include "config.h" +#include "basics/ray.h" +#include "renderables/sphere.h" +#include "utils/config.h" #include "scene.h" class tracer {