Files
EVEngine/test/GlobalIllumination.cpp
T
西风逍遥游 2e32afd71b feat(graphics): enhance rendering capabilities with 3D pipeline and ambient occlusion
- Added a new 3D rendering pipeline section in the documentation, detailing initialization, VKBuilder, and asynchronous frame handling.
- Updated the Ambient Occlusion module to support depth-based sampling, allowing for improved visual fidelity in 3D scenes.
- Introduced new shader functionalities for ambient occlusion and global illumination, enhancing the overall rendering quality.
- Updated GBuffer to include hardware depth texture for more accurate depth sampling in 3D rendering.
- Enhanced the RenderControl to manage new features for ambient occlusion and global illumination, ensuring they are enabled by default.

Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com>
2026-08-13 10:01:04 +08:00

94 lines
2.6 KiB
C++

#include "zeroerr/assert.h"
#include "zeroerr/unittest.h"
#include <SDL2/SDL.h>
#include <cmath>
#include <memory>
#include <string>
#include <vector>
#include "graphics/Canvas.h"
#include "graphics/GlobalIllumination.h"
#include "graphics/Graphics.h"
#include "graphics/RenderControl.h"
#include "graphics/Texture.h"
#include "window/Window.h"
using namespace eve::graphics;
namespace {
void openGfxWindow(eve::window::Window *&win, Graphics *&gfx, int w = 320, int h = 240) {
win = eve::window::Window::create();
gfx = Graphics::create();
REQUIRE(win != nullptr);
REQUIRE(gfx != nullptr);
win->setGraphics(gfx);
eve::window::WindowSettings s;
s.width = w;
s.height = h;
s.centered = true;
REQUIRE(win->setWindowSettings(s));
}
Texture *makePackedAlbedoDepth(Graphics *gfx, int w, int h) {
std::vector<uint8_t> px(size_t(w * h * 4));
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
const size_t i = size_t((y * w + x) * 4);
const bool wall = (x > w / 3 && x < w / 2);
px[i + 0] = wall ? 220 : 40;
px[i + 1] = wall ? 40 : 40;
px[i + 2] = wall ? 40 : 40;
px[i + 3] = wall ? 80 : 200;
}
}
return gfx->newTexture(w, h, px.data());
}
} // namespace
TEST_CASE("gi.qualityAndApplyFromDepth") {
eve::window::Window *win = nullptr;
Graphics *gfx = nullptr;
openGfxWindow(win, gfx);
GlobalIllumination *raw = gfx->newGlobalIllumination();
REQUIRE(raw != nullptr);
std::unique_ptr<GlobalIllumination> gi(raw);
REQUIRE(gi->getShader() != nullptr);
CHECK(gi->getQuality() == "medium");
CHECK(gi->getSampleCount() >= 8);
gi->setQuality("low");
CHECK(gi->getQuality() == "low");
CHECK(gi->getSampleCount() == 8);
gi->setQuality("high");
CHECK(gi->getSampleCount() == 24);
gi->setQuality("nope");
CHECK(gi->getQuality() == "medium");
gi->setQuality("low");
gi->setIntensity(0.8f);
gi->setRadius(1.1f);
gi->setLightDirection(0.4f, 1.f, 0.3f);
gi->setLightColor(1.f, 0.9f, 0.7f);
gi->setCamera(0.f, 1.f, 4.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 60.f, 320.f / 240.f, 0.1f, 40.f);
Texture *packed = makePackedAlbedoDepth(gfx, 64, 48);
REQUIRE(packed != nullptr);
Canvas *dest = gfx->newCanvas(64, 48);
REQUIRE(dest != nullptr);
gi->applyFromDepthTo(gfx, packed, dest);
REQUIRE(dest->getTexture() != nullptr);
RenderControl *rc = gfx->getRenderControl();
REQUIRE(rc != nullptr);
CHECK(rc->supports("ao"));
CHECK(rc->supports("gi"));
CHECK(rc->isEnabled("gi"));
CHECK(rc->isEnabled("ao"));
win->close();
}