Fixing skybox

This commit is contained in:
Dynamitos
2024-01-02 16:48:03 +01:00
parent 4b58ab84be
commit 1ff3ddf9a3
11 changed files with 159 additions and 49 deletions
+1 -1
View File
@@ -29,5 +29,5 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
{ {
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf); result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
} }
return float4(params.vertexColor, 1.0f); return float4(result, 1.0f);
} }
+1 -2
View File
@@ -51,7 +51,7 @@ void taskMain(
{ {
uint m = mesh.meshletOffset + i; uint m = mesh.meshletOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m]; MeshletDescription meshlet = pScene.meshletInfos[m];
if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum)) //if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum))
{ {
uint index; uint index;
InterlockedAdd(head, 1, index); InterlockedAdd(head, 1, index);
@@ -120,7 +120,6 @@ void meshMain(
{ {
uint vertexIndex = pScene.vertexIndices[m.vertexOffset + v]; uint vertexIndex = pScene.vertexIndices[m.vertexOffset + v];
VertexAttributes attr = pVertexData.getAttributes(md.indicesOffset + vertexIndex); VertexAttributes attr = pVertexData.getAttributes(md.indicesOffset + vertexIndex);
attr.vertexColor = m.color;
vertices[v] = attr.getParameter(inst.transformMatrix); vertices[v] = attr.getParameter(inst.transformMatrix);
} }
} }
+20 -13
View File
@@ -34,23 +34,30 @@ struct BlinnPhong : IBRDF
} }
}; };
struct DisneyBRDF : IBRDF struct CelShading : IBRDF
{ {
float3 baseColor; float3 baseColor;
float metallic = 0; float3 normal;
float3 normal = float3(0, 1, 0);
float subsurface = 0; __init()
float specular = 0.5; {
float roughness = 0.5; normal = float3(0, 0, 1);
float specularTint = 0; }
float anisotropic = 0;
float sheen = 0;
float sheenTint = 0.5f;
float clearCoat = 0;
float clearCoatGloss = 1;
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor) float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
{ {
return baseColor; float3 normal_TS = normalize(normal);
float nDotL = dot(normal_TS, lightDir_TS);
float diffuse = max(nDotL, 0);
float3 darkenedBase = baseColor * 0.8;
if(diffuse > 0.5)
{
return baseColor * lightColor;
}
else
{
return darkenedBase * lightColor;
}
} }
}; };
+2 -2
View File
@@ -51,7 +51,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
std::string materialName = std::format("{0}{1}{2}", baseName, material->GetName().C_Str(), i); std::string materialName = std::format("{0}{1}{2}", baseName, material->GetName().C_Str(), i);
materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); // dots break adding the .asset extension later materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); // dots break adding the .asset extension later
matCode["name"] = materialName; matCode["name"] = materialName;
matCode["profile"] = "BlinnPhong"; //TODO: other shading models matCode["profile"] = "CelShading";
aiString texPath; aiString texPath;
uint32 baseColorIndex = 0; uint32 baseColorIndex = 0;
uint32 normalIndex = 0; uint32 normalIndex = 0;
@@ -176,7 +176,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName
matCode["code"].push_back( matCode["code"].push_back(
{ {
{ "exp", "BRDF" }, { "exp", "BRDF" },
{ "profile", "BlinnPhong" }, { "profile", matCode["profile"]},
{ "values", { { "values", {
{ "baseColor", baseColorIndex }, { "baseColor", baseColorIndex },
{ "normal", normalIndex }, { "normal", normalIndex },
+7 -5
View File
@@ -28,13 +28,15 @@ struct Camera
void moveX(float amount); void moveX(float amount);
void moveY(float amount); void moveY(float amount);
void buildViewMatrix(); void buildViewMatrix();
Matrix4 viewMatrix;
Vector cameraPos;
//Transforms relative to actor
float yaw;
float pitch;
bool mainCamera = false; bool mainCamera = false;
private: private:
float yaw;
float pitch;
// Spring arm transform
Math::Transform relativeTransform;
Matrix4 viewMatrix;
Vector cameraPos;
bool bNeedsViewBuild; bool bNeedsViewBuild;
}; };
} // namespace Component } // namespace Component
@@ -11,7 +11,7 @@ SkyboxRenderPass::SkyboxRenderPass(Gfx::PGraphics graphics, PScene scene)
skybox = Seele::Component::Skybox{ skybox = Seele::Component::Skybox{
.day = AssetRegistry::findTexture("FS000_Day_01")->getTexture().cast<Gfx::TextureCube>(), .day = AssetRegistry::findTexture("FS000_Day_01")->getTexture().cast<Gfx::TextureCube>(),
.night = AssetRegistry::findTexture("FS000_Night_01")->getTexture().cast<Gfx::TextureCube>(), .night = AssetRegistry::findTexture("FS000_Night_01")->getTexture().cast<Gfx::TextureCube>(),
.fogColor = Vector(0.2, 0.1, 0.6), .fogColor = Vector(0.1, 0.1, 0.8),
.blendFactor = 0, .blendFactor = 0,
}; };
} }
@@ -27,8 +27,13 @@ void SkyboxRenderPass::beginFrame(const Component::Camera& cam)
skyboxDataLayout->reset(); skyboxDataLayout->reset();
textureLayout->reset(); textureLayout->reset();
skyboxData.transformMatrix = glm::rotate(skyboxData.transformMatrix, (float)(Gfx::getCurrentFrameDelta()), Vector(0, 1, 0));
skyboxBuffer->updateContents(DataSource{
.size = sizeof(SkyboxData),
.data = (uint8*)&skyboxData,
});
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet(); skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
skyboxDataSet->updateBuffer(0, viewParamsBuffer); skyboxDataSet->updateBuffer(0, skyboxBuffer);
skyboxDataSet->writeChanges(); skyboxDataSet->writeChanges();
textureSet = textureLayout->allocateDescriptorSet(); textureSet = textureLayout->allocateDescriptorSet();
textureSet->updateTexture(0, skybox.day); textureSet->updateTexture(0, skybox.day);
@@ -82,11 +87,24 @@ void SkyboxRenderPass::createRenderPass()
}; };
renderPass = graphics->createRenderPass(std::move(layout), viewport); renderPass = graphics->createRenderPass(std::move(layout), viewport);
ShaderCreateInfo createInfo; skyboxData.transformMatrix = Matrix4(1);
createInfo.name = "SkyboxVertex"; skyboxData.fogColor = skybox.fogColor;
createInfo.additionalModules.add("Skybox"); skyboxData.blendFactor = skybox.blendFactor;
createInfo.mainModule = "Skybox";
createInfo.entryPoint = "vertexMain"; skyboxBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData = {
.size = sizeof(SkyboxData),
.data = (uint8*)&skyboxData,
},
.dynamic = true,
});
ShaderCreateInfo createInfo = {
.mainModule = "Skybox",
.additionalModules = {"Skybox"},
.name = "SkyboxVertex",
.entryPoint = "vertexMain",
};
vertexShader = graphics->createVertexShader(createInfo); vertexShader = graphics->createVertexShader(createInfo);
createInfo.name = "SkyboxFragment"; createInfo.name = "SkyboxFragment";
@@ -103,7 +121,6 @@ void SkyboxRenderPass::createRenderPass()
gfxInfo.vertexShader = vertexShader; gfxInfo.vertexShader = vertexShader;
gfxInfo.fragmentShader = fragmentShader; gfxInfo.fragmentShader = fragmentShader;
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL; gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
gfxInfo.rasterizationState.lineWidth = 5.f;
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
gfxInfo.pipelineLayout = std::move(pipelineLayout); gfxInfo.pipelineLayout = std::move(pipelineLayout);
gfxInfo.renderPass = renderPass; gfxInfo.renderPass = renderPass;
@@ -28,6 +28,13 @@ private:
Gfx::OFragmentShader fragmentShader; Gfx::OFragmentShader fragmentShader;
Gfx::PGraphicsPipeline pipeline; Gfx::PGraphicsPipeline pipeline;
Gfx::OSampler skyboxSampler; Gfx::OSampler skyboxSampler;
struct SkyboxData
{
Matrix4 transformMatrix;
Vector fogColor;
float blendFactor;
} skyboxData;
Gfx::OUniformBuffer skyboxBuffer;
Component::Skybox skybox; Component::Skybox skybox;
}; };
DEFINE_REF(SkyboxRenderPass) DEFINE_REF(SkyboxRenderPass)
+1 -1
View File
@@ -367,5 +367,5 @@ OStagingBuffer StagingManager::create(uint64 size, Gfx::QueueType owner)
void StagingManager::release(OStagingBuffer buffer) void StagingManager::release(OStagingBuffer buffer)
{ {
freeBuffers.add(std::move(buffer)); //freeBuffers.add(std::move(buffer));
} }
+73
View File
@@ -252,7 +252,31 @@ void Buffer::unmap()
.dstOffset = pending.offset, .dstOffset = pending.offset,
.size = pending.size, .size = pending.size,
}; };
VkBufferMemoryBarrier barrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.pNext = nullptr,
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.buffer = buffers[currentBuffer].buffer,
.offset = 0,
.size = size,
};
vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr);
vkCmdCopyBuffer(cmdHandle, stagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region); vkCmdCopyBuffer(cmdHandle, stagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region);
barrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.pNext = nullptr,
.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.buffer = buffers[currentBuffer].buffer,
.offset = 0,
.size = size,
};
vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr);
} }
//requestOwnershipTransfer(pending.prevQueue); //requestOwnershipTransfer(pending.prevQueue);
graphics->getStagingManager()->release(std::move(pending.stagingBuffer)); graphics->getStagingManager()->release(std::move(pending.stagingBuffer));
@@ -317,7 +341,31 @@ void UniformBuffer::unmap()
VkBufferCopy region; VkBufferCopy region;
std::memset(&region, 0, sizeof(VkBufferCopy)); std::memset(&region, 0, sizeof(VkBufferCopy));
region.size = Vulkan::Buffer::size; region.size = Vulkan::Buffer::size;
VkBufferMemoryBarrier barrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.pNext = nullptr,
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.buffer = buffers[currentBuffer].buffer,
.offset = 0,
.size = size,
};
vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr);
vkCmdCopyBuffer(cmdHandle, dedicatedStagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region); vkCmdCopyBuffer(cmdHandle, dedicatedStagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region);
barrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.pNext = nullptr,
.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.buffer = buffers[currentBuffer].buffer,
.offset = 0,
.size = size,
};
vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr);
} }
else else
{ {
@@ -408,7 +456,32 @@ void ShaderBuffer::unmap()
.dstOffset = 0, .dstOffset = 0,
.size = Vulkan::Buffer::size, .size = Vulkan::Buffer::size,
}; };
VkBufferMemoryBarrier barrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.pNext = nullptr,
.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.buffer = buffers[currentBuffer].buffer,
.offset = 0,
.size = size,
};
vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr);
vkCmdCopyBuffer(cmdHandle, dedicatedStagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region); vkCmdCopyBuffer(cmdHandle, dedicatedStagingBuffer->getHandle(), buffers[currentBuffer].buffer, 1, &region);
barrier = {
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
.pNext = nullptr,
.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.buffer = buffers[currentBuffer].buffer,
.offset = 0,
.size = size,
};
vkCmdPipelineBarrier(cmdHandle, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 1, &barrier, 0, nullptr);
} }
else else
{ {
+19 -16
View File
@@ -360,29 +360,31 @@ Array<const char *> Graphics::getRequiredExtensions()
void Graphics::initInstance(GraphicsInitializer initInfo) void Graphics::initInstance(GraphicsInitializer initInfo)
{ {
glfwInit(); glfwInit();
VkApplicationInfo appInfo = {}; VkApplicationInfo appInfo = {
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
appInfo.pApplicationName = initInfo.applicationName; .pApplicationName = initInfo.applicationName,
appInfo.applicationVersion = VK_MAKE_VERSION(0, 0, 1); .applicationVersion = VK_MAKE_VERSION(0, 0, 1),
appInfo.pEngineName = initInfo.engineName; .pEngineName = initInfo.engineName,
appInfo.engineVersion = VK_MAKE_VERSION(0, 0, 1); .engineVersion = VK_MAKE_VERSION(0, 0, 1),
appInfo.apiVersion = VK_API_VERSION_1_2; .apiVersion = VK_API_VERSION_1_2,
};
VkInstanceCreateInfo info = {}; Array<const char*> extensions = getRequiredExtensions();
info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
info.pApplicationInfo = &appInfo;
Array<const char *> extensions = getRequiredExtensions();
for (uint32 i = 0; i < initInfo.instanceExtensions.size(); ++i) for (uint32 i = 0; i < initInfo.instanceExtensions.size(); ++i)
{ {
extensions.add(initInfo.instanceExtensions[i]); extensions.add(initInfo.instanceExtensions[i]);
} }
info.enabledExtensionCount = (uint32)extensions.size();
info.ppEnabledExtensionNames = extensions.data();
#if ENABLE_VALIDATION #if ENABLE_VALIDATION
initInfo.layers.add("VK_LAYER_KHRONOS_validation"); initInfo.layers.add("VK_LAYER_KHRONOS_validation");
#endif #endif
info.enabledLayerCount = (uint32)initInfo.layers.size(); VkInstanceCreateInfo info = {
info.ppEnabledLayerNames = initInfo.layers.data(); .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pApplicationInfo = &appInfo,
.enabledLayerCount = (uint32)initInfo.layers.size(),
.ppEnabledLayerNames = initInfo.layers.data(),
.enabledExtensionCount = (uint32)extensions.size(),
.ppEnabledExtensionNames = extensions.data(),
};
VK_CHECK(vkCreateInstance(&info, nullptr, &instance)); VK_CHECK(vkCreateInstance(&info, nullptr, &instance));
} }
void Graphics::setupDebugCallback() void Graphics::setupDebugCallback()
@@ -438,6 +440,7 @@ void Graphics::pickPhysicalDevice()
vkGetPhysicalDeviceProperties(physicalDevice, &props); vkGetPhysicalDeviceProperties(physicalDevice, &props);
vkGetPhysicalDeviceFeatures2(physicalDevice, &features); vkGetPhysicalDeviceFeatures2(physicalDevice, &features);
features.features.robustBufferAccess = 0;
if (Gfx::useMeshShading) if (Gfx::useMeshShading)
{ {
uint32 count = 0; uint32 count = 0;
@@ -448,7 +451,7 @@ void Graphics::pickPhysicalDevice()
{ {
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0) if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
{ {
meshShadingEnabled = true; //meshShadingEnabled = true;
break; break;
} }
} }
+2
View File
@@ -204,6 +204,8 @@ void TextureBase::changeLayout(Gfx::SeImageLayout newLayout)
VkImageMemoryBarrier barrier = { VkImageMemoryBarrier barrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.pNext = nullptr, .pNext = nullptr,
.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT,
.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT,
.oldLayout = cast(layout), .oldLayout = cast(layout),
.newLayout = cast(newLayout), .newLayout = cast(newLayout),
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,