-
Notifications
You must be signed in to change notification settings - Fork 1
Refraction #39
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
Open
derek-mcblane
wants to merge
5
commits into
jeffreypersons:main
Choose a base branch
from
derek-mcblane:feature-refraction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refraction #39
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
46b5cb9
export compile commands for language server config
derek-mcblane 5b05c5a
add build/ to .gitignore
derek-mcblane 5744104
fix getter for shadowColor
derek-mcblane 177ee10
remove #pragma once in .cpp files
derek-mcblane 7f01f5d
material changes to support refraction; refractive light incidence ca…
derek-mcblane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| #pragma once | ||
| #include "Files.hpp" | ||
| #include "FrameBuffer.hpp" | ||
| #include <fstream> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_; | ||
| } | ||
|
|
||
|
|
||
| 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; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_; | ||
| }; | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this doesn't get used and should probably be removed