Disabling lighting for now

This commit is contained in:
Dynamitos
2025-04-13 14:41:42 +02:00
parent 54c5f9a5d7
commit 19007ac601
15 changed files with 86 additions and 84 deletions
+1 -1
+3 -3
View File
@@ -25,10 +25,10 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
{ {
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf); result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
} }
for(uint i = 0; i < lightCount; ++i) for(uint i = 0; i < pLightEnv.numPointLights; ++i)
{ {
uint lightIndex = pLightCullingData.lightIndexList[startOffset + i]; //uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf); result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
} }
result += brdf.evaluateAmbient(lightingParams.viewDir_WS); result += brdf.evaluateAmbient(lightingParams.viewDir_WS);
return float4(result, brdf.getAlpha()); return float4(result, brdf.getAlpha());
+33 -33
View File
@@ -1,57 +1,57 @@
const static float3 vertices[] = { const static float3 vertices[] = {
// Right // Right
float3( 1, 1, 1),
float3( 1, -1, 1), float3( 1, -1, 1),
float3( 1, 1, 1),
float3( 1, -1, -1),
float3( 1, -1, -1),
float3( 1, 1, 1),
float3( 1, 1, -1), float3( 1, 1, -1),
float3( 1, 1, -1),
float3( 1, -1, 1),
float3( 1, -1, -1),
// Left // Left
float3(-1, 1, -1),
float3(-1, -1, -1), float3(-1, -1, -1),
float3(-1, 1, -1),
float3(-1, -1, 1),
float3(-1, -1, 1),
float3(-1, 1, -1),
float3(-1, 1, 1), float3(-1, 1, 1),
float3(-1, 1, 1),
float3(-1, -1, -1),
float3(-1, -1, 1),
// Bottom // Bottom
float3(-1, 1, 1), float3(-1, -1, 1),
float3(-1, 1, -1), float3(-1, -1, -1),
float3( 1, 1, 1), float3( 1, -1, 1),
float3( 1, 1, 1), float3( 1, -1, 1),
float3(-1, 1, -1), float3(-1, -1, -1),
float3( 1, 1, -1), float3( 1, -1, -1),
// Top // Top
float3(-1, -1, -1), float3(-1, 1, -1),
float3(-1, -1, 1),
float3( 1, -1, -1),
float3( 1, -1, -1),
float3(-1, -1, 1),
float3( 1, -1, 1),
// Back
float3(-1, -1, 1),
float3(-1, 1, 1), float3(-1, 1, 1),
float3( 1, -1, 1), float3( 1, 1, -1),
float3( 1, -1, 1), float3( 1, 1, -1),
float3(-1, 1, 1), float3(-1, 1, 1),
float3( 1, 1, 1), float3( 1, 1, 1),
// Front // Back
float3( 1, -1, -1), float3(-1, 1, 1),
float3( 1, 1, -1), float3(-1, -1, 1),
float3(-1, -1, -1), float3( 1, 1, 1),
float3(-1, -1, -1), float3( 1, 1, 1),
float3(-1, -1, 1),
float3( 1, -1, 1),
// Front
float3( 1, 1, -1), float3( 1, 1, -1),
float3( 1, -1, -1),
float3(-1, 1, -1), float3(-1, 1, -1),
float3(-1, 1, -1),
float3( 1, -1, -1),
float3(-1, -1, -1),
}; };
struct ViewParams struct ViewParams
+1 -2
View File
@@ -8,8 +8,7 @@ struct QuadOutput
QuadOutput quadMain(uint vertexIndex : SV_VertexID) QuadOutput quadMain(uint vertexIndex : SV_VertexID)
{ {
QuadOutput result; QuadOutput result;
result.uv = float2((vertexIndex << 1) & 2, vertexIndex & 2); result.uv = float2(vertexIndex & 2, (vertexIndex << 1) & 2);
result.position = float4(result.uv * 2.0f + -1.0f, 0.0f, 1.0f); result.position = float4(result.uv * 2.0f + -1.0f, 0.0f, 1.0f);
result.uv.y = 1 - result.uv.y;
return result; return result;
} }
+2 -2
View File
@@ -68,7 +68,7 @@ float4 screenToView(float4 screen)
float2 texCoord = screen.xy / pViewParams.screenDimensions; float2 texCoord = screen.xy / pViewParams.screenDimensions;
// Convert to clip space // Convert to clip space
float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w); float4 clip = float4( texCoord * 2.0f - 1.0f, screen.z, screen.w);
return clipToView(clip); return clipToView(clip);
} }
@@ -94,7 +94,7 @@ float4 clipToScreen(float4 clip)
float oz = 1; float oz = 1;
float pz = 0 - 1; float pz = 0 - 1;
float zf = pz * ndc.z + oz; float zf = pz * ndc.z + oz;
return float4(float2(texCoords.x, 1 - texCoords.y) * pViewParams.screenDimensions, zf, 1.0f); return float4(texCoords * pViewParams.screenDimensions, zf, 1.0f);
} }
struct Plane struct Plane
+1 -1
View File
@@ -337,7 +337,7 @@ struct CookTorrance : IBRDF
float nDotL = max(dot(n, lightDir_WS), 0.0); float nDotL = max(dot(n, lightDir_WS), 0.0);
float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor; float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor;
return result; return baseColor;
} }
[mutating] [mutating]
void transformNormal(float3x3 tangentToWorld) void transformNormal(float3x3 tangentToWorld)
@@ -154,8 +154,6 @@ void BasePass::render() {
// Base Rendering // Base Rendering
for (VertexData* vertexData : VertexData::getList()) { for (VertexData* vertexData : VertexData::getList()) {
transparentData.addAll(vertexData->getTransparentData()); transparentData.addAll(vertexData->getTransparentData());
vertexData->getInstanceDataSet()->updateBuffer(VertexData::CULLINGDATA_NAME, 0, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges();
permutation.setVertexData(vertexData->getTypeName()); permutation.setVertexData(vertexData->getTypeName());
for (const auto& materialData : vertexData->getMaterialData()) { for (const auto& materialData : vertexData->getMaterialData()) {
// material not used for any active meshes, skip // material not used for any active meshes, skip
@@ -125,8 +125,6 @@ void DepthCullingPass::render() {
permutation.setDepthCulling(getGlobals().useDepthCulling); permutation.setDepthCulling(getGlobals().useDepthCulling);
for (VertexData* vertexData : VertexData::getList()) { for (VertexData* vertexData : VertexData::getList()) {
permutation.setVertexData(vertexData->getTypeName()); permutation.setVertexData(vertexData->getTypeName());
vertexData->getInstanceDataSet()->updateBuffer(VertexData::CULLINGDATA_NAME, 0, cullingBuffer);
vertexData->getInstanceDataSet()->writeChanges();
// Create Pipeline(VertexData) // Create Pipeline(VertexData)
// Descriptors: // Descriptors:
// ViewData => global, static // ViewData => global, static
+2 -1
View File
@@ -104,7 +104,8 @@ void BufferAllocation::updateContents(uint64 regionOffset, uint64 regionSize, vo
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT, .flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT,
.usage = VMA_MEMORY_USAGE_AUTO, .usage = VMA_MEMORY_USAGE_AUTO,
}; };
OBufferAllocation staging = new BufferAllocation(graphics, fmt::format("{0}UpdateStaging", name), stagingInfo, stagingAlloc, Gfx::QueueType::GRAPHICS); OBufferAllocation staging =
new BufferAllocation(graphics, fmt::format("{0}UpdateStaging", name), stagingInfo, stagingAlloc, Gfx::QueueType::GRAPHICS);
uint8* data; uint8* data;
VK_CHECK(vmaMapMemory(graphics->getAllocator(), staging->allocation, (void**)&data)); VK_CHECK(vmaMapMemory(graphics->getAllocator(), staging->allocation, (void**)&data));
+4 -6
View File
@@ -269,8 +269,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) {
VkDescriptorSet setHandle = descriptorSet->getHandle(); VkDescriptorSet setHandle = descriptorSet->getHandle();
Gfx::PPipelineLayout layout = pipeline != nullptr ? pipeline->getPipelineLayout() : rtPipeline->getPipelineLayout(); Gfx::PPipelineLayout layout = pipeline != nullptr ? pipeline->getPipelineLayout() : rtPipeline->getPipelineLayout();
vkCmdBindDescriptorSets(handle, pipeline != nullptr ? VK_PIPELINE_BIND_POINT_GRAPHICS : VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, vkCmdBindDescriptorSets(handle, pipeline != nullptr ? VK_PIPELINE_BIND_POINT_GRAPHICS : VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR,
pipeline->getLayout(), layout->findParameter(descriptorSet->getName()), 1, &setHandle, 0, pipeline->getLayout(), layout->findParameter(descriptorSet->getName()), 1, &setHandle, 0, nullptr);
nullptr);
} }
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) { void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) {
@@ -442,8 +441,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptor) {
VkDescriptorSet setHandle = descriptorSet->getHandle(); VkDescriptorSet setHandle = descriptorSet->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(),
pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle,0, pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, 0, nullptr);
nullptr);
} }
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) { void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) {
@@ -465,8 +463,8 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptor
} }
sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle(); sets[pipeline->getPipelineLayout()->findParameter(descriptorSet->getName())] = descriptorSet->getHandle();
} }
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, 0,
0, nullptr); nullptr);
delete[] sets; delete[] sets;
} }
+17 -6
View File
@@ -161,6 +161,14 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
if (cachedHandles[setIndex]->getHandle() == VK_NULL_HANDLE) { if (cachedHandles[setIndex]->getHandle() == VK_NULL_HANDLE) {
// If it hasnt been initialized, allocate it // If it hasnt been initialized, allocate it
VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle)); VK_CHECK(vkAllocateDescriptorSets(graphics->getDevice(), &allocInfo, &cachedHandles[setIndex]->setHandle));
VkDebugUtilsObjectNameInfoEXT nameInfo = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
.pNext = nullptr,
.objectType = VK_OBJECT_TYPE_DESCRIPTOR_SET,
.objectHandle = (uint64)cachedHandles[setIndex]->setHandle,
.pObjectName = name.c_str(),
};
vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo);
} }
PDescriptorSet vulkanSet = cachedHandles[setIndex]; PDescriptorSet vulkanSet = cachedHandles[setIndex];
@@ -193,6 +201,7 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
boundResources.resize(owner->getLayout()->getBindings().size()); boundResources.resize(owner->getLayout()->getBindings().size());
for (uint32 i = 0; i < boundResources.size(); ++i) { for (uint32 i = 0; i < boundResources.size(); ++i) {
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount); boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
std::memset(boundResources[i].data(), 0, sizeof(PCommandBoundResource) * boundResources[i].size());
} }
constantData.resize(owner->getLayout()->constantsSize); constantData.resize(owner->getLayout()->constantsSize);
} }
@@ -208,9 +217,10 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>(); PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
const auto& map = owner->getLayout()->mappings[mappingName]; const auto& map = owner->getLayout()->mappings[mappingName];
uint32 binding = map.binding; uint32 binding = map.binding;
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) { // if the buffer is empty
if (vulkanBuffer->getAlloc() == nullptr)
return; return;
}
bufferInfos.add(VkDescriptorBufferInfo{ bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(), .buffer = vulkanBuffer->getHandle(),
.offset = 0, .offset = 0,
@@ -234,9 +244,10 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G
PVertexBuffer vulkanBuffer = indexBuffer.cast<VertexBuffer>(); PVertexBuffer vulkanBuffer = indexBuffer.cast<VertexBuffer>();
const auto& map = owner->getLayout()->mappings[mappingName]; const auto& map = owner->getLayout()->mappings[mappingName];
uint32 binding = map.binding; uint32 binding = map.binding;
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) { // if the buffer is empty
if (vulkanBuffer->getAlloc() == nullptr)
return; return;
}
bufferInfos.add(VkDescriptorBufferInfo{ bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(), .buffer = vulkanBuffer->getHandle(),
@@ -261,9 +272,9 @@ void DescriptorSet::updateBuffer(const std::string& mappingName, uint32 index, G
PIndexBuffer vulkanBuffer = indexBuffer.cast<IndexBuffer>(); PIndexBuffer vulkanBuffer = indexBuffer.cast<IndexBuffer>();
const auto& map = owner->getLayout()->mappings[mappingName]; const auto& map = owner->getLayout()->mappings[mappingName];
uint32 binding = map.binding; uint32 binding = map.binding;
if (boundResources[binding][index] == vulkanBuffer->getAlloc() || vulkanBuffer->getAlloc() == nullptr) { // if the buffer is empty
if (vulkanBuffer->getAlloc() == nullptr)
return; return;
}
bufferInfos.add(VkDescriptorBufferInfo{ bufferInfos.add(VkDescriptorBufferInfo{
.buffer = vulkanBuffer->getHandle(), .buffer = vulkanBuffer->getHandle(),
+2 -4
View File
@@ -295,8 +295,7 @@ Viewport::Viewport(PWindow owner, const ViewportCreateInfo& viewportInfo) : Gfx:
handle.width = static_cast<float>(sizeX); handle.width = static_cast<float>(sizeX);
handle.height = static_cast<float>(sizeY); handle.height = static_cast<float>(sizeY);
handle.x = static_cast<float>(offsetX); handle.x = static_cast<float>(offsetX);
handle.y = static_cast<float>(offsetY) + handle.height; handle.y = static_cast<float>(offsetY);
handle.height = -handle.height;
handle.minDepth = 1.f; handle.minDepth = 1.f;
handle.maxDepth = 0.f; handle.maxDepth = 0.f;
} }
@@ -307,8 +306,7 @@ void Viewport::resize(uint32 newX, uint32 newY) {
sizeX = newX; sizeX = newX;
sizeY = newY; sizeY = newY;
handle.width = static_cast<float>(sizeX); handle.width = static_cast<float>(sizeX);
handle.y = static_cast<float>(sizeY + offsetX); handle.height = static_cast<float>(sizeY);
handle.height = -static_cast<float>(sizeY);
} }
void Viewport::move(uint32 newOffsetX, uint32 newOffsetY) { void Viewport::move(uint32 newOffsetX, uint32 newOffsetY) {
+7 -13
View File
@@ -20,19 +20,13 @@ Viewport::~Viewport() {}
Matrix4 Viewport::getProjectionMatrix() const { Matrix4 Viewport::getProjectionMatrix() const {
if (fieldOfView > 0.0f) { if (fieldOfView > 0.0f) {
// float h = 1.0 / tan(fieldOfView * 0.5); Matrix4 projectionMatrix = glm::perspective(fieldOfView, sizeX / static_cast<float>(sizeY), 0.1f, 1000.0f);
// float w = h / (sizeX / static_cast<float>(sizeY)); Matrix4 correctionMatrix = Matrix4(
// float zFar = 1000.0f; 1, 0, 0, 0,
// float zNear = 0.1f; 0, -1, 0, 0,
// float a = -zNear / (zFar - zNear); 0, 0, 1 / 2.f, 0,
// float b = (zNear * zFar) / (zFar - zNear); 0, 0, 1 / 2.f, 1);
// return Matrix4( return correctionMatrix * projectionMatrix;
// w, 0, 0, 0,
// 0, -h, 0, 0,
// 0, 0, a, b,
// 0, 0, 1, 0
//);
return glm::perspective(fieldOfView, sizeX / static_cast<float>(sizeY), 0.1f, 1000.0f);
} else { } else {
return glm::ortho(0.0f, (float)sizeX, (float)sizeY, 0.0f); return glm::ortho(0.0f, (float)sizeX, (float)sizeY, 0.0f);
} }
+5
View File
@@ -28,6 +28,10 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
.name = "irradianceMap", .name = "irradianceMap",
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
}); });
layout->addDescriptorBinding(Gfx::DescriptorBinding{
.name = "irradianceSampler",
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
layout->create(); layout->create();
directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{ directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
@@ -78,6 +82,7 @@ void LightEnvironment::commit() {
set->updateConstants("numDirectionalLights", 0, &numDirectionalLights); set->updateConstants("numDirectionalLights", 0, &numDirectionalLights);
set->updateBuffer("directionalLights", 0, directionalLights); set->updateBuffer("directionalLights", 0, directionalLights);
set->updateTexture("irradianceMap", 0, environment->getIrradianceMap()); set->updateTexture("irradianceMap", 0, environment->getIrradianceMap());
set->updateSampler("irradianceSampler", 0, environmentSampler);
set->writeChanges(); set->writeChanges();
} }
+2 -2
View File
@@ -9,6 +9,6 @@ CameraUpdater::~CameraUpdater() {}
void CameraUpdater::update(Component::Camera& camera, Component::Transform& transform) { void CameraUpdater::update(Component::Camera& camera, Component::Transform& transform) {
Vector eyePos = transform.getPosition(); Vector eyePos = transform.getPosition();
Vector lookAt = eyePos - transform.getForward(); Vector lookAt = eyePos + transform.getForward();
camera.viewMatrix = glm::lookAtLH(eyePos, lookAt, Vector(0, 1, 0)); camera.viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
} }