Implemented proper checker floor scene for aliasing testing

This commit is contained in:
Maximilian Giller 2022-12-14 00:08:08 +01:00
parent 9580b96868
commit 78b0a4f455

59
ex6.cpp
View file

@ -19,37 +19,66 @@
#include "light/ambientlight.h"
#include "light/pointlight.h"
#include "light/spotlight.h"
#include "shader/flatshader.h"
#include "primitive/triangle.h"
void renderAliasingScene()
void addSquareInGrid(Scene *scene, int r, int c, float scale = 1.0f, float z = 0.0f)
{
// Adds a square in the specified position on a grid to the scene in either white or black
float x = (float) r * scale;
float y = (float) c * scale;
float colorChannel = abs(r + c) % 2;
//! Assuming background is white, omit white triangles
if (colorChannel == 1)
return;
auto color = std::make_shared<FlatShader>(Color(colorChannel, colorChannel, colorChannel));
// Add two triangles that form a square to the scene
auto triangle1 = std::make_shared<Triangle>(Vector3d(x, y, z), Vector3d(x + scale, y, z),
Vector3d(x, y + scale, z), color);
auto triangle2 = std::make_shared<Triangle>(Vector3d(x + scale, y, z), Vector3d(x + scale, y + scale, z),
Vector3d(x, y + scale, z), color);
scene->add(triangle1);
scene->add(triangle2);
}
void renderAliasingScenes()
{
// Checker Scene
FastScene scene;
scene.setBackgroundColor(Color(0.5f, 0.5f, 1));
scene.setBackgroundColor(Color(1, 1, 1)); //! Has to be white for the checker pattern to work, since white squares are omitted
// Set up the camera
PerspectiveCamera camera;
camera.setPosition(Vector3d(0, 0, 0));
camera.setForwardDirection(normalized(Vector3d(1, 0, 0)));
camera.setUpDirection(normalized(Vector3d(0.0f, 1.0f, 0.0f)));
camera.setFovAngle(75.0f);
camera.setPosition(Vector3d(0, 0, 5));
camera.setForwardDirection(normalized(Vector3d(1, 0, -0.3f)));
camera.setUpDirection(normalized(Vector3d(0.0f, 0.0f, 1.0f)));
camera.setFovAngle(90.0f);
auto orange = std::make_shared<FlatShader>(Color(1, 0.8f, 0.2f));
auto sphere = std::make_shared<Sphere>(Vector3d(5, 0, 0), 3, orange);
// Add a grid of squares to the scene
for (int r = 0; r < 200; r++)
{
for (int c = 0; c < 12 + r; c++)
{
addSquareInGrid(&scene, r, c);
addSquareInGrid(&scene, r, -c);
}
}
scene.add(sphere);
// build the tree
scene.buildTree();
// Render the scene
SimpleRenderer renderer;
renderer.renderImage(scene, camera, 64, 64).save("aliasing.png");
renderer.renderImage(scene, camera, 512, 256).save("checker.png");
#ifdef SUPERRENDERER_FOUND
SuperRenderer sr;
sr.setSuperSamplingFactor(4);
sr.renderImage(scene, camera, 64, 64).save("aliasing_super.png");
sr.renderImage(scene, camera, 512, 256).save("checker_super.png");
#endif
}
@ -121,7 +150,7 @@ int main()
sr.renderImage(scene, camera, 1024, 768).save("result_super.png");
#endif
renderAliasingScene();
renderAliasingScenes();
return 0;
}