From 325b47817ed24654bf7bfd12f100cd0531ab6b5c Mon Sep 17 00:00:00 2001 From: Pascal Engeler <engelerp@phys.ethz.ch> Date: Tue, 19 Oct 2021 17:12:04 +0200 Subject: [PATCH] Changed directory structure --- src/Makefile | 63 ++++++++++++++++++++-------------- src/camera.cpp | 2 +- src/camera.hpp | 26 -------------- src/color.hpp | 9 ----- src/constant_deformer.hpp | 16 --------- src/deformer.hpp | 9 ----- src/dielectric.hpp | 24 ------------- src/hittable.hpp | 21 ------------ src/hittable_list.hpp | 22 ------------ src/linear_deformer.hpp | 20 ----------- src/main.cpp | 28 ++++++++++++++-- src/material.hpp | 25 -------------- src/quadratic_deformer.hpp | 20 ----------- src/quartic_deformer.hpp | 20 ----------- src/radiator.hpp | 21 ------------ src/ray.cpp | 2 +- src/ray.hpp | 37 -------------------- src/raytracing.hpp | 24 ------------- src/triangle.hpp | 28 ---------------- src/triangle_mesh.hpp | 25 -------------- src/vec3.hpp | 69 -------------------------------------- src/wavelength2rgb.hpp | 17 ---------- src/xyplane.hpp | 21 ------------ 23 files changed, 64 insertions(+), 485 deletions(-) delete mode 100644 src/camera.hpp delete mode 100644 src/color.hpp delete mode 100644 src/constant_deformer.hpp delete mode 100644 src/deformer.hpp delete mode 100644 src/dielectric.hpp delete mode 100644 src/hittable.hpp delete mode 100644 src/hittable_list.hpp delete mode 100644 src/linear_deformer.hpp delete mode 100644 src/material.hpp delete mode 100644 src/quadratic_deformer.hpp delete mode 100644 src/quartic_deformer.hpp delete mode 100644 src/radiator.hpp delete mode 100644 src/ray.hpp delete mode 100644 src/raytracing.hpp delete mode 100644 src/triangle.hpp delete mode 100644 src/triangle_mesh.hpp delete mode 100644 src/vec3.hpp delete mode 100644 src/wavelength2rgb.hpp delete mode 100644 src/xyplane.hpp diff --git a/src/Makefile b/src/Makefile index feedcf0..2364f85 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,71 +1,82 @@ -include config.mk -CXX = /usr/local/bin/g++-11 - -CXXFLAGS = -std=c++11 -CXXFLAGS += -I. -CXXFLAGS += -Wall -Wpedantic +CXXFLAGS = -std=c++14 +CXXFLAGS += -I../include/ +CXXFLAGS += -Wall -Wpedantic -Wextra CXXFLAGS += -DNDEBUG CXXFLAGS += -mtune=native -march=native -O3 CXXFLAGS += -fopenmp +HPP = ../include +BIN = ../bin + .PHONY: all -all: image.ppm +all: main -image.ppm: main - ./main > image.ppm +.PHONY: image +image: ${BIN}/image.ppm -main: main.o wavelength2rgb.o quadratic_deformer.o quartic_deformer.o constant_deformer.o radiator.o dielectric.o xyplane.o triangle_mesh.o triangle.o hittable_list.o camera.o raytracing.o ray.o color.o vec3.o +${BIN}/image.ppm: main + ${BIN}/main 1> ${BIN}/image.ppm 2> ${BIN}/dbg.txt + +main: main.o wavelength2rgb.o interpolating_deformer.o linear_deformer.o quadratic_deformer.o quartic_deformer.o constant_deformer.o radiator.o dielectric.o xyplane.o triangle_mesh.o triangle.o hittable_list.o camera.o raytracing.o ray.o color.o vec3.o ${CXX} ${CXXFLAGS} -o $@ $^ + mv main ${BIN}/ + +main.o: main.cpp ${HPP}/radiator.hpp ${HPP}/dielectric.hpp ${HPP}/triangle.hpp ${HPP}/hittable_list.hpp ${HPP}/camera.hpp ${HPP}/ray.hpp ${HPP}/color.hpp ${HPP}/vec3.hpp + ${CXX} ${CXXFLAGS} -c $< + +color.o: color.cpp ${HPP}/color.hpp + ${CXX} ${CXXFLAGS} -c $< -main.o: main.cpp radiator.hpp dielectric.hpp triangle.hpp hittable_list.hpp camera.hpp ray.hpp color.hpp vec3.hpp +vec3.o: vec3.cpp ${HPP}/vec3.hpp ${CXX} ${CXXFLAGS} -c $< -color.o: color.cpp color.hpp +ray.o: ray.cpp ${HPP}/ray.hpp ${CXX} ${CXXFLAGS} -c $< -vec3.o: vec3.cpp vec3.hpp +raytracing.o: raytracing.cpp ${HPP}/raytracing.hpp ${CXX} ${CXXFLAGS} -c $< -ray.o: ray.cpp ray.hpp +camera.o: camera.cpp ${HPP}/camera.hpp ${CXX} ${CXXFLAGS} -c $< -raytracing.o: raytracing.cpp raytracing.hpp +hittable_list.o: hittable_list.cpp ${HPP}/hittable_list.hpp ${CXX} ${CXXFLAGS} -c $< -camera.o: camera.cpp camera.hpp +triangle.o: triangle.cpp ${HPP}/triangle.hpp ${CXX} ${CXXFLAGS} -c $< -hittable_list.o: hittable_list.cpp hittable_list.hpp +xyplane.o: xyplane.cpp ${HPP}/xyplane.hpp ${CXX} ${CXXFLAGS} -c $< -triangle.o: triangle.cpp triangle.hpp +dielectric.o: dielectric.cpp ${HPP}/dielectric.hpp ${HPP}/material.hpp ${CXX} ${CXXFLAGS} -c $< -xyplane.o: xyplane.cpp xyplane.hpp +radiator.o: radiator.cpp ${HPP}/radiator.hpp ${HPP}/material.hpp ${CXX} ${CXXFLAGS} -c $< -dielectric.o: dielectric.cpp dielectric.hpp material.hpp +quartic_deformer.o: quartic_deformer.cpp ${HPP}/quartic_deformer.hpp ${CXX} ${CXXFLAGS} -c $< -radiator.o: radiator.cpp radiator.hpp material.hpp +constant_deformer.o: constant_deformer.cpp ${HPP}/constant_deformer.hpp ${CXX} ${CXXFLAGS} -c $< -quartic_deformer.o: quartic_deformer.cpp quartic_deformer.hpp +triangle_mesh.o: triangle_mesh.cpp ${HPP}/triangle_mesh.hpp ${CXX} ${CXXFLAGS} -c $< -constant_deformer.o: constant_deformer.cpp constant_deformer.hpp +wavelength2rgb.o: wavelength2rgb.cpp ${HPP}/wavelength2rgb.hpp ${CXX} ${CXXFLAGS} -c $< -triangle_mesh.o: triangle_mesh.cpp triangle_mesh.hpp +quadratic_deformer.o: quadratic_deformer.cpp ${HPP}/quadratic_deformer.hpp ${CXX} ${CXXFLAGS} -c $< -wavelength2rgb.o: wavelength2rgb.cpp wavelength2rgb.hpp +linear_deformer.o: linear_deformer.cpp ${HPP}/linear_deformer.hpp ${CXX} ${CXXFLAGS} -c $< -quadratic_deformer.o: quadratic_deformer.cpp quadratic_deformer.hpp +interpolating_deformer.o: interpolating_deformer.cpp ${HPP}/interpolating_deformer.hpp ${CXX} ${CXXFLAGS} -c $< .PHONY: clean clean: - ${RM} -v *.o main image.ppm + ${RM} -v *.o ${BIN}/main image.ppm dbg.txt diff --git a/src/camera.cpp b/src/camera.cpp index a773b12..be117ad 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -12,7 +12,7 @@ camera::camera(){ horizontal = vec3(viewport_width, 0., 0.); vertical = vec3(0., viewport_height, 0.); lower_left_corner = origin - horizontal/2. - vertical/2. - vec3(0., 0., focal_length); - max_bounces = 9; + max_bounces = 5; } camera::camera(double aspect_ratio, double viewport_height, double viewport_width, double focal_length){ diff --git a/src/camera.hpp b/src/camera.hpp deleted file mode 100644 index b885667..0000000 --- a/src/camera.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef CAMERA_HPP_INCLUDED -#define CAMERA_HPP_INCLUDED - -#include <raytracing.hpp> - -/* -The focus is at (0,0,0). -The camera screen is in the axis aligned plane through (0, 0, -focal_length) -The scene is in the negative-z domain. -Rays start at the focal point and flow through the camera pixels into the scene. -*/ -class camera{ -public: - camera(); - camera(double aspect_ratio, double viewport_height, double viewport_width, double focal_length); - ray get_ray(double u, double v) const; - -private: - point3 origin; - point3 lower_left_corner; - vec3 horizontal; - vec3 vertical; - int max_bounces; //maximum number of bounces cast rays can perform -}; - -#endif diff --git a/src/color.hpp b/src/color.hpp deleted file mode 100644 index 6441e1f..0000000 --- a/src/color.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef COLOR_HPP_INCLUDED -#define COLOR_HPP_INCLUDED - -#include <vec3.hpp> -#include <iostream> - -void write_color(std::ostream&, const color&, int samples_per_pixel); - -#endif diff --git a/src/constant_deformer.hpp b/src/constant_deformer.hpp deleted file mode 100644 index 102af81..0000000 --- a/src/constant_deformer.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef CONSTANT_DEFORMER_HPP_INCLUDED -#define CONSTANT_DEFORMER_HPP_INCLUDED - -#include <deformer.hpp> - -class constant_deformer: public deformer{ -public: - //z coordinate will always be set to z - constant_deformer(double z); - virtual double z(double x, double y) const override; - -private: - double z_const; -}; - -#endif diff --git a/src/deformer.hpp b/src/deformer.hpp deleted file mode 100644 index 2161c48..0000000 --- a/src/deformer.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef DEFORMER_HPP_INCLUDED -#define DEFORMER_HPP_INCLUDED - -class deformer{ -public: - virtual double z(double x, double y) const = 0; -}; - -#endif diff --git a/src/dielectric.hpp b/src/dielectric.hpp deleted file mode 100644 index e48f173..0000000 --- a/src/dielectric.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef DIELECTRIC_HPP_INCLUDED -#define DIELECTRIC_HPP_INCLUDED - -#include <material.hpp> - -class dielectric: public material{ -public: - dielectric(double index_of_refraction_inside, double index_of_refraction_outside); - - virtual bool scatter( - const ray& r_in, const hit_record& rec, - double& fraction_reflected, ray& r_reflected, - double& fraction_refracted, ray& r_refracted - ) const override; - -private: - double reflectance(double cos_theta_in, double cos_theta_out, double ir_in, double ir_out) const; - double transmittance(double cos_theta_in, double cos_theta_out, double ir_in, double ir_out) const; - - double ir_inside; //index of refraction inside material - double ir_outside; //index of refraction outside material -}; - -#endif diff --git a/src/hittable.hpp b/src/hittable.hpp deleted file mode 100644 index 9259120..0000000 --- a/src/hittable.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef HITTABLE_HPP_INCLUDED -#define HITTABLE_HPP_INCLUDED - -#include <raytracing.hpp> - -class material; - -struct hit_record{ - point3 p; - vec3 normal; - std::shared_ptr<material> mat_ptr; - double t; - bool inbound; /*ray towards material? (direction ~= -normal)*/ -}; - -class hittable{ -public: - virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const = 0; -}; - -#endif diff --git a/src/hittable_list.hpp b/src/hittable_list.hpp deleted file mode 100644 index 5863a0c..0000000 --- a/src/hittable_list.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef HITTABLE_LIST_HPP_INCLUDED -#define HITTABLE_LIST_HPP_INCLUDED - -#include <hittable.hpp> -#include <memory> -#include <vector> - -class hittable_list: public hittable{ -public: - hittable_list(); - hittable_list(std::shared_ptr<hittable> object); - - void clear(); - void add(std::shared_ptr<hittable> object); - - virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const override; - -private: - std::vector<std::shared_ptr<hittable> > objects; -}; - -#endif diff --git a/src/linear_deformer.hpp b/src/linear_deformer.hpp deleted file mode 100644 index 6eae295..0000000 --- a/src/linear_deformer.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef LINEAR_DEFORMER_HPP_INCLUDED -#define LINEAR_DEFORMER_HPP_INCLUDED - -#include <deformer.hpp> -#include <vec3.hpp> - -class linear_deformer: public deformer{ -public: - //up = -1 to deform drum towards positive z - linear_deformer(double maxelong, double z_zero, double up, vec3 center); - virtual double z(double x, double y) const override; - -private: - double maxelong; - double z_zero; - double up; - point3 center; //drum center -}; - -#endif diff --git a/src/main.cpp b/src/main.cpp index 018fd9f..728811b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,8 +12,10 @@ #include <memory> #include <quartic_deformer.hpp> #include <quadratic_deformer.hpp> +#include <linear_deformer.hpp> #include <constant_deformer.hpp> #include <wavelength2rgb.hpp> +#include <chrono> #ifdef _OPENMP #include <omp.h> #endif @@ -44,7 +46,7 @@ color pixel_color(const ray& r, const hittable& world, const std::vector<vec3> s std::cerr << "Reflected: " << frac_refl << ", Refracted: " << frac_refr << "\n"; #endif /*We scattered*/ - if(std::fabs(r_refl.get_amplitude()) > 1e-6){ + if(std::fabs(r_refl.get_amplitude()) >= 1e-6){ rays_en_route.push_back(r_refl); } if(std::fabs(r_refr.get_amplitude()) >= 1e-6){ @@ -97,13 +99,14 @@ color pixel_color(const ray& r, const hittable& world, const std::vector<vec3> s int main(){ + auto start_main = std::chrono::high_resolution_clock::now(); #ifdef _OPENMP std::cerr << "Available Processing Units: " << omp_get_num_procs() << std::endl; #endif /*Image*/ - const int image_width = 512; - const int image_height = 512; + const int image_width = 256; + const int image_height = 256; /*World*/ hittable_list world; @@ -151,6 +154,7 @@ int main(){ quartic_deformer bot_def_quart_d1_2(0.000009, -2.0015, -1., vec3(-0.6581793068761733, -0.38, 0.)); quartic_deformer bot_def_quart_d2_2(0.000009, -2.0015, -1., vec3(0.6581793068761733, -0.38, 0.)); */ + /* quadratic_deformer top_def_quad_1(0.000999, -1.9995, 1., vec3(0., 0., 0.)); quadratic_deformer top_def_quad_2(0.000999, -2.0000, 1., vec3(0., 0., 0.)); quadratic_deformer bot_def_quad_d0_1(0.000999, -2.001, -1., vec3(0., 0.76, 0.)); @@ -159,6 +163,15 @@ int main(){ quadratic_deformer bot_def_quad_d0_2(0.000999, -2.0015, -1., vec3(0., 0.76, 0.)); quadratic_deformer bot_def_quad_d1_2(0.000999, -2.0015, -1., vec3(-0.6581793068761733, -0.38, 0.)); quadratic_deformer bot_def_quad_d2_2(0.000999, -2.0015, -1., vec3(0.6581793068761733, -0.38, 0.)); + */ + linear_deformer top_def_quad_1(0.000999, -1.9995, 1., vec3(0., 0., 0.)); + linear_deformer top_def_quad_2(0.000999, -2.0000, 1., vec3(0., 0., 0.)); + linear_deformer bot_def_quad_d0_1(0., -2.001, -1., vec3(0., 0.76, 0.)); + linear_deformer bot_def_quad_d1_1(0., -2.001, -1., vec3(-0.6581793068761733, -0.38, 0.)); + linear_deformer bot_def_quad_d2_1(0., -2.001, -1., vec3(0.6581793068761733, -0.38, 0.)); + linear_deformer bot_def_quad_d0_2(0., -2.0015, -1., vec3(0., 0.76, 0.)); + linear_deformer bot_def_quad_d1_2(0., -2.0015, -1., vec3(-0.6581793068761733, -0.38, 0.)); + linear_deformer bot_def_quad_d2_2(0., -2.0015, -1., vec3(0.6581793068761733, -0.38, 0.)); constant_deformer bot_def_sio2_si3n4(-2.0015); constant_deformer bot_def_si_sio2(-2.0018); constant_deformer bot_def_si_air(-2.3818); @@ -221,6 +234,7 @@ int main(){ /*Render*/ std::cout << "P3\n" << image_width << " " << image_height << "\n255\n"; + auto start_parallel = std::chrono::high_resolution_clock::now(); #ifdef _OPENMP int scanlines_done = 0; #pragma omp parallel shared(cam, world, colors, wavelengths, color_storage, scanlines_done) @@ -264,8 +278,16 @@ int main(){ #ifdef _OPENMP } #endif + auto end_parallel = std::chrono::high_resolution_clock::now(); for(const auto& col: color_storage){ write_color(std::cout, col, 1); } std::cerr << "\nDone.\n"; + auto end_main = std::chrono::high_resolution_clock::now(); + using namespace std::literals; + std::cerr << "\nTiming Information:\n" + << "Setup Time: " << (start_parallel - start_main) / 1us / 1000000. << "s\n" + << "Parallel Time: " << static_cast<int>((end_parallel - start_parallel) / 1h) << "h " << static_cast<int>((end_parallel - start_parallel) / 1min) % 60 << "min " << static_cast<int>((end_parallel - start_parallel) / 1s) % 60 << "s\n" + << "Output Time: " << (end_main - end_parallel) / 1us / 1000000. << "s\n" + << "Total Time: " << static_cast<int>((end_main - start_main) / 1h) << "h " << static_cast<int>((end_main - start_main) / 1min) % 60 << "min " << static_cast<int>((end_main - start_main) / 1s) % 60 << "s\n"; } diff --git a/src/material.hpp b/src/material.hpp deleted file mode 100644 index 903de94..0000000 --- a/src/material.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef MATERIAL_HPP_INCLUDED -#define MATERIAL_HPP_INCLUDED - -#include <raytracing.hpp> -#include <hittable.hpp> - -class material{ -public: - /*returns true if ray was scattered, false if it arrived at a source or was absorbed*/ - /* return fraction_reflected fraction_refracted meaning - * true !=0 !=0 ray was reflected and refracted, results in r_reflected and r_refracted - * true 0 1. everything was refracted, result in r_refracted - * true 1. 0. everything was reflected, result in r_reflected - * false 0. X ray was absorbed, bounce limit reached - * false 1. X ray hit source, final ray in r_reflected - * - */ - virtual bool scatter( - const ray& r_in, const hit_record& rec, - double& fraction_reflected, ray& r_reflected, - double& fraction_refracted, ray& r_refracted - ) const = 0; -}; - -#endif diff --git a/src/quadratic_deformer.hpp b/src/quadratic_deformer.hpp deleted file mode 100644 index 622617c..0000000 --- a/src/quadratic_deformer.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef QUADRATIC_DEFORMER_HPP_INCLUDED -#define QUADRATIC_DEFORMER_HPP_INCLUDED - -#include <deformer.hpp> -#include <vec3.hpp> - -class quadratic_deformer: public deformer{ -public: - //up = -1 to deform drum towards positive z - quadratic_deformer(double maxelong, double z_zero, double up, vec3 center); - virtual double z(double x, double y) const override; - -private: - double maxelong; - double z_zero; - double up; - point3 center; //drum center -}; - -#endif diff --git a/src/quartic_deformer.hpp b/src/quartic_deformer.hpp deleted file mode 100644 index effb46a..0000000 --- a/src/quartic_deformer.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef QUARTIC_DEFORMER_HPP_INCLUDED -#define QUARTIC_DEFORMER_HPP_INCLUDED - -#include <deformer.hpp> -#include <vec3.hpp> - -class quartic_deformer: public deformer{ -public: - //up = -1 to deform drum towards positive z - quartic_deformer(double maxelong, double z_zero, double up, vec3 center); - virtual double z(double x, double y) const override; - -private: - double maxelong; - double z_zero; - double up; - point3 center; //drum center -}; - -#endif diff --git a/src/radiator.hpp b/src/radiator.hpp deleted file mode 100644 index b138316..0000000 --- a/src/radiator.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef RADIATOR_HPP_INCLUDED -#define RADIATOR_HPP_INCLUDED - -#include <material.hpp> -#include <vec3.hpp> - -class radiator: public material{ -public: - radiator(int sourceID); - - virtual bool scatter( - const ray& r_in, const hit_record& rec, - double& fraction_reflected, ray& r_reflected, - double& fraction_refracted, ray& r_refracted - ) const override; - -private: - int sourceID; -}; - -#endif diff --git a/src/ray.cpp b/src/ray.cpp index 9fa3594..d012aee 100644 --- a/src/ray.cpp +++ b/src/ray.cpp @@ -3,7 +3,7 @@ ray::ray() {} ray::ray(const point3& origin, const vec3& direction, double amplitude, double opl, double index_of_refraction, int phase_flips, int max_bounces) -: orig(origin), dir(direction), optical_path(opl), amplitude(amplitude), refractive_index(index_of_refraction), +: orig(origin), dir(direction), optical_path(opl), refractive_index(index_of_refraction), amplitude(amplitude), phase_flips(phase_flips), source(0), bounces_left(max_bounces){ } diff --git a/src/ray.hpp b/src/ray.hpp deleted file mode 100644 index 87f481a..0000000 --- a/src/ray.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef RAY_HPP_INCLUDED -#define RAY_HPP_INCLUDED - -#include <vec3.hpp> - -class ray{ -public: - ray(); - ray(const point3& origin, const vec3& direction, double amplitude, double opl, double refractive_index, int phase_flips, int max_bounces); - - point3 origin() const; - vec3 direction() const; - - point3 at(double t) const; - - double optical_path_to(double t) const; - double refractive_index_current() const; - - int get_bounces_left() const; - int get_phaseflips() const; - void set_source(int n); - int get_source() const; - - double get_amplitude() const; - -private: - point3 orig; - vec3 dir; - double optical_path; //optical path since pixel - double refractive_index; //refractive index of next straight path - int phase_flips; //number of phase flips accumulated so far (from refl.) - int source; //information about the source the ray ended at (0 for none) - int bounces_left; //number of bounces the ray can perform - double amplitude; //amplitude left in the ray -}; - -#endif diff --git a/src/raytracing.hpp b/src/raytracing.hpp deleted file mode 100644 index 835431e..0000000 --- a/src/raytracing.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef RAYTRACING_HPP_INCLUDED -#define RAYTRACING_HPP_INCLUDED - -#include <cmath> -#include <limits> -#include <memory> -#include <random> - -/*Constants*/ -const double infinity = std::numeric_limits<double>::infinity(); -const double pi = 3.141592653589793238462643383279; - -/*Utility*/ -double degrees_to_radians(double degrees); -double random_double(); -double random_double(double min, double max); -double clamp(double x, double min, double max); - -/*Includes*/ -#include <ray.hpp> -#include <vec3.hpp> -#include <color.hpp> - -#endif diff --git a/src/triangle.hpp b/src/triangle.hpp deleted file mode 100644 index f766f87..0000000 --- a/src/triangle.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TRIANGLE_HPP_INCLUDED -#define TRIANGLE_HPP_INCLUDED - -#include <hittable.hpp> -#include <vec3.hpp> -#include <material.hpp> -#include <memory> - -/*normals always point towards the lower refractive index (i.e. outwards)*/ -/*c1, c2, c3 are to be given in anti-clockwise direction as seen from outside*/ -class triangle: public hittable{ -public: - triangle(); - /*normal = (c2-c1) x (c3-c1)*/ - triangle(point3 c1, point3 c2, point3 c3, std::shared_ptr<material> m); - - virtual bool hit( - const ray& r, double t_min, double t_max, hit_record& rec) const override; - -private: - point3 c1, c2, c3; /*corners of the triangle*/ - vec3 normal; /*normal on the triangle, facing outwards*/ - double D; /*offset of plane, E: A*nx+B*ny+C*nz+D=0 */ - vec3 c1c2, c1c3; /*in-plane vectors*/ - std::shared_ptr<material> mat_ptr; /*material bounded by triangle*/ -}; - -#endif diff --git a/src/triangle_mesh.hpp b/src/triangle_mesh.hpp deleted file mode 100644 index 92ae4e5..0000000 --- a/src/triangle_mesh.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef TRIANGLE_MESH_HPP_INCLUDED -#define TRIANGLE_MESH_HPP_INCLUDED - -#include <hittable.hpp> -#include <vec3.hpp> -#include <material.hpp> -#include <memory> -#include <string> -#include <triangle.hpp> -#include <deformer.hpp> - -class triangle_mesh: public hittable{ -public: - //n_z_sign = sign that triangle normals z component should have - triangle_mesh(std::string filename, std::shared_ptr<material> m, double n_z_sign, const deformer* fun); - - virtual bool hit( - const ray& r, double t_min, double t_max, hit_record& rec) const override; - -private: - std::vector<triangle> triangles; - std::string mesh_file; -}; - -#endif diff --git a/src/vec3.hpp b/src/vec3.hpp deleted file mode 100644 index 946fbd3..0000000 --- a/src/vec3.hpp +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef VEC3_HPP_INCLUDED -#define VEC3_HPP_INCLUDED - -#include <cmath> -#include <iostream> - -class vec3{ -public: - vec3(); - vec3(double x, double y, double z); - - double x() const; - double y() const; - double z() const; - - vec3 operator-() const; - double operator[](int i) const; - double& operator[](int i); - - vec3& operator+=(const vec3&); - vec3& operator-=(const vec3&); - vec3& operator*=(const double); - vec3& operator/=(const double); - - double length() const; - double length_squared() const; - bool near_zero() const; - - static vec3 random(); - static vec3 random(double min, double max); - -private: - double e[3]; -}; - -using point3 = vec3; -using color = vec3; - -/*Utility*/ -std::ostream& operator<<(std::ostream & out, const vec3& v); - -vec3 operator+(const vec3 lhs, const vec3& rhs); - -vec3 operator-(const vec3 lhs, const vec3& rhs); - -vec3 operator*(const vec3 lhs, const vec3& rhs); - -vec3 operator*(vec3 lhs, const double t); - -vec3 operator*(const double t, vec3 rhs); - -vec3 operator/(vec3 v, double t); - -double dot(const vec3& lhs, const vec3& rhs); - -vec3 cross(const vec3& lhs, const vec3& rhs); - -vec3 unit_vector(vec3 v); - -vec3 random_in_unit_sphere(); - -/*n points up, v points down*/ -vec3 reflect(const vec3& v, const vec3& n); - -/*n points up, v points down*/ -/*refraction_ratio = n_old / n_new */ -vec3 refract(const vec3& unit_v, const vec3& n, double refraction_ratio); - -#endif diff --git a/src/wavelength2rgb.hpp b/src/wavelength2rgb.hpp deleted file mode 100644 index b3eedf4..0000000 --- a/src/wavelength2rgb.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WAVELENGTH2RGB_HPP_INCLUDED -#define WAVELENGTH2RGB_HPP_INCLUDED -#include <vec3.hpp> - -class wavelength2rgb{ -public: - wavelength2rgb(double nm_min, double nm_max, double nm_step); - - color operator()(double nm) const; - -private: - double nm_min; - double nm_max; - double nm_step; -}; - -#endif diff --git a/src/xyplane.hpp b/src/xyplane.hpp deleted file mode 100644 index 8df9bb7..0000000 --- a/src/xyplane.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef XYPLANE_HPP_INCLUDED -#define XYPLANE_HPP_INCLUDED - -#include <hittable.hpp> -#include <memory> - -class xyplane: public hittable{ -public: - xyplane(); - xyplane(double z, std::shared_ptr<material> mat_ptr); - - virtual bool hit( - const ray& r, double t_min, double t_max, hit_record& rec) const override; - -private: - const double z; - vec3 normal; - std::shared_ptr<material> mat_ptr; -}; - -#endif -- GitLab