Skip to content

Commit

Permalink
added precommit (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
abdelrahim-hentabli and pre-commit-ci[bot] authored Apr 29, 2024
1 parent 24c11bf commit af150e7
Show file tree
Hide file tree
Showing 46 changed files with 1,981 additions and 2,015 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BasedOnStyle: Google
24 changes: 11 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ jobs:
Build-And-test:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: install ffmpeg
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libavutil58 libavcodec-dev libavformat-dev libswscale-dev libswresample-dev
version: 1.2
execute_install_scripts: true
- name: CMake config & build
run: |
sudo apt-get update
sudo apt-get install ffmpeg
- run: mkdir build
- run: cd build
- name: Run Cmake Config step
run: cmake -DCMAKE_BUILD_TYPE=Release ../ray-tracing
- name: Run build
run: cmake --build . --parallel 2
cmake -B build -DCMAKE_BUILD_TYPE=Release .
cmake --build build --parallel 4
- name: Run test
run: ./tools/test/tests
run: ./build/tools/test/tests
- name: Run benchmark
run: ./tools/benchmark/benchmarks
run: ./build/tools/benchmark/benchmarks
23 changes: 23 additions & 0 deletions .github/workflows/pcm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: pre-commit

on:
pull_request:

jobs:
Build-And-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libavutil58 libavcodec-dev libavformat-dev libswscale-dev libswresample-dev
version: 1.2
execute_install_scripts: true
- name: CMake config & build
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release .
cmake --build build --parallel 4
- name: Run test
run: ./build/tools/test/tests
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: '' # Use the sha / tag you want to point at
hooks:
- id: clang-format
41 changes: 19 additions & 22 deletions include/acceleration_structures/bounding_box.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
#ifndef __BOUNDING_BOX_H__
#define __BOUNDING_BOX_H__

//#####################################################################
// Function #in
//#####################################################################
// #####################################################################
// Function #in
// #####################################################################
#include "objects/object.hpp"
#include "ray.hpp"
#include "vec.hpp"

template<class T, int d>
vec<T,d> componentwise_max(const vec<T,d>& a, const vec<T,d>& b)
{
vec<T,d> r;
for(int i=0; i<d; i++) r[i] = std::max(a[i], b[i]);
return r;
template <class T, int d>
vec<T, d> componentwise_max(const vec<T, d> &a, const vec<T, d> &b) {
vec<T, d> r;
for (int i = 0; i < d; i++) r[i] = std::max(a[i], b[i]);
return r;
}

template<class T, int d>
vec<T,d> componentwise_min(const vec<T,d>& a, const vec<T,d>& b)
{
vec<T,d> r;
for(int i=0; i<d; i++) r[i] = std::min(a[i], b[i]);
return r;
template <class T, int d>
vec<T, d> componentwise_min(const vec<T, d> &a, const vec<T, d> &b) {
vec<T, d> r;
for (int i = 0; i < d; i++) r[i] = std::min(a[i], b[i]);
return r;
}

class Bounding_Box
{
public:
// lowermost and uppermost corners of bounding box
vec3 lo,hi;
class Bounding_Box {
public:
// lowermost and uppermost corners of bounding box
vec3 lo, hi;

bool Intersection(const Ray& ray, double& dist);
bool Intersection(const Ray &ray, double &dist);

Bounding_Box Union(const Bounding_Box& bb) const;
Bounding_Box Union(const Bounding_Box &bb) const;
};

#endif
30 changes: 15 additions & 15 deletions include/acceleration_structures/box.hpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#ifndef __BOX_H__
#define __BOX_H__

#include "ray.hpp"
#include "misc.hpp"
#include <limits>

class Box
{
public:
// lowermost and uppermost corners of bounding box
vec3 lo,hi;
#include "misc.hpp"
#include "ray.hpp"

class Box {
public:
// lowermost and uppermost corners of bounding box
vec3 lo, hi;

// Return whether the ray intersects this box.
bool Intersection(const Ray& ray) const;
// Return whether the ray intersects this box.
bool Intersection(const Ray &ray) const;

// Compute the smallest box that contains both *this and bb.
Box Union(const Box& bb) const;
// Compute the smallest box that contains both *this and bb.
Box Union(const Box &bb) const;

// Enlarge this box (if necessary) so that pt also lies inside it.
void Include_Point(const vec3& pt);
// Enlarge this box (if necessary) so that pt also lies inside it.
void Include_Point(const vec3 &pt);

// Create a box to which points can be correctly added using Include_Point.
void Make_Empty();
// Create a box to which points can be correctly added using Include_Point.
void Make_Empty();
};
#endif
37 changes: 18 additions & 19 deletions include/acceleration_structures/hierarchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,29 @@
The last n elements of tree correspond to the elements of entries (in order).
*/

struct Entry
{
Object* obj;
int part;
Box box;
struct Entry {
Object *obj;
int part;
Box box;
};

class Hierarchy
{
public:
// List of primitives (or parts of primitives) that can be intersected
std::vector<Entry> entries;
class Hierarchy {
public:
// List of primitives (or parts of primitives) that can be intersected
std::vector<Entry> entries;

// Flattened hierarchy
std::vector<Box> tree;
// Flattened hierarchy
std::vector<Box> tree;

// Reorder the entries vector so that adjacent entries tend to be nearby.
void Reorder_Entries();
// Reorder the entries vector so that adjacent entries tend to be nearby.
void Reorder_Entries();

// Populate tree from entries.
void Build_Tree();
// Populate tree from entries.
void Build_Tree();

// Return a list of candidates (indices into the entries list) whose
// bounding boxes intersect the ray.
void Intersection_Candidates(const Ray& ray, std::vector<int>& candidates) const;
// Return a list of candidates (indices into the entries list) whose
// bounding boxes intersect the ray.
void Intersection_Candidates(const Ray &ray,
std::vector<int> &candidates) const;
};
#endif
99 changes: 49 additions & 50 deletions include/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,68 @@
#define __CAMERA_H__

#include <algorithm>
#include "vec.hpp"

#include "misc.hpp"
#include "vec.hpp"

typedef unsigned int Pixel;

inline Pixel Pixel_Color(const vec3& color)
{
unsigned int r=std::min(color[0],1.0)*255;
unsigned int g=std::min(color[1],1.0)*255;
unsigned int b=std::min(color[2],1.0)*255;
return (r<<24)|(g<<16)|(b<<8)|0xff;
inline Pixel Pixel_Color(const vec3 &color) {
unsigned int r = std::min(color[0], 1.0) * 255;
unsigned int g = std::min(color[1], 1.0) * 255;
unsigned int b = std::min(color[2], 1.0) * 255;
return (r << 24) | (g << 16) | (b << 8) | 0xff;
}

inline vec3 From_Pixel(Pixel color)
{
return vec3(color>>24,(color>>16)&0xff,(color>>8)&0xff)/255.;
inline vec3 From_Pixel(Pixel color) {
return vec3(color >> 24, (color >> 16) & 0xff, (color >> 8) & 0xff) / 255.;
}

class Camera
{
public:
// Describes camera in space
vec3 position; // camera position
vec3 film_position; // where (0.0, 0.0) in the image plane is located in space
vec3 look_vector; // points from the position to the focal point - normalized
vec3 vertical_vector; // point up in the image plane - normalized
vec3 horizontal_vector; // points to the right on the image plane - normalized
class Camera {
public:
// Describes camera in space
vec3 position; // camera position
vec3
film_position; // where (0.0, 0.0) in the image plane is located in space
vec3 look_vector; // points from the position to the focal point - normalized
vec3 vertical_vector; // point up in the image plane - normalized
vec3
horizontal_vector; // points to the right on the image plane - normalized

// Describes the coordinate system of the image plane
vec2 min,max; // coordinates of film corners: min = (left,bottom), max = (right,top)
vec2 image_size; // physical dimensions of film
vec2 pixel_size; // physical dimensions of a pixel
// Describes the coordinate system of the image plane
vec2 min, max; // coordinates of film corners: min = (left,bottom), max =
// (right,top)
vec2 image_size; // physical dimensions of film
vec2 pixel_size; // physical dimensions of a pixel

// Describes the pixels of the image
ivec2 number_pixels; // number of pixels: x and y direction
Pixel* colors; // Pixel data; row-major order

Camera();
~Camera();
Camera(const Camera& other);
Camera& operator=(const Camera &other);
// Describes the pixels of the image
ivec2 number_pixels; // number of pixels: x and y direction
Pixel *colors; // Pixel data; row-major order

Camera();
~Camera();
Camera(const Camera &other);
Camera &operator=(const Camera &other);

// Used for setting up camera parameters
void Position_And_Aim_Camera(const vec3& position_input,
const vec3& look_at_point,const vec3& pseudo_up_vector);
void Focus_Camera(double focal_distance,double aspect_ratio,
double field_of_view);
void Set_Resolution(const ivec2& number_pixels_input);
// Used for setting up camera parameters
void Position_And_Aim_Camera(const vec3 &position_input,
const vec3 &look_at_point,
const vec3 &pseudo_up_vector);
void Focus_Camera(double focal_distance, double aspect_ratio,
double field_of_view);
void Set_Resolution(const ivec2 &number_pixels_input);

// Used for determining the where pixels are
vec3 World_Position(const ivec2& pixel_index);
vec2 Cell_Center(const ivec2& index) const
{
return min+(vec2(index)+vec2(.5,.5))*pixel_size;
}
// Used for determining the where pixels are
vec3 World_Position(const ivec2 &pixel_index);
vec2 Cell_Center(const ivec2 &index) const {
return min + (vec2(index) + vec2(.5, .5)) * pixel_size;
}

// Call to set the color of a pixel
void Set_Pixel(const ivec2& pixel_index,const Pixel& color)
{
int i=pixel_index[0];
int j=pixel_index[1];
colors[j*number_pixels[0]+i]=color;
}
// Call to set the color of a pixel
void Set_Pixel(const ivec2 &pixel_index, const Pixel &color) {
int i = pixel_index[0];
int j = pixel_index[1];
colors[j * number_pixels[0] + i] = color;
}
};
#endif
23 changes: 11 additions & 12 deletions include/lights/direction_light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
#define __DIRECTION_LIGHT_H__

#include <math.h>
#include <vector>

#include <iostream>
#include <limits>
#include "vec.hpp"
#include <vector>

#include "light.hpp"
#include "vec.hpp"

class Direction_Light : public Light
{
public:
Direction_Light(const vec3& direction,const vec3& color,double brightness)
:Light(direction.normalized()*1e10,color,brightness)
{}
class Direction_Light : public Light {
public:
Direction_Light(const vec3 &direction, const vec3 &color, double brightness)
: Light(direction.normalized() * 1e10, color, brightness) {}

vec3 Emitted_Light(const vec3& vector_to_light) const
{
return color*brightness;
}
vec3 Emitted_Light(const vec3 &vector_to_light) const {
return color * brightness;
}
};
#endif
Loading

0 comments on commit af150e7

Please sign in to comment.