Skip to content
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

Open
wants to merge 8 commits into
base: development
Choose a base branch
from

Conversation

mahesh0537
Copy link

No description provided.

return std::acos(dot(v1,v2)/(v1.norm()*v2.norm()));
}
CONSTEXPR_CMATH vec4 unit() const{
constexpr vec4 unit() const{
return *this/this->norm();
}

Copy link
Contributor

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;
Copy link
Owner

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
Copy link
Owner

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{
Copy link
Owner

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.

Copy link
Owner

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}{};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Members of structs 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}{};

};

Copy link
Owner

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");
Copy link
Owner

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;
Copy link
Owner

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()}{}
Copy link
Owner

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>

Copy link
Owner

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.

Comment on lines -63 to +68
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{
Copy link
Owner

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{
Copy link
Owner

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;
Copy link
Owner

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.

Copy link
Owner

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{
Copy link
Owner

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;
Copy link
Owner

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;
Copy link
Owner

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>.

Copy link
Owner

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];
Copy link
Owner

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(){
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants