Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
*.sln
*.suo
*.vcxproj*
.cache/
tags
compile_commands.json

# Build Files
*.exe
x86/
x64/
bin/
build/
*/Debug/*
*/Release/*
Release/
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.15.0)

project(RayTracer VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_compile_definitions(
$<$<CONFIG:DEBUG>:DEBUG>
Expand Down
19 changes: 17 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
#!/bin/bash

BUILD_TYPE=${1:-Release}
mkdir $BUILD_TYPE >/dev/null
mkdir $BUILD_TYPE 2>/dev/null
pushd $BUILD_TYPE
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} && cmake --build . && cmake --install . --prefix .

CMAKE_OPTIONS="-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"

if cmake .. ${CMAKE_OPTIONS} ; then
echo "CMake finished"
else
exit $?
fi
if cmake --build . && cmake --install . --prefix . ; then
echo "Build finished"
else
exit $?
fi

cp compile_commands.json .. 2>/dev/null

popd
1 change: 0 additions & 1 deletion src/App.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#include "App.hpp"
#include "Text.hpp"
#include "Files.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_library(RayTracerCore
FrameBuffer.cpp
Lights.cpp
Material.cpp
LightIncidence.cpp
Objects.cpp
RayTracer.cpp
Scene.cpp
Expand Down
1 change: 0 additions & 1 deletion src/Files.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#include "Files.hpp"
#include "FrameBuffer.hpp"
#include <fstream>
Expand Down
1 change: 0 additions & 1 deletion src/FrameBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#include "FrameBuffer.hpp"
#include "Math.hpp"
#include "Color.hpp"
Expand Down
70 changes: 70 additions & 0 deletions src/LightIncidence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "LightIncidence.hpp"
#include "Ray.hpp"
#include "Math.hpp"

#include <optional>

LightIncidenceFresnel::LightIncidenceFresnel(const Ray& ray, const Intersection& intersection, float indexOfRefractionFrom, float indexOfRefractionTo) :
ray_(ray),
intersection_(intersection),
n1_(indexOfRefractionFrom),
n2_(indexOfRefractionTo)
{
computeHelperVars();
}

void LightIncidenceFresnel::computeHelperVars()
{
n1_over_n2_ = n1_ / n2_;

cos_theta_i_ = -Math::dot(ray_.direction, intersection_.normal);
cos_theta_i_squared_ = Math::square(cos_theta_i_);
sin_theta_i_squared_ = 1.0f - cos_theta_i_squared_;

if (Math::square(n1_over_n2_) * sin_theta_i_squared_ > 1.0f) {
reflectedProportion_ = 1.0f;
transmittedProportion_ = 0.0f;
return;
}

sin_theta_t_squared_ = Math::square(n1_over_n2_)*sin_theta_i_squared_;
cos_theta_t_squared_ = 1.0f - sin_theta_t_squared_;
cos_theta_t_ = Math::squareRoot(cos_theta_t_squared_);

R_normal_ = Math::square((n1_ * cos_theta_i_ - n2_ * cos_theta_t_) / (n1_ * cos_theta_i_ + n2_ * cos_theta_t_));
R_tangent_ = Math::square((n2_ * cos_theta_i_ - n1_ * cos_theta_t_) / (n2_ * cos_theta_i_ + n1_ * cos_theta_t_));

reflectedProportion_ = (R_normal_ + R_tangent_) / 2.0f;
transmittedProportion_ = 1.0f - reflectedProportion_;
}

Vec3 LightIncidenceFresnel::reflectedDirection() const
{
return ray_.direction + 2.0f * cos_theta_i_ * intersection_.normal;
}

Vec3 LightIncidenceFresnel::refractedDirection() const
{
return n1_over_n2_ * ray_.direction + (n1_over_n2_ * cos_theta_i_ - Math::squareRoot(1.0f - sin_theta_t_squared_)) * intersection_.normal;
}

float LightIncidenceFresnel::reflectedProportion() const
{
return reflectedProportion_;
}

float LightIncidenceFresnel::transmittedProportion() const
{
return transmittedProportion_;
}
Comment on lines +56 to +59
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this doesn't get used and should probably be removed



LightIncidenceReflect::LightIncidenceReflect(const Ray &ray, const Intersection &intersection) :
ray_(ray),
intersection_(intersection)
{
}

Vec3 LightIncidenceReflect::reflectedDirection() const {
return ray_.direction + 2.0f * -Math::dot(ray_.direction, intersection_.normal) * intersection_.normal;
}
50 changes: 50 additions & 0 deletions src/LightIncidence.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "Math.hpp"
#include "Ray.hpp"

#include <optional>

class LightIncidenceFresnel {
public:
LightIncidenceFresnel(const Ray &ray, const Intersection &intersection,
const float indexOfRefractionFrom,
const float indexOfRefractionTo);

Vec3 reflectedDirection() const;
Vec3 refractedDirection() const;
float reflectedProportion() const;
float transmittedProportion() const;

private:
void computeHelperVars();

const Ray& ray_;
const Intersection& intersection_;
const float n1_;
const float n2_;

bool total_internal_reflection_;
float n1_over_n2_;
float cos_theta_i_;
float cos_theta_i_squared_;
float sin_theta_i_squared_;
float sin_theta_t_squared_;
float cos_theta_t_squared_;
float cos_theta_t_;

float R_normal_;
float R_tangent_;
float reflectedProportion_;
float transmittedProportion_;
};

class LightIncidenceReflect {
public:
LightIncidenceReflect(const Ray &ray, const Intersection &intersection);

Vec3 reflectedDirection() const;

private:
const Ray &ray_;
const Intersection &intersection_;
};

Loading