-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Developmentnow it's rendring #37
base: development
Are you sure you want to change the base?
Conversation
return std::acos(dot(v1,v2)/(v1.norm()*v2.norm())); | ||
} | ||
CONSTEXPR_CMATH vec4 unit() const{ | ||
constexpr vec4 unit() const{ | ||
return *this/this->norm(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that supposed to be taken care of by the std library we are using?
@@ -41,7 +58,8 @@ class Cube | |||
vec3 m_position; | |||
vec3 m_a, m_b, m_c; | |||
Material m_material; | |||
static const double m_epsilon = 1e-5; | |||
vec3 int_pt; | |||
const double m_epsilon = 1e-5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you make m_epsilon
a non-static member?
@@ -7,6 +7,23 @@ | |||
#include "ray.hpp" | |||
#include "material.hpp" | |||
|
|||
|
|||
//debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this comment mean?
@@ -7,6 +7,23 @@ | |||
#include "ray.hpp" | |||
#include "material.hpp" | |||
|
|||
|
|||
//debug | |||
class HitInfo{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HitInfo
struct should be in its own header file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a class
? It should be a struct
.
int depth; | ||
|
||
public: | ||
HitInfo(bool if_hit, vec3 v, Material m, ray r, int d):if_hit{if_hit}, dist_v{v}, mat{m}, r{r}, depth{d}{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Members of struct
s are public by default. Also, this constructor is not needed. The compiler will auto-generate it for you.
HitInfo(bool if_hit, vec3 v, Material m, ray r, int d):if_hit{if_hit}, dist_v{v}, mat{m}, r{r}, depth{d}{}; | ||
|
||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there so many blank spaces?
|
||
sc.render(); | ||
|
||
int max_col = 255; | ||
std::ofstream image("sphere.ppm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add the ppm code back in, and remove the png/jpg code?
@@ -35,6 +35,8 @@ class alignas(ALIGN_WIDTH) vec3 : public vec4{ | |||
constexpr explicit vec3(Utype x) : vec4{x,x,x,0} {} | |||
constexpr vec3(Utype x,Utype y,Utype z) : vec4{x,y,z,0} {} | |||
explicit vec3(xsimd::batch<Utype,UArch> x) : vec4{x} {} | |||
constexpr vec3(vec4 a): vec4{a.x(), a.y(), a.z(), a.w()}{} | |||
vec3() = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this constructor necessary?
@@ -35,6 +35,8 @@ class alignas(ALIGN_WIDTH) vec3 : public vec4{ | |||
constexpr explicit vec3(Utype x) : vec4{x,x,x,0} {} | |||
constexpr vec3(Utype x,Utype y,Utype z) : vec4{x,y,z,0} {} | |||
explicit vec3(xsimd::batch<Utype,UArch> x) : vec4{x} {} | |||
constexpr vec3(vec4 a): vec4{a.x(), a.y(), a.z(), a.w()}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you trying to do here?
@@ -7,7 +7,6 @@ | |||
#include <type_traits> // for std::is_constant_evaluated | |||
|
|||
#include <xsimd/xsimd.hpp> | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this blank line? It exists to provide a little separation between a library include and our own project's include.
CONSTEXPR_CMATH Utype norm() const{ | ||
constexpr Utype norm() const{ | ||
return std::sqrt(dot(*this,*this)); | ||
} | ||
|
||
CONSTEXPR_CMATH Utype angle(const vec4& v1,const vec4& v2){ | ||
constexpr Utype angle(const vec4& v1,const vec4& v2){ | ||
return std::acos(dot(v1,v2)/(v1.norm()*v2.norm())); | ||
} | ||
CONSTEXPR_CMATH vec4 unit() const{ | ||
constexpr vec4 unit() const{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change these functions from the CONSTEXPR_CMATH
macro to constexpr
?
As of C++20, the <cmath>
functions are not constexpr
and hence cannot be used in a constant expression context. However, GCC implements the <cmath>
functions as constexpr
in their implementation of the standard library as a non-standard extension. That's why the CONSTEXPR_CMATH
macro is necessary.
@@ -7,6 +7,23 @@ | |||
#include "ray.hpp" | |||
#include "material.hpp" | |||
|
|||
|
|||
//debug | |||
class HitInfo{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a class
? It should be a struct
.
@@ -41,7 +58,8 @@ class Cube | |||
vec3 m_position; | |||
vec3 m_a, m_b, m_c; | |||
Material m_material; | |||
static const double m_epsilon = 1e-5; | |||
vec3 int_pt; | |||
const double m_epsilon = 1e-5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you make this a non-static
member? Now every Cube
object will have its own copy of m_epsilon
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it static constexpr double m_epsilon = 1e-5;
@@ -4,7 +4,7 @@ | |||
#include "sphere.hpp" | |||
#include "intersection.hpp" | |||
#include "camera.hpp" | |||
|
|||
#include "cube.hpp" | |||
class Hitinfo{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a One Definition Rule (ODR) violation. You can only have definition for a class. Why did you define HitInfo
multiple times?
@@ -41,7 +58,8 @@ class Cube | |||
vec3 m_position; | |||
vec3 m_a, m_b, m_c; | |||
Material m_material; | |||
static const double m_epsilon = 1e-5; | |||
vec3 int_pt; | |||
const double m_epsilon = 1e-5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it static constexpr double m_epsilon = 1e-5;
@@ -54,21 +55,25 @@ color lighting(Material mat, ray cam_ray, ray normal, vec3 point, vec3 light_src | |||
|
|||
class Scene{ | |||
public: | |||
int n_sphere; | |||
int n_sphere = 1; | |||
int n_cube = 0; | |||
uint16_t img_width; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a 32 bit int (std::uint32_t
). To use these types, you should also include <cstddef>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for img_height
.
@@ -54,21 +55,25 @@ color lighting(Material mat, ray cam_ray, ray normal, vec3 point, vec3 light_src | |||
|
|||
class Scene{ | |||
public: | |||
int n_sphere; | |||
int n_sphere = 1; | |||
int n_cube = 0; | |||
uint16_t img_width; | |||
uint16_t img_height; | |||
Hitinfo *hitinfo = new Hitinfo[img_height*img_width]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line because we are going depth-first.
@@ -85,29 +90,34 @@ class Scene{ | |||
|
|||
} | |||
~Scene(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't a manually defined destructor because we are removing the array of HitInfo
structs.
No description provided.