diff --git a/README.md b/README.md index b5e6198..c16f3d7 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,8 @@ From Chapter 09: From Chapter 10: -![Chapter 10 rendering test](output/ch10_test.png) \ No newline at end of file +![Chapter 10 rendering test](output/ch10_test.png) + +From Chapter 11: + +![Chapter 11 reflections rendering test](output/ch11_reflection.png) \ No newline at end of file diff --git a/output/ch11_reflection.png b/output/ch11_reflection.png new file mode 100644 index 0000000..19d1620 Binary files /dev/null and b/output/ch11_reflection.png differ diff --git a/tests/ch10_test.cpp b/tests/ch10_test.cpp index 68a3a32..5b1ea8c 100644 --- a/tests/ch10_test.cpp +++ b/tests/ch10_test.cpp @@ -1,6 +1,6 @@ /* * DoRayMe - a quick and dirty Raytracer - * Render test for chapter 5 "Put it together". + * Render test for chapter 10 * * Created by Manoël Trapier * Copyright (c) 2020 986-Studio. @@ -79,7 +79,7 @@ int main() w.addLight(&light); /* Set the camera */ - Camera camera = Camera(100, 50, M_PI / 3); + Camera camera = Camera(1920, 1080, M_PI / 3); camera.setTransform(viewTransform(Point(0, 1.5, -5), Point(0, 1, 0), Vector(0, 1, 0))); diff --git a/tests/ch11_reflection.cpp b/tests/ch11_reflection.cpp new file mode 100644 index 0000000..ed2ab4e --- /dev/null +++ b/tests/ch11_reflection.cpp @@ -0,0 +1,117 @@ +/* + * DoRayMe - a quick and dirty Raytracer + * Render test for reflection in chapter 11. + * + * Created by Manoël Trapier + * Copyright (c) 2020 986-Studio. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +int main() +{ + /* First we need to construct the world */ + Plane floor = Plane(); + floor.material.specular = 0; + floor.material.pattern = new RingPattern(Colour(1, 0.9, 0.9), Colour(1, 0.2, 0.2)); + floor.material.reflective = 0.1; + + Plane wall = Plane(); + wall.material.specular = 0; + wall.material.pattern = new StripPattern(Colour(1, 0.9, 0.9), Colour(1, 0.2, 0.2)); + wall.material.pattern->setTransform(translation(0, 0, 1) * rotationY(M_PI/4)); + wall.setTransform(translation(0, 0, 5) * rotationX(M_PI/2)); + + Sphere middle = Sphere(); + middle.setTransform(translation(-0.7, 1, 0.6)); + middle.material.diffuse = 0.7; + middle.material.specular = 0.3; + middle.material.pattern = new StripPattern(Colour(0.1, 1, 0.5), Colour(0, 0.2, 0.2)); + middle.material.pattern->setTransform((rotationZ(M_PI/4) * rotationY(M_PI/5) * scaling(0.2, 0.2, 0.2))); + + Sphere right = Sphere(); + right.setTransform(translation(1.5, 0.5, -0.5) * scaling(0.5, 0.5, 0.5)); + right.material.diffuse = 0.7; + right.material.specular = 0.3; + right.material.pattern = new StripPattern(Colour(0.5, 1, 0.1), Colour(0, 0, 0)); + right.material.pattern->setTransform((scaling(0.1, 0.1, 0.1))); + right.material.reflective = 0.1; + + Sphere left = Sphere(); + left.setTransform(translation(-1.5, 0.33, -0.75) * scaling(0.33, 0.33, 0.33)); + left.material.diffuse = 0.7; + left.material.specular = 0.3; + left.material.pattern = new GradientPattern(Colour(1, 0.8, 0.1), Colour(0.1, 0.1, 1)); + left.material.pattern->setTransform(translation(1.5, 0, 0) * scaling(2.1, 2, 2) * rotationY(-M_PI/4)); + + Sphere fourth = Sphere(); + fourth.setTransform(translation(.5, 0.25, 0.4) * scaling(0.3, 0.3, 0.3)); + fourth.material.diffuse = 0.7; + fourth.material.specular = 0.3; + fourth.material.pattern = new CheckersPattern(Colour(0.1, 0.8, 0.1), Colour(0.8, 1, 0.8)); + fourth.material.pattern->setTransform( scaling(0.2, 0.2, 0.2)); + fourth.material.reflective = 0.4; + + World w = World(); + + w.addObject(&floor); + w.addObject(&wall); + w.addObject(&middle); + w.addObject(&left); + w.addObject(&right); + w.addObject(&fourth); + + /* Add some more reflective spheres */ + Sphere ref1 = Sphere(); + ref1.setTransform(translation(1, 1, .4) * scaling(0.2, 0.2, 0.2)); + ref1.material.reflective = 1; + ref1.material.colour = Colour(0.3, 0.7, 0.6); + w.addObject(&ref1); + + Sphere ref2 = Sphere(); + ref2.setTransform(translation(1.5, 2, -.8) * scaling(0.2, 0.2, 0.2)); + ref2.material.reflective = 1; + ref2.material.specular = 0.5; + ref2.material.colour = Colour(0.3, 0.3, 0.3); + w.addObject(&ref2); + + Sphere ref3 = Sphere(); + ref3.setTransform(translation(-2, 1.678, .4) * scaling(0.4, 0.4, 0.4)); + ref3.material.reflective = 1; + ref3.material.specular = 0.5; + w.addObject(&ref3); + + /* Add light */ + Light light = Light(POINT_LIGHT, Point(-10, 10, -10), Colour(1, 1, 1)); + + w.addLight(&light); + + /* Set the camera */ + Camera camera = Camera(100, 50, M_PI / 3); + camera.setTransform(viewTransform(Point(0, 1.5, -5), + Point(0, 1, 0), + Vector(0, 1, 0))); + + /* Now render it */ + Canvas image = camera.render(w); + + image.SaveAsPNG("ch11_reflection.png"); + + + return 0; +} \ No newline at end of file diff --git a/tests/ch6_test.cpp b/tests/ch6_test.cpp index 796d84a..6a822a2 100644 --- a/tests/ch6_test.cpp +++ b/tests/ch6_test.cpp @@ -1,6 +1,6 @@ /* * DoRayMe - a quick and dirty Raytracer - * Render test for chapter 5 "Put it together". + * Render test for chapter 6 "Put it together". * * Created by Manoël Trapier * Copyright (c) 2020 986-Studio. diff --git a/tests/ch7_test.cpp b/tests/ch7_test.cpp index e0b150b..4cee1a5 100644 --- a/tests/ch7_test.cpp +++ b/tests/ch7_test.cpp @@ -1,6 +1,6 @@ /* * DoRayMe - a quick and dirty Raytracer - * Render test for chapter 5 "Put it together". + * Render test for chapter 7 "Put it together". * * Created by Manoël Trapier * Copyright (c) 2020 986-Studio. diff --git a/tests/ch9_test.cpp b/tests/ch9_test.cpp index 2fd73d2..cb6048e 100644 --- a/tests/ch9_test.cpp +++ b/tests/ch9_test.cpp @@ -1,6 +1,6 @@ /* * DoRayMe - a quick and dirty Raytracer - * Render test for chapter 5 "Put it together". + * Render test for chapter 9. * * Created by Manoël Trapier * Copyright (c) 2020 986-Studio.