diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/camera.hpp | 24 | ||||
| -rw-r--r-- | include/dielectric.hpp | 18 | ||||
| -rw-r--r-- | include/hittable.hpp | 28 | ||||
| -rw-r--r-- | include/hittable_list.hpp | 21 | ||||
| -rw-r--r-- | include/lambertian.hpp | 15 | ||||
| -rw-r--r-- | include/material.hpp | 17 | ||||
| -rw-r--r-- | include/metal.hpp | 16 | ||||
| -rw-r--r-- | include/ray.hpp | 18 | ||||
| -rw-r--r-- | include/rt.hpp | 35 | ||||
| -rw-r--r-- | include/sphere.hpp | 15 | ||||
| -rw-r--r-- | include/utils.hpp | 20 | ||||
| -rw-r--r-- | include/vk-renderer.hpp | 34 |
12 files changed, 55 insertions, 206 deletions
diff --git a/include/camera.hpp b/include/camera.hpp index 858833b..43ed755 100644 --- a/include/camera.hpp +++ b/include/camera.hpp @@ -1,35 +1,31 @@ #ifndef __CAMERA_HPP_ #define __CAMERA_HPP_ -#include "ray.hpp" +#include "vec3.hpp" class camera { public: camera( point3 position, point3 target, - double v_fov, - double aspect_ratio, - double aperture, - double focus_dist + float v_fov, + float aspect_ratio, + float aperture, + float focus_dist ); - ray get_ray(double u, double v) const; - point3 position; - float lens_radius; - float viewport_width; - float viewport_height; + vec3 right; + vec3 up; vec3 horizontal; vec3 vertical; - vec3 forward; - vec3 right; - vec3 up; + vec3 first_pixel; - point3 bottom_left_pixel; + float lens_radius; + float padding[3]; }; #endif // !__CAMERA_HPP_ diff --git a/include/dielectric.hpp b/include/dielectric.hpp deleted file mode 100644 index 91f1541..0000000 --- a/include/dielectric.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __DIELECTRIC_HPP_ -#define __DIELECTRIC_HPP_ - -#include "material.hpp" - -class dielectric : public material { - public: - dielectric(double index_of_refraction); - - virtual bool scatter(const ray& r, const struct hit_info& info, color& attenuation, ray& scattered) const; - - double ior; - - private: - static double reflectance(double cosine, double ref_idx); -}; - -#endif // !__DIELECTRIC_HPP_ diff --git a/include/hittable.hpp b/include/hittable.hpp deleted file mode 100644 index 074de55..0000000 --- a/include/hittable.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __HITTABLE_HPP_ -#define __HITTABLE_HPP_ - -#include <memory> - -#include "ray.hpp" - -class material; - -struct hit_info { - double t; - point3 point; - vec3 normal; - bool front_face; - std::shared_ptr<material> mat_ptr; - - inline void set_face_normal(const ray& r, const vec3& outward_normal) { - front_face = r.direction.dot(outward_normal) < 0.0; - normal = front_face ? outward_normal : (-outward_normal); - } -}; - -class hittable { - public: - virtual bool hit(const ray& r, double t_min, double t_max, struct hit_info& info) const = 0; -}; - -#endif // !__HITTABLE_HPP_ diff --git a/include/hittable_list.hpp b/include/hittable_list.hpp deleted file mode 100644 index 41d8f4a..0000000 --- a/include/hittable_list.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __HITTABLE_LIST_HPP_ -#define __HITTABLE_LIST_HPP_ - -#include <vector> -#include <memory> - -#include "hittable.hpp" - -class hittable_list : public hittable { - public: - hittable_list(); - - void add(std::shared_ptr<hittable> hittable); - void clear(); - - virtual bool hit(const ray&r, double t_min, double t_max, struct hit_info& info) const; - - std::vector<std::shared_ptr<hittable>> hittables; -}; - -#endif // !__HITTABLE_LIST_HPP_ diff --git a/include/lambertian.hpp b/include/lambertian.hpp deleted file mode 100644 index b9b7509..0000000 --- a/include/lambertian.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __LAMBERTIAN_HPP_ -#define __LAMBERTIAN_HPP_ - -#include "material.hpp" - -class lambertian : public material { - public: - lambertian(const color& albedo); - - virtual bool scatter(const ray& r, const struct hit_info& info, color& attenuation, ray& scattered) const; - - color albedo; -}; - -#endif // !__LAMBERTIAN_HPP_ diff --git a/include/material.hpp b/include/material.hpp index 5e6f095..10886da 100644 --- a/include/material.hpp +++ b/include/material.hpp @@ -1,13 +1,20 @@ #ifndef __MATERIAL_HPP_ #define __MATERIAL_HPP_ -#include "ray.hpp" +#include "vec3.hpp" -struct hit_info; +enum MATERIAL_TYPE: uint32_t { + LAMBERTIAN = 0, + METAL = 1, + DIELECTRIC = 2, +}; -class material { - public: - virtual bool scatter(const ray& r, const struct hit_info& info, color& attenuation, ray& scaterred) const = 0; +struct material { + color albedo; + float fuzz; + float ior; + uint32_t type; + uint32_t padding; }; #endif // !__MATERIAL_HPP_ diff --git a/include/metal.hpp b/include/metal.hpp deleted file mode 100644 index 5516890..0000000 --- a/include/metal.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __METAL_HPP_ -#define __METAL_HPP_ - -#include "material.hpp" - -class metal : public material { - public: - metal(const color& albedo, double f); - - virtual bool scatter(const ray& r, const struct hit_info& info, color& attenuation, ray& scattered) const; - - color albedo; - double fuzz; -}; - -#endif // !__METAL_HPP_ diff --git a/include/ray.hpp b/include/ray.hpp deleted file mode 100644 index e18812e..0000000 --- a/include/ray.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __RAY_HPP_ -#define __RAY_HPP_ - -#include "vec3.hpp" - -class ray { - public: - - ray(); - ray(const point3& origin, const vec3& direction); - - point3 at(double t) const; - - point3 origin; - vec3 direction; -}; - -#endif // !__RAY_HPP_ diff --git a/include/rt.hpp b/include/rt.hpp index 09cf1b0..2898045 100644 --- a/include/rt.hpp +++ b/include/rt.hpp @@ -1,40 +1,11 @@ #ifndef __RT_HPP_ #define __RT_HPP_ -#include <limits> -#include <cstdlib> - -const float pi = 3.1415926535897932385f; -const float infinity = std::numeric_limits<float>::infinity(); - -inline float deg_to_rad(float deg) { - return deg * pi / 180.0; -} - -inline float randd() { - return rand() / (RAND_MAX + 1.0); -} - -inline float randd(float min, float max) { - return min + randd() * (max - min); -} - -inline float clamp(float x, float min, float max) { - if (x < min) return min; - if (x > max) return max; - return x; -} - - +#include "utils.hpp" #include "vec3.hpp" -#include "ray.hpp" #include "color.hpp" -// #include "sphere.hpp" +#include "sphere.hpp" #include "camera.hpp" -// #include "material.hpp" -// #include "lambertian.hpp" -// #include "metal.hpp" -// #include "dielectric.hpp" -// #include "hittable_list.hpp" +#include "material.hpp" #endif // !__RT_HPP_ diff --git a/include/sphere.hpp b/include/sphere.hpp index c33a796..a338f2e 100644 --- a/include/sphere.hpp +++ b/include/sphere.hpp @@ -1,19 +1,18 @@ #ifndef __SPHERE_HPP_ #define __SPHERE_HPP_ -#include "hittable.hpp" #include "material.hpp" -class sphere : public hittable { - public: - sphere(point3 center, double radius, std::shared_ptr<material> material); +struct sphere{ + sphere() = default; + sphere(point3 center, material material, float radius); - virtual bool hit(const ray& r, double t_min, double t_max, struct hit_info& info) const; + point3 center; - point3 center; - double radius; + material mat; - std::shared_ptr<material> mat_ptr; + float radius; + float padding[3]; }; #endif // !__SPHERE_HPP_ diff --git a/include/utils.hpp b/include/utils.hpp index efa007d..0bef213 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -5,6 +5,26 @@ #include <vector> +#include <cmath> +#include <cstdlib> + std::vector<uint8_t> get_shader_code(const char* path); +inline float deg_to_rad(float deg) { + return deg * M_PI / 180.0; +} + +inline float randd() { + return rand() / (RAND_MAX + 1.0); +} + +inline float randd(float min, float max) { + return min + randd() * (max - min); +} +inline float clamp(float x, float min, float max) { + if (x < min) return min; + if (x > max) return max; + return x; +} + #endif // !__UTILS_HPP_ diff --git a/include/vk-renderer.hpp b/include/vk-renderer.hpp index 70fcc7e..37a3494 100644 --- a/include/vk-renderer.hpp +++ b/include/vk-renderer.hpp @@ -5,42 +5,14 @@ #include "thirdparty/vk_mem_alloc.h" #include "vec3.hpp" - -enum MATERIAL_TYPE: uint32_t { - LAMBERTIAN = 0, - METAL = 1, - DIELECTRIC = 2, -}; - -struct material { - color albedo; - float fuzz; - float ior; - uint32_t type; - uint32_t padding; -}; - -struct sphere { - vec3 position; - material mat; - float radius; - float padding[3]; -}; +#include "camera.hpp" +#include "sphere.hpp" struct input_data { color sky_color; color ground_color; - struct camera { - vec3 position; - vec3 up; - vec3 right; - vec3 forward; - float viewport_width; - float viewport_height; - float lens_radius; - float focus_distance; - } cam; + camera cam; float random_offset[2000]; float random_disk[2000]; |
