-
Notifications
You must be signed in to change notification settings - Fork 52
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
Assignment 2 - Solution #2
Open
abendo
wants to merge
1
commit into
Jacobs-University:master
Choose a base branch
from
abendo:master
base: master
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
Changes from all commits
Commits
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 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 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 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 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 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 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 |
---|---|---|
|
@@ -30,6 +30,7 @@ class CScene | |
void add(const ptr_prim_t pPrim) | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
m_vpPrims.push_back(pPrim); | ||
} | ||
/** | ||
* @brief Adds a new light to the scene | ||
|
@@ -38,6 +39,7 @@ class CScene | |
void add(const ptr_light_t pLight) | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
m_vpLights.push_back(pLight); | ||
} | ||
/** | ||
* @brief Adds a new camera to the scene and makes it to ba active | ||
|
@@ -46,6 +48,8 @@ class CScene | |
void add(const ptr_camera_t pCamera) | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
m_vpCameras.push_back(pCamera); | ||
m_activeCamera = m_vpCameras.size() - 1; | ||
} | ||
/** | ||
* @brief Returns the container with all scene light source objects | ||
|
@@ -68,6 +72,10 @@ class CScene | |
bool intersect(Ray& ray) const | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
for(auto& prim : m_vpPrims) { | ||
if(prim->intersect(ray)) { return true; } | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
@@ -77,6 +85,10 @@ class CScene | |
bool occluded(Ray& ray) | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
for(auto& prim : m_vpPrims) { | ||
if(prim->intersect(ray)) { return true; } | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
@@ -87,7 +99,8 @@ class CScene | |
Vec3f RayTrace(Ray& ray) const | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
return Vec3f(); | ||
if(intersect(ray)) { return ray.hit->getShader()->shade(ray); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getShader() method throws an error because you do not fill ray.hit in your interestion algorithms. |
||
else { return m_bgColor; } | ||
} | ||
|
||
|
||
|
This file contains 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 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 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 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 |
---|---|---|
|
@@ -27,7 +27,37 @@ class CShaderPhong : public CShaderFlat | |
virtual Vec3f shade(const Ray& ray) const override | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
return RGB(0, 0, 0); | ||
Vec3f nrm = ray.hit->getNormal(ray); | ||
double ray_dnrm = ray.dir.dot(nrm); | ||
|
||
if(ray_dnrm > 0) { nrm = -nrm; } | ||
|
||
Vec3f ambient_col = CShaderFlat::shade(ray); | ||
Vec3f diffuse_col = 0; | ||
Vec3f specular_col = 0; | ||
|
||
Ray shade; | ||
|
||
int n = 1; | ||
|
||
shade.org = ray.dir * ray.t + ray.org; | ||
|
||
for(auto light : m_scene.getLights()) { | ||
for(int i = 0; i < n; i ++) { | ||
if(!light->illuminate(shade)) | ||
if(m_scene.occluded(shade)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow the shadows are not rendered at all |
||
continue; | ||
|
||
Vec3f res = 2 * shade.dir.dot(nrm) * nrm - shade.dir; | ||
|
||
diffuse_col += *light->illuminate(shade) * std::max(0.f, shade.dir.dot(nrm)); | ||
specular_col += *light->illuminate(shade) * std::pow(std::max(0.f, res.dot(-ray.dir)), m_ke); | ||
} | ||
} | ||
|
||
return m_ka * ambient_col * 1.1 + | ||
m_kd * ambient_col.mul(diffuse_col / n) + | ||
m_ks * RGB(1, 1, 1).mul(specular_col / n); | ||
} | ||
|
||
|
||
|
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.
This function is implemented wrong. You return the first found intersection, instead of checking all possible intersections.