Skip to content

Commit

Permalink
#pragma once
Browse files Browse the repository at this point in the history
  • Loading branch information
catinjar committed Dec 6, 2021
1 parent 4137616 commit b2e29fe
Show file tree
Hide file tree
Showing 40 changed files with 78 additions and 251 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ project(RayTracer)

set(CMAKE_CXX_STANDARD 20)

add_executable(RayTracer src/main.cpp src/Vector3.cpp src/Vector3.hpp src/Ray.hpp src/HitRecord.hpp src/Hitable.hpp src/Sphere.cpp src/Sphere.hpp src/HitableList.cpp src/HitableList.hpp src/Camera.cpp src/Camera.hpp src/Material.hpp src/Lambertian.cpp src/Lambertian.hpp src/MathHelpers.cpp src/MathHelpers.hpp src/Metal.cpp src/Metal.hpp src/Dielectric.cpp src/Dielectric.hpp src/AABB.cpp src/AABB.hpp src/BvhNode.cpp src/BvhNode.hpp src/Texture.hpp src/ConstantTexture.cpp src/ConstantTexture.hpp src/CheckerTexture.cpp src/CheckerTexture.hpp src/Perlin.cpp src/Perlin.hpp src/NoiseTexture.cpp src/NoiseTexture.hpp src/ImageHelpers.cpp src/ImageHelpers.hpp src/ImageTexture.cpp src/ImageTexture.hpp src/DiffuseLight.cpp src/DiffuseLight.hpp src/Rect.hpp src/Scene.cpp src/Scene.hpp src/FlipNormals.cpp src/FlipNormals.hpp src/Box.cpp src/Box.hpp src/Translate.cpp src/Translate.hpp src/RotateY.cpp src/RotateY.hpp src/Isotropic.cpp src/Isotropic.hpp src/ConstantMedium.cpp src/ConstantMedium.hpp src/OrthoNormalBasis.cpp src/OrthoNormalBasis.hpp src/Pdf.hpp src/CosinePdf.cpp src/CosinePdf.hpp src/HitablePdf.cpp src/HitablePdf.hpp src/MixturePdf.cpp src/MixturePdf.hpp src/ScatterRecord.h src/ColorHelpers.cpp src/ColorHelpers.h)
add_executable(RayTracer src/main.cpp src/Vector3.cpp src/Vector3.hpp src/Ray.hpp src/HitRecord.hpp src/Hitable.hpp src/Sphere.cpp src/Sphere.hpp src/HitableList.cpp src/HitableList.hpp src/Camera.cpp src/Camera.hpp src/Material.hpp src/Lambertian.cpp src/Lambertian.hpp src/MathHelpers.cpp src/MathHelpers.hpp src/Metal.cpp src/Metal.hpp src/Dielectric.cpp src/Dielectric.hpp src/AABB.cpp src/AABB.hpp src/BvhNode.cpp src/BvhNode.hpp src/Texture.hpp src/ConstantTexture.cpp src/ConstantTexture.hpp src/CheckerTexture.cpp src/CheckerTexture.hpp src/Perlin.cpp src/Perlin.hpp src/NoiseTexture.cpp src/NoiseTexture.hpp src/ImageHelpers.cpp src/ImageHelpers.hpp src/ImageTexture.cpp src/ImageTexture.hpp src/DiffuseLight.cpp src/DiffuseLight.hpp src/Rect.hpp src/Scene.cpp src/Scene.hpp src/FlipNormals.cpp src/FlipNormals.hpp src/Box.cpp src/Box.hpp src/Translate.cpp src/Translate.hpp src/RotateY.cpp src/RotateY.hpp src/Isotropic.cpp src/Isotropic.hpp src/ConstantMedium.cpp src/ConstantMedium.hpp src/OrthoNormalBasis.cpp src/OrthoNormalBasis.hpp src/Pdf.hpp src/CosinePdf.cpp src/CosinePdf.hpp src/HitablePdf.cpp src/HitablePdf.hpp src/MixturePdf.cpp src/MixturePdf.hpp src/ScatterRecord.hpp src/ColorHelpers.cpp src/ColorHelpers.hpp)
8 changes: 2 additions & 6 deletions src/AABB.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_AABB_HPP
#define RAYTRACER_AABB_HPP

#pragma once

#include "Vector3.hpp"
#include "Ray.hpp"
Expand All @@ -17,6 +15,4 @@ class AABB
Vector3 max;
};

AABB SurroundingBox(AABB box1, AABB box2);

#endif //RAYTRACER_AABB_HPP
AABB SurroundingBox(AABB box1, AABB box2);
9 changes: 2 additions & 7 deletions src/Box.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_BOX_HPP
#define RAYTRACER_BOX_HPP

#pragma once

#include "HitableList.hpp"

Expand All @@ -15,7 +13,4 @@ class Box : public Hitable
Vector3 min;
Vector3 max;
HitableList sides;
};


