Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tippesi committed Oct 16, 2024
1 parent 0bdc241 commit 17d418b
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 29 deletions.
8 changes: 7 additions & 1 deletion data/shader/raytracer/structures.hsh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ struct RaytraceMaterial {
float reflectance;

float normalScale;


float tiling;

int invertUVs;
int twoSided;
int cullBackFaces;
Expand All @@ -136,6 +138,10 @@ struct RaytraceMaterial {
int aoTexture;
int emissiveTexture;

int padding0;
int padding1;
int padding2;

};

struct PackedLight {
Expand Down
3 changes: 2 additions & 1 deletion data/shader/raytracer/surface.hsh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Surface GetSurfaceParameters(Instance instance, Triangle tri, Ray ray,
vec4 vertexColor = r * tri.color0 + s * tri.color1 + t * tri.color2;

texCoord = rayMat.invertUVs > 0 ? vec2(texCoord.x, 1.0 - texCoord.y) : texCoord;
texCoord *= rayMat.tiling;

// Produces some problems in the bottom left corner of the Sponza scene,
// but fixes the cube. Should work in theory.
Expand Down Expand Up @@ -157,6 +158,6 @@ float GetOpacity(Triangle tri, vec2 barrycentric, int materialOffset, int textur
vec2 texCoord = r * tri.uv0 + s * tri.uv1 + t * tri.uv2;
texCoord = rayMat.invertUVs > 0 ? vec2(texCoord.x, 1.0 - texCoord.y) : texCoord;

return SampleOpacityBilinear(rayMat.opacityTexture, float(textureLevel), texCoord)
return SampleOpacityBilinear(rayMat.opacityTexture, float(textureLevel), texCoord * rayMat.tiling)
* rayMat.opacity;
}
4 changes: 2 additions & 2 deletions data/shader/text.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ struct GlyphInfo {
vec2 size;
};

layout (set = 3, binding = 1, std430) buffer GlyphBuffer {
layout (set = 3, binding = 1, std430) readonly buffer GlyphBuffer {
GlyphInfo glyphs[];
};

layout (set = 3, binding = 2, std430) buffer InstancesBuffer {
layout (set = 3, binding = 2, std430) readonly buffer InstancesBuffer {
vec4 instances[];
};

Expand Down
1 change: 1 addition & 0 deletions src/engine/buffer/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ namespace Atlas {
.usageFlags = usageFlags | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
.domain = hostAccessible ? Graphics::BufferDomain::Host : Graphics::BufferDomain::Device,
.data = data,
.dataSize = elementCount * elementSize,
.size = sizeInBytes,
.dedicatedMemory = (usageFlags & BufferUsageBits::DedicatedMemoryBit) > 0,
.priority = (usageFlags & BufferUsageBits::HighPriorityMemoryBit) > 0 ? 1.0f : 0.5f
Expand Down
2 changes: 1 addition & 1 deletion src/engine/graphics/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Atlas {
&allocationCreateInfo, alignment, &buffer, &allocation, nullptr))
}

if (desc.data) SetData(desc.data, 0, desc.size);
if (desc.data) SetData(desc.data, 0, desc.dataSize > 0 ? desc.dataSize : desc.size);

}

Expand Down
2 changes: 2 additions & 0 deletions src/engine/graphics/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace Atlas {
BufferHostAccess hostAccess = BufferHostAccess::Sequential;

void* data = nullptr;
size_t dataSize = 0;

size_t size;
size_t alignment = 0;

Expand Down
5 changes: 3 additions & 2 deletions src/engine/graphics/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ namespace Atlas {

#ifdef AE_BUILDTYPE_DEBUG
validationFeatures.sType = VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT;
validationFeatures.enabledValidationFeatureCount = std::size(enables);
validationFeatures.pEnabledValidationFeatures = enables;
// This doesn't seem to work anymore with newer VulkanSDKs on Nvidia hardware
//validationFeatures.enabledValidationFeatureCount = std::size(enables);
//validationFeatures.pEnabledValidationFeatures = enables;

structureChainBuilder.Append(validationFeatures);
#endif
Expand Down
18 changes: 17 additions & 1 deletion src/engine/loader/ModelImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ namespace Atlas {
lightMap[light->mName.C_Str()] = light;
}

std::map<std::string, aiCamera*> cameraMap;
for (uint32_t i = 0; i < state.scene->mNumCameras; i++) {
auto camera = state.scene->mCameras[i];
cameraMap[camera->mName.C_Str()] = camera;
}

auto rootEntity = scene->CreateEntity();
rootEntity.AddComponent<NameComponent>("Root");
auto& rootHierarchy = rootEntity.AddComponent<HierarchyComponent>();
Expand Down Expand Up @@ -472,7 +478,17 @@ namespace Atlas {
lightComp.properties.point.radius = std::max(glm::sqrt(100.0f * light->mAttenuationQuadratic), intensityRadius);
lightComp.AddSpotShadow(3.0f, 1024);
}
}
}

if (cameraMap.contains(node->mName.C_Str())) {
auto camera = cameraMap[node->mName.C_Str()];

float verticalFOV = glm::degrees(camera->mHorizontalFOV) / camera->mAspect;
vec3 position = vec3(camera->mPosition.x, camera->mPosition.y, camera->mPosition.z);
vec2 rotation = vec2(0.0f);
parentEntity.AddComponent<CameraComponent>(verticalFOV, camera->mAspect, camera->mClipPlaneNear,
camera->mClipPlaneFar, position, rotation);
}

for (uint32_t i = 0; i < node->mNumChildren; i++) {
auto nodeEntity = scene->CreatePrefab<Scene::Prefabs::Node>(node->mChildren[i]->mName.C_Str(), nodeTransform);
Expand Down
4 changes: 3 additions & 1 deletion src/engine/raytracing/RTStructures.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Atlas {
int32_t valid = -1;
};

struct GPUMaterial {
struct alignas(16) GPUMaterial {
int32_t ID = 0;

vec3 baseColor = vec3(1.0f);
Expand All @@ -64,6 +64,8 @@ namespace Atlas {

float normalScale = 1.0f;

float tiling = 1.0f;

int32_t invertUVs = 0;
int32_t twoSided = 0;
int32_t cullBackFaces = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/engine/raytracing/RayTracingWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ namespace Atlas {

gpuMaterial.normalScale = material->normalScale;

gpuMaterial.tiling = material->tiling;

gpuMaterial.invertUVs = mesh->invertUVs ? 1 : 0;
gpuMaterial.twoSided = material->twoSided ? 1 : 0;
gpuMaterial.cullBackFaces = mesh->cullBackFaces ? 1 : 0;
Expand Down
2 changes: 0 additions & 2 deletions src/engine/renderer/MainRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ namespace Atlas {
textRenderer.Init(device);
textureRenderer.Init(device);

font = Atlas::CreateRef<Atlas::Font>("font/roboto.ttf", 22.0f, 5);

}

void MainRenderer::RenderScene(Ref<Viewport> viewport, Ref<RenderTarget> target, Ref<Scene::Scene> scene,
Expand Down
2 changes: 0 additions & 2 deletions src/engine/renderer/MainRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ namespace Atlas {
AtmosphereRenderer atmosphereRenderer;
PathTracingRenderer pathTracingRenderer;

Ref<Font> font;

private:
void CreateGlobalDescriptorSetLayout();

Expand Down
13 changes: 8 additions & 5 deletions src/engine/renderer/VolumetricRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ namespace Atlas {
auto mainLightEntity = GetMainLightEntity(scene);

VolumetricUniforms uniforms;
uniforms.sampleCount = fog->rayMarchStepCount;
uniforms.intensity = fog->volumetricIntensity;
uniforms.sampleCount = fog ? fog->rayMarchStepCount : 1;
uniforms.intensity = fog ? fog->volumetricIntensity : 0.0f;
uniforms.lightCount = std::min(128, int32_t(renderState->volumetricLights.size()));
uniforms.directionalLightCount = 0;

for (const auto& lightEntity : renderState->lightEntities) {
if (lightEntity.comp.type != LightType::DirectionalLight)
for (auto& light : renderState->volumetricLights) {
auto packedType = reinterpret_cast<uint32_t&>(light.color.a);
auto type = static_cast<LightType>(packedType);

if (type != LightType::DirectionalLight)
break;

uniforms.directionalLightCount++;
Expand Down Expand Up @@ -213,7 +216,7 @@ namespace Atlas {
volumetricPipelineConfig.ManageMacro("CLOUDS", cloudsEnabled);
volumetricPipelineConfig.ManageMacro("CLOUD_SHADOWS", cloudShadowsEnabled);
volumetricPipelineConfig.ManageMacro("OCEAN", oceanEnabled);
volumetricPipelineConfig.ManageMacro("LOCAL_LIGHTS", fog->localLights);
volumetricPipelineConfig.ManageMacro("LOCAL_LIGHTS", fogEnabled && fog->localLights);
auto volumetricPipeline = PipelineManager::GetPipeline(volumetricPipelineConfig);

commandList->BindPipeline(volumetricPipeline);
Expand Down
10 changes: 9 additions & 1 deletion src/engine/scene/SceneRenderState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ namespace Atlas::Scene {
// We need to have at least a fake light
auto type = 0;
auto packedType = reinterpret_cast<float&>(type);
lights.push_back(Renderer::Light {
lights.emplace_back(Renderer::Light {
.direction = vec4(0.0f, -1.0f, 0.0f, 0.0f),
.color = vec4(vec3(0.0f), packedType),
.intensity = 0.0f,
Expand All @@ -536,6 +536,14 @@ namespace Atlas::Scene {
lightBuffer.SetData(lights.data(), 0, lights.size());
}

if (volumetricLights.empty()) {
volumetricLights.emplace_back(Renderer::VolumetricLight {
.intensity = 0.0f,
.shadowIdx = -1,
});
volumetricShadows.emplace_back(Renderer::Shadow {});
}

if (volumetricLightBuffer.GetElementCount() < volumetricLights.size()) {
volumetricLightBuffer = Buffer::Buffer(Buffer::BufferUsageBits::HostAccessBit | Buffer::BufferUsageBits::MultiBufferedBit
| Buffer::BufferUsageBits::StorageBufferBit, sizeof(Renderer::VolumetricLight), volumetricLights.size(), volumetricLights.data());
Expand Down
10 changes: 5 additions & 5 deletions src/tests/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ void App::LoadContent(AppConfiguration config) {

viewport = Atlas::CreateRef<Atlas::Viewport>(0, 0, renderTarget->GetWidth(), renderTarget->GetHeight());

auto icon = Atlas::Texture::Texture2D("icon.png");
auto icon = Atlas::ResourceManager<Atlas::Texture::Texture2D>::GetOrLoadResource("icon.png");
window.SetIcon(&icon);

loadingTexture = Atlas::CreateRef<Atlas::Texture::Texture2D>("loading.png");

font = Atlas::CreateRef<Atlas::Font>("font/roboto.ttf", 22.0f, 5);
font = Atlas::ResourceManager<Atlas::Font>::GetOrLoadResource("font/roboto.ttf", 22.0f, 5);

scene = Atlas::CreateRef<Atlas::Scene::Scene>("testscene", glm::vec3(-2048.0f), glm::vec3(2048.0f));

Expand Down Expand Up @@ -126,7 +126,7 @@ void App::LoadContent(AppConfiguration config) {

if (config.ocean) {
scene->ocean = Atlas::CreateRef<Atlas::Ocean::Ocean>(9, 4096.0f,
glm::vec3(0.0f, 5.0f, 0.0f), 512, 86);
glm::vec3(0.0f, 5.0f, 0.0f), 128, 86);
}

scene->physicsWorld = Atlas::CreateRef<Atlas::Physics::PhysicsWorld>();
Expand Down Expand Up @@ -274,7 +274,7 @@ void App::DisplayLoadingScreen(float deltaTime) {
rotation += deltaTime * abs(sin(Atlas::Clock::Get())) * 10.0f;

mainRenderer->textureRenderer.RenderTexture2D(commandList, viewport,
loadingTexture.get(), x, y, width, height, rotation);
loadingTexture.Get().get(), x, y, width, height, rotation);

float textWidth, textHeight;
font->ComputeDimensions("Loading...", 2.0f, &textWidth, &textHeight);
Expand All @@ -283,7 +283,7 @@ void App::DisplayLoadingScreen(float deltaTime) {
y = windowSize.y / 2 - textHeight / 2 + float(loadingTexture->height) + 20.0f;

viewport->Set(0, 0, windowSize.x, windowSize.y);
mainRenderer->textRenderer.Render(commandList, viewport, font,
mainRenderer->textRenderer.Render(commandList, viewport, font.Get(),
"Loading...", x, y, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), 2.0f);

commandList->EndRenderPass();
Expand Down
5 changes: 3 additions & 2 deletions src/tests/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <input/Controller.h>
#include <input/Touch.h>
#include <loader/ModelImporter.h>
#include <resource/ResourceManager.h>
#include <ImguiExtension/ImguiWrapper.h>

#include <renderer/PathTracingRenderer.h>
Expand Down Expand Up @@ -62,7 +63,7 @@ class App : public Atlas::EngineInstance {
Ref<Atlas::Renderer::RenderTarget> renderTarget;
Ref<Atlas::Viewport> viewport;

Ref<Atlas::Font> font;
Atlas::ResourceHandle<Atlas::Font> font;

Ref<Atlas::Scene::Scene> scene;

Expand All @@ -76,7 +77,7 @@ class App : public Atlas::EngineInstance {
Atlas::Input::MouseHandler mouseHandler;
Atlas::Input::KeyboardHandler keyboardHandler;

Ref<Atlas::Texture::Texture2D> loadingTexture;
Atlas::ResourceHandle<Atlas::Texture::Texture2D> loadingTexture;

Atlas::Renderer::ExampleRenderer exampleRenderer;

Expand Down
4 changes: 1 addition & 3 deletions src/tests/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class EngineEndToEndTest : public testing::TestWithParam<AppConfiguration> {
void TearDown() override {
delete engineInstance;

Atlas::PipelineManager::Clear();

graphicsDevice->ForceMemoryCleanup();
}

Expand Down Expand Up @@ -107,7 +105,7 @@ auto testingValues = testing::Values(
AppConfiguration { .recreateSwapchain = true },
AppConfiguration { .resize = true },
AppConfiguration { .exampleRenderer = true },
AppConfiguration{ .minimizeWindow = true }
AppConfiguration { .minimizeWindow = true }
);

INSTANTIATE_TEST_SUITE_P(DemoTestSuite, EngineEndToEndTest, testingValues);
Expand Down

0 comments on commit 17d418b

Please sign in to comment.