-
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
Assignment2 #3
base: master
Are you sure you want to change the base?
Assignment2 #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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_activeCamera + 1; | ||
} | ||
/** | ||
* @brief Returns the container with all scene light source objects | ||
|
@@ -68,6 +72,12 @@ class CScene | |
bool intersect(Ray& ray) const | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
bool hit = false; | ||
for (auto pPrim : m_vpPrims) { | ||
if (pPrim->intersect(ray)) { | ||
hit = true; | ||
} | ||
} | ||
return false; | ||
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. This is obviously wrong. You return false all the time - so nothing can be rendered! Did you even check any results? |
||
} | ||
|
||
|
@@ -77,7 +87,15 @@ class CScene | |
bool occluded(Ray& ray) | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
return false; | ||
//return false; | ||
for (auto pPrim : m_vpPrims) { | ||
if (pPrim->occluded(ray)) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -87,7 +105,8 @@ class CScene | |
Vec3f RayTrace(Ray& ray) const | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
return Vec3f(); | ||
//return Vec3f(); | ||
return intersect(ray) ? ray.hit->getShader()->shade(ray) : m_bgColor; | ||
} | ||
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() causes error here, because you never initialize ray.hit in the intersection algorithms |
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,44 @@ class CShaderPhong : public CShaderFlat | |
virtual Vec3f shade(const Ray& ray) const override | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
return RGB(0, 0, 0); | ||
//return RGB(0, 0, 0); | ||
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. Phong images are too dark |
||
Vec3f normal = ray.hit->getNormal(ray); | ||
if (ray.dir.dot(normal) > 0) { | ||
normal *= -1; | ||
} | ||
//ambient intensity | ||
Vec3f ambienceIntensity(1, 1, 1); | ||
|
||
//ambient color c_a | ||
Vec3f reflect = normalize(ray.dir - 2 * (ray.dir.dot(normal)) * normal); | ||
Vec3f color = CShaderFlat::shade(); | ||
Vec3f c_a = m_ka * color; | ||
Vec3f endproduct = c_a.mul(ambienceIntensity); | ||
Vec3f res = c_a.mul(ambienceIntensity); | ||
|
||
|
||
Ray shadow; | ||
shadow.org = ray.org + ray.t * ray.dir; | ||
for (auto pLight : m_scene.getLights()) { | ||
std::optional<Vec3f> lightIntensity = pLight->illuminate(shadow); | ||
float cosLightNormal = shadow.dir.dot(normal); | ||
if (cosLightNormal > 0) { | ||
if (m_scene.occluded(shadow)) { | ||
continue; | ||
} | ||
Vec3f diffuseColor = m_kd * color; | ||
res += (diffuseColor * cosLightNormal).mul(cosLightNormal).mul(lightIntensity.value()); | ||
} | ||
float cosLightReflect = shadow.dir.dot(reflect); | ||
if (cosLightReflect > 0) { | ||
Vec3f specularColor = m_ks * RGB(1, 1, 1); | ||
res += (specularColor * powf(cosLightReflect, m_ke)).mul(lightIntensity.value()); | ||
} | ||
|
||
} | ||
for (int i = 0; i < 3; i++) | ||
if (res.val[i] > 1) res.val[i] = 1; | ||
return res; | ||
} | ||
|
||
|
||
|
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 is valid approach, but only in case, when you initialize m_activeCamera to be equal to -1 on construction. This also requires to have m_activeCamera variable of type int, not size_t.
How it is implemented now, it shows an error on execution.