Add semantic pixel asserts for lighting scenes

This commit is contained in:
2026-04-05 16:46:47 +08:00
parent cda4a57756
commit 54a699aa26
11 changed files with 282 additions and 96 deletions

View File

@@ -3,6 +3,7 @@
#include <gtest/gtest.h>
#include "../RenderingIntegrationImageAssert.h"
#include "../RenderingIntegrationMain.h"
#include <XCEngine/Components/CameraComponent.h>
@@ -45,6 +46,20 @@ constexpr const char* kVulkanScreenshot = "spot_light_scene_vulkan.ppm";
constexpr uint32_t kFrameWidth = 1280;
constexpr uint32_t kFrameHeight = 720;
void ExpectSpotLightKeyPixels(const RenderingIntegrationTestUtils::PpmImage& image) {
using namespace RenderingIntegrationTestUtils;
ExpectPixelLuminanceAtMost(image, 320, 320, 18, "background remains unlit");
ExpectPixelLuminanceAtLeast(image, 640, 320, 700, "spot hot area stays bright");
ExpectPixelNear(image, 640, 320, { 255, 255, 203 }, 2, "spot hot area color");
ExpectPixelLuminanceAtLeast(image, 676, 289, 560, "upper cone receives spotlight");
ExpectPixelChannelDominates(image, 676, 289, 0, 40, "upper cone keeps warm tint");
ExpectPixelLuminanceAtLeast(image, 700, 376, 540, "ground inside cone stays lit");
ExpectPixelChannelDominates(image, 700, 376, 0, 30, "ground inside cone stays warm");
ExpectPixelLuminanceAtMost(image, 760, 320, 210, "edge cube outside cone stays dark");
ExpectPixelLuminanceAtMost(image, 640, 406, 160, "ground outside cone stays dark");
}
void AppendQuadFace(
std::vector<StaticMeshVertex>& vertices,
std::vector<uint32_t>& indices,
@@ -420,6 +435,8 @@ TEST_P(SpotLightSceneTest, RenderSpotLightScene) {
if (frameCount >= targetFrameCount) {
commandQueue->WaitForIdle();
ASSERT_TRUE(TakeScreenshot(screenshotFilename));
const auto screenshotImage = RenderingIntegrationTestUtils::LoadPpmImage(screenshotFilename);
ExpectSpotLightKeyPixels(screenshotImage);
ASSERT_TRUE(CompareWithGoldenTemplate(screenshotFilename, "GT.ppm", static_cast<float>(comparisonThreshold)));
break;
}