#endif //RAYTRACER_BOX_HPP
};
8 changes: 2 additions & 6 deletions src/BvhNode.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef RAYTRACER_BVHNODE_HPP
#define RAYTRACER_BVHNODE_HPP
#pragma once

#include <vector>

Expand All @@ -18,7 +17,4 @@ class BvhNode : public Hitable
std::shared_ptr<Hitable> right {};

AABB boundingBox {};
};


#endif //RAYTRACER_BVHNODE_HPP
};
9 changes: 2 additions & 7 deletions src/Camera.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_CAMERA_HPP
#define RAYTRACER_CAMERA_HPP

#pragma once

#include "Vector3.hpp"
#include "Ray.hpp"
Expand All @@ -25,7 +23,4 @@ class Camera
float lensRadius = 0;
float timeStart = 0;
float timeEnd = 1;
};


#endif //RAYTRACER_CAMERA_HPP
};
9 changes: 2 additions & 7 deletions src/CheckerTexture.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_CHECKERTEXTURE_HPP
#define RAYTRACER_CHECKERTEXTURE_HPP

#pragma once

#include <utility>

Expand All @@ -16,7 +14,4 @@ class CheckerTexture : public Texture

std::shared_ptr<Texture> even;
std::shared_ptr<Texture> odd;
};


#endif //RAYTRACER_CHECKERTEXTURE_HPP
};
2 changes: 1 addition & 1 deletion src/ColorHelpers.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ColorHelpers.h"
#include "ColorHelpers.hpp"

Vector3 DeNan(const Vector3 &color)
{
Expand Down
10 changes: 0 additions & 10 deletions src/ColorHelpers.h

This file was deleted.

6 changes: 6 additions & 0 deletions src/ColorHelpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "Vector3.hpp"

Vector3 DeNan(const Vector3 &color);
Vector3 GammaCorrect(const Vector3 &color);
9 changes: 2 additions & 7 deletions src/ConstantMedium.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_CONSTANTMEDIUM_HPP
#define RAYTRACER_CONSTANTMEDIUM_HPP

#pragma once

#include "Hitable.hpp"
#include "Texture.hpp"
Expand All @@ -19,7 +17,4 @@ class ConstantMedium : public Hitable
std::shared_ptr<Hitable> hitable;
float density;
std::shared_ptr<Material> phaseFunction;
};


#endif //RAYTRACER_CONSTANTMEDIUM_HPP
};
9 changes: 2 additions & 7 deletions src/ConstantTexture.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_CONSTANTTEXTURE_HPP
#define RAYTRACER_CONSTANTTEXTURE_HPP

#pragma once

#include "Texture.hpp"

Expand All @@ -13,7 +11,4 @@ class ConstantTexture : public Texture
Vector3 Value(float u, float v, const Vector3& point) const override;

Vector3 color {};
};


#endif //RAYTRACER_CONSTANTTEXTURE_HPP
};
9 changes: 2 additions & 7 deletions src/CosinePdf.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_COSINEPDF_HPP
#define RAYTRACER_COSINEPDF_HPP

#pragma once

#include "Pdf.hpp"
#include "OrthoNormalBasis.hpp"
Expand All @@ -14,7 +12,4 @@ class CosinePdf : public Pdf
Vector3 Generate() const override;

OrthoNormalBasis onb;
};


#endif //RAYTRACER_COSINEPDF_HPP
};
9 changes: 2 additions & 7 deletions src/Dielectric.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_DIELECTRIC_HPP
#define RAYTRACER_DIELECTRIC_HPP

#pragma once

#include "Material.hpp"

Expand All @@ -12,7 +10,4 @@ class Dielectric : public Material
bool Scatter(const Ray &ray, const HitRecord &hitRecord, ScatterRecord &scatterRecord) const override;

float refractiveIndex;
};


#endif //RAYTRACER_DIELECTRIC_HPP
};
9 changes: 2 additions & 7 deletions src/DiffuseLight.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_DIFFUSELIGHT_HPP
#define RAYTRACER_DIFFUSELIGHT_HPP

#pragma once

#include <utility>

Expand All @@ -16,7 +14,4 @@ class DiffuseLight : public Material
Vector3 Emitted(const Ray &ray, const HitRecord &hitRecord, float u, float v, const Vector3 &point) const override;

std::shared_ptr<Texture> texture;
};


#endif //RAYTRACER_DIFFUSELIGHT_HPP
};
9 changes: 2 additions & 7 deletions src/FlipNormals.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_FLIPNORMALS_HPP
#define RAYTRACER_FLIPNORMALS_HPP

#pragma once

#include "Hitable.hpp"

Expand All @@ -13,7 +11,4 @@ class FlipNormals : public Hitable
bool BoundingBox(AABB &box, float timeStart, float timeEnd) const override;

