Compare commits

..

No commits in common. "a790c26f1c69a6931521bc8b6e1112f902ca411f" and "703624eb8681b118877b9e1bdd2ed0e915f47ec5" have entirely different histories.

93 changed files with 105 additions and 8874 deletions

View File

@ -7,7 +7,7 @@ INTERFACE
"global.h"
"constants.h"
"config.h"
"instance.h"
"context.h"
"physical_device.h"
"device.h"
"swapchain.h"

View File

@ -8,25 +8,25 @@
#include "global.h"
/**
* @class Instance
* @class Context
*
* @brief Vulkan context to handle device initialization logic.
*
* Handles the required hardware interactions.
*/
struct Instance final
struct Context final
{
// Members
vk::Instance m_Instance = nullptr;
vk::DebugUtilsMessengerEXT m_DebugMessenger = nullptr;
// Ctor/Dtor
Instance(cstr appName, Version version, bool enableValidation = ENABLE_LAYER_MESSAGES_DEFAULT_VALUE);
~Instance();
Context(cstr appName, Version version, bool enableValidation = ENABLE_LAYER_MESSAGES_DEFAULT_VALUE);
~Context();
// Move
Instance(Instance &&other) noexcept;
Instance &operator=(Instance &&other) noexcept;
Context(Context &&other) noexcept;
Context &operator=(Context &&other) noexcept;
#if !defined(ASTER_NDEBUG)
constexpr static bool ENABLE_LAYER_MESSAGES_DEFAULT_VALUE = true;
@ -34,5 +34,5 @@ struct Instance final
constexpr static bool ENABLE_LAYER_MESSAGES_DEFAULT_VALUE = false;
#endif
DISALLOW_COPY_AND_ASSIGN(Instance);
DISALLOW_COPY_AND_ASSIGN(Context);
};

View File

