Fix gamma rendering issues

- Remove gamma correction from the Vulkan renderer
- Add SamplerCreator, used to specify Min/Mag filter
- Add character texture to example project
- Add AnimationSystem, DebugSystem and UiRenderSystem to example project
This commit is contained in:
Thraix
2023-06-19 12:37:11 +02:00
parent 76bda0ace4
commit 042d1b6c70
42 changed files with 510 additions and 123 deletions
+54 -19
View File
@@ -9,17 +9,20 @@
#include "copium/event/MouseMoveEvent.h"
#include "copium/example/CameraFollowPlayerSystem.h"
#include "copium/example/CameraUpdateSystem.h"
#include "copium/example/ColliderSystem.h"
#include "copium/example/Components.h"
#include "copium/example/DebugSystem.h"
#include "copium/example/AnimationSystem.h"
#include "copium/example/FrameCountSystem.h"
#include "copium/example/HealthChangeSystem.h"
#include "copium/example/HealthComponentListener.h"
#include "copium/example/HealthDisplaySystem.h"
#include "copium/example/MouseFollowSystem.h"
#include "copium/example/ColliderSystem.h"
#include "copium/example/PhysicsSystem.h"
#include "copium/example/PickupSystem.h"
#include "copium/example/PlayerControllerSystem.h"
#include "copium/example/RenderSystem.h"
#include "copium/example/PickupSystem.h"
#include "copium/example/UiRenderSystem.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
@@ -30,7 +33,9 @@ namespace Copium
Scene::Scene(CommandBuffer& commandBuffer, DescriptorPool& descriptorPool)
{
renderer = std::make_unique<Renderer>();
uiRenderer = std::make_unique<Renderer>();
descriptorSetRenderer = renderer->GetGraphicsPipeline().CreateDescriptorSet(descriptorPool, 1);
uiDescriptorSetRenderer = renderer->GetGraphicsPipeline().CreateDescriptorSet(descriptorPool, 1);
ecs = std::make_unique<ECSManager>();
ecs->AddSystem<PlayerControllerSystem>();
@@ -40,41 +45,54 @@ namespace Copium
ecs->AddSystem<HealthChangeSystem>();
ecs->AddSystem<HealthDisplaySystem>();
ecs->AddSystem<CameraFollowPlayerSystem>();
ecs->AddSystem<CameraUpdateSystem>(&viewMatrix, &projectionMatrix, &invPvMatrix);
ecs->AddSystem<CameraUpdateSystem>(&viewMatrix, &projectionMatrix, &invPvMatrix, &uiProjectionMatrix);
ecs->AddSystem<MouseFollowSystem>(&invPvMatrix);
ecs->AddSystem<FrameCountSystem>();
ecs->AddSystem<DebugSystem>();
ecs->AddSystem<AnimationSystem>();
ecs->AddSystem<RenderSystem>(renderer.get(), descriptorSetRenderer.get(), &commandBuffer, &viewMatrix, &projectionMatrix); // better way to store the RenderSystem data?
ecs->AddSystem<UiRenderSystem>(uiRenderer.get(), uiDescriptorSetRenderer.get(), &commandBuffer, &uiProjectionMatrix);
ecs->SetComponentListener<HealthComponentListener>();
// TODO: Load from scene file
for (int y = 0; y < 10; y++)
for (int y = 0; y < 20; y++)
{
{
Entity entity = Entity::Create(ecs.get());
entity.AddComponent<TransformC>(glm::vec2{-10.0f + 0.4f, -11.0f + y * 1.6 + 0.4f}, glm::vec2{0.8f, 0.8f});
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
entity.AddComponent<TransformC>(glm::vec2{-10.0f, -10.0f + y * 1.0}, glm::vec2{1.0f, 1.0f});
if(y == 0 || y == 19)
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{0.25f, 1.0f});
else
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.75f, 0.0f}, glm::vec2{1.0f, 1.0f});
entity.AddComponent<StaticColliderC>(true);
entity.AddComponent<Renderable>();
}
{
Entity entity = Entity::Create(ecs.get());
entity.AddComponent<TransformC>(glm::vec2{10.0f - 0.4f, -10.0f + y * 1.6 + 0.4f}, glm::vec2{0.8f, 0.8f});
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
entity.AddComponent<TransformC>(glm::vec2{10.0f, -10.0f + y * 1.0}, glm::vec2{1.0f, 1.0f});
if(y == 0 || y == 19)
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.5f, 0.0f}, glm::vec2{0.75f, 1.0f});
else
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.75f, 0.0f}, glm::vec2{1.0f, 1.0f});
entity.AddComponent<StaticColliderC>(true);
entity.AddComponent<Renderable>();
}
}
for (int x = 0; x < 10; x++)
for (int x = 1; x < 20; x++)
{
{
Entity entity = Entity::Create(ecs.get());
entity.AddComponent<TransformC>(glm::vec2{-11.0f + x * 1.6 + 0.4f, -10.0f + 0.4f, }, glm::vec2{0.8f, 0.8f});
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
entity.AddComponent<TransformC>(glm::vec2{-10.0f + x * 1.0, -10.0f}, glm::vec2{1.0f, 1.0f});
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.25f, 0.0f}, glm::vec2{0.5f, 1.0f});
entity.AddComponent<StaticColliderC>(true);
entity.AddComponent<Renderable>();
}
{
Entity entity = Entity::Create(ecs.get());
entity.AddComponent<TransformC>(glm::vec2{-11.0f + x * 1.6 + 0.4f, 10.0f - 0.4f, }, glm::vec2{0.8f, 0.8f});
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
entity.AddComponent<TransformC>(glm::vec2{-10.0f + x * 1.0, 10.0f}, glm::vec2{1.0f, 1.0f});
entity.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("stone.meta")}, glm::vec2{0.25f, 0.0f}, glm::vec2{0.5f, 1.0f});
entity.AddComponent<StaticColliderC>(true);
entity.AddComponent<Renderable>();
}
}
for (int y = 0; y < 10; y++)
@@ -86,6 +104,7 @@ namespace Copium
entity.AddComponent<ColorC>(glm::vec3{x * 0.1f, y * 0.1f, 1.0f});
entity.AddComponent<StaticColliderC>(false);
entity.AddComponent<PickupC>();
entity.AddComponent<Renderable>();
}
}
@@ -94,34 +113,50 @@ namespace Copium
entityFox.AddComponent<TransformC>(glm::vec2{-0.9f, -0.4f}, glm::vec2{0.8f, 0.8f});
entityFox.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
entityFox.AddComponent<StaticColliderC>(true);
entityFox.AddComponent<Renderable>();
Entity entityFontAtlas = Entity::Create(ecs.get());
entityFontAtlas.AddComponent<TransformC>(glm::vec2{0.1f, -0.4f}, glm::vec2{0.8, 0.8});
entityFontAtlas.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("font.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
entityFontAtlas.AddComponent<StaticColliderC>(false);
entityFontAtlas.AddComponent<PickupC>();
entityFontAtlas.AddComponent<Renderable>();
Entity entityMouse = Entity::Create(ecs.get());
entityMouse.AddComponent<TransformC>(glm::vec2(0.1), glm::vec2{0.2});
entityMouse.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox2.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
entityMouse.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
entityMouse.AddComponent<MouseFollowC>();
entityMouse.AddComponent<Renderable>();
Entity entityText = Entity::Create(ecs.get());
entityText.AddComponent<TransformC>(glm::vec2{-aspect * 10.0f + 0.1f, 9.4f}, glm::vec2{1.0});
entityText.AddComponent<TextC>(AssetRef{AssetManager::LoadAsset("font.meta")}, std::to_string(0) + " fps", 0.6f);
entityText.AddComponent<FrameCountC>();
entityText.AddComponent<Renderable>();
Entity entityCamera = Entity::Create(ecs.get());
entityCamera.AddComponent<CameraC>(BoundingBox(-aspect, -1.0f, aspect, 1.0f), false);
entityCamera.AddComponent<TransformC>(glm::vec2{0.0f}, glm::vec2{4.0f});
entityCamera.AddComponent<CameraC>(BoundingBox(-aspect, -1.0f, aspect, 1.0f), false, false);
entityCamera.AddComponent<TransformC>(glm::vec2{0.0f}, glm::vec2{2.0f});
Entity entityUiCamera = Entity::Create(ecs.get());
entityUiCamera.AddComponent<CameraC>(BoundingBox(0.0f, 0.0f, Vulkan::GetSwapChain().GetExtent().width, Vulkan::GetSwapChain().GetExtent().height), false, true);
entityUiCamera.AddComponent<TransformC>(glm::vec2{0.0f}, glm::vec2{1.0f});
Entity entityPlayer = Entity::Create(ecs.get());
entityPlayer.AddComponent<PlayerC>(entityCamera);
entityPlayer.AddComponent<PlayerC>(entityCamera, false);
entityPlayer.AddComponent<HealthC>(10, 10);
entityPlayer.AddComponent<PhysicsC>(0.1f, glm::vec2{0.0f, 0.0f}, glm::vec2{0.0f, 0.0f});
entityPlayer.AddComponent<TransformC>(glm::vec2{0.0f, 2.0f}, glm::vec2{1.0f});
entityPlayer.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("fox2.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{1.0f, 1.0f});
entityPlayer.AddComponent<DynamicColliderC>(false, glm::vec2{0.0f});
entityPlayer.AddComponent<TextureC>(AssetRef{AssetManager::LoadAsset("character.meta")}, glm::vec2{0.0f, 0.0f}, glm::vec2{0.25f, 1.0f});
entityPlayer.AddComponent<AnimationC>(4, 4, 0, 3, 4, true, 0.5f);
entityPlayer.AddComponent<DynamicColliderC>(false, glm::vec2{14.0f / 32.0f, 0.0f / 32.0f}, glm::vec2{4.0f / 32.0f, 21.0f / 32.0f}, glm::vec2{0.0f});
entityPlayer.AddComponent<Renderable>();
Entity entityDebug = Entity::Create(ecs.get());
entityDebug.AddComponent<DebugC>(entityPlayer);
entityDebug.AddComponent<TextC>(AssetRef(AssetManager::LoadAsset("font.meta")), "", 20.0f);
entityDebug.AddComponent<TransformC>(glm::vec2{10.0f, Vulkan::GetSwapChain().GetExtent().height - 10.0f}, glm::vec2{1.0f});
entityDebug.AddComponent<UiRenderable>();
}
void Scene::Update()
+3
View File
@@ -13,11 +13,14 @@ namespace Copium
{
private:
std::unique_ptr<Renderer> renderer;
std::unique_ptr<Renderer> uiRenderer;
std::unique_ptr<ECSManager> ecs;
std::unique_ptr<DescriptorSet> descriptorSetRenderer;
std::unique_ptr<DescriptorSet> uiDescriptorSetRenderer;
glm::mat4 projectionMatrix;
glm::mat4 viewMatrix;
glm::mat4 invPvMatrix;
glm::mat4 uiProjectionMatrix;
public:
Scene(CommandBuffer& commandBuffer, DescriptorPool& descriptorPool);
void Update();
+2 -2
View File
@@ -256,7 +256,7 @@ namespace Copium
void SwapChain::InitializeDepthAttachment()
{
depthAttachment = std::make_unique<DepthAttachment>(extent.width, extent.height);
depthAttachment = std::make_unique<DepthAttachment>(extent.width, extent.height, SamplerCreator{});
}
void SwapChain::InitializeRenderPass()
@@ -374,7 +374,7 @@ namespace Copium
{
for (auto&& availableFormat : availableFormats)
{
if (availableFormat.format == VK_FORMAT_B8G8R8A8_SRGB && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
if (availableFormat.format == VK_FORMAT_R8G8B8A8_UNORM && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
{
return availableFormat;
}
+8
View File
@@ -13,6 +13,7 @@ namespace Copium
std::unique_ptr<Window> Vulkan::window;
std::unique_ptr<Device> Vulkan::device;
std::unique_ptr<SwapChain> Vulkan::swapChain;
AssetHandle Vulkan::emptyTexture2D;
void Vulkan::Initialize()
{
@@ -30,10 +31,12 @@ namespace Copium
// TODO: Make the working directory always be relative to the assets folder
// By looking at where the executable is, since that should always be in the bin folder (it currently isn't though)
AssetManager::RegisterAssetDir("assets/");
emptyTexture2D = AssetManager::RegisterRuntimeAsset("empty_texture2d", std::make_unique<Texture2D>(std::vector<uint8_t>{0, 0, 0, 255}, 1, 1, SamplerCreator{}));
}
void Vulkan::Destroy()
{
AssetManager::UnloadAsset(emptyTexture2D);
AssetManager::UnregisterAssetDir("assets/");
AssetManager::Cleanup();
swapChain.reset();
@@ -62,6 +65,11 @@ namespace Copium
return *swapChain;
}
AssetHandle Vulkan::GetEmptyTexture2D()
{
return emptyTexture2D;
}
bool Vulkan::Valid()
{
return instance && window && device && swapChain;
+3 -1
View File
@@ -18,6 +18,8 @@ namespace Copium
static std::unique_ptr<Window> window;
static std::unique_ptr<Device> device;
static std::unique_ptr<SwapChain> swapChain;
static AssetHandle emptyTexture2D;
public:
static void Initialize();
static void Destroy();
@@ -26,6 +28,6 @@ namespace Copium
static Device& GetDevice();
static SwapChain& GetSwapChain();
static bool Valid();
static AssetHandle GetEmptyTexture2D();
};
}
+2
View File
@@ -118,6 +118,8 @@ namespace Copium
void Window::KeyCallback(GLFWwindow* glfwWindow, int key, int scancode, int action, int mods)
{
if (key == -1) // For some reason media keys count as keys with value -1
return;
try
{
if (action == GLFW_PRESS)