Skip to content

Commit

Permalink
Added Rasterizer Test
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliom committed Jul 23, 2024
1 parent 9afc5e7 commit 54f05d7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
3 changes: 1 addition & 2 deletions BasicRenderer/include/Rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace BasicRenderer
return { (uv1.z - (uv1.x + uv1.y)) * (1.0f / uv1.z), uv1.y * (1.0f / uv1.z), uv1.x * (1.0f / uv1.z) };
}

inline Vector2 Clamp(Vector2& v, const Vector2& min, const Vector2& max) const
inline void Clamp(Vector2& v, const Vector2& min, const Vector2& max) const
{
if (v.x < min.x)
{
Expand All @@ -62,7 +62,6 @@ namespace BasicRenderer
{
v.y = max.y;
}
return v;
}
};
}
19 changes: 11 additions & 8 deletions BasicRenderer/source/Rasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,20 @@ namespace BasicRenderer

inline Vector4 Rasterizer::BoundingBox(const Face& f, const float fwidth, const float fheight) const
{
Vector2 v0 = Vector2(f.v0.pos.x, f.v0.pos.y);
Vector2 v1 = Vector2(f.v1.pos.x, f.v1.pos.y);
Vector2 v2 = Vector2(f.v2.pos.x, f.v2.pos.y);
const Vector2 v0 = Vector2(f.v0.pos.x, f.v0.pos.y);
const Vector2 v1 = Vector2(f.v1.pos.x, f.v1.pos.y);
const Vector2 v2 = Vector2(f.v2.pos.x, f.v2.pos.y);

Vector2 mini = Vector2::Min(Vector2::Min(v0, v1), v2);
Vector2 maxi = Vector2::Max(Vector2::Max(v0, v1), v2);
const Vector2 mini = Vector2::Min(Vector2::Min(v0, v1), v2);
const Vector2 maxi = Vector2::Max(Vector2::Max(v0, v1), v2);

Vector2 lim = Vector2(fwidth - 1.0f, fheight - 1.0f);
const Vector2 lim = Vector2(fwidth - 1.0f, fheight - 1.0f);

Vector2 finalMin = Clamp(Vector2::Min(mini, maxi), Vector2(0.0f, 0.0f), lim);
Vector2 finalMax = Clamp(Vector2::Max(mini, maxi), Vector2(0.0f, 0.0f), lim);
Vector2 finalMin = Vector2::Min(mini, maxi);
Vector2 finalMax = Vector2::Max(mini, maxi);

Clamp(finalMin, Vector2::Zero(), lim);
Clamp(finalMax, Vector2::Zero(), lim);

return Vector4(finalMin.x, finalMin.y, finalMax.x, finalMax.y);
}
Expand Down
19 changes: 16 additions & 3 deletions BasicRenderer/test/TestRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ World* TestScene()
}


TEST(SUITE_NAME, Render)
TEST(SUITE_NAME, Raytracer)
{
// TODO
Renderer renderer;
std::unique_ptr<Model> model = std::make_unique<Model>(TestScene());

const uint width = 320;
const uint height = 240;
model->SetMainCameraAspectRatio(static_cast<float>(width), static_cast<float>(height));
model->Update(model->UpdateTime());
std::unique_ptr<RenderState> renderState(model->ProcessForRendering());

Raytracer& raytracer = renderer.GetRaytracer();
Expand All @@ -65,5 +63,20 @@ TEST(SUITE_NAME, Render)

const FrameBuffer* frame = renderer.Render(*renderState, width, height, Renderer::RenderingMode::RAYTRACER, Renderer::ShadingMode::LIT);

EXPECT_TRUE(frame != nullptr);
}

TEST(SUITE_NAME, Rasterizer)
{
Renderer renderer;
std::unique_ptr<Model> model = std::make_unique<Model>(TestScene());

const uint width = 320;
const uint height = 240;
model->SetMainCameraAspectRatio(static_cast<float>(width), static_cast<float>(height));
std::unique_ptr<RenderState> renderState(model->ProcessForRendering());

const FrameBuffer* frame = renderer.Render(*renderState, width, height, Renderer::RenderingMode::RASTERIZER, Renderer::ShadingMode::LIT);

EXPECT_TRUE(frame != nullptr);
}

0 comments on commit 54f05d7

Please sign in to comment.