@ -11,7 +11,7 @@
#include <EASTL/vector.h>
struct QueueAllocation;
struct Instance;
struct Context;
struct PhysicalDevice;
struct Features
@ -40,9 +40,9 @@ struct Device final
void WaitIdle() const;
// Ctor/Dtor
Device(const Instance *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
Device(const Context *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
const eastl::vector<QueueAllocation> &queueAllocations, NameString &&name);
Device(const Instance *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
Device(const Context *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
const eastl::vector<QueueAllocation> &queueAllocations, eastl::span<u8> &&pipelineCacheData,
NameString &&name);
~Device();

View File

@ -11,7 +11,7 @@
#include <EASTL/fixed_vector.h>
struct Window;
struct Instance;
struct Context;
enum class QueueSupportFlagBits
{
@ -54,5 +54,5 @@ struct PhysicalDevice final
class PhysicalDevices : public eastl::fixed_vector<PhysicalDevice, 4>
{
public:
PhysicalDevices(const Surface *surface, const Instance *context);
PhysicalDevices(const Surface *surface, const Context *context);
};

View File

@ -7,17 +7,17 @@
#include "global.h"
struct Instance;
struct Context;
struct Window;
struct Surface
{
Instance *m_Context;
Context *m_Context;
vk::SurfaceKHR m_Surface;
NameString m_Name;
// Ctor Dtor
Surface(Instance *context, const Window *window, cstr name);
Surface(Context *context, const Window *window, cstr name);
~Surface();
// Move

View File

@ -30,6 +30,5 @@ class BufferManager final
[[nodiscard]] Ref<StorageBuffer> CreateStorageBuffer(usize size, cstr name = nullptr) const;
[[nodiscard]] Ref<UniformBuffer> CreateUniformBuffer(usize size, cstr name = nullptr) const;
[[nodiscard]] Ref<StagingBuffer> CreateStagingBuffer(usize size, cstr name = nullptr) const;
[[nodiscard]] Ref<VertexBuffer> CreateVertexBuffer(usize size, cstr name = nullptr) const;
};
} // namespace systems

View File

@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.13)
target_sources(aster_core
PRIVATE
"global.cpp"
"instance.cpp"
"context.cpp"
"physical_device.cpp"
"device.cpp"
"swapchain.cpp"

View File

@ -3,7 +3,7 @@
// Copyright (c) 2020-2025 Anish Bhobe
// =============================================
#include "core/instance.h"
#include "core/context.h"
#include <EASTL/array.h>
#include <EASTL/fixed_vector.h>
@ -35,7 +35,7 @@ DebugCallback(const VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
return false;
}
Instance::Instance(const cstr appName, const Version version, bool enableValidation)
Context::Context(const cstr appName, const Version version, bool enableValidation)
{
INFO_IF(enableValidation, "Validation Layers enabled");
@ -97,7 +97,7 @@ Instance::Instance(const cstr appName, const Version version, bool enableValidat
}
}
Instance::~Instance()
Context::~Context()
{
if (m_DebugMessenger)
{
@ -108,14 +108,14 @@ Instance::~Instance()
DEBUG("Instance destroyed");
}
Instance::Instance(Instance &&other) noexcept
Context::Context(Context &&other) noexcept
: m_Instance(Take(other.m_Instance))
, m_DebugMessenger(Take(other.m_DebugMessenger))
{
}
Instance &
Instance::operator=(Instance &&other) noexcept
Context &
Context::operator=(Context &&other) noexcept
{
if (this == &other)
return *this;

View File

@ -5,7 +5,7 @@
#include "core/device.h"
#include "core/instance.h"
#include "core/context.h"
#include "core/physical_device.h"
#include "core/queue_allocation.h"
@ -17,13 +17,13 @@ constexpr eastl::array DEVICE_EXTENSIONS = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
};
Device::Device(const Instance *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
Device::Device(const Context *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
const eastl::vector<QueueAllocation> &queueAllocations, NameString &&name)
: Device(context, physicalDevice, enabledFeatures, queueAllocations, {}, std::move(name))
{
}
Device::Device(const Instance *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
Device::Device(const Context *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
const eastl::vector<QueueAllocation> &queueAllocations, eastl::span<u8> &&pipelineCacheData,
NameString &&name)
: m_Name(std::move(name))

View File

@ -5,7 +5,7 @@
#include "core/physical_device.h"
#include "core/instance.h"
#include "core/context.h"
#include "core/surface.h"
[[nodiscard]] vk::SurfaceCapabilitiesKHR
@ -154,7 +154,7 @@ EnumeratePhysicalDevices(const vk::Instance instance)
return physicalDevices;
}
PhysicalDevices::PhysicalDevices(const Surface *surface, const Instance *context)
PhysicalDevices::PhysicalDevices(const Surface *surface, const Context *context)
{
auto physicalDevices = EnumeratePhysicalDevices(context->m_Instance);
for (auto physicalDevice : physicalDevices)

View File

@ -5,10 +5,10 @@
#include "core/surface.h"
#include "core/instance.h"
#include "core/context.h"
#include "core/window.h"
Surface::Surface(Instance *context, const Window *window, cstr name)
Surface::Surface(Context *context, const Window *window, cstr name)
: m_Context(context)
, m_Name(name)
{

View File

@ -5,7 +5,7 @@
#include "core/window.h"
#include "core/instance.h"
#include "core/context.h"
#include "util/logger.h"
std::atomic_uint64_t Window::m_WindowCount = 0;

View File

@ -43,16 +43,6 @@ BufferManager::CreateStagingBuffer(const usize size, const cstr name) const
return std::make_shared<StagingBuffer>(Buffer{m_Device, size, usage, createFlags, memoryUsage, name});
}
Ref<VertexBuffer>
BufferManager::CreateVertexBuffer(const usize size, const cstr name) const
{
constexpr vk::BufferUsageFlags usage = vk::BufferUsageFlagBits::eVertexBuffer;
constexpr VmaAllocationCreateFlags createFlags =
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT;
constexpr VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_AUTO;
return std::make_shared<VertexBuffer>(Buffer{m_Device, size, usage, createFlags, memoryUsage, name});
}
//
// void
// UniformBuffer::Init(const Device *device, const usize size, const cstr name)

View File

@ -5,7 +5,7 @@
#include "gui.h"
#include "aster/core/instance.h"
#include "aster/core/context.h"
#include "aster/core/device.h"
#include "aster/core/window.h"
#include "helpers.h"
@ -26,7 +26,7 @@ VulkanAssert(VkResult result)
}
void
Init(const Instance *context, const Device *device, const Window *window, vk::Format attachmentFormat,
Init(const Context *context, const Device *device, const Window *window, vk::Format attachmentFormat,
const u32 imageCount, const u32 queueFamily, const vk::Queue queue)
{
g_AttachmentFormat = attachmentFormat;

View File

@ -10,14 +10,14 @@
#include <imgui.h>
struct Device;
struct Instance;
struct Context;
struct Window;
struct Swapchain;
// ReSharper disable once CppInconsistentNaming
namespace ImGui
{
void Init(const Instance *context, const Device *device, const Window *window, vk::Format attachmentFormat,
void Init(const Context *context, const Device *device, const Window *window, vk::Format attachmentFormat,
u32 imageCount, u32 queueFamily, vk::Queue queue);
void Destroy(const Device *device);

View File

@ -7,7 +7,7 @@
#include "aster/core/buffer.h"
#include "aster/core/constants.h"
#include "aster/core/instance.h"
#include "aster/core/context.h"
#include "aster/core/device.h"
#include "aster/core/physical_device.h"
#include "aster/core/pipeline.h"
@ -15,7 +15,6 @@
#include "aster/core/window.h"
#include "helpers.h"
#include "aster/systems/resource_manager.h"
#include <EASTL/array.h>
@ -76,7 +75,7 @@ main(int, char **)
MIN_LOG_LEVEL(Logger::LogType::eInfo);
Window window = {"Triangle (Aster)", {640, 480}};
Instance context = {"Triangle", VERSION};
Context context = {"Triangle", VERSION};
Surface surface = {&context, &window, "Primary"};
PhysicalDevices physicalDevices = {&surface, &context};
@ -93,7 +92,6 @@ main(int, char **)
vk::Queue commandQueue = device.GetQueue(queueAllocation.m_Family, 0);
Swapchain swapchain = {&surface, &device, window.GetSize(), "Primary Chain"};
Pipeline pipeline = CreatePipeline(&device, &swapchain);
systems::ResourceManager resourceManager{&device};
vk::CommandPool copyPool;
vk::CommandBuffer copyBuffer;
@ -119,8 +117,45 @@ main(int, char **)
Vertex{.m_Position = {0.5f, -0.5f, 0.0f}, .m_Color = {0.0f, 1.0f, 0.0f}},
Vertex{.m_Position = {0.0f, 0.5f, 0.0f}, .m_Color = {0.0f, 0.0f, 1.0f}},
};
auto vbo = resourceManager.Buffers().CreateVertexBuffer(vertices.size() * sizeof vertices[0], "VBO");
vbo->Write(0, vertices.size() * sizeof vertices[0], vertices.data());
VertexBuffer vbo;
vbo.Init(&device, vertices.size() * sizeof vertices[0], "VBO");
{
StagingBuffer staging;
staging.Init(&device, vertices.size() * sizeof vertices[0], "Staging");
staging.Write(0, vertices.size() * sizeof vertices[0], vertices.data());
vk::Fence fence;
vk::FenceCreateInfo fenceCreateInfo = {};
auto result = device.m_Device.createFence(&fenceCreateInfo, nullptr, &fence);
ERROR_IF(Failed(result), "Fence creation failed. Cause: {}", result) THEN_ABORT(result);
vk::CommandBufferBeginInfo beginInfo = {.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit};
result = copyBuffer.begin(&beginInfo);
ERROR_IF(Failed(result), "Copy begin failed. Cause: {}", result) THEN_ABORT(result);
vk::BufferCopy bufferCopy = {.srcOffset = 0, .dstOffset = 0, .size = staging.m_Size};
copyBuffer.copyBuffer(staging.m_Buffer, vbo.m_Buffer, 1, &bufferCopy);
result = copyBuffer.end();
ERROR_IF(Failed(result), "Copy end failed. Cause: {}", result) THEN_ABORT(result);
vk::SubmitInfo submitInfo = {
.commandBufferCount = 1,
.pCommandBuffers = &copyBuffer,
};
result = commandQueue.submit(1, &submitInfo, fence);
ERROR_IF(Failed(result), "Submit failed. Cause: {}", result) THEN_ABORT(result) ELSE_INFO("Submit copy");
result = device.m_Device.waitForFences(1, &fence, true, MaxValue<u64>);
ERROR_IF(Failed(result), "Fence wait failed. Cause: {}", result) THEN_ABORT(result) ELSE_INFO("Fence wait");
result = device.m_Device.resetCommandPool(copyPool, {});
ERROR_IF(Failed(result), "Couldn't reset command pool. Cause: {}", result) THEN_ABORT(result);
device.m_Device.destroy(fence, nullptr);
staging.Destroy();
}
// Persistent variables
vk::Viewport viewport = {
@ -259,7 +294,7 @@ main(int, char **)
cmd.setScissor(0, 1, &scissor);
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.m_Pipeline);
usize offsets = 0;
cmd.bindVertexBuffers(0, 1, &vbo->m_Buffer, &offsets);
cmd.bindVertexBuffers(0, 1, &vbo.m_Buffer, &offsets);
cmd.draw(3, 1, 0, 0);
cmd.endRendering();
@ -317,6 +352,7 @@ main(int, char **)
device.WaitIdle();
device.m_Device.destroy(copyPool, nullptr);
vbo.Destroy();
return 0;
}

View File

@ -7,7 +7,7 @@
#include "aster/core/buffer.h"
#include "aster/core/constants.h"
#include "aster/core/instance.h"
#include "aster/core/context.h"
#include "aster/core/device.h"
#include "aster/core/image.h"
#include "aster/core/physical_device.h"
@ -99,7 +99,7 @@ main(int, char **)
MIN_LOG_LEVEL(Logger::LogType::eInfo);
Window window = {"Box (Aster)", {640, 480}};
Instance context = {"Box", VERSION};
Context context = {"Box", VERSION};
Surface surface = {&context, &window, "Primary"};
PhysicalDevices physicalDevices = {&surface, &context};

View File

@ -367,21 +367,14 @@ GenerateMipMaps(vk::CommandBuffer commandBuffer, const Ref<Texture> &texture, vk
#endif
}
std::tuple<systems::ResId<TextureView>, Ref<StagingBuffer>>
AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb, cstr name) const
std::tuple<systems::ResId<TextureView>, Ref<Buffer>>
AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb) const
{
// TODO(Something not loading properly).
assert(image->component == 4);
assert(image->height > 0 && image->width > 0);
#if !defined(ASTER_NDEBUG)
auto assignedName = name ? name : image->name.empty() ? image->uri.c_str() : image->name.c_str();
#else
auto assignedName = nullptr;
#endif
u32 height = Cast<u32>(image->height);
u32 width = Cast<u32>(image->width);
@ -391,7 +384,7 @@ AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb, cstr name) cons
auto texture = m_ResourceManager->Images().CreateTexture2D<Texture>({
.m_Format = imageFormat,
.m_Extent = {width, height},
.m_Name = assignedName,
.m_Name = image->name.c_str(),
.m_IsSampled = true,
.m_IsMipMapped = true,
.m_IsStorage = false,
@ -402,7 +395,7 @@ AssetLoader::LoadImageToGpu(tinygltf::Image *image, bool isSrgb, cstr name) cons
#if !defined(ASTER_NDEBUG)
StackString<128> loadActionName = "Load: ";
loadActionName += assignedName;
loadActionName += image->name.empty() ? "<texture>" : image->name.c_str();
vk::DebugUtilsLabelEXT debugLabel = {
.pLabelName = loadActionName.c_str(),
.color = std::array{1.0f, 1.0f, 1.0f, 1.0f},
@ -548,7 +541,7 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
m_CommandBuffer.beginDebugUtilsLabelEXT(&debugLabel);
#endif
eastl::vector<Ref<StagingBuffer>> stagingBuffers;
eastl::vector<Ref<Buffer>> stagingBuffers;
eastl::hash_map<i32, systems::ResId<TextureView>> textureHandleMap;
@ -569,9 +562,8 @@ AssetLoader::LoadModelToGpu(cstr path, cstr name)
return iter->second;
}
const auto &texture = model.textures[index];
auto *image = &model.images[texture.source];
auto [handle, staging] = LoadImageToGpu(image, isSrgb, texture.name.empty() ? nullptr : texture.name.c_str());
auto *image = &model.images[index];
auto [handle, staging] = LoadImageToGpu(image, isSrgb);
textureHandleMap.emplace(index, handle);
stagingBuffers.emplace_back(std::move(staging));
return handle;

View File

@ -112,6 +112,7 @@ struct AssetLoader
u32 m_GraphicsQueueIndex;
Ref<TextureView> LoadHdrImage(cstr path, cstr name = nullptr) const;
std::tuple<systems::ResId<TextureView>, Ref<Buffer>> LoadImageToGpu(tinygltf::Image *image, bool isSrgb) const;
Model LoadModelToGpu(cstr path, cstr name = nullptr);
constexpr static auto ANormal = "NORMAL";
@ -131,10 +132,6 @@ struct AssetLoader
AssetLoader &operator=(AssetLoader &&other) noexcept;
DISALLOW_COPY_AND_ASSIGN(AssetLoader);
private:
std::tuple<systems::ResId<TextureView>, Ref<StagingBuffer>>
LoadImageToGpu(tinygltf::Image *image, bool isSrgb, cstr name = nullptr) const;
};
void

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -7,7 +7,7 @@
#include "aster/core/buffer.h"
#include "aster/core/constants.h"
#include "aster/core/instance.h"
#include "aster/core/context.h"
#include "aster/core/device.h"
#include "aster/core/image.h"
#include "aster/core/physical_device.h"
@ -33,7 +33,7 @@
constexpr u32 MAX_FRAMES_IN_FLIGHT = 3;
constexpr auto PIPELINE_CACHE_FILE = "PipelineCacheData.bin";
constexpr auto MODEL_FILE = "model/Sponza/Sponza.gltf";
constexpr auto MODEL_FILE = "model/DamagedHelmet.glb";
constexpr auto BACKDROP_FILE = "image/photo_studio_loft_hall_4k.hdr";
constexpr u32 INIT_WIDTH = 1280;
constexpr u32 INIT_HEIGHT = 720;
@ -136,7 +136,7 @@ main(int, char **)
MIN_LOG_LEVEL(Logger::LogType::eInfo);
Window window = {"ModelRender (Aster)", {INIT_WIDTH, INIT_HEIGHT}};
Instance context = {"ModelRender", VERSION};
Context context = {"ModelRender", VERSION};
Surface surface = {&context, &window, "Primary Surface"};
PhysicalDevices physicalDevices = {&surface, &context};

View File

@ -15,38 +15,38 @@ struct FS_Output
float4 GetAlbedo(float2 UV, float4 InColor)
{
float4 AlbedoFactor = (float4) MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].AlbedoFactor;
uint AlbedoTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].AlbedoTex;
float4 AlbedoFactor = (float4) MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].AlbedoFactor;
uint AlbedoTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].AlbedoTex;
return AlbedoFactor * InColor * (AlbedoTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(AlbedoTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(AlbedoTexId)], UV) : 1.0f.xxxx);
return AlbedoFactor * InColor * (AlbedoTexId != INVALID_HANDLE ? Textures[AlbedoTexId].Sample(ImmutableSamplers[AlbedoTexId], UV) : 1.0f.xxxx);
}
float GetOcclusion(float2 UV)
{
uint OcclusionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].OcclusionTex;
uint OcclusionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].OcclusionTex;
return OcclusionTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(OcclusionTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(OcclusionTexId)], UV).r : 1.0f;
return OcclusionTexId != INVALID_HANDLE ? Textures[OcclusionTexId].Sample(ImmutableSamplers[OcclusionTexId], UV).r : 1.0f;
}
float3 GetEmissive(float2 UV)
{
float3 EmissionFactor = (float3) MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].EmissionFactor;
uint EmissionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].EmissionTex;
float3 EmissionFactor = (float3) MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].EmissionFactor;
uint EmissionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].EmissionTex;
return EmissionFactor * (EmissionTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(EmissionTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(EmissionTexId)], UV).rgb : 1.0f.xxx);
return EmissionFactor * (EmissionTexId != INVALID_HANDLE ? Textures[EmissionTexId].Sample(ImmutableSamplers[EmissionTexId], UV).rgb : 1.0f.xxx);
}
float3 GetNormal(float3 Position, float3 Normal, float2 UV)
{
float3 N = normalize(Normal);
uint NormalTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].NormalTex;
uint NormalTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].NormalTex;
if (NormalTexId == INVALID_HANDLE)
{
return N;
}
float3 TangentSpaceNormal = Textures[NonUniformResourceIndex(NormalTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(NormalTexId)], UV).xyz * 2.0f - 1.0f;
float3 TangentSpaceNormal = Textures[NormalTexId].Sample(ImmutableSamplers[NormalTexId], UV).xyz * 2.0f - 1.0f;
float3 q1 = ddx(Position);
float3 q2 = ddy(Position);
@ -62,10 +62,10 @@ float3 GetNormal(float3 Position, float3 Normal, float2 UV)
float2 GetMetalRough(float2 UV)
{
float2 MetalRoughFactors = float2(MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].MetalFactor, MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].RoughFactor);
uint MetalRoughTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].MetalRoughTex;
float2 MetalRoughFactors = float2(MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].MetalFactor, MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].RoughFactor);
uint MetalRoughTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].MetalRoughTex;
return MetalRoughFactors * (MetalRoughTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(MetalRoughTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(MetalRoughTexId)], UV).bg : 1.0f.xx); // Metal is B, Rough is G.
return MetalRoughFactors * (MetalRoughTexId != INVALID_HANDLE ? Textures[MetalRoughTexId].Sample(ImmutableSamplers[MetalRoughTexId], UV).bg : 1.0f.xx); // Metal is B, Rough is G.
}
float3 SampleIrradiance(float3 Direction)

View File

@ -3,7 +3,7 @@
cmake_minimum_required(VERSION 3.13)
add_subdirectory("00_util")
add_subdirectory("01_triangle")
# add_subdirectory("01_triangle")
add_subdirectory("02_box")
add_subdirectory("03_model_render")
# add_subdirectory("04_scenes")