Add NanoVDB occlusion and transform integration tests
This commit is contained in:
@@ -22,3 +22,5 @@ add_subdirectory(camera_post_process_scene camera_post_process_scene_builtin)
|
|||||||
add_subdirectory(final_color_scene)
|
add_subdirectory(final_color_scene)
|
||||||
add_subdirectory(alpha_cutout_scene)
|
add_subdirectory(alpha_cutout_scene)
|
||||||
add_subdirectory(volume_scene)
|
add_subdirectory(volume_scene)
|
||||||
|
add_subdirectory(volume_occlusion_scene)
|
||||||
|
add_subdirectory(volume_transform_scene)
|
||||||
|
|||||||
284
tests/Rendering/integration/VolumeIntegrationSceneFixture.h
Normal file
284
tests/Rendering/integration/VolumeIntegrationSceneFixture.h
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "RenderingIntegrationImageAssert.h"
|
||||||
|
#include "RenderingIntegrationMain.h"
|
||||||
|
|
||||||
|
#include <XCEngine/Components/CameraComponent.h>
|
||||||
|
#include <XCEngine/Components/GameObject.h>
|
||||||
|
#include <XCEngine/Core/Asset/IResource.h>
|
||||||
|
#include <XCEngine/Core/Math/Color.h>
|
||||||
|
#include <XCEngine/Core/Math/Vector3.h>
|
||||||
|
#include <XCEngine/Core/Math/Vector4.h>
|
||||||
|
#include <XCEngine/Rendering/Execution/SceneRenderer.h>
|
||||||
|
#include <XCEngine/Rendering/RenderContext.h>
|
||||||
|
#include <XCEngine/Rendering/RenderSurface.h>
|
||||||
|
#include <XCEngine/Resources/BuiltinResources.h>
|
||||||
|
#include <XCEngine/Resources/Material/Material.h>
|
||||||
|
#include <XCEngine/Resources/Mesh/Mesh.h>
|
||||||
|
#include <XCEngine/Resources/Shader/Shader.h>
|
||||||
|
#include <XCEngine/Resources/Texture/Texture.h>
|
||||||
|
#include <XCEngine/Resources/Volume/VolumeField.h>
|
||||||
|
#include <XCEngine/Resources/Volume/VolumeFieldLoader.h>
|
||||||
|
#include <XCEngine/RHI/RHITexture.h>
|
||||||
|
#include <XCEngine/Scene/Scene.h>
|
||||||
|
|
||||||
|
#include "../../RHI/integration/fixtures/RHIIntegrationFixture.h"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace VolumeIntegrationTestUtils {
|
||||||
|
|
||||||
|
using namespace XCEngine::Components;
|
||||||
|
using namespace XCEngine::Math;
|
||||||
|
using namespace XCEngine::Rendering;
|
||||||
|
using namespace XCEngine::Resources;
|
||||||
|
using namespace XCEngine::RHI;
|
||||||
|
using namespace XCEngine::RHI::Integration;
|
||||||
|
|
||||||
|
constexpr uint32_t kFrameWidth = 1280;
|
||||||
|
constexpr uint32_t kFrameHeight = 720;
|
||||||
|
constexpr const char* kCloudVolumeRelativePath = "Res/Volumes/cloud.nvdb";
|
||||||
|
|
||||||
|
inline Material* CreateVolumetricMaterial(
|
||||||
|
const char* name,
|
||||||
|
const char* path,
|
||||||
|
const Vector4& tint = Vector4(1.0f, 1.0f, 1.0f, 1.0f),
|
||||||
|
float densityScale = 0.2f,
|
||||||
|
float stepSize = 1.0f,
|
||||||
|
float maxSteps = 2000.0f,
|
||||||
|
float ambientStrength = 0.005f,
|
||||||
|
const Vector3& lightDirection = Vector3(0.5f, 0.8f, 0.3f),
|
||||||
|
float lightSamples = 8.0f) {
|
||||||
|
auto* material = new Material();
|
||||||
|
IResource::ConstructParams params = {};
|
||||||
|
params.name = name;
|
||||||
|
params.path = path;
|
||||||
|
params.guid = ResourceGUID::Generate(path);
|
||||||
|
material->Initialize(params);
|
||||||
|
material->SetShader(ResourceManager::Get().Load<Shader>(GetBuiltinVolumetricShaderPath()));
|
||||||
|
material->SetRenderQueue(MaterialRenderQueue::Transparent);
|
||||||
|
material->SetFloat4("_Tint", tint);
|
||||||
|
material->SetFloat("_DensityScale", densityScale);
|
||||||
|
material->SetFloat("_StepSize", stepSize);
|
||||||
|
material->SetFloat("_MaxSteps", maxSteps);
|
||||||
|
material->SetFloat("_AmbientStrength", ambientStrength);
|
||||||
|
material->SetFloat4("_LightDirection", Vector4(lightDirection, 0.0f));
|
||||||
|
material->SetFloat("_LightSamples", lightSamples);
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Material* CreateUnlitMaterial(
|
||||||
|
const char* name,
|
||||||
|
const char* path,
|
||||||
|
const Vector4& baseColor) {
|
||||||
|
static Texture* whiteTexture = []() -> Texture* {
|
||||||
|
auto* texture = new Texture();
|
||||||
|
IResource::ConstructParams params = {};
|
||||||
|
params.name = "IntegrationWhiteTexture";
|
||||||
|
params.path = "Tests/Rendering/Integration/white.texture";
|
||||||
|
params.guid = ResourceGUID::Generate(params.path);
|
||||||
|
texture->Initialize(params);
|
||||||
|
|
||||||
|
const unsigned char pixel[4] = { 255, 255, 255, 255 };
|
||||||
|
const bool created = texture->Create(
|
||||||
|
1u,
|
||||||
|
1u,
|
||||||
|
1u,
|
||||||
|
1u,
|
||||||
|
XCEngine::Resources::TextureType::Texture2D,
|
||||||
|
XCEngine::Resources::TextureFormat::RGBA8_UNORM,
|
||||||
|
pixel,
|
||||||
|
sizeof(pixel),
|
||||||
|
1u);
|
||||||
|
EXPECT_TRUE(created);
|
||||||
|
return texture;
|
||||||
|
}();
|
||||||
|
|
||||||
|
auto* material = new Material();
|
||||||
|
IResource::ConstructParams params = {};
|
||||||
|
params.name = name;
|
||||||
|
params.path = path;
|
||||||
|
params.guid = ResourceGUID::Generate(path);
|
||||||
|
material->Initialize(params);
|
||||||
|
material->SetShader(ResourceManager::Get().Load<Shader>(GetBuiltinUnlitShaderPath()));
|
||||||
|
material->SetRenderQueue(MaterialRenderQueue::Geometry);
|
||||||
|
material->SetFloat4("_BaseColor", baseColor);
|
||||||
|
material->SetTexture("_MainTex", ResourceHandle<Texture>(whiteTexture));
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline VolumeField* LoadCloudVolumeField(const char* relativePath = kCloudVolumeRelativePath) {
|
||||||
|
const std::filesystem::path volumePath =
|
||||||
|
RenderingIntegrationTestUtils::ResolveRuntimePath(relativePath);
|
||||||
|
EXPECT_TRUE(std::filesystem::exists(volumePath)) << volumePath.string();
|
||||||
|
if (!std::filesystem::exists(volumePath)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
VolumeFieldLoader loader;
|
||||||
|
LoadResult result = loader.Load(volumePath.string().c_str());
|
||||||
|
EXPECT_TRUE(result);
|
||||||
|
EXPECT_NE(result.resource, nullptr);
|
||||||
|
return result ? static_cast<VolumeField*>(result.resource) : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ResourceHandle<Mesh> LoadBuiltinPrimitiveMesh(BuiltinPrimitiveType primitiveType) {
|
||||||
|
return ResourceManager::Get().Load<Mesh>(GetBuiltinPrimitiveMeshPath(primitiveType));
|
||||||
|
}
|
||||||
|
|
||||||
|
class VolumeIntegrationSceneFixture : public RHIIntegrationFixture {
|
||||||
|
protected:
|
||||||
|
virtual const char* GetSceneName() const = 0;
|
||||||
|
virtual void BuildScene() = 0;
|
||||||
|
virtual void ReleaseSceneResources() {}
|
||||||
|
|
||||||
|
void SetUp() override {
|
||||||
|
RHIIntegrationFixture::SetUp();
|
||||||
|
|
||||||
|
mSceneRenderer = std::make_unique<SceneRenderer>();
|
||||||
|
mScene = std::make_unique<Scene>(GetSceneName());
|
||||||
|
|
||||||
|
BuildScene();
|
||||||
|
|
||||||
|
TextureDesc depthDesc = {};
|
||||||
|
depthDesc.width = kFrameWidth;
|
||||||
|
depthDesc.height = kFrameHeight;
|
||||||
|
depthDesc.depth = 1;
|
||||||
|
depthDesc.mipLevels = 1;
|
||||||
|
depthDesc.arraySize = 1;
|
||||||
|
depthDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
||||||
|
depthDesc.textureType = static_cast<uint32_t>(XCEngine::RHI::TextureType::Texture2D);
|
||||||
|
depthDesc.sampleCount = 1;
|
||||||
|
depthDesc.sampleQuality = 0;
|
||||||
|
depthDesc.flags = 0;
|
||||||
|
mDepthTexture = GetDevice()->CreateTexture(depthDesc);
|
||||||
|
ASSERT_NE(mDepthTexture, nullptr);
|
||||||
|
|
||||||
|
ResourceViewDesc depthViewDesc = {};
|
||||||
|
depthViewDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
||||||
|
depthViewDesc.dimension = ResourceViewDimension::Texture2D;
|
||||||
|
depthViewDesc.mipLevel = 0;
|
||||||
|
mDepthView = GetDevice()->CreateDepthStencilView(mDepthTexture, depthViewDesc);
|
||||||
|
ASSERT_NE(mDepthView, nullptr);
|
||||||
|
|
||||||
|
mBackBufferViews.resize(2, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown() override {
|
||||||
|
mSceneRenderer.reset();
|
||||||
|
|
||||||
|
if (mDepthView != nullptr) {
|
||||||
|
mDepthView->Shutdown();
|
||||||
|
delete mDepthView;
|
||||||
|
mDepthView = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mDepthTexture != nullptr) {
|
||||||
|
mDepthTexture->Shutdown();
|
||||||
|
delete mDepthTexture;
|
||||||
|
mDepthTexture = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (RHIResourceView*& backBufferView : mBackBufferViews) {
|
||||||
|
if (backBufferView != nullptr) {
|
||||||
|
backBufferView->Shutdown();
|
||||||
|
delete backBufferView;
|
||||||
|
backBufferView = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mBackBufferViews.clear();
|
||||||
|
|
||||||
|
mScene.reset();
|
||||||
|
ReleaseSceneResources();
|
||||||
|
|
||||||
|
RHIIntegrationFixture::TearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderFrame() override {
|
||||||
|
ASSERT_NE(mScene, nullptr);
|
||||||
|
ASSERT_NE(mSceneRenderer, nullptr);
|
||||||
|
|
||||||
|
RHICommandList* commandList = GetCommandList();
|
||||||
|
ASSERT_NE(commandList, nullptr);
|
||||||
|
|
||||||
|
commandList->Reset();
|
||||||
|
|
||||||
|
RenderSurface surface(kFrameWidth, kFrameHeight);
|
||||||
|
surface.SetColorAttachment(GetCurrentBackBufferView());
|
||||||
|
surface.SetDepthAttachment(mDepthView);
|
||||||
|
|
||||||
|
RenderContext renderContext = {};
|
||||||
|
renderContext.device = GetDevice();
|
||||||
|
renderContext.commandList = commandList;
|
||||||
|
renderContext.commandQueue = GetCommandQueue();
|
||||||
|
renderContext.backendType = GetBackendType();
|
||||||
|
|
||||||
|
ASSERT_TRUE(mSceneRenderer->Render(*mScene, nullptr, renderContext, surface));
|
||||||
|
|
||||||
|
commandList->Close();
|
||||||
|
void* commandLists[] = { commandList };
|
||||||
|
GetCommandQueue()->ExecuteCommandLists(1, commandLists);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderAndCompare(const char* screenshotFilename, float comparisonThreshold = 0.0f) {
|
||||||
|
RHICommandQueue* commandQueue = GetCommandQueue();
|
||||||
|
RHISwapChain* swapChain = GetSwapChain();
|
||||||
|
ASSERT_NE(swapChain, nullptr);
|
||||||
|
|
||||||
|
constexpr int kTargetFrameCount = 30;
|
||||||
|
for (int frameCount = 0; frameCount <= kTargetFrameCount; ++frameCount) {
|
||||||
|
if (frameCount > 0) {
|
||||||
|
commandQueue->WaitForPreviousFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
BeginRender();
|
||||||
|
RenderFrame();
|
||||||
|
|
||||||
|
if (frameCount >= kTargetFrameCount) {
|
||||||
|
commandQueue->WaitForIdle();
|
||||||
|
ASSERT_TRUE(TakeScreenshot(screenshotFilename));
|
||||||
|
ASSERT_TRUE(CompareWithGoldenTemplate(
|
||||||
|
screenshotFilename,
|
||||||
|
"GT.ppm",
|
||||||
|
comparisonThreshold));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
swapChain->Present(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RHIResourceView* GetCurrentBackBufferView() {
|
||||||
|
const int backBufferIndex = GetCurrentBackBufferIndex();
|
||||||
|
if (backBufferIndex < 0) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (static_cast<size_t>(backBufferIndex) >= mBackBufferViews.size()) {
|
||||||
|
mBackBufferViews.resize(static_cast<size_t>(backBufferIndex) + 1, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mBackBufferViews[backBufferIndex] == nullptr) {
|
||||||
|
ResourceViewDesc viewDesc = {};
|
||||||
|
viewDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||||
|
viewDesc.dimension = ResourceViewDimension::Texture2D;
|
||||||
|
viewDesc.mipLevel = 0;
|
||||||
|
mBackBufferViews[backBufferIndex] =
|
||||||
|
GetDevice()->CreateRenderTargetView(GetCurrentBackBuffer(), viewDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mBackBufferViews[backBufferIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Scene> mScene;
|
||||||
|
std::unique_ptr<SceneRenderer> mSceneRenderer;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<RHIResourceView*> mBackBufferViews;
|
||||||
|
RHITexture* mDepthTexture = nullptr;
|
||||||
|
RHIResourceView* mDepthView = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace VolumeIntegrationTestUtils
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
project(rendering_integration_volume_occlusion_scene)
|
||||||
|
|
||||||
|
set(ENGINE_ROOT_DIR ${CMAKE_SOURCE_DIR}/engine)
|
||||||
|
set(PACKAGE_DIR ${CMAKE_SOURCE_DIR}/mvs/OpenGL/package)
|
||||||
|
|
||||||
|
get_filename_component(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../.. ABSOLUTE)
|
||||||
|
|
||||||
|
find_package(Vulkan QUIET)
|
||||||
|
|
||||||
|
add_executable(rendering_integration_volume_occlusion_scene
|
||||||
|
main.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/RHI/integration/fixtures/RHIIntegrationFixture.cpp
|
||||||
|
${PACKAGE_DIR}/src/glad.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(rendering_integration_volume_occlusion_scene PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/RHI/integration/fixtures
|
||||||
|
${ENGINE_ROOT_DIR}/include
|
||||||
|
${PACKAGE_DIR}/include
|
||||||
|
${PROJECT_ROOT_DIR}/engine/src
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(rendering_integration_volume_occlusion_scene PRIVATE
|
||||||
|
d3d12
|
||||||
|
dxgi
|
||||||
|
d3dcompiler
|
||||||
|
winmm
|
||||||
|
opengl32
|
||||||
|
XCEngine
|
||||||
|
GTest::gtest
|
||||||
|
)
|
||||||
|
|
||||||
|
if(TARGET Vulkan::Vulkan)
|
||||||
|
target_link_libraries(rendering_integration_volume_occlusion_scene PRIVATE Vulkan::Vulkan)
|
||||||
|
target_compile_definitions(rendering_integration_volume_occlusion_scene PRIVATE XCENGINE_SUPPORT_VULKAN)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_compile_definitions(rendering_integration_volume_occlusion_scene PRIVATE
|
||||||
|
UNICODE
|
||||||
|
_UNICODE
|
||||||
|
XCENGINE_SUPPORT_OPENGL
|
||||||
|
XCENGINE_SUPPORT_D3D12
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(TARGET rendering_integration_volume_occlusion_scene POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_occlusion_scene>/Res/Volumes
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/RHI/integration/compare_ppm.py
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_occlusion_scene>/
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/GT.ppm
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_occlusion_scene>/GT.ppm
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${CMAKE_SOURCE_DIR}/mvs/VolumeRenderer/Res/NanoVDB/cloud.nvdb
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_occlusion_scene>/Res/Volumes/cloud.nvdb
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${ENGINE_ROOT_DIR}/third_party/renderdoc/renderdoc.dll
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_occlusion_scene>/
|
||||||
|
)
|
||||||
|
|
||||||
|
include(GoogleTest)
|
||||||
|
gtest_discover_tests(rendering_integration_volume_occlusion_scene)
|
||||||
295341
tests/Rendering/integration/volume_occlusion_scene/GT.ppm
Normal file
295341
tests/Rendering/integration/volume_occlusion_scene/GT.ppm
Normal file
File diff suppressed because one or more lines are too long
123
tests/Rendering/integration/volume_occlusion_scene/main.cpp
Normal file
123
tests/Rendering/integration/volume_occlusion_scene/main.cpp
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "../VolumeIntegrationSceneFixture.h"
|
||||||
|
|
||||||
|
#include <XCEngine/Components/CameraComponent.h>
|
||||||
|
#include <XCEngine/Components/GameObject.h>
|
||||||
|
#include <XCEngine/Components/MeshFilterComponent.h>
|
||||||
|
#include <XCEngine/Components/MeshRendererComponent.h>
|
||||||
|
#include <XCEngine/Components/VolumeRendererComponent.h>
|
||||||
|
#include <XCEngine/Core/Math/Vector3.h>
|
||||||
|
#include <XCEngine/Rendering/Extraction/RenderSceneExtractor.h>
|
||||||
|
|
||||||
|
using namespace VolumeIntegrationTestUtils;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr const char* kD3D12Screenshot = "volume_occlusion_scene_d3d12.ppm";
|
||||||
|
|
||||||
|
class VolumeOcclusionSceneTest : public VolumeIntegrationSceneFixture {
|
||||||
|
protected:
|
||||||
|
const char* GetSceneName() const override { return "VolumeOcclusionScene"; }
|
||||||
|
|
||||||
|
void BuildScene() override {
|
||||||
|
mVolumeMaterial = CreateVolumetricMaterial(
|
||||||
|
"VolumeOcclusionMaterial",
|
||||||
|
"Tests/Rendering/VolumeOcclusionScene/Volume.material",
|
||||||
|
Vector4(1.0f, 1.0f, 1.0f, 1.0f),
|
||||||
|
0.24f,
|
||||||
|
0.75f,
|
||||||
|
2400.0f,
|
||||||
|
0.003f,
|
||||||
|
Vector3(0.42f, 0.86f, 0.29f),
|
||||||
|
10.0f);
|
||||||
|
ASSERT_NE(mVolumeMaterial, nullptr);
|
||||||
|
|
||||||
|
mOccluderMaterial = CreateUnlitMaterial(
|
||||||
|
"VolumeOccluderMaterial",
|
||||||
|
"Tests/Rendering/VolumeOcclusionScene/Occluder.material",
|
||||||
|
Vector4(0.92f, 0.36f, 0.18f, 1.0f));
|
||||||
|
ASSERT_NE(mOccluderMaterial, nullptr);
|
||||||
|
|
||||||
|
mVolumeField = LoadCloudVolumeField();
|
||||||
|
ASSERT_NE(mVolumeField, nullptr);
|
||||||
|
|
||||||
|
mCubeMesh = LoadBuiltinPrimitiveMesh(BuiltinPrimitiveType::Cube);
|
||||||
|
ASSERT_TRUE(mCubeMesh.IsValid());
|
||||||
|
|
||||||
|
GameObject* cameraObject = mScene->CreateGameObject("MainCamera");
|
||||||
|
auto* camera = cameraObject->AddComponent<CameraComponent>();
|
||||||
|
camera->SetPrimary(true);
|
||||||
|
camera->SetFieldOfView(45.0f);
|
||||||
|
camera->SetNearClipPlane(0.1f);
|
||||||
|
camera->SetFarClipPlane(5000.0f);
|
||||||
|
camera->SetClearColor(XCEngine::Math::Color(0.03f, 0.04f, 0.06f, 1.0f));
|
||||||
|
cameraObject->GetTransform()->SetLocalPosition(Vector3(220.0f, 300.0f, -1200.0f));
|
||||||
|
cameraObject->GetTransform()->LookAt(Vector3(220.0f, 73.0f, 0.0f));
|
||||||
|
|
||||||
|
GameObject* volumeObject = mScene->CreateGameObject("CloudVolume");
|
||||||
|
auto* volumeRenderer = volumeObject->AddComponent<VolumeRendererComponent>();
|
||||||
|
volumeRenderer->SetVolumeField(mVolumeField);
|
||||||
|
volumeRenderer->SetMaterial(mVolumeMaterial);
|
||||||
|
volumeRenderer->SetCastShadows(false);
|
||||||
|
volumeRenderer->SetReceiveShadows(false);
|
||||||
|
|
||||||
|
GameObject* occluderObject = mScene->CreateGameObject("Occluder");
|
||||||
|
occluderObject->GetTransform()->SetLocalPosition(Vector3(220.0f, 88.0f, -900.0f));
|
||||||
|
occluderObject->GetTransform()->SetLocalScale(Vector3(450.0f, 320.0f, 12.0f));
|
||||||
|
auto* meshFilter = occluderObject->AddComponent<MeshFilterComponent>();
|
||||||
|
auto* meshRenderer = occluderObject->AddComponent<MeshRendererComponent>();
|
||||||
|
meshFilter->SetMesh(mCubeMesh);
|
||||||
|
meshRenderer->SetMaterial(0, mOccluderMaterial);
|
||||||
|
meshRenderer->SetCastShadows(false);
|
||||||
|
meshRenderer->SetReceiveShadows(false);
|
||||||
|
|
||||||
|
RenderSceneExtractor extractor;
|
||||||
|
const RenderSceneData sceneData = extractor.Extract(*mScene, nullptr, kFrameWidth, kFrameHeight);
|
||||||
|
ASSERT_EQ(sceneData.visibleItems.size(), 1u);
|
||||||
|
ASSERT_EQ(sceneData.visibleVolumes.size(), 1u);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReleaseSceneResources() override {
|
||||||
|
delete mVolumeField;
|
||||||
|
mVolumeField = nullptr;
|
||||||
|
delete mVolumeMaterial;
|
||||||
|
mVolumeMaterial = nullptr;
|
||||||
|
delete mOccluderMaterial;
|
||||||
|
mOccluderMaterial = nullptr;
|
||||||
|
mCubeMesh.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Material* mVolumeMaterial = nullptr;
|
||||||
|
Material* mOccluderMaterial = nullptr;
|
||||||
|
VolumeField* mVolumeField = nullptr;
|
||||||
|
ResourceHandle<Mesh> mCubeMesh;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_P(VolumeOcclusionSceneTest, RenderNanoVdbVolumeOcclusionScene) {
|
||||||
|
RenderAndCompare(kD3D12Screenshot, 0.0f);
|
||||||
|
|
||||||
|
const RenderingIntegrationTestUtils::PpmImage image =
|
||||||
|
RenderingIntegrationTestUtils::LoadPpmImage(kD3D12Screenshot);
|
||||||
|
RenderingIntegrationTestUtils::ExpectPixelLuminanceAtMost(
|
||||||
|
image,
|
||||||
|
640u,
|
||||||
|
360u,
|
||||||
|
520,
|
||||||
|
"occluder center should stay opaque");
|
||||||
|
RenderingIntegrationTestUtils::ExpectPixelLuminanceAtLeast(
|
||||||
|
image,
|
||||||
|
1060u,
|
||||||
|
360u,
|
||||||
|
150,
|
||||||
|
"cloud edge should remain visible");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_SUITE_P(D3D12, VolumeOcclusionSceneTest, ::testing::Values(XCEngine::RHI::RHIType::D3D12));
|
||||||
|
|
||||||
|
GTEST_API_ int main(int argc, char** argv) {
|
||||||
|
return RunRenderingIntegrationTestMain(argc, argv);
|
||||||
|
}
|
||||||
@@ -1,110 +1,39 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "../RenderingIntegrationImageAssert.h"
|
#include "../VolumeIntegrationSceneFixture.h"
|
||||||
#include "../RenderingIntegrationMain.h"
|
|
||||||
|
|
||||||
#include <XCEngine/Components/CameraComponent.h>
|
#include <XCEngine/Components/CameraComponent.h>
|
||||||
#include <XCEngine/Components/GameObject.h>
|
#include <XCEngine/Components/GameObject.h>
|
||||||
#include <XCEngine/Components/VolumeRendererComponent.h>
|
#include <XCEngine/Components/VolumeRendererComponent.h>
|
||||||
#include <XCEngine/Core/Asset/IResource.h>
|
|
||||||
#include <XCEngine/Core/Math/Color.h>
|
#include <XCEngine/Core/Math/Color.h>
|
||||||
#include <XCEngine/Core/Math/Vector2.h>
|
|
||||||
#include <XCEngine/Core/Math/Vector3.h>
|
#include <XCEngine/Core/Math/Vector3.h>
|
||||||
#include <XCEngine/Rendering/RenderContext.h>
|
|
||||||
#include <XCEngine/Rendering/RenderSurface.h>
|
|
||||||
#include <XCEngine/Rendering/Execution/SceneRenderer.h>
|
|
||||||
#include <XCEngine/Rendering/Extraction/RenderSceneExtractor.h>
|
#include <XCEngine/Rendering/Extraction/RenderSceneExtractor.h>
|
||||||
#include <XCEngine/Resources/BuiltinResources.h>
|
|
||||||
#include <XCEngine/Resources/Material/Material.h>
|
|
||||||
#include <XCEngine/Resources/Shader/Shader.h>
|
|
||||||
#include <XCEngine/Resources/Volume/VolumeField.h>
|
|
||||||
#include <XCEngine/Resources/Volume/VolumeFieldLoader.h>
|
|
||||||
#include <XCEngine/RHI/RHITexture.h>
|
|
||||||
#include <XCEngine/Scene/Scene.h>
|
|
||||||
|
|
||||||
#include "../../../RHI/integration/fixtures/RHIIntegrationFixture.h"
|
using namespace VolumeIntegrationTestUtils;
|
||||||
|
|
||||||
#include <filesystem>
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace XCEngine::Components;
|
|
||||||
using namespace XCEngine::Math;
|
|
||||||
using namespace XCEngine::Rendering;
|
|
||||||
using namespace XCEngine::Resources;
|
|
||||||
using namespace XCEngine::RHI;
|
|
||||||
using namespace XCEngine::RHI::Integration;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr const char* kD3D12Screenshot = "volume_scene_d3d12.ppm";
|
constexpr const char* kD3D12Screenshot = "volume_scene_d3d12.ppm";
|
||||||
constexpr uint32_t kFrameWidth = 1280;
|
|
||||||
constexpr uint32_t kFrameHeight = 720;
|
|
||||||
constexpr const char* kVolumeFixtureRelativePath = "Res/Volumes/cloud.nvdb";
|
|
||||||
|
|
||||||
Material* CreateVolumetricMaterial() {
|
class VolumeSceneTest : public VolumeIntegrationSceneFixture {
|
||||||
auto* material = new Material();
|
|
||||||
IResource::ConstructParams params = {};
|
|
||||||
params.name = "VolumeMaterial";
|
|
||||||
params.path = "Tests/Rendering/VolumeScene/Volume.material";
|
|
||||||
params.guid = ResourceGUID::Generate(params.path);
|
|
||||||
material->Initialize(params);
|
|
||||||
material->SetShader(ResourceManager::Get().Load<Shader>(GetBuiltinVolumetricShaderPath()));
|
|
||||||
material->SetRenderQueue(MaterialRenderQueue::Transparent);
|
|
||||||
material->SetFloat4("_Tint", Vector4(1.0f, 1.0f, 1.0f, 1.0f));
|
|
||||||
material->SetFloat("_DensityScale", 0.2f);
|
|
||||||
material->SetFloat("_StepSize", 1.0f);
|
|
||||||
material->SetFloat("_MaxSteps", 2000.0f);
|
|
||||||
material->SetFloat("_AmbientStrength", 0.005f);
|
|
||||||
material->SetFloat4("_LightDirection", Vector4(0.5f, 0.8f, 0.3f, 0.0f));
|
|
||||||
material->SetFloat("_LightSamples", 8.0f);
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* GetScreenshotFilename(RHIType backendType) {
|
|
||||||
switch (backendType) {
|
|
||||||
case RHIType::D3D12:
|
|
||||||
default:
|
|
||||||
return kD3D12Screenshot;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class VolumeSceneTest : public RHIIntegrationFixture {
|
|
||||||
protected:
|
protected:
|
||||||
void SetUp() override;
|
const char* GetSceneName() const override { return "VolumeScene"; }
|
||||||
void TearDown() override;
|
void BuildScene() override;
|
||||||
void RenderFrame() override;
|
void ReleaseSceneResources() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RHIResourceView* GetCurrentBackBufferView();
|
|
||||||
|
|
||||||
std::unique_ptr<Scene> mScene;
|
|
||||||
std::unique_ptr<SceneRenderer> mSceneRenderer;
|
|
||||||
std::vector<RHIResourceView*> mBackBufferViews;
|
|
||||||
RHITexture* mDepthTexture = nullptr;
|
|
||||||
RHIResourceView* mDepthView = nullptr;
|
|
||||||
Material* mVolumeMaterial = nullptr;
|
Material* mVolumeMaterial = nullptr;
|
||||||
VolumeField* mVolumeField = nullptr;
|
VolumeField* mVolumeField = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void VolumeSceneTest::SetUp() {
|
void VolumeSceneTest::BuildScene() {
|
||||||
RHIIntegrationFixture::SetUp();
|
mVolumeMaterial = CreateVolumetricMaterial(
|
||||||
|
"VolumeMaterial",
|
||||||
mSceneRenderer = std::make_unique<SceneRenderer>();
|
"Tests/Rendering/VolumeScene/Volume.material");
|
||||||
mScene = std::make_unique<Scene>("VolumeScene");
|
|
||||||
|
|
||||||
mVolumeMaterial = CreateVolumetricMaterial();
|
|
||||||
ASSERT_NE(mVolumeMaterial, nullptr);
|
ASSERT_NE(mVolumeMaterial, nullptr);
|
||||||
|
|
||||||
const std::filesystem::path fixturePath =
|
mVolumeField = LoadCloudVolumeField();
|
||||||
RenderingIntegrationTestUtils::ResolveRuntimePath(kVolumeFixtureRelativePath);
|
ASSERT_NE(mVolumeField, nullptr);
|
||||||
ASSERT_TRUE(std::filesystem::exists(fixturePath)) << fixturePath.string();
|
|
||||||
|
|
||||||
VolumeFieldLoader volumeFieldLoader;
|
|
||||||
LoadResult volumeResult = volumeFieldLoader.Load(fixturePath.string().c_str());
|
|
||||||
ASSERT_TRUE(volumeResult);
|
|
||||||
ASSERT_NE(volumeResult.resource, nullptr);
|
|
||||||
mVolumeField = static_cast<VolumeField*>(volumeResult.resource);
|
|
||||||
|
|
||||||
GameObject* cameraObject = mScene->CreateGameObject("MainCamera");
|
GameObject* cameraObject = mScene->CreateGameObject("MainCamera");
|
||||||
auto* camera = cameraObject->AddComponent<CameraComponent>();
|
auto* camera = cameraObject->AddComponent<CameraComponent>();
|
||||||
@@ -123,141 +52,21 @@ void VolumeSceneTest::SetUp() {
|
|||||||
volumeRenderer->SetCastShadows(false);
|
volumeRenderer->SetCastShadows(false);
|
||||||
volumeRenderer->SetReceiveShadows(false);
|
volumeRenderer->SetReceiveShadows(false);
|
||||||
|
|
||||||
TextureDesc depthDesc = {};
|
|
||||||
depthDesc.width = kFrameWidth;
|
|
||||||
depthDesc.height = kFrameHeight;
|
|
||||||
depthDesc.depth = 1;
|
|
||||||
depthDesc.mipLevels = 1;
|
|
||||||
depthDesc.arraySize = 1;
|
|
||||||
depthDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
|
||||||
depthDesc.textureType = static_cast<uint32_t>(XCEngine::RHI::TextureType::Texture2D);
|
|
||||||
depthDesc.sampleCount = 1;
|
|
||||||
depthDesc.sampleQuality = 0;
|
|
||||||
depthDesc.flags = 0;
|
|
||||||
mDepthTexture = GetDevice()->CreateTexture(depthDesc);
|
|
||||||
ASSERT_NE(mDepthTexture, nullptr);
|
|
||||||
|
|
||||||
ResourceViewDesc depthViewDesc = {};
|
|
||||||
depthViewDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
|
||||||
depthViewDesc.dimension = ResourceViewDimension::Texture2D;
|
|
||||||
depthViewDesc.mipLevel = 0;
|
|
||||||
mDepthView = GetDevice()->CreateDepthStencilView(mDepthTexture, depthViewDesc);
|
|
||||||
ASSERT_NE(mDepthView, nullptr);
|
|
||||||
|
|
||||||
mBackBufferViews.resize(2, nullptr);
|
|
||||||
|
|
||||||
RenderSceneExtractor extractor;
|
RenderSceneExtractor extractor;
|
||||||
const RenderSceneData sceneData = extractor.Extract(*mScene, nullptr, kFrameWidth, kFrameHeight);
|
const RenderSceneData sceneData = extractor.Extract(*mScene, nullptr, kFrameWidth, kFrameHeight);
|
||||||
ASSERT_EQ(sceneData.visibleItems.size(), 0u);
|
ASSERT_EQ(sceneData.visibleItems.size(), 0u);
|
||||||
ASSERT_EQ(sceneData.visibleVolumes.size(), 1u);
|
ASSERT_EQ(sceneData.visibleVolumes.size(), 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VolumeSceneTest::TearDown() {
|
void VolumeSceneTest::ReleaseSceneResources() {
|
||||||
mSceneRenderer.reset();
|
|
||||||
|
|
||||||
if (mDepthView != nullptr) {
|
|
||||||
mDepthView->Shutdown();
|
|
||||||
delete mDepthView;
|
|
||||||
mDepthView = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mDepthTexture != nullptr) {
|
|
||||||
mDepthTexture->Shutdown();
|
|
||||||
delete mDepthTexture;
|
|
||||||
mDepthTexture = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (RHIResourceView*& backBufferView : mBackBufferViews) {
|
|
||||||
if (backBufferView != nullptr) {
|
|
||||||
backBufferView->Shutdown();
|
|
||||||
delete backBufferView;
|
|
||||||
backBufferView = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mBackBufferViews.clear();
|
|
||||||
|
|
||||||
mScene.reset();
|
|
||||||
|
|
||||||
delete mVolumeField;
|
delete mVolumeField;
|
||||||
mVolumeField = nullptr;
|
mVolumeField = nullptr;
|
||||||
delete mVolumeMaterial;
|
delete mVolumeMaterial;
|
||||||
mVolumeMaterial = nullptr;
|
mVolumeMaterial = nullptr;
|
||||||
|
|
||||||
RHIIntegrationFixture::TearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
RHIResourceView* VolumeSceneTest::GetCurrentBackBufferView() {
|
|
||||||
const int backBufferIndex = GetCurrentBackBufferIndex();
|
|
||||||
if (backBufferIndex < 0) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (static_cast<size_t>(backBufferIndex) >= mBackBufferViews.size()) {
|
|
||||||
mBackBufferViews.resize(static_cast<size_t>(backBufferIndex) + 1, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mBackBufferViews[backBufferIndex] == nullptr) {
|
|
||||||
ResourceViewDesc viewDesc = {};
|
|
||||||
viewDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
||||||
viewDesc.dimension = ResourceViewDimension::Texture2D;
|
|
||||||
viewDesc.mipLevel = 0;
|
|
||||||
mBackBufferViews[backBufferIndex] = GetDevice()->CreateRenderTargetView(GetCurrentBackBuffer(), viewDesc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mBackBufferViews[backBufferIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
void VolumeSceneTest::RenderFrame() {
|
|
||||||
ASSERT_NE(mScene, nullptr);
|
|
||||||
ASSERT_NE(mSceneRenderer, nullptr);
|
|
||||||
|
|
||||||
RHICommandList* commandList = GetCommandList();
|
|
||||||
ASSERT_NE(commandList, nullptr);
|
|
||||||
|
|
||||||
commandList->Reset();
|
|
||||||
|
|
||||||
RenderSurface surface(kFrameWidth, kFrameHeight);
|
|
||||||
surface.SetColorAttachment(GetCurrentBackBufferView());
|
|
||||||
surface.SetDepthAttachment(mDepthView);
|
|
||||||
|
|
||||||
RenderContext renderContext = {};
|
|
||||||
renderContext.device = GetDevice();
|
|
||||||
renderContext.commandList = commandList;
|
|
||||||
renderContext.commandQueue = GetCommandQueue();
|
|
||||||
renderContext.backendType = GetBackendType();
|
|
||||||
|
|
||||||
ASSERT_TRUE(mSceneRenderer->Render(*mScene, nullptr, renderContext, surface));
|
|
||||||
|
|
||||||
commandList->Close();
|
|
||||||
void* commandLists[] = { commandList };
|
|
||||||
GetCommandQueue()->ExecuteCommandLists(1, commandLists);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(VolumeSceneTest, RenderNanoVdbVolumeScene) {
|
TEST_P(VolumeSceneTest, RenderNanoVdbVolumeScene) {
|
||||||
RHICommandQueue* commandQueue = GetCommandQueue();
|
RenderAndCompare(kD3D12Screenshot, 0.0f);
|
||||||
RHISwapChain* swapChain = GetSwapChain();
|
|
||||||
ASSERT_NE(swapChain, nullptr);
|
|
||||||
|
|
||||||
const int targetFrameCount = 30;
|
|
||||||
const char* screenshotFilename = GetScreenshotFilename(GetBackendType());
|
|
||||||
|
|
||||||
for (int frameCount = 0; frameCount <= targetFrameCount; ++frameCount) {
|
|
||||||
if (frameCount > 0) {
|
|
||||||
commandQueue->WaitForPreviousFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
BeginRender();
|
|
||||||
RenderFrame();
|
|
||||||
|
|
||||||
if (frameCount >= targetFrameCount) {
|
|
||||||
commandQueue->WaitForIdle();
|
|
||||||
ASSERT_TRUE(TakeScreenshot(screenshotFilename));
|
|
||||||
ASSERT_TRUE(CompareWithGoldenTemplate(screenshotFilename, "GT.ppm", 0.0f));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
swapChain->Present(0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
project(rendering_integration_volume_transform_scene)
|
||||||
|
|
||||||
|
set(ENGINE_ROOT_DIR ${CMAKE_SOURCE_DIR}/engine)
|
||||||
|
set(PACKAGE_DIR ${CMAKE_SOURCE_DIR}/mvs/OpenGL/package)
|
||||||
|
|
||||||
|
get_filename_component(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../.. ABSOLUTE)
|
||||||
|
|
||||||
|
find_package(Vulkan QUIET)
|
||||||
|
|
||||||
|
add_executable(rendering_integration_volume_transform_scene
|
||||||
|
main.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/RHI/integration/fixtures/RHIIntegrationFixture.cpp
|
||||||
|
${PACKAGE_DIR}/src/glad.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(rendering_integration_volume_transform_scene PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/RHI/integration/fixtures
|
||||||
|
${ENGINE_ROOT_DIR}/include
|
||||||
|
${PACKAGE_DIR}/include
|
||||||
|
${PROJECT_ROOT_DIR}/engine/src
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(rendering_integration_volume_transform_scene PRIVATE
|
||||||
|
d3d12
|
||||||
|
dxgi
|
||||||
|
d3dcompiler
|
||||||
|
winmm
|
||||||
|
opengl32
|
||||||
|
XCEngine
|
||||||
|
GTest::gtest
|
||||||
|
)
|
||||||
|
|
||||||
|
if(TARGET Vulkan::Vulkan)
|
||||||
|
target_link_libraries(rendering_integration_volume_transform_scene PRIVATE Vulkan::Vulkan)
|
||||||
|
target_compile_definitions(rendering_integration_volume_transform_scene PRIVATE XCENGINE_SUPPORT_VULKAN)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_compile_definitions(rendering_integration_volume_transform_scene PRIVATE
|
||||||
|
UNICODE
|
||||||
|
_UNICODE
|
||||||
|
XCENGINE_SUPPORT_OPENGL
|
||||||
|
XCENGINE_SUPPORT_D3D12
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(TARGET rendering_integration_volume_transform_scene POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_transform_scene>/Res/Volumes
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/RHI/integration/compare_ppm.py
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_transform_scene>/
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/GT.ppm
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_transform_scene>/GT.ppm
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${CMAKE_SOURCE_DIR}/mvs/VolumeRenderer/Res/NanoVDB/cloud.nvdb
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_transform_scene>/Res/Volumes/cloud.nvdb
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
${ENGINE_ROOT_DIR}/third_party/renderdoc/renderdoc.dll
|
||||||
|
$<TARGET_FILE_DIR:rendering_integration_volume_transform_scene>/
|
||||||
|
)
|
||||||
|
|
||||||
|
include(GoogleTest)
|
||||||
|
gtest_discover_tests(rendering_integration_volume_transform_scene)
|
||||||
781156
tests/Rendering/integration/volume_transform_scene/GT.ppm
Normal file
781156
tests/Rendering/integration/volume_transform_scene/GT.ppm
Normal file
File diff suppressed because it is too large
Load Diff
143
tests/Rendering/integration/volume_transform_scene/main.cpp
Normal file
143
tests/Rendering/integration/volume_transform_scene/main.cpp
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "../VolumeIntegrationSceneFixture.h"
|
||||||
|
|
||||||
|
#include <XCEngine/Components/CameraComponent.h>
|
||||||
|
#include <XCEngine/Components/GameObject.h>
|
||||||
|
#include <XCEngine/Components/MeshFilterComponent.h>
|
||||||
|
#include <XCEngine/Components/MeshRendererComponent.h>
|
||||||
|
#include <XCEngine/Components/VolumeRendererComponent.h>
|
||||||
|
#include <XCEngine/Core/Math/Math.h>
|
||||||
|
#include <XCEngine/Core/Math/Quaternion.h>
|
||||||
|
#include <XCEngine/Core/Math/Vector3.h>
|
||||||
|
#include <XCEngine/Rendering/Extraction/RenderSceneExtractor.h>
|
||||||
|
|
||||||
|
using namespace VolumeIntegrationTestUtils;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr const char* kD3D12Screenshot = "volume_transform_scene_d3d12.ppm";
|
||||||
|
|
||||||
|
class VolumeTransformSceneTest : public VolumeIntegrationSceneFixture {
|
||||||
|
protected:
|
||||||
|
const char* GetSceneName() const override { return "VolumeTransformScene"; }
|
||||||
|
|
||||||
|
void BuildScene() override {
|
||||||
|
mVolumeMaterial = CreateVolumetricMaterial(
|
||||||
|
"VolumeTransformMaterial",
|
||||||
|
"Tests/Rendering/VolumeTransformScene/Volume.material",
|
||||||
|
Vector4(0.98f, 0.99f, 1.0f, 1.0f),
|
||||||
|
0.22f,
|
||||||
|
0.75f,
|
||||||
|
2400.0f,
|
||||||
|
0.003f,
|
||||||
|
Vector3(-0.28f, 0.91f, 0.31f),
|
||||||
|
10.0f);
|
||||||
|
ASSERT_NE(mVolumeMaterial, nullptr);
|
||||||
|
|
||||||
|
mBackplateMaterial = CreateUnlitMaterial(
|
||||||
|
"VolumeTransformBackplateMaterial",
|
||||||
|
"Tests/Rendering/VolumeTransformScene/Backplate.material",
|
||||||
|
Vector4(0.16f, 0.20f, 0.24f, 1.0f));
|
||||||
|
ASSERT_NE(mBackplateMaterial, nullptr);
|
||||||
|
|
||||||
|
mOriginMarkerMaterial = CreateUnlitMaterial(
|
||||||
|
"VolumeTransformOriginMarkerMaterial",
|
||||||
|
"Tests/Rendering/VolumeTransformScene/OriginMarker.material",
|
||||||
|
Vector4(0.90f, 0.10f, 0.70f, 1.0f));
|
||||||
|
ASSERT_NE(mOriginMarkerMaterial, nullptr);
|
||||||
|
|
||||||
|
mVolumeField = LoadCloudVolumeField();
|
||||||
|
ASSERT_NE(mVolumeField, nullptr);
|
||||||
|
|
||||||
|
mCubeMesh = LoadBuiltinPrimitiveMesh(BuiltinPrimitiveType::Cube);
|
||||||
|
ASSERT_TRUE(mCubeMesh.IsValid());
|
||||||
|
|
||||||
|
GameObject* cameraObject = mScene->CreateGameObject("MainCamera");
|
||||||
|
auto* camera = cameraObject->AddComponent<CameraComponent>();
|
||||||
|
camera->SetPrimary(true);
|
||||||
|
camera->SetFieldOfView(45.0f);
|
||||||
|
camera->SetNearClipPlane(0.1f);
|
||||||
|
camera->SetFarClipPlane(5000.0f);
|
||||||
|
camera->SetClearColor(XCEngine::Math::Color(0.03f, 0.04f, 0.06f, 1.0f));
|
||||||
|
cameraObject->GetTransform()->SetLocalPosition(Vector3(-120.0f, 320.0f, -1280.0f));
|
||||||
|
cameraObject->GetTransform()->LookAt(Vector3(140.0f, 125.0f, 120.0f));
|
||||||
|
|
||||||
|
GameObject* volumeObject = mScene->CreateGameObject("CloudVolume");
|
||||||
|
volumeObject->GetTransform()->SetLocalPosition(Vector3(220.0f, 60.0f, 160.0f));
|
||||||
|
volumeObject->GetTransform()->SetLocalRotation(Quaternion::FromEulerAngles(
|
||||||
|
Vector3(-12.0f, 37.0f, 19.0f) * XCEngine::Math::DEG_TO_RAD));
|
||||||
|
volumeObject->GetTransform()->SetLocalScale(Vector3(0.82f, 0.82f, 0.82f));
|
||||||
|
auto* volumeRenderer = volumeObject->AddComponent<VolumeRendererComponent>();
|
||||||
|
volumeRenderer->SetVolumeField(mVolumeField);
|
||||||
|
volumeRenderer->SetMaterial(mVolumeMaterial);
|
||||||
|
volumeRenderer->SetCastShadows(false);
|
||||||
|
volumeRenderer->SetReceiveShadows(false);
|
||||||
|
|
||||||
|
GameObject* backplateObject = mScene->CreateGameObject("Backplate");
|
||||||
|
backplateObject->GetTransform()->SetLocalPosition(Vector3(230.0f, 115.0f, 650.0f));
|
||||||
|
backplateObject->GetTransform()->SetLocalScale(Vector3(900.0f, 700.0f, 10.0f));
|
||||||
|
auto* backplateMeshFilter = backplateObject->AddComponent<MeshFilterComponent>();
|
||||||
|
auto* backplateMeshRenderer = backplateObject->AddComponent<MeshRendererComponent>();
|
||||||
|
backplateMeshFilter->SetMesh(mCubeMesh);
|
||||||
|
backplateMeshRenderer->SetMaterial(0, mBackplateMaterial);
|
||||||
|
backplateMeshRenderer->SetCastShadows(false);
|
||||||
|
backplateMeshRenderer->SetReceiveShadows(false);
|
||||||
|
|
||||||
|
GameObject* originMarkerObject = mScene->CreateGameObject("OriginMarker");
|
||||||
|
originMarkerObject->GetTransform()->SetLocalPosition(Vector3(-10.0f, 73.0f, 0.0f));
|
||||||
|
originMarkerObject->GetTransform()->SetLocalScale(Vector3(40.0f, 40.0f, 40.0f));
|
||||||
|
auto* originMarkerMeshFilter = originMarkerObject->AddComponent<MeshFilterComponent>();
|
||||||
|
auto* originMarkerMeshRenderer = originMarkerObject->AddComponent<MeshRendererComponent>();
|
||||||
|
originMarkerMeshFilter->SetMesh(mCubeMesh);
|
||||||
|
originMarkerMeshRenderer->SetMaterial(0, mOriginMarkerMaterial);
|
||||||
|
originMarkerMeshRenderer->SetCastShadows(false);
|
||||||
|
originMarkerMeshRenderer->SetReceiveShadows(false);
|
||||||
|
|
||||||
|
RenderSceneExtractor extractor;
|
||||||
|
const RenderSceneData sceneData = extractor.Extract(*mScene, nullptr, kFrameWidth, kFrameHeight);
|
||||||
|
ASSERT_EQ(sceneData.visibleItems.size(), 2u);
|
||||||
|
ASSERT_EQ(sceneData.visibleVolumes.size(), 1u);
|
||||||
|
EXPECT_EQ(sceneData.visibleVolumes[0].localToWorld.GetTranslation(), Vector3(220.0f, 60.0f, 160.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReleaseSceneResources() override {
|
||||||
|
delete mVolumeField;
|
||||||
|
mVolumeField = nullptr;
|
||||||
|
delete mVolumeMaterial;
|
||||||
|
mVolumeMaterial = nullptr;
|
||||||
|
delete mBackplateMaterial;
|
||||||
|
mBackplateMaterial = nullptr;
|
||||||
|
delete mOriginMarkerMaterial;
|
||||||
|
mOriginMarkerMaterial = nullptr;
|
||||||
|
mCubeMesh.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Material* mVolumeMaterial = nullptr;
|
||||||
|
Material* mBackplateMaterial = nullptr;
|
||||||
|
Material* mOriginMarkerMaterial = nullptr;
|
||||||
|
VolumeField* mVolumeField = nullptr;
|
||||||
|
ResourceHandle<Mesh> mCubeMesh;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_P(VolumeTransformSceneTest, RenderNanoVdbVolumeTransformScene) {
|
||||||
|
RenderAndCompare(kD3D12Screenshot, 0.0f);
|
||||||
|
|
||||||
|
const RenderingIntegrationTestUtils::PpmImage image =
|
||||||
|
RenderingIntegrationTestUtils::LoadPpmImage(kD3D12Screenshot);
|
||||||
|
RenderingIntegrationTestUtils::ExpectPixelLuminanceAtLeast(
|
||||||
|
image,
|
||||||
|
840u,
|
||||||
|
320u,
|
||||||
|
120,
|
||||||
|
"transformed volume should stay visible over the backplate");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_SUITE_P(D3D12, VolumeTransformSceneTest, ::testing::Values(XCEngine::RHI::RHIType::D3D12));
|
||||||
|
|
||||||
|
GTEST_API_ int main(int argc, char** argv) {
|
||||||
|
return RunRenderingIntegrationTestMain(argc, argv);
|
||||||
|
}
|
||||||
@@ -46,9 +46,22 @@ endif()
|
|||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tree_view_basic/CMakeLists.txt")
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tree_view_basic/CMakeLists.txt")
|
||||||
add_subdirectory(tree_view_basic)
|
add_subdirectory(tree_view_basic)
|
||||||
endif()
|
endif()
|
||||||
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tree_view_multiselect/CMakeLists.txt")
|
||||||
|
add_subdirectory(tree_view_multiselect)
|
||||||
|
endif()
|
||||||
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tree_view_inline_rename/CMakeLists.txt"
|
||||||
|
AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tree_view_inline_rename/main.cpp")
|
||||||
|
add_subdirectory(tree_view_inline_rename)
|
||||||
|
endif()
|
||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/list_view_basic/CMakeLists.txt")
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/list_view_basic/CMakeLists.txt")
|
||||||
add_subdirectory(list_view_basic)
|
add_subdirectory(list_view_basic)
|
||||||
endif()
|
endif()
|
||||||
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/list_view_multiselect/CMakeLists.txt")
|
||||||
|
add_subdirectory(list_view_multiselect)
|
||||||
|
endif()
|
||||||
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/list_view_inline_rename/CMakeLists.txt")
|
||||||
|
add_subdirectory(list_view_inline_rename)
|
||||||
|
endif()
|
||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/scroll_view_basic/CMakeLists.txt")
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/scroll_view_basic/CMakeLists.txt")
|
||||||
add_subdirectory(scroll_view_basic)
|
add_subdirectory(scroll_view_basic)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user