Compare commits

...

3 Commits

Author SHA1 Message Date
Anish Bhobe a790c26f1c Rename Context to Instance. 2025-04-28 21:37:03 +02:00
Anish Bhobe 668189acb5 Fixed bug in Model Loading.
Model Loader was loading indexes into image instead of going via texture.
TODO: Textures also have samplers.
2025-04-10 23:50:57 +02:00
Anish Bhobe b8b620a723 Triangle is ready. 2025-04-09 20:33:38 +02:00
93 changed files with 8874 additions and 105 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -30,5 +30,6 @@ 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"
"context.cpp"
"instance.cpp"
"physical_device.cpp"
"device.cpp"
"swapchain.cpp"

View File

@ -5,7 +5,7 @@
#include "core/device.h"
#include "core/context.h"
#include "core/instance.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 Context *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
Device::Device(const Instance *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
const eastl::vector<QueueAllocation> &queueAllocations, NameString &&name)
: Device(context, physicalDevice, enabledFeatures, queueAllocations, {}, std::move(name))
{
}
Device::Device(const Context *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
Device::Device(const Instance *context, PhysicalDevice *physicalDevice, Features *enabledFeatures,
const eastl::vector<QueueAllocation> &queueAllocations, eastl::span<u8> &&pipelineCacheData,
NameString &&name)
: m_Name(std::move(name))

View File

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

View File

@ -5,7 +5,7 @@
#include "core/physical_device.h"
#include "core/context.h"
#include "core/instance.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 Context *context)
PhysicalDevices::PhysicalDevices(const Surface *surface, const Instance *context)
{
auto physicalDevices = EnumeratePhysicalDevices(context->m_Instance);
for (auto physicalDevice : physicalDevices)

View File

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

View File

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

View File

@ -43,6 +43,16 @@ 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/context.h"
#include "aster/core/instance.h"
#include "aster/core/device.h"
#include "aster/core/window.h"
#include "helpers.h"
@ -26,7 +26,7 @@ VulkanAssert(VkResult result)
}
void
Init(const Context *context, const Device *device, const Window *window, vk::Format attachmentFormat,
Init(const Instance *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 Context;
struct Instance;
struct Window;
struct Swapchain;
// ReSharper disable once CppInconsistentNaming
namespace ImGui
{
void Init(const Context *context, const Device *device, const Window *window, vk::Format attachmentFormat,
void Init(const Instance *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/context.h"
#include "aster/core/instance.h"
#include "aster/core/device.h"
#include "aster/core/physical_device.h"
#include "aster/core/pipeline.h"
@ -15,6 +15,7 @@
#include "aster/core/window.h"
#include "helpers.h"
#include "aster/systems/resource_manager.h"
#include <EASTL/array.h>
@ -75,7 +76,7 @@ main(int, char **)
MIN_LOG_LEVEL(Logger::LogType::eInfo);
Window window = {"Triangle (Aster)", {640, 480}};
Context context = {"Triangle", VERSION};
Instance context = {"Triangle", VERSION};
Surface surface = {&context, &window, "Primary"};
PhysicalDevices physicalDevices = {&surface, &context};
@ -92,6 +93,7 @@ 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;
@ -117,45 +119,8 @@ 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}},
};
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();
}
auto vbo = resourceManager.Buffers().CreateVertexBuffer(vertices.size() * sizeof vertices[0], "VBO");
vbo->Write(0, vertices.size() * sizeof vertices[0], vertices.data());
// Persistent variables
vk::Viewport viewport = {
@ -294,7 +259,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();
@ -352,7 +317,6 @@ 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/context.h"
#include "aster/core/instance.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}};
Context context = {"Box", VERSION};
Instance context = {"Box", VERSION};
Surface surface = {&context, &window, "Primary"};
PhysicalDevices physicalDevices = {&surface, &context};

View File

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

View File

@ -112,7 +112,6 @@ 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";
@ -132,6 +131,10 @@ 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.

BIN
samples/03_model_render/model/Sponza/1219024358953944284.jpg (Stored with Git LFS) Normal file

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.

BIN
samples/03_model_render/model/Sponza/2051777328469649772.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/2185409758123873465.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/2299742237651021498.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/2374361008830720677.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/2411100444841994089.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/2775690330959970771.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/2969916736137545357.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/332936164838540657.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/3371964815757888145.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/3455394979645218238.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/3628158980083700836.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/3827035219084910048.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/4477655471536070370.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/4601176305987539675.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/466164707995436622.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/4675343432951571524.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/4871783166746854860.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/4910669866631290573.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/4975155472559461469.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/5061699253647017043.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/5792855332885324923.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/5823059166183034438.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/6047387724914829168.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/6151467286084645207.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/6593109234861095314.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/6667038893015345571.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/6772804448157695701.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/7056944414013900257.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/715093869573992647.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/7268504077753552595.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/7441062115984513793.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/755318871556304029.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/759203620573749278.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/7645212358685992005.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/7815564343179553343.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/8006627369776289000.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/8051790464816141987.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/8114461559286000061.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/8481240838833932244.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/8503262930880235456.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/8747919177698443163.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/8750083169368950601.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/8773302468495022225.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/8783994986360286082.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/9288698199695299068.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/9916269861720640319.jpg (Stored with Git LFS) Normal file

Binary file not shown.

BIN
samples/03_model_render/model/Sponza/Sponza.bin (Stored with Git LFS) Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
samples/03_model_render/model/Sponza/white.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -7,7 +7,7 @@
#include "aster/core/buffer.h"
#include "aster/core/constants.h"
#include "aster/core/context.h"
#include "aster/core/instance.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/DamagedHelmet.glb";
constexpr auto MODEL_FILE = "model/Sponza/Sponza.gltf";
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}};
Context context = {"ModelRender", VERSION};
Instance 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][PushConstant.MaterialIdx].AlbedoFactor;
uint AlbedoTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].AlbedoTex;
float4 AlbedoFactor = (float4) MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].AlbedoFactor;
uint AlbedoTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].AlbedoTex;
return AlbedoFactor * InColor * (AlbedoTexId != INVALID_HANDLE ? Textures[AlbedoTexId].Sample(ImmutableSamplers[AlbedoTexId], UV) : 1.0f.xxxx);
return AlbedoFactor * InColor * (AlbedoTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(AlbedoTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(AlbedoTexId)], UV) : 1.0f.xxxx);
}
float GetOcclusion(float2 UV)
{
uint OcclusionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].OcclusionTex;
uint OcclusionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].OcclusionTex;
return OcclusionTexId != INVALID_HANDLE ? Textures[OcclusionTexId].Sample(ImmutableSamplers[OcclusionTexId], UV).r : 1.0f;
return OcclusionTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(OcclusionTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(OcclusionTexId)], UV).r : 1.0f;
}
float3 GetEmissive(float2 UV)
{
float3 EmissionFactor = (float3) MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].EmissionFactor;
uint EmissionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].EmissionTex;
float3 EmissionFactor = (float3) MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].EmissionFactor;
uint EmissionTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].EmissionTex;
return EmissionFactor * (EmissionTexId != INVALID_HANDLE ? Textures[EmissionTexId].Sample(ImmutableSamplers[EmissionTexId], UV).rgb : 1.0f.xxx);
return EmissionFactor * (EmissionTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(EmissionTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(EmissionTexId)], UV).rgb : 1.0f.xxx);
}
float3 GetNormal(float3 Position, float3 Normal, float2 UV)
{
float3 N = normalize(Normal);
uint NormalTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].NormalTex;
uint NormalTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][NonUniformResourceIndex(PushConstant.MaterialIdx)].NormalTex;
if (NormalTexId == INVALID_HANDLE)
{
return N;
}
float3 TangentSpaceNormal = Textures[NormalTexId].Sample(ImmutableSamplers[NormalTexId], UV).xyz * 2.0f - 1.0f;
float3 TangentSpaceNormal = Textures[NonUniformResourceIndex(NormalTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(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][PushConstant.MaterialIdx].MetalFactor, MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].RoughFactor);
uint MetalRoughTexId = MaterialsBuffer[PushConstant.MaterialBufferHandle][PushConstant.MaterialIdx].MetalRoughTex;
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;
return MetalRoughFactors * (MetalRoughTexId != INVALID_HANDLE ? Textures[MetalRoughTexId].Sample(ImmutableSamplers[MetalRoughTexId], UV).bg : 1.0f.xx); // Metal is B, Rough is G.
return MetalRoughFactors * (MetalRoughTexId != INVALID_HANDLE ? Textures[NonUniformResourceIndex(MetalRoughTexId)].Sample(ImmutableSamplers[NonUniformResourceIndex(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")