diff --git a/CMakeLists.txt b/CMakeLists.txt index 87f452b..99d3487 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,8 @@ source_group("Source Files" FILES "src/main.cpp") source_group("Source Files\\Cameras" FILES "src/ICamera.h" "src/CameraPerspective.h") source_group("Source Files\\Lights" FILES "src/ILight.h" "src/LightOmni.h") source_group("Source Files\\Primitives" FILES "src/IPrim.h" "src/PrimSphere.h" "src/PrimPlane.h" "src/PrimTriangle.h") -source_group("Source Files\\Solids" FILES "src/Solid.h" "src/SolidQuad.h" "src/SolidCone.h" "src/SolidSphere.h") -source_group("Source Files\\Shaders" FILES "src/IShader.h" "src/ShaderFlat.h" "src/ShaderEyelight.h" "src/ShaderPhong.h") +source_group("Source Files\\Solids" FILES "src/Solid.h" "src/SolidQuad.h" "src/SolidCone.h" "src/SolidSphere.h" "src/SolidGeosphere.h") +source_group("Source Files\\Shaders" FILES "src/IShader.h" "src/ShaderFlat.h" "src/ShaderEyelight.h" "src/ShaderPhong.h" "src/ShaderPhongBumpMapped.h") source_group("Source Files\\Scene" FILES "src/Scene.h") source_group("Source Files\\utilities" FILES "src/ray.h" "src/timer.h" "src/Texture.h") source_group("Source Files\\utilities\\BSP Tree" FILES "src/BSPNode.h" "src/BSPTree.h" "src/BoundingBox.h" "src/BoundingBox.cpp") diff --git a/README.md b/README.md index 45001eb..6efbc8c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,13 @@ # Practical Assignment 4 -**Dealine**: 12.11.2020 +**Dealine**: 22.12.2020 Please put your name here: -**Name:** ....... +**Name:** Checiu Eliza and Abumansur Sabyrrakhim (we disccused and worked together on certain tasks, although we both wrote and compilied our own codes) + +GeoSphere: I tried to write the code for it and used any resource I found but in the end it didn't really work on and so I did the normal sphere and worked on it for the assignment. + +BONUS: I took the example given last year to run it and make it work. I tried to modified everything needed to make it work. + ## Problem 1 ### Sphere Solid (Points 25) In this assignment we will continue working with _compound objects_: solids. @@ -35,7 +40,7 @@ Proceed as follows: 6. Extend your code in ```CSolidSphere``` constructor in such a way that the triangles will be created with the additional normals. Calculate these normals (_e.g._ using the spherical coordinate system) and pass them within the triangles' and quads' constructors. 7. Test your implementation on the scene from Problem 1. Compare the difference between the Solid and Primitive spheres. Explain below why smoothed cone looks strange. How would you fix it? -**Explanation and Suggestion:** ... +**Explanation and Suggestion:** From my understanding, you can only assign one normal to the top vertex per triangle, which therefore means that there is not possible way to have smooth transition. To make it better though, I found that the method of multiple hight segments could work. If everything is correct your images should look like this: diff --git a/renders/1.jpg b/renders/1.jpg new file mode 100644 index 0000000..dcae243 Binary files /dev/null and b/renders/1.jpg differ diff --git a/renders/bump_mapping.jpg b/renders/bump_mapping.jpg new file mode 100644 index 0000000..00b8270 Binary files /dev/null and b/renders/bump_mapping.jpg differ diff --git a/renders/final1.jpg b/renders/final1.jpg new file mode 100644 index 0000000..b752bf3 Binary files /dev/null and b/renders/final1.jpg differ diff --git a/renders/final11.jpg b/renders/final11.jpg new file mode 100644 index 0000000..18a9de4 Binary files /dev/null and b/renders/final11.jpg differ diff --git a/renders/final2.jpg b/renders/final2.jpg new file mode 100644 index 0000000..8a0c8e5 Binary files /dev/null and b/renders/final2.jpg differ diff --git a/renders/final22.jpg b/renders/final22.jpg new file mode 100644 index 0000000..8a0c8e5 Binary files /dev/null and b/renders/final22.jpg differ diff --git a/renders/half.jpg b/renders/half.jpg new file mode 100644 index 0000000..41632d4 Binary files /dev/null and b/renders/half.jpg differ diff --git a/renders/image.jpg b/renders/image.jpg new file mode 100644 index 0000000..7430d7d Binary files /dev/null and b/renders/image.jpg differ diff --git a/renders/image1.jpg b/renders/image1.jpg new file mode 100644 index 0000000..7430d7d Binary files /dev/null and b/renders/image1.jpg differ diff --git a/renders/not_smooth.jpg b/renders/not_smooth.jpg new file mode 100644 index 0000000..5dfc751 Binary files /dev/null and b/renders/not_smooth.jpg differ diff --git a/renders/smooth.jpg b/renders/smooth.jpg new file mode 100644 index 0000000..456c9dc Binary files /dev/null and b/renders/smooth.jpg differ diff --git a/renders/textured.jpg b/renders/textured.jpg new file mode 100644 index 0000000..fd962a3 Binary files /dev/null and b/renders/textured.jpg differ diff --git a/renders/textured_final.jpg b/renders/textured_final.jpg new file mode 100644 index 0000000..8646ee4 Binary files /dev/null and b/renders/textured_final.jpg differ diff --git a/renders/textured_img.jpg b/renders/textured_img.jpg new file mode 100644 index 0000000..9fd6bee Binary files /dev/null and b/renders/textured_img.jpg differ diff --git a/renders/white1.jpg b/renders/white1.jpg new file mode 100644 index 0000000..af3e9b7 Binary files /dev/null and b/renders/white1.jpg differ diff --git a/src/PrimSphere.h b/src/PrimSphere.h index 04cd45e..79b77c4 100755 --- a/src/PrimSphere.h +++ b/src/PrimSphere.h @@ -67,7 +67,15 @@ class CPrimSphere : public IPrim virtual Vec2f getTextureCoords(const Ray& ray) const override { // --- PUT YOUR CODE HERE --- - return Vec2f(0, 0); + //return Vec2f(0, 0); + + Vec3f hitPoint = ray.org + ray.dir * ray.t - m_origin; + float theta = acosf(hitPoint.val[1] / m_radius); // [0; Pif] + + float phi = sinf(theta) > Epsilon ? acosf(hitPoint.val[0] / (m_radius * sinf(theta))) : 0; // [0; Pif] + if (hitPoint.val[2] < 0) phi = -phi; // [-Pif; Pif] + if (isnan(phi)) phi = 0; + return Vec2f(-0.5f * (1 + phi / Pif), theta / Pif); } virtual CBoundingBox getBoundingBox(void) const override diff --git a/src/PrimTriangle.h b/src/PrimTriangle.h index 55755cf..28f2cdd 100644 --- a/src/PrimTriangle.h +++ b/src/PrimTriangle.h @@ -75,6 +75,9 @@ class CPrimTriangle : public IPrim ray.t = f; ray.hit = shared_from_this(); // --- PUT YOUR CODE HERE --- + + ray.u = lambda; + ray.v = mue; return true; } @@ -83,7 +86,13 @@ class CPrimTriangle : public IPrim { if (m_na && m_nb && m_nc) { // --- PUT YOUR CODE HERE --- - return Vec3f(0, 0, 0); + //return Vec3f(0, 0, 0); + + Vec3f r0 = m_na.value(); + Vec3f r1 = m_nb.value(); + Vec3f r2 = m_nc.value(); + Vec3f interp_norm = ((1.0f - ray.u - ray.v) * r0 + ray.u * r1 + ray.v * r2); + return interp_norm; } else return normalize(m_edge1.cross(m_edge2)); @@ -92,7 +101,8 @@ class CPrimTriangle : public IPrim virtual Vec2f getTextureCoords(const Ray& ray) const override { // --- PUT YOUR CODE HERE --- - return Vec2f(0, 0); + //return Vec2f(0, 0); + return(1.0f - ray.u - ray.v) * m_ta + ray.u * m_tb + ray.v * m_tc; } virtual CBoundingBox getBoundingBox(void) const override diff --git a/src/Scene.h b/src/Scene.h index 66c7937..d61bcda 100644 --- a/src/Scene.h +++ b/src/Scene.h @@ -133,11 +133,13 @@ class CScene return intersect(ray) ? ray.hit->getShader()->shade(ray) : m_bgColor; } +public: + std::vector m_vpLights; ///< lights //eliza private: Vec3f m_bgColor; ///< background color std::vector m_vpPrims; ///< primitives - std::vector m_vpLights; ///< lights + std::vector m_vpCameras; ///< Cameras size_t m_activeCamera = 0; //< The index of the active camera #ifdef ENABLE_BSP diff --git a/src/ShaderFlat.h b/src/ShaderFlat.h index d43176c..abd688c 100644 --- a/src/ShaderFlat.h +++ b/src/ShaderFlat.h @@ -26,7 +26,10 @@ class CShaderFlat : public IShader { if (m_pTexture) { // --- PUT YOUR CODE HERE --- - return Vec3f(1, 1, 1); + //return Vec3f(1, 1, 1); + + Vec2f uv = ray.hit->getTextureCoords(ray); + return m_pTexture->getTexel(uv); } else return m_color; diff --git a/src/ShaderPhongBumpMapped.h b/src/ShaderPhongBumpMapped.h new file mode 100644 index 0000000..674c76d --- /dev/null +++ b/src/ShaderPhongBumpMapped.h @@ -0,0 +1,99 @@ +#pragma once + +#include "ShaderFlat.h" +#include "Scene.h" + +/** +* @brief Phong Shader with procedural bump mapping +*/ + +const int nAreaSamples = 1; + +class CShaderPhongBumpMapped : public CShaderFlat +{ +public: + /** + * @brief Constructor + * @param scene Reference to the scene + * @param color The color of the object + * @param ka The ambient coefficient + * @param kd The diffuse reflection coefficients + * @param ks The specular refelection coefficients + * @param ke The shininess exponent + */ + CShaderPhongBumpMapped(CScene& scene, Vec3f color, float ka, float kd, float ks, float ke) + : CShaderFlat(color) + , m_scene(scene) + , m_ka(ka) + , m_kd(kd) + , m_ks(ks) + , m_ke(ke) + {} + virtual ~CShaderPhongBumpMapped(void) = default; + + virtual Vec3f shade(const Ray& ray) const override + { + Vec3f dPdu = (1, 0, 0); + Vec3f dPdv = (0, 0, 1); + Vec3f h = ray.org + ray.t * ray.dir; + float delta_u = 0.5f * cos(3 * h[0] * sin(h[2])); + float delta_v = 0.5f * sin(13 * h[2]); + + Vec3f normal0 = ray.hit->getNormal(ray); + Vec3f normal = normalize(normal0 + delta_u * dPdu + delta_v * dPdv); + if (normal.dot(ray.dir) > 0) { + normal = -normal; + } + + Vec3f reflect = normalize(ray.dir - 2 * normal.dot(ray.dir) * normal); + Vec3f ambientIntensity(1,1,1); + + Vec3f color = CShaderFlat::shade(); + Vec3f ambientColor = m_ka * color; + Vec3f res = ambientColor.mul(ambientIntensity); + + Ray shadow; + shadow.org = ray.org + ray.t * ray.dir; + + for(auto pLight : m_scene.m_vpLights) + for(int s = 0; s < nAreaSamples; s++) { + std::optional lightIntensity = pLight->illuminate(shadow); + if (lightIntensity) { + float cosLightNormal = shadow.dir.dot(normal); + if (cosLightNormal > 0) { + if (m_scene.occluded(shadow)) { + continue; + } + + Vec3f diffuseColor = m_kd * color; + res += (diffuseColor * cosLightNormal).mul(lightIntensity.value()); + } + + float cosLightReflect = shadow.dir.dot(reflect); + if (cosLightReflect > 0) { + Vec3f specularColor = m_ks * RGB(1, 1, 1); // white highlight; + res += (specularColor * powf(cosLightReflect, m_ke)).mul(lightIntensity.value()); + } + } + } + + if (nAreaSamples > 1) { + res /= nAreaSamples; + } + + for (int i = 0; i < 3; i++) { + if (res.val[i] > 1) { + res.val[i] = 1; + } + } + + return res; + } + +private: + CScene& m_scene; + float m_ka; ///< ambient coefficient + float m_kd; ///< diffuse reflection coefficients + float m_ks; ///< specular refelection coefficients + float m_ke; ///< shininess exponent +}; diff --git a/src/SolidCone.h b/src/SolidCone.h index 17d3617..dc67c61 100644 --- a/src/SolidCone.h +++ b/src/SolidCone.h @@ -19,32 +19,66 @@ class CSolidCone : public CSolid { * @param height The height of the cone * @param sides The number of sides */ - CSolidCone(ptr_shader_t pShader, const Vec3f& origin = Vec3f::all(0), float radius = 1, float height = 1, size_t sides = 24) + CSolidCone(ptr_shader_t pShader, const Vec3f& origin = Vec3f::all(0), float radius = 1, float height = 1, size_t sides = 24) { - const Vec3f top(0, height, 0); // The top point - Vec3f dir0(1, 0, 0); // Initial direction - Vec3f p0 = origin + radius * dir0; // Initial point - Vec3f dir1, p1; // Next point - float t0 = 0; // Initial texture coordinate - for (size_t s = 0; s < sides; s++) { - float t1 = static_cast(s + 1) / sides; // Next texture coordinate: [1/sides; 1] - float alpha = -2 * Pif * t1; - dir1 = Vec3f(cosf(alpha), 0, sinf(alpha)); - p1 = origin + radius * dir1; - - // --- PUT YOUR CODE HERE --- - // Sides - if (height >= 0) add(std::make_shared(pShader, origin + top, p1, p0)); - else add(std::make_shared(pShader, origin + top, p0, p1)); - - // Cap - if (height >= 0) add(std::make_shared(pShader, origin, p1, p0)); - else add(std::make_shared(pShader, origin, p0, p1)); - - dir0 = dir1; - p0 = p1; - t0 = t1; - } + const Vec3f top(0, height, 0); // The top point + Vec3f dir0(1, 0, 0); // Initial direction + Vec3f p0 = origin + radius * dir0; // Initial point + float height_segments = sides / 12; + const Vec3f slope(0, radius / height, 0); + Vec3f n0 = normalize(dir0 + slope); + Vec3f dir1, p1, n1; // Next point + float t0 = 0; // Initial texture coordinate + + for (size_t s = 0; s < sides; s++) { + float t1 = static_cast(s + 1) / sides; // Next texture coordinate: [1/sides; 1] + float alpha = -2 * Pif * t1; + dir1 = Vec3f(cosf(alpha), 0, sinf(alpha)); + p1 = origin + radius * dir1; + n1 = normalize(dir1 + slope); + + // --- PUT YOUR CODE HERE --- + // inspired by OpenRT source code + + // initial height + float h0 = 0; + for (int h = 0; h < height_segments - 1; h++) { + float h1 = static_cast(h + 1) / height_segments; + add(std::make_shared(pShader, + p0 + h0 * (top - radius * dir0), + p0 + h1 * (top - radius * dir0), + p1 + h1 * (top - radius * dir1), + p1 + h0 * (top - radius * dir1), + Vec2f(t0, 1 - h0), Vec2f(t0, 1 - h1), Vec2f(t1, 1 - h1), Vec2f(t1, 1 - h0), + n0, n0, n1, n1)); + + h0 = h1; + } + // Sides + if (height >= 0) + add(std::make_shared(pShader, + origin + top, + p1 + h0 * (top - radius * dir1), + p0 + h0 * (top - radius * dir0), + Vec2f(0.5f, 0), Vec2f(t1, 1 - h0), Vec2f(t0, 1 - h0), + normalize(n0 + n1), n1, n0)); + else + add(std::make_shared(pShader, + origin + top, + p1 + h0 * (top - radius * dir1), + p0 + h0 * (top - radius * dir0), + Vec2f(0.5f, 0), Vec2f(t1, 1 - h0), Vec2f(t0, 1 - h0))); + + // Cap + if (height >= 0) add(std::make_shared(pShader, origin, p1, p0, Vec2f(0.5f, 1), Vec2f(t1, 1), Vec2f(t0, 1))); + else add(std::make_shared(pShader, origin, p0, p1, Vec2f(0.5f, 1), Vec2f(t0, 1), Vec2f(t1, 1))); + + dir0 = dir1; + p0 = p1; + n0 = n1; + t0 = t1; + + } } virtual ~CSolidCone(void) = default; }; diff --git a/src/SolidGeosphere.h b/src/SolidGeosphere.h new file mode 100644 index 0000000..7d53598 --- /dev/null +++ b/src/SolidGeosphere.h @@ -0,0 +1,121 @@ +#pragma once + +#include "SolidQuad.h" +#include "PrimTriangle.h" +#include "PrimSphere.h" +#include "PrimSphere.h" +#include "PrimPlane.h" +#include "PrimPlane.h" + +//const int MIN_SECTOR_COUNT = 3; +//const int MIN_STACK_COUNT = 2; + +class CSolidGeosphere : public CSolid +{ +public: + /** + * @brief Constructor + * @param pShader Pointer to the shader + * @param origin The origin of the geosphere + * @param radius The radius of the geosphere + * @param sides The number of sides + */ + CSolidGeosphere(float radius = 1, int sectorCount = 36, int stackCount = 18) + //CSolidGeosphere(ptr_shader_t pShader, const Vec3f& origin = Vec3f::all(0), float radius = 1, int stacks, int sectors, bool smooth) + { + // --- PUT YOUR CODE HERE --- + // inspired by http://www.songho.ca/opengl/gl_sphere.html + std::vector().swap(vertices); + std::vector().swap(normals); + std::vector().swap(texCoords); + + float x, y, z, xy; + float nx, ny, nz, lengthInv = 1.0 / radius; + float s, t; + + float sectorStep = 2 * Pif / sectorCount; + float stackStep = Pif / stackCount; + float sectorAngle, stackAngle; + + for (int i = 0; i <= stackCount; ++i) { + // starting from pi/2 to -pi/2 + stackAngle = Pif / 2 - i * stackStep; + xy = radius * cosf(stackAngle); + z = radius * sinf(stackAngle); + + // adding (sectorCount+1) vertices per stack + // the first and last vertices have same position and normal, but different tex coords + for (int j = 0; j <= sectorCount; ++j) { + // starting from 0 to 2pi + sectorAngle = j * sectorStep; + + x = xy * cosf(sectorAngle); + y = xy * sinf(sectorAngle); + vertices.push_back(x); + vertices.push_back(y); + vertices.push_back(z); + + // normalized vertex normal (nx, ny, nz) + nx = x * lengthInv; + ny = y * lengthInv; + nz = z * lengthInv; + normals.push_back(nx); + normals.push_back(ny); + normals.push_back(nz); + + // vertex tex coord (s, t) range between [0, 1] + s = (float)j / sectorCount; + t = (float)i / stackCount; + texCoords.push_back(s); + texCoords.push_back(t); + } + } + + unsigned int k1, k2; + for (int i = 0; i < stackCount; ++i) { + k1 = i * (sectorCount + 1); // beginning of current stack + k2 = k1 + sectorCount + 1; // beginning of next stack + + for (int j = 0; j < sectorCount; ++j, ++k1, ++k2) { + // 2 triangles per sector excluding 1st and last stacks + if (i != 0) { + addIndices(k1, k2, k1 + 1); // k1---k2---k1+1 + } + + if (i != (stackCount - 1)) { + addIndices(k1 + 1, k2, k2 + 1); // k1+1---k2---k2+1 + } + + // vertical lines for all stacks + lineIndices.push_back(k1); + lineIndices.push_back(k2); + if (i != 0) { + lineIndices.push_back(k1); + lineIndices.push_back(k1 + 1); + } + } + } + } + + CSolidGeosphere(const CSolidGeosphere&) = delete; + virtual ~CSolidGeosphere(void) = default; + CSolidGeosphere& operator=(const CSolidGeosphere&) = delete; + +protected: + void addIndices(unsigned int i1, unsigned int i2, unsigned int i3) { + indices.push_back(i1); + indices.push_back(i2); + indices.push_back(i3); + } + +private: + float radius; + int stackCount = 0; + int sectorCount = 0; + + std::vector vertices; + std::vector normals; + std::vector texCoords; + std::vector indices; + std::vector lineIndices; +}; \ No newline at end of file diff --git a/src/SolidSphere.h b/src/SolidSphere.h index f050f4e..f1f7d66 100644 --- a/src/SolidSphere.h +++ b/src/SolidSphere.h @@ -1,6 +1,12 @@ #pragma once #include "SolidQuad.h" +#include "PrimTriangle.h" +#include "PrimSphere.h" +#include "PrimSphere.h" +#include "PrimPlane.h" +#include "PrimPlane.h" + class CSolidSphere : public CSolid { @@ -8,6 +14,89 @@ class CSolidSphere : public CSolid CSolidSphere(ptr_shader_t pShader, const Vec3f& origin = Vec3f::all(0), float radius = 1, size_t sides = 24) { // --- PUT YOUR CODE HERE --- + //taken from the OpenRT github + size_t height_segments = (sides / 2); + float t0 = 0; // Initial texture coordinate + float phi0 = 0; + for (size_t s = 0; s < sides; s++) { + float t1 = static_cast(s + 1) / sides; // Next texture coordinate: [1/sides; 1] + float phi1 = -2 * Pif * t1; + + float h0 = 0.0f / height_segments; // Initial height + float theta0 = Pif * (h0 - 0.5f); + + Vec3f n00(cosf(theta0) * cosf(phi0), sinf(theta0), cosf(theta0) * sinf(phi0)); + + Vec3f n10(cosf(theta0) * cosf(phi1), sinf(theta0), cosf(theta0) * sinf(phi1)); + + bool smooth = true; + //changing this depending on the task. + + for (size_t h = 0; h < height_segments; h++) { + float h1 = static_cast(h + 1) / height_segments; // Next height: [1/height_segments; 1] + float theta1 = Pif * (h1 - 0.5f); + + Vec3f n01(cosf(theta1) * cosf(phi0), sinf(theta1), cosf(theta1) * sinf(phi0)); + + Vec3f n11(cosf(theta1) * cosf(phi1), sinf(theta1), cosf(theta1) * sinf(phi1)); + + if (h == 0) { // ----- Bottom cap: triangles ----- + if (smooth) + add(std::make_shared(pShader, + origin + n00 * radius, + origin + n11 * radius, + origin + n01 * radius, + Vec2f(t0, 1 - h0), Vec2f(t1, 1 - h1), Vec2f(t0, 1 - h1), + n00, n11, n01)); + else + add(std::make_shared(pShader, + origin + n00 * radius, + origin + n11 * radius, + origin + n01 * radius, + Vec2f(t0, 1 - h0), Vec2f(t1, 1 - h1), Vec2f(t0, 1 - h1))); + } + else if (h == height_segments - 1) { // ----- Top cap: triangles ----- + if (smooth) + add(std::make_shared(pShader, + origin + n00 * radius, + origin + n10 * radius, + origin + n11 * radius, + Vec2f(t0, 1 - h0), Vec2f(t1, 1 - h0), Vec2f(t1, 1 - h1), + n00, n10, n11)); + else + add(std::make_shared(pShader, + origin + n00 * radius, + origin + n10 * radius, + origin + n11 * radius, + Vec2f(t0, 1 - h0), Vec2f(t1, 1 - h0), Vec2f(t1, 1 - h1))); + } + else { // ----- Sides: quads ----- + if (smooth) + add(std::make_shared(pShader, + origin + n00 * radius, + origin + n10 * radius, + origin + n11 * radius, + origin + n01 * radius, + Vec2f(t0, 1 - h0), Vec2f(t1, 1 - h0), Vec2f(t1, 1 - h1), Vec2f(t0, 1 - h1), + n00, n10, n11, n01)); + else + add(std::make_shared(pShader, + origin + n00 * radius, + origin + n10 * radius, + origin + n11 * radius, + origin + n01 * radius, + Vec2f(t0, 1 - h0), Vec2f(t1, 1 - h0), Vec2f(t1, 1 - h1), Vec2f(t0, 1 - h1))); + } + h0 = h1; + theta0 = theta1; + n00 = n01; + n10 = n11; + } // h + t0 = t1; + phi0 = phi1; + } // s + + } virtual ~CSolidSphere(void) = default; -}; \ No newline at end of file +}; diff --git a/src/main.cpp b/src/main.cpp index 0efa211..b3cd144 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,10 +9,12 @@ #include "SolidQuad.h" #include "SolidCone.h" #include "SolidSphere.h" +#include "SolidGeosphere.h" #include "ShaderFlat.h" #include "ShaderEyelight.h" #include "ShaderPhong.h" +#include "ShaderPhongBumpMapped.h" #include "Texture.h" @@ -33,7 +35,7 @@ Mat RenderFrame(void) #ifdef WIN32 const std::string dataPath = "../data/"; #else - const std::string dataPath = "../../data/"; + const std::string dataPath = "C:\Users\checi\source\repos\eyden-tracer-04-master\data"; #endif // Texture @@ -42,12 +44,15 @@ Mat RenderFrame(void) auto pTexture = std::make_shared(earth); // Shaders - auto pShader = std::make_shared(RGB(0.5f, 1, 0)); + //auto pShader = std::make_shared(RGB(0.5f, 1, 0)); + auto pShader = std::make_shared(RGB(1, 1, 1)); + auto pShader1 = std::make_shared(pTexture); // Geometry CSolidCone solid_cone(pShader, Vec3f(10, -4, 0), 4, 8); CSolidSphere solid_sphere(pShader, Vec3f(0, 0, 0), 4, 36); - auto prim_sphere = std::make_shared(pShader, Vec3f(-10, 0, 0), 4); + auto prim_sphere = std::make_shared(pShader1, Vec3f(-10, 0, 0), 4); + //CSolidGeosphere solid_geosphere(pShader, Vec3f(0, 0, 0), 4, 36); // Add everything to the scene scene.add(pCamera); @@ -55,6 +60,28 @@ Mat RenderFrame(void) scene.add(solid_sphere); scene.add(prim_sphere); + // --- Scene description for bonus task only --- + + //auto shd1 = std::make_shared(scene, RGB(1, 0, 0), 0.1f, 0.5f, 0.5f, 40); // red surface + //auto shd2 = std::make_shared(scene, RGB(1, 1, 0), 0.1f, 0.5f, 0.5f, 40); // yellow surface + + //auto shd3 = std::make_shared(scene, RGB(0, 1, 1), 0.1f, 0.5f, 0.5f, 40); // cyan surface + //auto shd4 = std::make_shared(scene, RGB(0, 0, 1), 0.1f, 0.5f, 0.5f, 40); // blue surface + + //scene.add(std::make_shared(shd1, Vec3f(-2, 1.7f, 0), 2)); + //scene.add(std::make_shared(shd3, Vec3f(1, -1, 1), 2.2f)); + //scene.add(std::make_shared(shd4, Vec3f(3, 0.8f, -2), 2)); + //scene.add(std::make_shared(shd2, Vec3f(0, -1, 0), Vec3f(0, 1, 0))); + + //Vec3f pointLightIntensity(7, 7, 7); + //Vec3f lightPosition2(-3, 5, 4); + //Vec3f lightPosition3(0, 1, 4); + + //scene.add(std::make_shared(pointLightIntensity, lightPosition2)); + //scene.add(std::make_shared(pointLightIntensity, lightPosition3)); + + // --- End description for bonus task --- + // Build BSPTree scene.buildAccelStructure(20, 3);