std::shared_ptr<Hitable> hitable;
};


#endif //RAYTRACER_FLIPNORMALS_HPP
};
9 changes: 2 additions & 7 deletions src/HitRecord.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_HITRECORD_HPP
#define RAYTRACER_HITRECORD_HPP

#pragma once

#include "Vector3.hpp"

Expand All @@ -14,7 +12,4 @@ struct HitRecord
Material* material;
float u;
float v;
};


#endif //RAYTRACER_HITRECORD_HPP
};
9 changes: 2 additions & 7 deletions src/Hitable.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_HITABLE_HPP
#define RAYTRACER_HITABLE_HPP

#pragma once

#include "Ray.hpp"
#include "HitRecord.hpp"
Expand All @@ -14,7 +12,4 @@ class Hitable

virtual float PdfValue(const Vector3 &origin, const Vector3 &direction) const { return 0; }
virtual Vector3 Random(const Vector3 &origin) const { return { 1, 0, 0 }; }
};


#endif //RAYTRACER_HITABLE_HPP
};
9 changes: 2 additions & 7 deletions src/HitableList.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_HITABLELIST_HPP
#define RAYTRACER_HITABLELIST_HPP

#pragma once

#include <utility>
#include <vector>
Expand Down Expand Up @@ -28,7 +26,4 @@ class HitableList : public Hitable

private:
std::vector<std::shared_ptr<Hitable>> hitables;
};


#endif //RAYTRACER_HITABLELIST_HPP
};
9 changes: 2 additions & 7 deletions src/HitablePdf.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_HITABLEPDF_HPP
#define RAYTRACER_HITABLEPDF_HPP

#pragma once

#include "Pdf.hpp"

Expand All @@ -18,7 +16,4 @@ class HitablePdf : public Pdf

std::shared_ptr<Hitable> hitable;
Vector3 origin;
};


#endif //RAYTRACER_HITABLEPDF_HPP
};
9 changes: 2 additions & 7 deletions src/ImageHelpers.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#ifndef RAYTRACER_IMAGEHELPERS_HPP
#define RAYTRACER_IMAGEHELPERS_HPP

#pragma once

#include <vector>

#include "Vector3.hpp"

unsigned char* LoadPng(const char* filename, int &width, int &height);
void SavePng(const char* filename, int width, int height, const std::vector<Vector3> &pixels);


#endif //RAYTRACER_IMAGEHELPERS_HPP
void SavePng(const char* filename, int width, int height, const std::vector<Vector3> &pixels);
9 changes: 2 additions & 7 deletions src/ImageTexture.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_IMAGETEXTURE_HPP
#define RAYTRACER_IMAGETEXTURE_HPP

#pragma once

#include "Texture.hpp"

Expand All @@ -14,7 +12,4 @@ class ImageTexture : public Texture

int width = 0, height = 0;
unsigned char* pixels;
};


#endif //RAYTRACER_IMAGETEXTURE_HPP
};
9 changes: 2 additions & 7 deletions src/Isotropic.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_ISOTROPIC_HPP
#define RAYTRACER_ISOTROPIC_HPP

#pragma once

#include <utility>

Expand All @@ -16,7 +14,4 @@ class Isotropic : public Material
float ScatteringPdf(const Ray &ray, const HitRecord &hitRecord, const Ray &scattered) const override;

std::shared_ptr<Texture> texture;
};


#endif //RAYTRACER_ISOTROPIC_HPP
};
9 changes: 2 additions & 7 deletions src/Lambertian.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef RAYTRACER_LAMBERTIAN_HPP
#define RAYTRACER_LAMBERTIAN_HPP

#pragma once

#include <utility>

Expand All @@ -17,7 +15,4 @@ class Lambertian : public Material
float ScatteringPdf(const Ray &ray, const HitRecord &hitRecord, const Ray &scattered) const override;

std::shared_ptr<Texture> texture;
};


#endif //RAYTRACER_LAMBERTIAN_HPP
};
11 changes: 3 additions & 8 deletions src/Material.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#ifndef RAYTRACER_MATERIAL_HPP
#define RAYTRACER_MATERIAL_HPP

#pragma once

#include "Ray.hpp"
#include "HitRecord.hpp"
#include "ScatterRecord.h"
#include "ScatterRecord.hpp"

class Material
{
public:
virtual bool Scatter(const Ray& ray, const HitRecord& hitRecord, ScatterRecord &scatterRecord) const { return false; }
virtual float ScatteringPdf(const Ray &ray, const HitRecord &hitRecord, const Ray &scattered) const { return 0; }
virtual Vector3 Emitted(const Ray &ray, const HitRecord &hitRecord, float u, float v, const Vector3 &point) const { return {0, 0, 0}; }
};


#endif //RAYTRACER_MATERIAL_HPP
};
Loading

0 comments on commit b2e29fe

Please sign in to comment.