Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
d7c48d28c7 | |
|
|
1a9fac5e21 | |
|
|
e0e4a6a766 |
|
|
@ -1,46 +1,46 @@
|
||||||
public static const float PI = 3.14159265f;
|
public static const float PI = 3.14159265f;
|
||||||
|
|
||||||
public float TrowbridgeReitzGGX(float3 normal, float3 halfway, float roughness)
|
float TrowbridgeReitzGGX(float3 normal, float3 halfway, float roughness)
|
||||||
{
|
{
|
||||||
float alpha = roughness * roughness;
|
float alpha = roughness * roughness;
|
||||||
float alpha2 = alpha * alpha;
|
float alpha2 = alpha * alpha;
|
||||||
float n_dot_h = max(dot(normal, halfway), 0.0f);
|
float n_dot_h = max(dot(normal, halfway), 0.0f);
|
||||||
float n_dot_h_2 = n_dot_h * n_dot_h;
|
float n_dot_h_2 = n_dot_h * n_dot_h;
|
||||||
|
|
||||||
float numerator = alpha2;
|
float numerator = alpha2;
|
||||||
float denominator = n_dot_h_2 * (alpha2 - 1.0f) + 1.0f;
|
float denominator = n_dot_h_2 * (alpha2 - 1.0f) + 1.0f;
|
||||||
denominator = PI * denominator * denominator;
|
denominator = PI * denominator * denominator;
|
||||||
|
|
||||||
return numerator / denominator;
|
return numerator / denominator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GeometrySchlickGGX(float n_dot_v, float roughness)
|
float GeometrySchlickGGX(float n_dot_v, float roughness)
|
||||||
{
|
{
|
||||||
float r = roughness + 1.0f;
|
float r = roughness + 1.0f;
|
||||||
float k = (r * r) / 8.0f;
|
float k = (r * r) / 8.0f;
|
||||||
|
|
||||||
float numerator = n_dot_v;
|
float numerator = n_dot_v;
|
||||||
float denominator = n_dot_v * (1.0f - k) + k;
|
float denominator = n_dot_v * (1.0f - k) + k;
|
||||||
|
|
||||||
return numerator / denominator;
|
return numerator / denominator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GeometrySmith(float n_dot_v, float n_dot_l, float roughness)
|
float GeometrySmith(float n_dot_v, float n_dot_l, float roughness)
|
||||||
{
|
{
|
||||||
float ggx1 = GeometrySchlickGGX(n_dot_v, roughness);
|
float ggx1 = GeometrySchlickGGX(n_dot_v, roughness);
|
||||||
float ggx2 = GeometrySchlickGGX(n_dot_l, roughness);
|
float ggx2 = GeometrySchlickGGX(n_dot_l, roughness);
|
||||||
|
|
||||||
return ggx1 * ggx2;
|
return ggx1 * ggx2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Schlick%27s_approximation
|
// https://en.wikipedia.org/wiki/Schlick%27s_approximation
|
||||||
public float3 FresnelSchlick(float cosine, float3 f_0)
|
float3 FresnelSchlick(float cosine, float3 f_0)
|
||||||
{
|
{
|
||||||
return f_0 + (1.0f - f_0) * pow(clamp(1.0f - cosine, 0.0f, 1.0f), 5.0f); // Clamp to avoid artifacts.
|
return f_0 + (1.0f - f_0) * pow(clamp(1.0f - cosine, 0.0f, 1.0f), 5.0f); // Clamp to avoid artifacts.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sebastian Lagarde
|
// Sebastian Lagarde
|
||||||
public float3 FresnelSchlickRoughness(float cosine, float3 f_0, float roughness)
|
float3 FresnelSchlickRoughness(float cosine, float3 f_0, float roughness)
|
||||||
{
|
{
|
||||||
return f_0 + (max((1.0f - roughness).xxx, f_0) - f_0) * pow(clamp(1.0f - cosine, 0.0f, 1.0f), 5.0f); // Clamp to avoid artifacts.
|
return f_0 + (max((1.0f - roughness).xxx, f_0) - f_0) * pow(clamp(1.0f - cosine, 0.0f, 1.0f), 5.0f); // Clamp to avoid artifacts.
|
||||||
}
|
}
|
||||||
|
|
@ -64,29 +64,26 @@ public struct BRDFCookTorranceGGX : IBRDF {
|
||||||
m_f0 = f0;
|
m_f0 = f0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float3 Evaluate(
|
public float3 Evaluate(float3 radiance, float3 view_dir, float3 light_dir)
|
||||||
float3 radiance,
|
|
||||||
float3 view_dir,
|
|
||||||
float3 light_dir)
|
|
||||||
{
|
{
|
||||||
float3 halfway = normalize(view_dir + light_dir);
|
float3 halfway = normalize(view_dir + light_dir);
|
||||||
|
|
||||||
float cosine_factor = max(dot(halfway, view_dir), 0.0f);
|
float cosine_factor = max(dot(halfway, view_dir), 0.0f);
|
||||||
float n_dot_v = max(dot(m_normal, view_dir), 0.0f);
|
float n_dot_v = max(dot(m_normal, view_dir), 0.0f);
|
||||||
float n_dot_l = max(dot(m_normal, light_dir), 0.0f);
|
float n_dot_l = max(dot(m_normal, light_dir), 0.0f);
|
||||||
|
|
||||||
float normal_dist = TrowbridgeReitzGGX(m_normal, halfway, m_roughness);
|
float normal_dist = TrowbridgeReitzGGX(m_normal, halfway, m_roughness);
|
||||||
float geometry = GeometrySmith(n_dot_v, n_dot_l, m_roughness);
|
float geometry = GeometrySmith(n_dot_v, n_dot_l, m_roughness);
|
||||||
float3 fresnel = FresnelSchlickRoughness(cosine_factor, m_f0, m_roughness);
|
float3 fresnel = FresnelSchlickRoughness(cosine_factor, m_f0, m_roughness);
|
||||||
|
|
||||||
float3 numerator = (normal_dist * geometry) * fresnel;
|
float3 numerator = (normal_dist * geometry) * fresnel;
|
||||||
float denominator = 4.0f * n_dot_v * n_dot_l;
|
float denominator = 4.0f * n_dot_v * n_dot_l;
|
||||||
float3 specular = numerator / (denominator + 0.00001f);
|
float3 specular = numerator / (denominator + 0.00001f);
|
||||||
|
|
||||||
float3 k_specular = fresnel;
|
float3 k_specular = fresnel;
|
||||||
float3 k_diffuse = 1.0f.xxx - k_specular;
|
float3 k_diffuse = 1.0f.xxx - k_specular;
|
||||||
|
|
||||||
k_diffuse *= 1.0f - m_metallic;
|
k_diffuse *= 1.0f - m_metallic;
|
||||||
|
|
||||||
return n_dot_l * radiance * (k_diffuse * m_albedo / PI + specular);
|
return n_dot_l * radiance * (k_diffuse * m_albedo / PI + specular);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
</Link>
|
</Link>
|
||||||
<CustomBuild>
|
<CustomBuild>
|
||||||
<Command>slangc %(FullPath) -profile sm_6_6 -target spirv -o %(Filename).spv</Command>
|
<Command>slangc %(FullPath) -profile sm_6_6 -target spirv -matrix-layout-column-major -o %(Filename).spv</Command>
|
||||||
</CustomBuild>
|
</CustomBuild>
|
||||||
<CustomBuild>
|
<CustomBuild>
|
||||||
<Message>Compiling %(Filename)</Message>
|
<Message>Compiling %(Filename)</Message>
|
||||||
|
|
|
||||||
|
|
@ -39,24 +39,6 @@
|
||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="README.md">
|
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="PLAN.md">
|
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include=".clang-format">
|
|
||||||
<Filter>Resource Files\Config</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include=".gitignore">
|
|
||||||
<Filter>Resource Files\Config</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="vcpkg.json">
|
|
||||||
<Filter>Resource Files\Config</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="vcpkg-configuration.json">
|
|
||||||
<Filter>Resource Files\Config</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="Assets\Shaders\Bindless.slang">
|
<None Include="Assets\Shaders\Bindless.slang">
|
||||||
<Filter>Resource Files\Shader Files</Filter>
|
<Filter>Resource Files\Shader Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
|
@ -66,6 +48,30 @@
|
||||||
<None Include="Assets\Shaders\Material.slang">
|
<None Include="Assets\Shaders\Material.slang">
|
||||||
<Filter>Resource Files\Shader Files</Filter>
|
<Filter>Resource Files\Shader Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
|
<None Include="..\vcpkg-configuration.json">
|
||||||
|
<Filter>Resource Files\Config</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\vcpkg.json">
|
||||||
|
<Filter>Resource Files\Config</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\.gitignore">
|
||||||
|
<Filter>Resource Files\Config</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\.clang-format">
|
||||||
|
<Filter>Resource Files\Config</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\.gitattributes">
|
||||||
|
<Filter>Resource Files\Config</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\README.md">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\LICENSE">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="..\PLAN.md">
|
||||||
|
<Filter>Resource Files</Filter>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Source\AppState.cpp">
|
<ClCompile Include="Source\AppState.cpp">
|
||||||
|
|
@ -104,9 +110,6 @@
|
||||||
<ClCompile Include="Source\TextureManager.cpp">
|
<ClCompile Include="Source\TextureManager.cpp">
|
||||||
<Filter>Source Files\Render</Filter>
|
<Filter>Source Files\Render</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Source\RID.cpp">
|
|
||||||
<Filter>Source Files\Render</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Source\RenderDevice.cpp">
|
<ClCompile Include="Source\RenderDevice.cpp">
|
||||||
<Filter>Source Files\Render</Filter>
|
<Filter>Source Files\Render</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -140,9 +143,6 @@
|
||||||
<ClInclude Include="Source\ModelLoader.h">
|
<ClInclude Include="Source\ModelLoader.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Source\MathUtil.h">
|
|
||||||
<Filter>Header Files\Util</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Source\MacroUtils.h">
|
<ClInclude Include="Source\MacroUtils.h">
|
||||||
<Filter>Header Files\Util</Filter>
|
<Filter>Header Files\Util</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
||||||
|
|
@ -74,23 +74,21 @@ SDL_AppResult SDL_AppInit( void** appstate, int, char** )
|
||||||
|
|
||||||
app_state.miscData->lightData.pointLightCount = _countof( point_light );
|
app_state.miscData->lightData.pointLightCount = _countof( point_light );
|
||||||
|
|
||||||
app_state.renderDevice->bufferManager->WriteToBuffer( app_state.miscData->pointLights, point_light );
|
app_state.renderDevice->bufferManager->WriteRangeToBuffer( app_state.miscData->pointLights, point_light );
|
||||||
|
|
||||||
Blaze::MiscData::DirectionalLight dir_light[] = {
|
Blaze::MiscData::DirectionalLight dir_light[] = {
|
||||||
{
|
{
|
||||||
.direction = { 1.0f, -1.0f, 0.0f },
|
.direction = { -1.0f, -1.0f, -1.0f },
|
||||||
.color = { 12.0f, 10.0f, 5.0f },
|
.color = { 12.0f, 10.0f, 5.0f },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
app_state.miscData->lightData.dirLightCount = _countof( dir_light );
|
app_state.miscData->lightData.dirLightCount = _countof( dir_light );
|
||||||
|
|
||||||
app_state.renderDevice->bufferManager->WriteToBuffer( app_state.miscData->directionalLights, dir_light );
|
app_state.renderDevice->bufferManager->WriteRangeToBuffer( app_state.miscData->directionalLights, dir_light );
|
||||||
|
|
||||||
memcpy(
|
app_state.renderDevice->bufferManager->WriteObjectToBuffer(
|
||||||
app_state.miscData->cameraUniformBufferPtr + sizeof( Blaze::MiscData::CameraData ),
|
app_state.miscData->uniformBuffer, sizeof( Blaze::MiscData::CameraData ), app_state.miscData->lightData );
|
||||||
&app_state.miscData->lightData,
|
|
||||||
sizeof app_state.miscData->lightData );
|
|
||||||
|
|
||||||
return SDL_APP_CONTINUE;
|
return SDL_APP_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +141,7 @@ SDL_AppResult SDL_AppIterate( void* appstate )
|
||||||
VK_CHECK( vkAcquireNextImageKHR(
|
VK_CHECK( vkAcquireNextImageKHR(
|
||||||
render_device.device,
|
render_device.device,
|
||||||
render_device.swapchain,
|
render_device.swapchain,
|
||||||
std::numeric_limits<uint32_t>::max(),
|
UINT32_MAX,
|
||||||
current_frame.imageAcquiredSemaphore,
|
current_frame.imageAcquiredSemaphore,
|
||||||
nullptr,
|
nullptr,
|
||||||
¤t_image_index ) );
|
¤t_image_index ) );
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ Blaze::Buffer& BufferManager::FetchBufferUnchecked( BufferID const& rid )
|
||||||
return m_buffers[inner_index];
|
return m_buffers[inner_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferManager::WriteToBufferImpl( BufferID const& rid, void const* data, size_t const size )
|
void BufferManager::WriteToBuffer( BufferID const& rid, void const* data, size_t const size, size_t const offset )
|
||||||
{
|
{
|
||||||
ASSERT( IsValidID( rid ) );
|
ASSERT( IsValidID( rid ) );
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ void BufferManager::WriteToBufferImpl( BufferID const& rid, void const* data, si
|
||||||
|
|
||||||
ASSERT( size <= buffer.size );
|
ASSERT( size <= buffer.size );
|
||||||
|
|
||||||
memcpy( buffer.mappedData, data, size );
|
memcpy( buffer.mappedData + offset, data, size );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BufferManager::IsValidID( BufferID const& rid ) const
|
bool BufferManager::IsValidID( BufferID const& rid ) const
|
||||||
|
|
@ -248,6 +248,73 @@ Blaze::BufferID BufferManager::CreateStorageBuffer( size_t const size )
|
||||||
return *reinterpret_cast<BufferID*>( &index );
|
return *reinterpret_cast<BufferID*>( &index );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Blaze::BufferID BufferManager::CreateUniformBuffer( size_t const size )
|
||||||
|
{
|
||||||
|
ASSERT( not m_freeList.Empty() );
|
||||||
|
|
||||||
|
Buffer* buffer_slot = reinterpret_cast<Buffer*>( m_freeList.PopFront() );
|
||||||
|
++m_count;
|
||||||
|
|
||||||
|
ASSERT( m_renderDevice );
|
||||||
|
RenderDevice const& render_device = *m_renderDevice;
|
||||||
|
|
||||||
|
VkBufferCreateInfo const buffer_create_info = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.size = size,
|
||||||
|
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
|
||||||
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.queueFamilyIndexCount = 0,
|
||||||
|
.pQueueFamilyIndices = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
|
VmaAllocationCreateInfo constexpr allocation_create_info = {
|
||||||
|
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
||||||
|
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||||
|
.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
||||||
|
.preferredFlags = 0,
|
||||||
|
.memoryTypeBits = 0,
|
||||||
|
.pool = nullptr,
|
||||||
|
.pUserData = nullptr,
|
||||||
|
.priority = 1.0f,
|
||||||
|
};
|
||||||
|
|
||||||
|
VmaAllocationInfo allocation_info;
|
||||||
|
VkBuffer storage_buffer;
|
||||||
|
VmaAllocation storage_buffer_allocation;
|
||||||
|
|
||||||
|
VK_CHECK( vmaCreateBuffer(
|
||||||
|
render_device.gpuAllocator,
|
||||||
|
&buffer_create_info,
|
||||||
|
&allocation_create_info,
|
||||||
|
&storage_buffer,
|
||||||
|
&storage_buffer_allocation,
|
||||||
|
&allocation_info ) );
|
||||||
|
|
||||||
|
VkBufferDeviceAddressInfo const device_address_info = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.buffer = storage_buffer,
|
||||||
|
};
|
||||||
|
|
||||||
|
VkDeviceAddress const device_address = vkGetBufferDeviceAddress( render_device.device, &device_address_info );
|
||||||
|
|
||||||
|
// NOTE: bufferSlot preserves index between uses.
|
||||||
|
uint32_t index = buffer_slot->index;
|
||||||
|
new ( buffer_slot ) Buffer{
|
||||||
|
.buffer = storage_buffer,
|
||||||
|
.allocation = storage_buffer_allocation,
|
||||||
|
.mappedData = static_cast<std::byte*>( allocation_info.pMappedData ),
|
||||||
|
.deviceAddress = device_address,
|
||||||
|
.size = size,
|
||||||
|
.index = index,
|
||||||
|
};
|
||||||
|
|
||||||
|
// NOTE: Memory hackery to create BufferID;
|
||||||
|
return *reinterpret_cast<BufferID*>( &index );
|
||||||
|
}
|
||||||
|
|
||||||
void BufferManager::FreeBuffer( BufferID* rid )
|
void BufferManager::FreeBuffer( BufferID* rid )
|
||||||
{
|
{
|
||||||
if ( not IsValidID( *rid ) ) return;
|
if ( not IsValidID( *rid ) ) return;
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,6 @@ private:
|
||||||
void DestroyBuffer( Buffer& buf );
|
void DestroyBuffer( Buffer& buf );
|
||||||
|
|
||||||
Buffer& FetchBufferUnchecked( BufferID const& rid );
|
Buffer& FetchBufferUnchecked( BufferID const& rid );
|
||||||
void WriteToBufferImpl( BufferID const& rid, void const* data, size_t size );
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] bool IsValidID( BufferID const& rid ) const;
|
[[nodiscard]] bool IsValidID( BufferID const& rid ) const;
|
||||||
|
|
@ -60,6 +59,7 @@ public:
|
||||||
BufferID CreateVertexBuffer( size_t size );
|
BufferID CreateVertexBuffer( size_t size );
|
||||||
BufferID CreateIndexBuffer( size_t size );
|
BufferID CreateIndexBuffer( size_t size );
|
||||||
BufferID CreateStorageBuffer( size_t size );
|
BufferID CreateStorageBuffer( size_t size );
|
||||||
|
BufferID CreateUniformBuffer( size_t size );
|
||||||
|
|
||||||
void FreeBuffer( BufferID* rid );
|
void FreeBuffer( BufferID* rid );
|
||||||
|
|
||||||
|
|
@ -67,13 +67,23 @@ public:
|
||||||
std::optional<VkBuffer> FetchBuffer( BufferID const& rid );
|
std::optional<VkBuffer> FetchBuffer( BufferID const& rid );
|
||||||
std::optional<VkDeviceAddress> FetchDeviceAddress( BufferID const& rid );
|
std::optional<VkDeviceAddress> FetchDeviceAddress( BufferID const& rid );
|
||||||
|
|
||||||
|
void WriteToBuffer( BufferID const& rid, void const* data, size_t size, size_t offset );
|
||||||
|
|
||||||
// Utility to directly muck the data
|
// Utility to directly muck the data
|
||||||
void WriteToBuffer( BufferID const& rid, std::ranges::contiguous_range auto const& data )
|
void WriteRangeToBuffer( BufferID const& rid, std::ranges::contiguous_range auto const& data )
|
||||||
{
|
{
|
||||||
WriteToBufferImpl(
|
WriteToBuffer(
|
||||||
rid,
|
rid,
|
||||||
std::ranges::data( data ),
|
std::ranges::data( data ),
|
||||||
std::ranges::size( data ) * sizeof( std::ranges::range_value_t<decltype( data )> ) );
|
std::ranges::size( data ) * sizeof( std::ranges::range_value_t<decltype( data )> ),
|
||||||
|
0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utility to directly muck the data
|
||||||
|
void WriteObjectToBuffer( BufferID const& rid, size_t const offset, auto const& data )
|
||||||
|
requires not std::ranges::range<decltype( data )>
|
||||||
|
{
|
||||||
|
WriteToBuffer( rid, &data, sizeof data, offset );
|
||||||
}
|
}
|
||||||
|
|
||||||
static BufferManager* Create( GlobalMemory* mem, RenderDevice* render_device, uint32_t max_count );
|
static BufferManager* Create( GlobalMemory* mem, RenderDevice* render_device, uint32_t max_count );
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ bool MiscData::Init( RenderDevice const& render_device )
|
||||||
.depthClampEnable = VK_TRUE,
|
.depthClampEnable = VK_TRUE,
|
||||||
.rasterizerDiscardEnable = VK_FALSE,
|
.rasterizerDiscardEnable = VK_FALSE,
|
||||||
.polygonMode = VK_POLYGON_MODE_FILL,
|
.polygonMode = VK_POLYGON_MODE_FILL,
|
||||||
.cullMode = VK_CULL_MODE_NONE,
|
.cullMode = VK_CULL_MODE_BACK_BIT,
|
||||||
.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
|
.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
|
||||||
.depthBiasEnable = VK_FALSE,
|
.depthBiasEnable = VK_FALSE,
|
||||||
.depthBiasConstantFactor = 0.0f,
|
.depthBiasConstantFactor = 0.0f,
|
||||||
|
|
@ -268,14 +268,12 @@ bool MiscData::Init( RenderDevice const& render_device )
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
{
|
{
|
||||||
cameraData.cameraPosition = DirectX::XMVectorSet( 0.0f, 2.0f, -2.0f, 1.0f );
|
cameraData.cameraPosition = DirectX::XMVectorSet( 0.0f, 1.0f, 2.0f, 1.0f );
|
||||||
cameraTarget = DirectX::XMVectorSet( 0.0f, 0.0f, 0.0f, 1.0f );
|
cameraTarget = DirectX::XMVectorSet( 0.0f, 0.0f, 0.0f, 1.0f );
|
||||||
cameraUp = DirectX::XMVectorSet( 0.0f, 1.0f, 0.0f, 1.0f );
|
cameraUp = DirectX::XMVectorSet( 0.0f, 1.0f, 0.0f, 1.0f );
|
||||||
cameraData.viewMatrix = DirectX::XMMatrixLookAtLH( cameraData.cameraPosition, cameraTarget, cameraUp );
|
cameraData.viewMatrix = DirectX::XMMatrixLookAtRH( cameraData.cameraPosition, cameraTarget, cameraUp );
|
||||||
cameraData.projectionMatrix =
|
cameraData.projectionMatrix =
|
||||||
DirectX::XMMatrixPerspectiveFovLH( DirectX::XMConvertToRadians( 70.0f ), 16.0f / 9.0f, 0.1f, 1000.0f );
|
DirectX::XMMatrixPerspectiveFovRH( DirectX::XMConvertToRadians( 70.0f ), 16.0f / 9.0f, 0.1f, 1000.0f );
|
||||||
|
|
||||||
cameraUniformBufferSize = sizeof( CameraData ) + sizeof( LightData );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -295,45 +293,10 @@ bool MiscData::Init( RenderDevice const& render_device )
|
||||||
|
|
||||||
// Uniform Buffer
|
// Uniform Buffer
|
||||||
{
|
{
|
||||||
|
uniformBuffer = render_device.bufferManager->CreateUniformBuffer( sizeof( CameraData ) + sizeof( LightData ) );
|
||||||
|
|
||||||
VkBufferCreateInfo const buffer_create_info = {
|
render_device.bufferManager->WriteObjectToBuffer( uniformBuffer, 0, cameraData );
|
||||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
render_device.bufferManager->WriteObjectToBuffer( uniformBuffer, sizeof CameraData, lightData );
|
||||||
.pNext = nullptr,
|
|
||||||
.flags = 0,
|
|
||||||
.size = cameraUniformBufferSize,
|
|
||||||
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
||||||
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
||||||
.queueFamilyIndexCount = 0,
|
|
||||||
.pQueueFamilyIndices = nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
VmaAllocationCreateInfo constexpr allocation_create_info = {
|
|
||||||
.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
|
||||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
|
||||||
.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
|
|
||||||
.preferredFlags = 0,
|
|
||||||
.memoryTypeBits = 0,
|
|
||||||
.pool = nullptr,
|
|
||||||
.pUserData = nullptr,
|
|
||||||
.priority = 1.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
VmaAllocationInfo allocation_info;
|
|
||||||
|
|
||||||
VK_CHECK( vmaCreateBuffer(
|
|
||||||
render_device.gpuAllocator,
|
|
||||||
&buffer_create_info,
|
|
||||||
&allocation_create_info,
|
|
||||||
&cameraUniformBuffer,
|
|
||||||
&cameraUniformBufferAllocation,
|
|
||||||
&allocation_info ) );
|
|
||||||
|
|
||||||
if ( allocation_info.pMappedData )
|
|
||||||
{
|
|
||||||
cameraUniformBufferPtr = static_cast<uint8_t*>( allocation_info.pMappedData );
|
|
||||||
memcpy( cameraUniformBufferPtr, &cameraData, sizeof cameraData );
|
|
||||||
memcpy( cameraUniformBufferPtr + sizeof cameraData, &lightData, sizeof lightData );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Descriptors
|
// Descriptors
|
||||||
|
|
@ -364,9 +327,9 @@ bool MiscData::Init( RenderDevice const& render_device )
|
||||||
VK_CHECK( vkAllocateDescriptorSets( device, &descriptor_set_allocate_info, &descriptorSet ) );
|
VK_CHECK( vkAllocateDescriptorSets( device, &descriptor_set_allocate_info, &descriptorSet ) );
|
||||||
|
|
||||||
VkDescriptorBufferInfo const descriptor_buffer_info = {
|
VkDescriptorBufferInfo const descriptor_buffer_info = {
|
||||||
.buffer = cameraUniformBuffer,
|
.buffer = render_device.bufferManager->FetchBuffer( uniformBuffer ).value(),
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
.range = cameraUniformBufferSize,
|
.range = sizeof( CameraData ) + sizeof( LightData ),
|
||||||
};
|
};
|
||||||
|
|
||||||
VkWriteDescriptorSet write_descriptor_sets[] = {
|
VkWriteDescriptorSet write_descriptor_sets[] = {
|
||||||
|
|
@ -464,7 +427,8 @@ void MiscData::Destroy( Blaze::RenderDevice const& render_device )
|
||||||
VkDevice const device = render_device.device;
|
VkDevice const device = render_device.device;
|
||||||
|
|
||||||
vkDestroyDescriptorPool( device, Take( descriptorPool ), nullptr );
|
vkDestroyDescriptorPool( device, Take( descriptorPool ), nullptr );
|
||||||
vmaDestroyBuffer( render_device.gpuAllocator, Take( cameraUniformBuffer ), Take( cameraUniformBufferAllocation ) );
|
|
||||||
|
render_device.bufferManager->FreeBuffer( &uniformBuffer );
|
||||||
|
|
||||||
render_device.bufferManager->FreeBuffer( &pointLights );
|
render_device.bufferManager->FreeBuffer( &pointLights );
|
||||||
render_device.bufferManager->FreeBuffer( &directionalLights );
|
render_device.bufferManager->FreeBuffer( &directionalLights );
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,7 @@ struct MiscData
|
||||||
BufferID directionalLights;
|
BufferID directionalLights;
|
||||||
LightData lightData;
|
LightData lightData;
|
||||||
|
|
||||||
VkBuffer cameraUniformBuffer;
|
BufferID uniformBuffer;
|
||||||
VmaAllocation cameraUniformBufferAllocation;
|
|
||||||
size_t cameraUniformBufferSize;
|
|
||||||
uint8_t* cameraUniformBufferPtr;
|
|
||||||
VkDescriptorPool descriptorPool;
|
VkDescriptorPool descriptorPool;
|
||||||
VkDescriptorSet descriptorSet;
|
VkDescriptorSet descriptorSet;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -793,12 +793,12 @@ Entity* LoadModel( Blaze::RenderDevice* render_device, EntityManager* entity_man
|
||||||
entity->model.vertexBuffer = render_device->bufferManager->CreateVertexBuffer( vertices.size() * sizeof vertices[0] );
|
entity->model.vertexBuffer = render_device->bufferManager->CreateVertexBuffer( vertices.size() * sizeof vertices[0] );
|
||||||
if ( not entity->model.vertexBuffer ) return nullptr;
|
if ( not entity->model.vertexBuffer ) return nullptr;
|
||||||
|
|
||||||
render_device->bufferManager->WriteToBuffer( entity->model.vertexBuffer, vertices );
|
render_device->bufferManager->WriteRangeToBuffer( entity->model.vertexBuffer, vertices );
|
||||||
|
|
||||||
entity->model.indexBuffer = render_device->bufferManager->CreateIndexBuffer( indices.size() * sizeof indices[0] );
|
entity->model.indexBuffer = render_device->bufferManager->CreateIndexBuffer( indices.size() * sizeof indices[0] );
|
||||||
if ( not entity->model.indexBuffer ) return nullptr;
|
if ( not entity->model.indexBuffer ) return nullptr;
|
||||||
|
|
||||||
render_device->bufferManager->WriteToBuffer( entity->model.indexBuffer, std::span{ indices } );
|
render_device->bufferManager->WriteRangeToBuffer( entity->model.indexBuffer, indices );
|
||||||
|
|
||||||
cgltf_free( gltf_model );
|
cgltf_free( gltf_model );
|
||||||
return entity;
|
return entity;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue