From 6e9f54987f2ec25d0a04a35587447684881a766c Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 26 Oct 2022 22:40:04 +0800 Subject: [PATCH 01/22] Prepared light global desc set layout data and render graph resources - Fixed material padding - Lighting desc sets now have a buffer at binding 0 to store light counts. - Added position, normals, albedo resources in render graph --- .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 8 +- .../GlobalData/SHGraphicsGlobalData.cpp | 31 ++++---- .../MiddleEnd/Interface/SHGraphicsConstants.h | 32 ++------ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 40 ++++++++-- .../MiddleEnd/Interface/SHRenderable.cpp | 2 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 71 +++++++++++++----- .../MiddleEnd/Lights/SHLightingSubSystem.h | 19 ++++- TempShaderFolder/DeferredCompositeCs.glsl | 30 ++++++++ TempShaderFolder/DeferredCompositeCs.spv | Bin 0 -> 1716 bytes TempShaderFolder/TestCubeFs.glsl | 17 +++-- TempShaderFolder/TestCubeFs.spv | Bin 2300 -> 2536 bytes TempShaderFolder/TestCubeVs.glsl | 12 ++- TempShaderFolder/TestCubeVs.spv | Bin 2492 -> 2684 bytes 13 files changed, 175 insertions(+), 87 deletions(-) create mode 100644 TempShaderFolder/DeferredCompositeCs.glsl create mode 100644 TempShaderFolder/DeferredCompositeCs.spv diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 09fde60f..f5c51914 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -180,7 +180,8 @@ namespace SHADE { SHLOG_WARNING("[SHBatch] Entity with a missing SHRenderable found!"); } - propsCurrPtr += singleMatPropAlignedSize; + //propsCurrPtr += singleMatPropAlignedSize; + propsCurrPtr += singleMatPropSize; } // Transfer to GPU @@ -302,7 +303,7 @@ namespace SHADE { singleMatPropSize = SHADER_INFO->GetBytesRequired(); singleMatPropAlignedSize = device->PadSSBOSize(static_cast(singleMatPropSize)); - matPropTotalBytes = numTotalElements * singleMatPropAlignedSize; + matPropTotalBytes = numTotalElements * singleMatPropSize; if (matPropsDataSize < matPropTotalBytes) { matPropsData.reset(new char[matPropTotalBytes]); @@ -361,7 +362,8 @@ namespace SHADE { SHLOG_WARNING("[SHBatch] Entity with a missing SHRenderable found!"); } - propsCurrPtr += singleMatPropAlignedSize; + //propsCurrPtr += singleMatPropAlignedSize; + propsCurrPtr += singleMatPropSize; } } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp index 0f1658f3..d5fb81bd 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp @@ -47,36 +47,35 @@ namespace SHADE // For global data (generic data and textures) Handle staticGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS,{ genericDataBinding, texturesBinding }); + std::vector lightBindings{}; - for (uint32_t i = 0; i < SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES); ++i) + + // This is the binding we use to count the lights (binding 0) + lightBindings.push_back(SHVkDescriptorSetLayout::Binding + { + .Type = vk::DescriptorType::eUniformBufferDynamic, + .Stage = vk::ShaderStageFlagBits::eCompute, + .BindPoint = 0, + .DescriptorCount = 1, + + }); + + for (uint32_t i = 1; i <= SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES); ++i) { lightBindings.push_back (SHVkDescriptorSetLayout::Binding { .Type = vk::DescriptorType::eStorageBufferDynamic, - .Stage = vk::ShaderStageFlagBits::eFragment, + .Stage = vk::ShaderStageFlagBits::eCompute, .BindPoint = i, .DescriptorCount = 1, }); } - //SHVkDescriptorSetLayout::Binding pointLightBinding - //{ - // .Type = vk::DescriptorType::eStorageBufferDynamic, - // .Stage = vk::ShaderStageFlagBits::eFragment, - // .BindPoint = SHGraphicsConstants::DescriptorSetBindings::POINT_LIGHT_DATA, - // .DescriptorCount = 1, - //}; - //SHVkDescriptorSetLayout::Binding spotLightBinding - //{ - // .Type = vk::DescriptorType::eStorageBufferDynamic, - // .Stage = vk::ShaderStageFlagBits::eFragment, - // .BindPoint = SHGraphicsConstants::DescriptorSetBindings::SPOT_LIGHT_DATA, - // .DescriptorCount = 1, - //}; // For Dynamic global data (lights) Handle dynamicGlobalLayout = logicalDevice->CreateDescriptorSetLayout(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, lightBindings); + SHVkDescriptorSetLayout::Binding cameraDataBinding { .Type = vk::DescriptorType::eUniformBufferDynamic, diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index 4c3ba7f9..a39ec10e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -94,32 +94,14 @@ namespace SHADE /***************************************************************************/ static constexpr uint32_t IMAGE_AND_SAMPLERS_DATA = 1; - ///***************************************************************************/ - ///*! - // \brief - // DescriptorSet binding for directional lights. + /***************************************************************************/ + /*! + \brief + DescriptorSet binding for combined image sampler data. - //*/ - ///***************************************************************************/ - //static constexpr uint32_t DIRECTIONAL_LIGHT_DATA = 0; - - ///***************************************************************************/ - ///*! - // \brief - // DescriptorSet binding for directional lights. - - //*/ - ///***************************************************************************/ - //static constexpr uint32_t POINT_LIGHT_DATA = 1; - - ///***************************************************************************/ - ///*! - // \brief - // DescriptorSet binding for directional lights. - - //*/ - ///***************************************************************************/ - //static constexpr uint32_t SPOT_LIGHT_DATA = 2; + */ + /***************************************************************************/ + static constexpr uint32_t LIGHTING_COUNT = 0; /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 9b984a4b..dfa4e41e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -127,15 +127,20 @@ namespace SHADE shaderSourceLibrary.LoadShader(2, "KirschCs.glsl", SH_SHADER_TYPE::COMPUTE, true); shaderSourceLibrary.LoadShader(3, "PureCopyCs.glsl", SH_SHADER_TYPE::COMPUTE, true); + shaderSourceLibrary.LoadShader(4, "DeferredCompositeCs.glsl", SH_SHADER_TYPE::COMPUTE, true); + + shaderModuleLibrary.ImportFromSourceLibrary(device, shaderSourceLibrary); auto cubeVS = shaderModuleLibrary.GetShaderModule("TestCubeVs.glsl"); auto cubeFS = shaderModuleLibrary.GetShaderModule("TestCubeFs.glsl"); auto greyscale = shaderModuleLibrary.GetShaderModule("KirschCs.glsl"); auto pureCopy = shaderModuleLibrary.GetShaderModule("PureCopyCs.glsl"); + auto deferredComposite = shaderModuleLibrary.GetShaderModule("DeferredCompositeCs.glsl"); cubeVS->Reflect(); cubeFS->Reflect(); greyscale->Reflect(); pureCopy->Reflect(); + deferredComposite->Reflect(); } void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept @@ -176,26 +181,45 @@ namespace SHADE // Initialize world render graph worldRenderGraph->Init(device, swapchain); - worldRenderGraph->AddResource("Scene Pre-Process", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); - worldRenderGraph->AddResource("Scene", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); + worldRenderGraph->AddResource("Position", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); + worldRenderGraph->AddResource("Normals", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); + worldRenderGraph->AddResource("Albedo", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); worldRenderGraph->AddResource("Depth Buffer", { SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); worldRenderGraph->AddResource("Entity ID", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); worldRenderGraph->AddResource("Light Layer Indices", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + worldRenderGraph->AddResource("Scene", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); + + auto gBufferNode = worldRenderGraph->AddNode("G-Buffer", + { + "Position", + "Entity ID", + "Light Layer Indices", + "Normals", + "Albedo", + "Depth Buffer", + "Scene" + }, + {}); // no predecessors - auto gBufferNode = worldRenderGraph->AddNode("G-Buffer", { "Light Layer Indices", "Entity ID", "Depth Buffer", "Scene", "Scene Pre-Process"}, {}); // no predecessors auto gBufferSubpass = gBufferNode->AddSubpass("G-Buffer Write"); - gBufferSubpass->AddColorOutput("Scene Pre-Process"); + gBufferSubpass->AddColorOutput("Position"); gBufferSubpass->AddColorOutput("Entity ID"); gBufferSubpass->AddColorOutput("Light Layer Indices"); + gBufferSubpass->AddColorOutput("Normals"); + gBufferSubpass->AddColorOutput("Albedo"); gBufferSubpass->AddDepthOutput("Depth Buffer", SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL); //// kirsch //auto kirschShader = shaderModuleLibrary.GetShaderModule("KirschCs.glsl"); - //gBufferNode->AddNodeCompute(kirschShader, { "Scene Pre-Process", "Scene" }); + //gBufferNode->AddNodeCompute(kirschShader, { "Position", "Scene" }); - // copy - auto pureCopyShader = shaderModuleLibrary.GetShaderModule("PureCopyCs.glsl"); - gBufferNode->AddNodeCompute(pureCopyShader, { "Scene Pre-Process", "Scene" }); + //// copy + //auto pureCopyShader = shaderModuleLibrary.GetShaderModule("PureCopyCs.glsl"); + //gBufferNode->AddNodeCompute(pureCopyShader, { "Position", "Scene" }); + + // deferred composite + auto deferredCompositeShader = shaderModuleLibrary.GetShaderModule("DeferredCompositeCs.glsl"); + gBufferNode->AddNodeCompute(deferredCompositeShader, { "Albedo", "Scene" }); auto dummyNode = worldRenderGraph->AddNode("Dummy Pass", { "Scene" }, {"G-Buffer"}); // no predecessors diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp index 7c4d0bb9..c935194f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderable.cpp @@ -28,7 +28,7 @@ namespace SHADE material = {}; oldMaterial = {}; - lightLayer = 0; + lightLayer = 1; } void SHRenderable::OnDestroy() diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 8d9efe54..a22fb662 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -76,8 +76,8 @@ namespace SHADE // boilerplate intermediateData = nullptr; - // initialize alignment - lightDataAlignmentSize = logicalDevice->PadSSBOSize(GetLightTypeSize(type)); + // Get data required for struct + lightDataSize = GetLightTypeSize(type); // So create some data! Expand(logicalDevice); @@ -94,7 +94,7 @@ namespace SHADE /***************************************************************************/ void SHLightingSubSystem::PerTypeData::Expand(Handle logicalDevice) noexcept { - if (lightDataAlignmentSize == 0) + if (lightDataSize == 0) { SHLOG_ERROR ("One of the types of lights have not been accounted for. Make sure lightDataAlignmentSize is not nullptr."); return; @@ -111,10 +111,12 @@ namespace SHADE numLights = 0; // Initialize the data for lights - intermediateData = std::make_unique(lightDataAlignmentSize * maxLights); + intermediateData = std::make_unique(lightDataSize * maxLights); + + lightDataAlignedSize = logicalDevice->PadSSBOSize(lightDataSize * maxLights); // We want to initialize 3 times the amount of data required. - dataBuffer = logicalDevice->CreateBuffer(maxLights * lightDataAlignmentSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, maxLights * lightDataAlignmentSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); + dataBuffer = logicalDevice->CreateBuffer(lightDataAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, lightDataAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); } else { @@ -122,24 +124,27 @@ namespace SHADE uint32_t const OLD_MAX_LIGHTS = maxLights; // before we increase the number of lights, create space to store old data. - std::unique_ptr oldData = std::make_unique(lightDataAlignmentSize * OLD_MAX_LIGHTS); + std::unique_ptr oldData = std::make_unique(lightDataSize * OLD_MAX_LIGHTS); // copy data over. - std::memcpy (oldData.get(), intermediateData.get(), lightDataAlignmentSize * OLD_MAX_LIGHTS); + std::memcpy (oldData.get(), intermediateData.get(), lightDataSize * OLD_MAX_LIGHTS); // now we start to expand.... // double space for lights maxLights *= 2; + // calculate total + padding + lightDataAlignedSize = logicalDevice->PadSSBOSize(lightDataSize * maxLights); + // destroy old data and initialize container for double the amount of data. - intermediateData = std::make_unique(lightDataAlignmentSize * maxLights); + intermediateData = std::make_unique(lightDataSize * maxLights); // copy old data to new container - std::memcpy(intermediateData.get(), oldData.get(), lightDataAlignmentSize * OLD_MAX_LIGHTS); + std::memcpy(intermediateData.get(), oldData.get(), lightDataSize * OLD_MAX_LIGHTS); // Resize the GPU buffer. TODO: Replace with Resize no copy here - dataBuffer->ResizeReplace(maxLights * lightDataAlignmentSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, oldData.get(), lightDataAlignmentSize * OLD_MAX_LIGHTS); + dataBuffer->ResizeReplace(maxLights * lightDataAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, oldData.get(), lightDataAlignedSize * OLD_MAX_LIGHTS); } @@ -187,7 +192,12 @@ namespace SHADE uint32_t SHLightingSubSystem::PerTypeData::GetAlignmentSize(void) const noexcept { - return lightDataAlignmentSize; + return lightDataAlignedSize; + } + + uint32_t SHLightingSubSystem::PerTypeData::GetDataSize(void) const noexcept + { + return lightDataSize; } uint32_t SHLightingSubSystem::PerTypeData::GetNumLights(void) const noexcept @@ -231,7 +241,7 @@ namespace SHADE // Now that the container is big enough, bind the new light // Get address of write location - void* writeLocation = reinterpret_cast(intermediateData.get()) + (lightDataAlignmentSize * numLights); + void* writeLocation = reinterpret_cast(intermediateData.get()) + (lightDataSize * numLights); // Write the light data to address WriteLightToAddress(writeLocation, unboundLight); @@ -257,7 +267,7 @@ namespace SHADE /***************************************************************************/ void SHLightingSubSystem::PerTypeData::ModifyLight(SHLightComponent* lightComp) noexcept { - void* writeLocation = reinterpret_cast(intermediateData.get()) + (lightDataAlignmentSize * lightComp->GetIndexInBuffer()); + void* writeLocation = reinterpret_cast(intermediateData.get()) + (lightDataSize * lightComp->GetIndexInBuffer()); WriteLightToAddress(writeLocation, lightComp); } @@ -266,7 +276,7 @@ namespace SHADE if (intermediateData) { // we want to write to the offset of the current frame - dataBuffer->WriteToMemory(intermediateData.get(), lightDataAlignmentSize * numLights, 0, lightDataAlignmentSize * maxLights * frameIndex); + dataBuffer->WriteToMemory(intermediateData.get(), lightDataSize * numLights, 0, lightDataSize * maxLights * frameIndex); } } @@ -287,12 +297,12 @@ namespace SHADE // We bind the buffer with the correct desc set binding lightingDataDescSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, - binding, + binding + 1, // we want to +1 here because the first binding is reserved for count { &buffer, 1 }, 0, - perTypeData[binding].GetAlignmentSize() * perTypeData[binding].GetMaxLights()); + perTypeData[binding].GetDataSize() * perTypeData[binding].GetMaxLights()); - lightingDataDescSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, binding); + lightingDataDescSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, binding + 1); // +1 here, same reason. see above } /***************************************************************************/ @@ -307,11 +317,13 @@ namespace SHADE { for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i) { - for (uint32_t j = 0; j < dynamicOffsets.size(); ++j) + dynamicOffsets[i][0] = i * lightCountsAlignedSize; + // Even if the first binding is a count, we want to account for that too + for (uint32_t j = 1; j < static_cast(dynamicOffsets.size()); ++j) { auto const& typeData = perTypeData[j]; { - dynamicOffsets[i][j] = j * typeData.GetAlignmentSize() * typeData.GetMaxLights(); + dynamicOffsets[i][j] = j * typeData.GetAlignmentSize(); } } } @@ -346,11 +358,23 @@ namespace SHADE // initialize all the data first. We add more lights here as we add more types. perTypeData[i].InitializeData(logicalDevice, static_cast(i)); UpdateDescSet(i); + + // no lights at first + lightCountsData[i] = 0; } + + lightCountsAlignedSize = sizeof (uint32_t) * NUM_LIGHT_TYPES; + lightCountsAlignedSize = logicalDevice->PadUBOSize(lightCountsAlignedSize); + + // Create the GPU buffer to hold light count + lightCountsBuffer = logicalDevice->CreateBuffer(lightCountsAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, lightCountsAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eUniformBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); + + lightingDataDescSet->ModifyWriteDescBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::LIGHTING_COUNT, {&lightCountsBuffer, 1}, 0, sizeof (uint32_t) * NUM_LIGHT_TYPES); + lightingDataDescSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::LIGHTING_COUNT); for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i) { - dynamicOffsets[i].resize(NUM_LIGHT_TYPES); + dynamicOffsets[i].resize(NUM_LIGHT_TYPES + 1); // +1 for the count } } @@ -366,6 +390,8 @@ namespace SHADE /***************************************************************************/ void SHLightingSubSystem::Run(Handle cmdBuffer, uint32_t frameIndex) noexcept { + static uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES); + auto& lightComps = SHComponentManager::GetDense(); bool expanded = false; for (auto& light : lightComps) @@ -377,6 +403,9 @@ namespace SHADE if (!light.GetBound()) { perTypeData[enumValue].AddLight(logicalDevice, &light, expanded); + + // add to light count + ++lightCountsData[enumValue]; } // if there was modification to the light data @@ -396,6 +425,8 @@ namespace SHADE data.WriteToGPU(frameIndex); } + lightCountsBuffer->WriteToMemory(lightCountsData.data(), lightCountsData.size() * sizeof (uint32_t), 0, lightCountsAlignedSize * frameIndex); + // If any of the buffers got expanded, the descriptor set is invalid because the expanded buffer // is a new buffer. If some expansion was detected, update descriptor sets. if (expanded) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index e5336b4e..6c974730 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -17,7 +17,7 @@ namespace SHADE class SHVkCommandBuffer; // Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU. - struct SHDirectionalLightData + struct SHDirectionalLightData { //! Direction of the light SHVec3 direction; @@ -53,8 +53,11 @@ namespace SHADE //! Capacity of the container. uint32_t maxLights; - //! SSBOs need to be aligned. This is to pad lighting structs - uint32_t lightDataAlignmentSize; + //! SSBOs need to be aligned. This is to pad descriptor offset + uint32_t lightDataAlignedSize; + + //! size needed to store 1 struct object + uint32_t lightDataSize; //! type of the light. Will be used later when we want to expand SH_LIGHT_TYPE lightType; @@ -87,6 +90,7 @@ namespace SHADE static uint32_t GetLightTypeSize (SH_LIGHT_TYPE type) noexcept; Handle GetDataBuffer (void) const noexcept; uint32_t GetAlignmentSize (void) const noexcept; + uint32_t GetDataSize (void) const noexcept; uint32_t GetNumLights (void) const noexcept; uint32_t GetMaxLights (void) const noexcept; }; @@ -105,6 +109,15 @@ namespace SHADE //! Container to store dynamic offsets for binding descriptor sets std::array, static_cast(SHGraphicsConstants::NUM_FRAME_BUFFERS)> dynamicOffsets; + //! holds the data that represents how many lights are in the scene + std::array(SH_LIGHT_TYPE::NUM_TYPES)> lightCountsData; + + //! GPU buffer to hold lightCountData + Handle lightCountsBuffer; + + //! For padding in the buffer + uint32_t lightCountsAlignedSize; + /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ diff --git a/TempShaderFolder/DeferredCompositeCs.glsl b/TempShaderFolder/DeferredCompositeCs.glsl new file mode 100644 index 00000000..354a8954 --- /dev/null +++ b/TempShaderFolder/DeferredCompositeCs.glsl @@ -0,0 +1,30 @@ +#version 450 + +struct DirectionalLightStruct +{ + vec3 direction; + uint isActive; + uint cullingMask; + vec4 diffuseColor; +}; + +layout(local_size_x = 16, local_size_y = 16) in; +layout(set = 4, binding = 0, rgba8) uniform image2D inputImage; +layout(set = 4, binding = 1, rgba8) uniform image2D targetImage; + +layout(set = 1, binding = 0) buffer DirectionalLightData +{ + DirectionalLightStruct dLightData[]; +} DirLightData; + +void main() +{ + // convenient variables + ivec2 globalThread = ivec2(gl_GlobalInvocationID); + + vec3 color = imageLoad (inputImage, globalThread).rgb; + + // store result into result image + imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(color, 1.0f)); + +} \ No newline at end of file diff --git a/TempShaderFolder/DeferredCompositeCs.spv b/TempShaderFolder/DeferredCompositeCs.spv new file mode 100644 index 0000000000000000000000000000000000000000..679dc135f5f556eb95565c51c1c9f1c2aca8821a GIT binary patch literal 1716 zcmZ9MYflqF6ov=dLID900dL@zs;FSSp)oOPjF`1aO)>brS++~rxa>CVmc+yl{x*M= zUrc!{Tj=H15rizhIa zOvw`AEQ?c-E=$gWIK{Cjxhx!P#qP1mVsx^k=*Ik#QC3#J)$!YHzxA;b_WPY-{ym90 zNt{NVZaj#>JU)-$RVR3H8YZLeB%vb4Wd4eB&nZVQ$&Q2M>**j0x-wN~)z;QaI=*!^ z)AKA0@;FPI2i9LU8`5ExWCLqg%nj){?T_;2SzgF`b9CWt&BkxICF`I?_Ib5aOM<_5{;wxIT(Huf7Zrf`rY{CWHgLE zxKeFzPlf+q!$FV-f^9DRtgfwY>|s{Vh3VV`YK*Uma*qp=TM}$$u`OZNg$?Zcr+g!CvYupy`3dynYMee+w>m#{UJg!)A{B4`9EM zO^r(u?&XJU?u358z91r@GMfsQs1^Vw?i_z**$mnQsmJ$ z{~-0nH~%VMtn&NWn+XeD)z{tM?&<07>AlXe<>SW8n0a%`d}F3`&KwhB4D!#{rt&W@ z|CXFLb7p(%hj{a+@8i@~qtcD*qKsXh+Gj4`H7Cq$bG|>^9F30hT_>}m(_>%a#ctiY1d{$?PRk6}Ks?3;wl&Gsy{b9WR-NU%DctqjRAQVZ`R*jywei~O&2cjNMS14PLrZy)PjdIPDEH%ECrRd> zI$O#=kH7!qNq@K*kH+J;st+?8XD+vK>Pp?@4lH*yd3>D9N7*E82lN!t?zv}rP2c09 zaZZIwS3&ld_} zZun-z)}=?W)R(#4y?U4&+Hx9APWEq*uPT49*~4N|Z|1eD4+k4UjyHSx!Z|l;hS%3U z>~feDHhbN+c@J#nfS>okW;d{T4|;@xy(pd9AL;gxYncF1!0>~eZDI5Wrcd`Mj(fo( zG5Oz;oE7t-k}Hygh=Ka5G?L^T@ze&l?M2xTvCQstqjwwqd9NL_BK!{(Lmc-7{o^CO z+svCYGh*)JKLDFv&g&PssPo*9eo-3rN8(G0=YIm5c}Du3lOz`WuD5w3FyiMWi6_^B z`sbS?792^Alakbfj~v*%E7%3u^c#8mhPThihB(ig5ZkVSJ)njV&l^!gsFA(Ee_0## zx+FD{qfNoSqR7i~5O-Dj8U z_f6lSYd(?=g&C|$CqHjWzB`h{hxfhbZTiLkm1IXuebj@!;W7N1(#hBMv!|T7tscqE z{y|{>3h7C%>z7?PCuV=xk$Z}yj#tIt_jQ8(#18Qnq!Z7Mg!qfn!HH*=u!(0@?~0jU z$j@Bf^Z2@MV_qMKm&C;2W1i$D_CqoLZEvr5jQq@&ZGcOz^R?L`%D~a#~1n}=jYxZ^4*pFa=tHwfs>E7zb_8? z@P#?E4_|u!mSV~Oz+>QnfA{^Y3*-I=;@>>>P&$3$#_+KBF{BO_S zh)zk0kv}xGA_1|_ zDoR}(+K*j|;RDeX(buAfqK@dC?%<;$CDl}sG5;t)UEbYZ)cNUgG`6ESi*p-|_u_%g zqT%zGwx5sR^^r-XMM<3QPU2k~tt>B%;{GeenIaCYq{DQQx);N2KYBfh6ZgW|O!jH) z-Dl6bz0IgU8b#y$D6vuEQX36ircCa@lBUh8JDlWChRHBf zTS6L|kukYF%qN*u2PJl1{ArwTXT#A(oX47OL%S(Y-(PNOLSW3+-``>%cm;oE7bl~= zxPq~f=T<>=8j5j2T)AxK;)H}Y%N>;v0~=>R5jymAQQX%iy=E?B(4n3n@B4V6pr-C& zqgLw%$G+5;xZS8d|4?%~fqsIRJ19|vD%Ne}oU(;IbQ1V~;B4SY+yCN64Tawr< zb>Rn&ogC~4TT3##Kqnu2E$2|?LuWr=H+;TJk~!p`6>p>Hw6tr!5psc-wz_6e)`yKA z(Agt3lXK3?+zUCvez1Qgocv|4_2R8bEoMZ|Ur44md|J}^mgpIr`(KHZ3!MDu{J#$Q zzwvVL=iL&E7@?k3j}dRp%j87=PMmquFY(cNV_?`HiIb~p?|A!~W=1aF5{Eng3TcRU z^vi5M6)`X7{!pIG;i?F{qbiwCTg0C5!N&Z8@4V!;Xvg2ZCK-(Q3*vk?;eP~oczb+5 z;P^0~8zN>F;xen79{*K7%<7hid*Gq=Mal2iep?tgwKMBGqEI`w&?hmMy*Gb7JQ|h`{mZU7!d5$CB|6HRAt71de~l>;LHmt&83QTD-=O diff --git a/TempShaderFolder/TestCubeVs.glsl b/TempShaderFolder/TestCubeVs.glsl index 7b58d1cf..bac9444d 100644 --- a/TempShaderFolder/TestCubeVs.glsl +++ b/TempShaderFolder/TestCubeVs.glsl @@ -14,13 +14,14 @@ layout(location = 8) in uvec2 integerData; layout(location = 0) out struct { - vec4 vertColor; // location 0 + vec4 vertPos; // location 0 vec2 uv; // location = 1 + vec4 normal; // location = 2 } Out; // material stuff -layout(location = 2) out struct +layout(location = 3) out struct { int materialIndex; uint eid; @@ -36,10 +37,13 @@ layout(set = 2, binding = 0) uniform CameraData void main() { - Out.uv = aUV; + Out2.materialIndex = gl_InstanceIndex; Out2.eid = integerData[0]; Out2.lightLayerIndex = integerData[1]; + + Out.vertPos = worldTransform * vec4(aVertexPos, 1.0f); + Out.uv = aUV; + Out.normal = vec4 (aNormal, 1.0f); gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); - Out.vertColor = vec4 (aVertexPos, 1.0f); } \ No newline at end of file diff --git a/TempShaderFolder/TestCubeVs.spv b/TempShaderFolder/TestCubeVs.spv index 731e31d107fda1e44cdbef3c2445017205b6b841..9cf9d86def3a980db6b334d741cd492d99e8a0bc 100644 GIT binary patch literal 2684 zcmZ9OX>%Jz5QfLr;Uvz9$w3H4vI!U*4CEpZau^@7K|X>Ve^pIMi`lC6O0`;>B%ksZ z;3x5`_(B!$GrR3ZRM)Of zx7XR(>2%k6{n4m5&R-`{FNxErH;A*SpT{Q=yfYPEoc5FBL6y)DqgqQtXPnU)tfref zwU2xrWwB2-(?Rqq#K=r1oQvYYDVO?^`0$Us>t9D%!R8F^xO1G}m2wT`<-UhWZ!;a| zKJ7=ARc{XY_<(YjFW%=%KEUX?dYB@f6$Dx*Vm>v0qGi#x@ zszG)$^!U$VmJIeYpN@YQ3r-{S-5)4%^orDBAMfB_9>}hT_wd_AQu3@QrhDv0S+Pm3 z&;rLMHXO%!JWPd71wM5KT$kL7-{_T!UXzQO6pdkrg7FK7v!r$!N>x((K=m?pOAMF?)XBr-xAr&2`H6oRv*Y_`K(| zWU=&_W#Y^T@!O>@75s(LXZDCQ@9Cc90qE{@=WEln@3~d;Dz^K(Q zY_Q_|TF7U)tzYwsvo^%CUNwUMu6J-QzlZ4uB48bz$UgFN2YNgAp5KxH`5wU*%beE7mi+U=$xj~m z_`EL|ael$rOWgKfkxl%%;vYzJHZ{YaktPOCK78f_jQw!0N?7o(NfWdBKa$OP_;%jM zvdM4zZ^>rQH8ES#2(`3Jn|H>aD}DCTuX$-W;03qtK9kLP#Hbga`31Wn|8r@$Emf$~>hD*)t$LD(i zBmRRle2bHx?}zv;#ebG=1)Clezg6uLBUZ%gZdEpURwSH*&u(WhPArY+4ssO*PNoVoc+d5PVVa5fxj zWsV+5m}To3K0IohlYS&&mf$l-KT6ELY%q!MZ&C6r}h2U5;wmqpLh6Mdw7>E2^?^{&$jI9+w8~( vW7&OnWrJ1k^P5=4rhyKdR literal 2492 zcmZ9MX-^bE5QbY=78Su;@j?)96fab~56}f&MdR^x)7c$yl3{i;JD~W#cgLy1J`o2M4Byo!jAdyHWSn6>Gm6kj1$XR}Xum`Jp-6&pWeox39w( zbAy2hXRm&&nqk-K@$!W=~iU_!5oP&8H|b`< zUJG{av%cXRG2CHgJr6o}@t-~i{g8B4-3>d_*L)sju}_xMPV_zaYQaaoDDG@=xoZ-y ze$AVHGs+4!_3}!voHF&y4(HEAuU{oJSR$kNI;6y7pU^Jq277Jcqzsk%Bp%(bm7VJv)A^xG4E$)PmI^|nP;@)Ch)UXvt=kcv4$(E1z zqQ5L^WJnhLT9o-vVyGnyj_f@vM0&mCQp-l~jnB0c&qK5;@!XNw`PR*n&d1EB{V&~Y zt>7|GzPPsTh^-dp%fA)HCm|oR=0Ey$HA*?cHN>I6696qRJqA+?n4W-n3ovs`%uI=y zY5Y4SOFD&jW5HpWjeOYH%|=dayrtRDu`#<1d8`lk?d_)JV=ak=jhsUP7aTC0ecNpM zz=Msv#MzyA=QG>zlrW1s^XA;KsHqmdT`&uOQ+xG|cxNzoIjB=OXG#c+eneVb`=sQk z;;9QvelTwdhC3n5w+aXQr0{O-mT=rL(AETs!BH2R@kDvKmfECl)_% za!NaA@g~IczHqS<4`vpzabC4%_*13N>OCt=ez4VdUOM?L{(^M!omBjcc6x$sLfRGW z);D|z=UmlJUi{Pr=05@3xbQXY#L;Vd%N&BS6MsWHHDD(m%zWCtZPyPqm@nMG#=D!0Q_lEme;@r`X8m%W+XUIW9;n$0h05Eyrc)f`s$oa0mMSLc;9YTZ7?QZ7-!)YikH&V_6+b(y>)*TP|(Y+Fr> Date: Thu, 27 Oct 2022 02:28:38 +0800 Subject: [PATCH 02/22] Lighting shader kind of done (still has bugs) --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 3 +- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 12 +++-- .../MiddleEnd/Lights/SHLightingSubSystem.h | 2 +- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 1 - TempShaderFolder/DeferredCompositeCs.glsl | 47 +++++++++++++++--- TempShaderFolder/DeferredCompositeCs.spv | Bin 1716 -> 3384 bytes TempShaderFolder/TestCubeFs.glsl | 2 +- TempShaderFolder/TestCubeVs.glsl | 2 +- TempShaderFolder/TestCubeVs.spv | Bin 2684 -> 3036 bytes 9 files changed, 54 insertions(+), 15 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index dfa4e41e..58a86bcd 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -219,7 +219,7 @@ namespace SHADE // deferred composite auto deferredCompositeShader = shaderModuleLibrary.GetShaderModule("DeferredCompositeCs.glsl"); - gBufferNode->AddNodeCompute(deferredCompositeShader, { "Albedo", "Scene" }); + gBufferNode->AddNodeCompute(deferredCompositeShader, { "Position", "Normals", "Albedo", "Scene" }); auto dummyNode = worldRenderGraph->AddNode("Dummy Pass", { "Scene" }, {"G-Buffer"}); // no predecessors @@ -403,6 +403,7 @@ namespace SHADE // Force set the pipeline layout currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::GRAPHICS); + currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout(), SH_PIPELINE_TYPE::COMPUTE); // Bind all the buffers required for meshes for (auto& [buffer, bindingPoint] : MESH_DATA) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index a22fb662..6e8dd916 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -319,11 +319,12 @@ namespace SHADE { dynamicOffsets[i][0] = i * lightCountsAlignedSize; // Even if the first binding is a count, we want to account for that too - for (uint32_t j = 1; j < static_cast(dynamicOffsets.size()); ++j) + for (uint32_t j = 0; j < static_cast(SH_LIGHT_TYPE::NUM_TYPES); ++j) { auto const& typeData = perTypeData[j]; { - dynamicOffsets[i][j] = j * typeData.GetAlignmentSize(); + // +1 because 1st reserved for count + dynamicOffsets[i][j + 1] = i * typeData.GetAlignmentSize(); } } } @@ -376,6 +377,7 @@ namespace SHADE { dynamicOffsets[i].resize(NUM_LIGHT_TYPES + 1); // +1 for the count } + } /***************************************************************************/ @@ -425,7 +427,7 @@ namespace SHADE data.WriteToGPU(frameIndex); } - lightCountsBuffer->WriteToMemory(lightCountsData.data(), lightCountsData.size() * sizeof (uint32_t), 0, lightCountsAlignedSize * frameIndex); + lightCountsBuffer->WriteToMemory(lightCountsData.data(), static_cast(lightCountsData.size()) * sizeof (uint32_t), 0, lightCountsAlignedSize * frameIndex); // If any of the buffers got expanded, the descriptor set is invalid because the expanded buffer // is a new buffer. If some expansion was detected, update descriptor sets. @@ -442,8 +444,10 @@ namespace SHADE // so we do it anyway. #NoteToSelf: if at any point it affects performance, do a check before computing. ComputeDynamicOffsets(); + //cmdBuffer->ForceSetPipelineLayout() + // Bind descriptor set (We bind at an offset because the buffer holds NUM_FRAME_BUFFERS sets of data). - cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, {dynamicOffsets[frameIndex]}); + cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, {dynamicOffsets[frameIndex]}); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index 6c974730..efc6ddf6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -31,7 +31,7 @@ namespace SHADE uint32_t cullingMask; //! Diffuse color emitted by the light - SHVec4 diffuseColor; + alignas (16) SHVec4 diffuseColor; }; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index a5208fcf..678fc41b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -53,7 +53,6 @@ namespace SHADE descSetGroups[i] = graphStorage->descriptorPool->Allocate(layouts, variableCounts); } - HandleResize(); } diff --git a/TempShaderFolder/DeferredCompositeCs.glsl b/TempShaderFolder/DeferredCompositeCs.glsl index 354a8954..c5e543db 100644 --- a/TempShaderFolder/DeferredCompositeCs.glsl +++ b/TempShaderFolder/DeferredCompositeCs.glsl @@ -9,22 +9,57 @@ struct DirectionalLightStruct }; layout(local_size_x = 16, local_size_y = 16) in; -layout(set = 4, binding = 0, rgba8) uniform image2D inputImage; -layout(set = 4, binding = 1, rgba8) uniform image2D targetImage; +layout(set = 4, binding = 0, rgba8) uniform image2D positions; +layout(set = 4, binding = 1, rgba8) uniform image2D normals; +layout(set = 4, binding = 2, rgba8) uniform image2D albedo; +layout(set = 4, binding = 3, rgba8) uniform image2D targetImage; -layout(set = 1, binding = 0) buffer DirectionalLightData +layout(set = 1, binding = 0) uniform LightCounts +{ + uint directionalLights; + uint pointLights; + uint spotLights; + +} lightCounts; + +layout(std430, set = 1, binding = 1) buffer DirectionalLightData { DirectionalLightStruct dLightData[]; } DirLightData; void main() -{ +{ // convenient variables ivec2 globalThread = ivec2(gl_GlobalInvocationID); - vec3 color = imageLoad (inputImage, globalThread).rgb; + // Get the diffuse color of the pixel + vec3 pixelDiffuse = imageLoad (albedo, globalThread).rgb; + + // Get position of fragment in world space + vec3 positionWorld = imageLoad (positions, globalThread).rgb; + + // normal of fragment + vec3 normalWorld = imageLoad(normals, globalThread).rgb; + normalWorld = normalize (normalWorld); + + vec3 fragColor = vec3 (0.0f); + + for (int i = 0; i < lightCounts.directionalLights; ++i) + { + // get normalized direction of light + vec3 dLightNormalized = vec3 (0.0f, 0.0f, 1.0f); + //vec3 dLightNormalized = normalize (DirLightData.dLightData[i].direction); + + // Get diffuse strength + float diffuseStrength = max (0, dot (dLightNormalized, normalWorld)); + + //fragColor += vec3 (1.0f) * diffuseStrength.rrr * pixelDiffuse; + fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse; + //fragColor += vec3 (dLightNormalized.rgb); + } // store result into result image - imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(color, 1.0f)); + //imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor, 1.0f)); + imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(normalWorld, 1.0f)); } \ No newline at end of file diff --git a/TempShaderFolder/DeferredCompositeCs.spv b/TempShaderFolder/DeferredCompositeCs.spv index 679dc135f5f556eb95565c51c1c9f1c2aca8821a..ffd0343f71e1704bba6f534f17d842cba15ac6cf 100644 GIT binary patch literal 3384 zcmZ9O`*Ku85XL8$O#(>>2qAbOZio^UjHuicxx_3k(S-zp;(a;UJ=q*NIcID4gi^~t z@DJa>2k{wvC`zre%I|k}I!@Fk2i{s7>xx;SSZ5l7re8A!~GVk(lO!fupgIHrZ8;^B^!IyP0Dc8(~!bAQShRn>Z< zSzlkTH*Pmu-EOmA{FKJcG|A#-JL$!(B6%7UHxa}oSu5RZhXEBug!L<`eMmJrX}%Su z4|jTT)Rw6}C(7PBX|rCs*0QI0D=LyaTdS4+F*hgKO@55iTC%;p*H?A+jk=d4qjW27 z>ypS{mEFzz37a3~y_5nK{aXn5zUR(LW_fQnN(YhTTiWOP<-TRv+r6l>nx}cM+&ALh zlT1pz;;unzlxM;<#McJn+wVyMd#z&77k<`$ z-_q#|o_>@5il6-dJpH!zQaz2%-KhUW(c@)2FVXj4S6B9MPyE3iYEco1E^Fau4bC?3 zFxL%n+E<>~;+ZQOi>TL$i?!XT6YK1wqgAIzCL?4vF=by)1T`Gj?BHgHoxoYmp; zZF@(g6IT_;e^+u$;LC#;yL-z|e{k$0o*9JwVbh=W8+pIoGd6zPpGjvfFAB$XYI^^$OV7R+k6jN{u$}yC;p`V zo{+2xMUB&v)F9sc3({F;FAYq0 zPEo|Zw&vCt=r~Z;+vPw`@?4cx+J~8(H}N% z5YEo{K)TIq)BDJ4{-*RH!R|Ja&SDlVNqVt-=&5j2U_bV*z<$ojo8nCq1Mpqe-Lju~ zvgqY6G5i)&llRMSAoqaHo8q@Ew5tc~vj^sr%du(uw2j8;Yaeae-KTH*`|Y1xFp;`^y4v9h-Q*kBQmRer7T+ z5Cgxio8c|ID!>C4^|(*+b5Hm!{~75E-X{N|5axePHZky)|8?o`fEDJi%EoW`-;loK zZSubv;igO1F;vwm>|e9ekV_KRh~fzu&N+WqUcMVX6^MbK(#wJSOyF*~Z@yQE zA$MI8pPlQzbk4P+eVdXGg$;po;Cmnt%lrFWz;Cnr!gKH}n;r4=@JOKEhM(7$o`VO! zssCBYuLN@8w=;e%eNM2LZ=@3kZ!zCWXU4z!Jl{!&Bi7~*$4swCa>q#aGt=({&i+jM zu^$U?O@aOR9t+`{VOH!vCAlR;-ky|f3w%$k>n>Z8vFG4f+z;=E&&IZZ-_FvJ&P@4E s;qG<>IF@mVbU5-D_k-t#B{!6rIXw~BPdxsb&{AFcr7r$|mF24NAM&9b*#H0l delta 778 zcmYjP%Sr=55bS*<@wK3+1S6XD{fdbi4}wT8N(?9}=*iQPgmp0{5;r#?{(z_X5>dg6 z|KQbwpCVYbnUzc^db+Bor+Ts`?jP-q}pn<+K37KGKfL* zz7tmNJip%KTyUY+_UoEV$bb~om6@F?K;fzd?Rqr~T21Ve_!ZQ%nT}KwOtsT!1Wo_c zd$@&`g8FGr8{6s|9kzKKt9BCjH{qcddb~3!MKxxPt34~%rCJtST*P_6?#t(}H*}sy z90sOEq~<+-M(X^*D8H4_3CYPXdhW6T6Okm&J-Wo}t$wBE81m znA5Ag{@7Wg>vD^gMk&jN09x2UK7qIbh&+{;Q_BIg7U!GTvvm%pI5J0P4MA-dJjb5| zc%GPvU~z;h$U69Q&Z|C@NgnB(0vKHRsv@*nkJ9^Zly0 Oh=zGF^PpcWd0L&ED1CCW3$Y z74#$dsr<((pWp0uxMEUW-Tm~_Gd(@MSEra>Y93W`#I+%+-T#wYS?V zlYF>xUPP$4U!g*PLtg2+s$0_zv$qC6B$wkQ}$p@0pBpZ^RWGJcVZ&vyrZB$iO ztKDyPI<5BI{$M=rPx5C;)KB6x>JQ^A8szbT3aq*#Q@l7GB>Tf@LQRb6T53Auh|XZu z-Q1zQ=kq9weX^Afqo*Op&UC`LC>|bisV|9lf6LqcS(FuQ&ft!n{rs|&t7%{EyPNd4 z(n;>qL1f!1RttTI(>&UZvUQ((Ar-eoqE=m=*#}XUcSjRp)qqjU{=st&wWOnL&nKK& z3B6Sfvg@J8zmKwH*vou6`Bf}9wa|CJqm84dY#s7=2mfeCb~U_*e^6}7KHn&&dvv3$ zNRlhGz_E#qCUG8*QlWE!Pn`kRCAZ^0!WdbMniX41;_-T1^yV;+DI&I?B!@BX#eA@+ z|B>{X--|LIS{G^oV~wp4+4K>dS`NndeJ)M@x6*^Dd@yFu_k6k=rO;ffe9r~h)P&D_ z9+NDW{uycF%m{Jj8lQ#FjN>zV_{{rsoSx%TA920|eEPGgn&>-=Gg*eg2SXc14j8o> zh7DGnUkUr!-qx=r#aWwTS+8orf8IMdue^Zi2O?lCok$-0atC_5_=4Y*&mvBrxg)im zRu*|pdHC38#i>g-B-{_5v+!99>I?mb175_c?j_mmLF|Td@cACWmdib@j}7_9g|k2V zz{lr(!HDwy0>L>9x>|0XMVxX%YR22E_+h% zyV5ffaQOJlHyCHWFWr!k4}V#j7&v@<<{ymvG^AG~&i#2C{uNo|HYNDiq~TIC`S^S< zV8lO{hEJS&Z%K0&n4PyF+xS~$tRZdvd?1@1T~Pi*=|-^WS@GM}EHPq5yy~`Pa|Yig z=iv8BY(YNX0(ta_I(MWw0~|g+-v}7-$E9t3rB6f2jO3c$4jym7;@p3Q@O|DCT9-a4 zVQyE2GP8WA%ssPyOBwiZh|f!(lQ5UeB6~1z=Oy59n8Vj4?7_UV2Rw6OB2cLKQP{MpXR1FR3k0f9$!}v!7jNTabNr};?u5Qzm zzAPahK5^#kFYQb0Qwe9op;qSZs)X6Mp5eozwngdd5@ruRbN7V=zV!zmj@|8sZ0>ek zFT`EHlu$E!5$lybxG9?$ccHf15-?Urzhv~~jszTGu@85(oK@N6fLqR2vcVA+vFV&O z`Q(6E&bn-Hgk?Eh-GOiGuH=q{z2VxswPbHd=r8qdO5lR8Dwpr>YYF{g7MMF~Z%E&h zz-KWd@W3puE!*;#HOsp%n>=bH4<4B1b!1x}-?-&c>n37>yrNgtsCHs delta 934 zcmZ8fO-lk%6ut8tlZt`FAj%Leis)3rYB^0SD9J(gA06accp`#}x6kq+r(p)>F^? zJdi=(1#LwpVB Date: Thu, 27 Oct 2022 02:46:38 +0800 Subject: [PATCH 03/22] Working abit more now. Error with device extension thingy. --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 4 ++-- TempShaderFolder/DeferredCompositeCs.glsl | 6 +++--- TempShaderFolder/DeferredCompositeCs.spv | Bin 3384 -> 3332 bytes TempShaderFolder/TestCubeVs.glsl | 3 ++- TempShaderFolder/TestCubeVs.spv | Bin 3036 -> 3296 bytes 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 58a86bcd..df884f57 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -181,8 +181,8 @@ namespace SHADE // Initialize world render graph worldRenderGraph->Init(device, swapchain); - worldRenderGraph->AddResource("Position", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); - worldRenderGraph->AddResource("Normals", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); + worldRenderGraph->AddResource("Position", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); + worldRenderGraph->AddResource("Normals", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); worldRenderGraph->AddResource("Albedo", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); worldRenderGraph->AddResource("Depth Buffer", { SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); worldRenderGraph->AddResource("Entity ID", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); diff --git a/TempShaderFolder/DeferredCompositeCs.glsl b/TempShaderFolder/DeferredCompositeCs.glsl index c5e543db..c0e42cea 100644 --- a/TempShaderFolder/DeferredCompositeCs.glsl +++ b/TempShaderFolder/DeferredCompositeCs.glsl @@ -40,7 +40,7 @@ void main() // normal of fragment vec3 normalWorld = imageLoad(normals, globalThread).rgb; - normalWorld = normalize (normalWorld); + //normalWorld = normalize (normalWorld); vec3 fragColor = vec3 (0.0f); @@ -59,7 +59,7 @@ void main() } // store result into result image - //imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor, 1.0f)); - imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(normalWorld, 1.0f)); + imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor, 1.0f)); + //imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(normalWorld, 1.0f)); } \ No newline at end of file diff --git a/TempShaderFolder/DeferredCompositeCs.spv b/TempShaderFolder/DeferredCompositeCs.spv index ffd0343f71e1704bba6f534f17d842cba15ac6cf..a87b7548fb45981226d5a85fa1e4c3f4cf88dbd4 100644 GIT binary patch literal 3332 zcmZ9OZF5sq5XVoOCM|`6$fFO`lqyxJ^{GV^0Yi(S7-(uyd=9tCZF=Q4Hi7a* z_znCZeg;33qs}-sy3c-Tm*L-95W|Q%mFXlg^E~X*c8c+~}Ni<3gM}>MEYs z8(WQ~VcuC_TBX&1GKkxG@+8J@s^FLO+Ub6$=unnNF@IUPk0?hs&9ucU#ap%PQ$q#Y5mh9~850#yJ6YhEODBX@b z8G6N4rT4R8!sUnAASFRr|IHQfVZbhl_p-rWl#V=!w{UqV(|A#X+hafhDwv!s^?i{Z>**v}01HCz*x z7IKu`q^k+*_`CQ03zDDW(94RujcwGXt$Yyoy7{i+Ou4(l*GA(zs7Vg{?R-=hcFsZF zlBo-vdXr%-O#XkIdfWS{R-=0_8a|fyr1xhNLk-qCUqeIq;TqPWJQD14VdsqAHnK3+ z`@(e3zu5elYfE?@4Z3l@z87_4SJw>L^P{2{Md<9vMbSh-pOZ}O*pZ8NbclnUohaJT zv5$%Fs0QZAnIEwO3_BQk&5xX5Q=+=QIqq5=%$YpgBQH96INZ1S6!X|@z>XFCEDzte z-7QJRuPP$`C*l=ZkV4}|TCddq$0 z$)T3Ngz&eRoa`@u1L*@gJH_9&qFz0uUpk~O7Ify!_glPQE9mr`zX#Z_D<3r<7tM%% zmd^h3KCn$y$)4E%8%R9Bo|TLrZ*R(vc&9}8V!NT2@-8s)u@V+~QxB3=VOM@tGrb-ogy|ZjqTE-{#+X={w@=3;a*@ZCQLp#KC?= z96Ovknb&(FVldBX@v8x=sn2|~*F}8C>2qAbOZio^UjHuicxx_3k(S-zp;(a;UJ=q*NIcID4gi^~t z@DJa>2k{wvC`zre%I|k}I!@Fk2i{s7>xx;SSZ5l7re8A!~GVk(lO!fupgIHrZ8;^B^!IyP0Dc8(~!bAQShRn>Z< zSzlkTH*Pmu-EOmA{FKJcG|A#-JL$!(B6%7UHxa}oSu5RZhXEBug!L<`eMmJrX}%Su z4|jTT)Rw6}C(7PBX|rCs*0QI0D=LyaTdS4+F*hgKO@55iTC%;p*H?A+jk=d4qjW27 z>ypS{mEFzz37a3~y_5nK{aXn5zUR(LW_fQnN(YhTTiWOP<-TRv+r6l>nx}cM+&ALh zlT1pz;;unzlxM;<#McJn+wVyMd#z&77k<`$ z-_q#|o_>@5il6-dJpH!zQaz2%-KhUW(c@)2FVXj4S6B9MPyE3iYEco1E^Fau4bC?3 zFxL%n+E<>~;+ZQOi>TL$i?!XT6YK1wqgAIzCL?4vF=by)1T`Gj?BHgHoxoYmp; zZF@(g6IT_;e^+u$;LC#;yL-z|e{k$0o*9JwVbh=W8+pIoGd6zPpGjvfFAB$XYI^^$OV7R+k6jN{u$}yC;p`V zo{+2xMUB&v)F9sc3({F;FAYq0 zPEo|Zw&vCt=r~Z;+vPw`@?4cx+J~8(H}N% z5YEo{K)TIq)BDJ4{-*RH!R|Ja&SDlVNqVt-=&5j2U_bV*z<$ojo8nCq1Mpqe-Lju~ zvgqY6G5i)&llRMSAoqaHo8q@Ew5tc~vj^sr%du(uw2j8;Yaeae-KTH*`|Y1xFp;`^y4v9h-Q*kBQmRer7T+ z5Cgxio8c|ID!>C4^|(*+b5Hm!{~75E-X{N|5axePHZky)|8?o`fEDJi%EoW`-;loK zZSubv;igO1F;vwm>|e9ekV_KRh~fzu&N+WqUcMVX6^MbK(#wJSOyF*~Z@yQE zA$MI8pPlQzbk4P+eVdXGg$;po;Cmnt%lrFWz;Cnr!gKH}n;r4=@JOKEhM(7$o`VO! zssCBYuLN@8w=;e%eNM2LZ=@3kZ!zCWXU4z!Jl{!&Bi7~*$4swCa>q#aGt=({&i+jM zu^$U?O@aOR9t+`{VOH!vCAlR;-ky|f3w%$k>n>Z8vFG4f+z;=E&&IZZ-_FvJ&P@4E s;qG<>IF@mVbU5-D_k-t#B{!6rIXw~BPdxsb&{AFcr7r$|mF24NAM&9b*#H0l diff --git a/TempShaderFolder/TestCubeVs.glsl b/TempShaderFolder/TestCubeVs.glsl index dc8f0b98..49f107dd 100644 --- a/TempShaderFolder/TestCubeVs.glsl +++ b/TempShaderFolder/TestCubeVs.glsl @@ -44,6 +44,7 @@ void main() Out.vertPos = worldTransform * vec4(aVertexPos, 1.0f); Out.uv = aUV; - Out.normal.rgb = mat3 (transpose (inverse (worldTransform))) * aNormal.rgb; + Out.normal.rgb = mat3(transpose(inverse(worldTransform))) * aNormal.rgb; + Out.normal.rgb = normalize (Out.normal.rgb); gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); } \ No newline at end of file diff --git a/TempShaderFolder/TestCubeVs.spv b/TempShaderFolder/TestCubeVs.spv index 0dfd6cf270dcc59b66eab56b32b571b5f96caa4c..d8c3c3d072f76728073803b4f4baa5c981426184 100644 GIT binary patch delta 966 zcmZ9L&rVZO5XR@8{v*X2Nf!;2kSfvm4_7Ws3?y9`a6zOhYPGdq|4^%VO9CNb)$j;- z7OZ&$!V~x&F7zQ>n)v@quQ|a+RT#E zgX1Xb`5D)k?J35F+k=hq?r3i`PONMd>-n~8O4Coj4_vcGC05dB;7?qAX^;`N6ABfV z$;wB<{?2;5Cr?G}f4X{<_+QT72+y2W4qH?W@iwuE_MLHjcs zvX($D%NMP$GkcJ~uX1AU6mB7(nYwF2OYs|dW??4u#IXQJ{%v-?m=++oB_cUHtn3!z zyE=A+t3p#)R+`?A1^7ocWjE!Y93T#Dt zY|6t0)pMQ01l&$XZ>uH$LI|CyLkAb?y8c_WF?pG*m!oLzTAK$%x=r)vqeCTMY>5g^j4ARFMtfsdv&EAhV;U zKUBhS^{3LC;WHPZF^bU1v49gR~de2#NDi*pN@QA1u6S@}a`K{9A?XLW0$MrD)^unJ`G{@jf=2cQ<{mYm|u_n>}= zcGkR8a+&$g>{|yM)aS_Dg*(yDnmduBei59P{017fLAbN$Sl=8`y9DTu14ocK_X;2% z*4H?1057;l>NfyA Date: Thu, 27 Oct 2022 11:31:11 +0800 Subject: [PATCH 04/22] Some lighting fixes --- .../Graphics/Devices/SHVkLogicalDevice.cpp | 5 +++-- TempShaderFolder/DeferredCompositeCs.glsl | 12 ++++-------- TempShaderFolder/DeferredCompositeCs.spv | Bin 3332 -> 3460 bytes TempShaderFolder/TestCubeFs.glsl | 2 -- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index a6b415a9..6bf2e731 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -186,9 +186,10 @@ namespace SHADE vk::PhysicalDeviceFeatures features{}; // ADD MORE FEATURES HERE IF NEEDED // point and lines fill mode - features.fillModeNonSolid = true; + features.fillModeNonSolid = VK_TRUE; features.samplerAnisotropy = VK_TRUE; - features.multiDrawIndirect = true; + features.multiDrawIndirect = VK_TRUE; + features.independentBlend = VK_TRUE; // for wide lines features.wideLines = true; diff --git a/TempShaderFolder/DeferredCompositeCs.glsl b/TempShaderFolder/DeferredCompositeCs.glsl index c0e42cea..c707901f 100644 --- a/TempShaderFolder/DeferredCompositeCs.glsl +++ b/TempShaderFolder/DeferredCompositeCs.glsl @@ -9,8 +9,8 @@ struct DirectionalLightStruct }; layout(local_size_x = 16, local_size_y = 16) in; -layout(set = 4, binding = 0, rgba8) uniform image2D positions; -layout(set = 4, binding = 1, rgba8) uniform image2D normals; +layout(set = 4, binding = 0, rgba32f) uniform image2D positions; +layout(set = 4, binding = 1, rgba32f) uniform image2D normals; layout(set = 4, binding = 2, rgba8) uniform image2D albedo; layout(set = 4, binding = 3, rgba8) uniform image2D targetImage; @@ -40,26 +40,22 @@ void main() // normal of fragment vec3 normalWorld = imageLoad(normals, globalThread).rgb; - //normalWorld = normalize (normalWorld); vec3 fragColor = vec3 (0.0f); for (int i = 0; i < lightCounts.directionalLights; ++i) { // get normalized direction of light - vec3 dLightNormalized = vec3 (0.0f, 0.0f, 1.0f); - //vec3 dLightNormalized = normalize (DirLightData.dLightData[i].direction); + vec3 dLightNormalized = normalize (DirLightData.dLightData[i].direction); // Get diffuse strength float diffuseStrength = max (0, dot (dLightNormalized, normalWorld)); - //fragColor += vec3 (1.0f) * diffuseStrength.rrr * pixelDiffuse; + // Calculate the fragment color fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse; - //fragColor += vec3 (dLightNormalized.rgb); } // store result into result image imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor, 1.0f)); - //imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(normalWorld, 1.0f)); } \ No newline at end of file diff --git a/TempShaderFolder/DeferredCompositeCs.spv b/TempShaderFolder/DeferredCompositeCs.spv index a87b7548fb45981226d5a85fa1e4c3f4cf88dbd4..455ab5483f63c9c8c37d786c435e1d7ca6138b50 100644 GIT binary patch literal 3460 zcmZvd>2e!I5XZ-de8hH)$;lBT#~cX>CO{GbA&0Sp;-Ewh&cQ9#(pp};-WAe11r#5` z2i|}O;Td=+3aFxr|8F#Hwp>iA)7}5>>0`QA9vNO7cW%fXax<>)24~I<3vq7Bjd@#?3Uz;$}PP#jPTF65}^f@=LN-y4Nl{ROC_4Us3K!<>;jOW|ThI z?!{4Cs_LBZwRO^F&70P;CwVI>k~~{m_4YA$LcE)NAE&Fy*4AEM*||6Bo)?eO&A6ST zkGZP!Zr)G0{5bEWB&g`$VhQIx!OnJjkveP z6E9cXRq=Y#*)CS{y{zb~f(efacHyb=EK0o#dB^mRJG^-}PqHFd3}*)YZf>xz;hM0t zl%wLt-HNcbzkAPjko*|$za?+BIvCS_?v0|i*D412v2*t8lT3ba>Pq^{VZ#66)YaNc zwE~^HQGZ9?*035Ckzk(-J7>_tz{31)3)4N{nfZe^@Ezn) zD{*~3VB|H7oM028n!Y*iS{=-pJlrEMI(azUXFi;A9x%%@E!q4m58t<8 zBjIjUocOoI$3*;i;A1nf_|yl+J^YzXxjuC2vwGXXPQUo0W4HT!Kg{Jh(Ghh`jSI43 zM?R)I)Ke7^^MrK$2zm^ARXXnm2H}6mSm0NK&VE?@S;^$Y|G54? zDqa;4>zFvY#X2r|ke41N-N|4lR{2mXZ$N%}<={(xboP-$j#J{~z@L~4LI1y)V8lEv z&cTZNWbPalx-34g$gASiVX=6JQ+jE365G6Fb`PC6HF08skq4dqvpjc#OicXm ziPHO?$KG^DvU5*wpkwQb_})zaPBQU$ zbM}w@#|Of8S#L@_X3wFvKZR7psexUe6wwDd`^VqGvR*x)pE;oO_sjg5FMqpCC*Dd) z=gk^HzovZDd|1Ty@{{ygary(huPWJ(xqyl7W6uVR-q+82W^V^NjrtUMNc@aL~4ZRF=en|ulamdGe5}$X%PP_&2mqmOd7XKB=<@m1#A8?ER znq+W@Q;uJij@{zFF8OTGssEg)9RIv@e84UK8hz*G z`vU(%eO?xSSH!`7MI1YvI+@pdB4RL4cJ}>%E$f~6R&R*-e#yZdd~S-sf0NI$_=h6y z-4y*TAM{Hi@{ya~Sn*mw)}6`c6^ ztc$=*zb~1$`&G5_?SCS|2YgyJfNh9~iyyy#_z;`j$7Z!ZkZiR-lKfa?wPSlI!k7L0 zRD|7T`&q!iIW}ATso`@G`PM_PUjz&s`bG8A- zX0Ro`9WZbX@54^=?Ia@X*2}k&>4o1M-Yyk^aSYp)3`QKovVaYXuPZWh%0=AAAN!7| PrM%QjUhMxU$`#SSUL_#7 literal 3332 zcmZ9OZF5sq5XVoOCM|`6$fFO`lqyxJ^{GV^0Yi(S7-(uyd=9tCZF=Q4Hi7a* z_znCZeg;33qs}-sy3c-Tm*L-95W|Q%mFXlg^E~X*c8c+~}Ni<3gM}>MEYs z8(WQ~VcuC_TBX&1GKkxG@+8J@s^FLO+Ub6$=unnNF@IUPk0?hs&9ucU#ap%PQ$q#Y5mh9~850#yJ6YhEODBX@b z8G6N4rT4R8!sUnAASFRr|IHQfVZbhl_p-rWl#V=!w{UqV(|A#X+hafhDwv!s^?i{Z>**v}01HCz*x z7IKu`q^k+*_`CQ03zDDW(94RujcwGXt$Yyoy7{i+Ou4(l*GA(zs7Vg{?R-=hcFsZF zlBo-vdXr%-O#XkIdfWS{R-=0_8a|fyr1xhNLk-qCUqeIq;TqPWJQD14VdsqAHnK3+ z`@(e3zu5elYfE?@4Z3l@z87_4SJw>L^P{2{Md<9vMbSh-pOZ}O*pZ8NbclnUohaJT zv5$%Fs0QZAnIEwO3_BQk&5xX5Q=+=QIqq5=%$YpgBQH96INZ1S6!X|@z>XFCEDzte z-7QJRuPP$`C*l=ZkV4}|TCddq$0 z$)T3Ngz&eRoa`@u1L*@gJH_9&qFz0uUpk~O7Ify!_glPQE9mr`zX#Z_D<3r<7tM%% zmd^h3KCn$y$)4E%8%R9Bo|TLrZ*R(vc&9}8V!NT2@-8s)u@V+~QxB3=VOM@tGrb-ogy|ZjqTE-{#+X={w@=3;a*@ZCQLp#KC?= z96Ovknb&(FVldBX@v8x=sn2|~*F}8C Date: Thu, 27 Oct 2022 19:02:55 +0800 Subject: [PATCH 05/22] Ambient lighting added --- SHADE_Application/src/Scenes/SBTestScene.cpp | 10 +++++++ .../MiddleEnd/Lights/SHLightComponent.cpp | 15 ++++++++-- .../MiddleEnd/Lights/SHLightComponent.h | 4 ++- .../Graphics/MiddleEnd/Lights/SHLightData.cpp | 2 +- .../Graphics/MiddleEnd/Lights/SHLightData.h | 6 +++- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 26 ++++++++++++++---- .../MiddleEnd/Lights/SHLightingSubSystem.h | 20 ++++++++++++++ TempShaderFolder/DeferredCompositeCs.glsl | 21 ++++++++++++++ TempShaderFolder/DeferredCompositeCs.spv | Bin 3460 -> 4532 bytes 9 files changed, 94 insertions(+), 10 deletions(-) diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index a06e68c2..eb6149ad 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -162,12 +162,22 @@ namespace Sandbox SHComponentManager::AddComponent(0); SHComponentManager::RemoveComponent (0); SHComponentManager::RemoveComponent (0); + + auto ambientLight = SHEntityManager::CreateEntity(); + SHComponentManager::GetComponent(ambientLight)->SetColor(SHVec4(1.0f, 1.0f, 1.0f, 1.0f)); + SHComponentManager::GetComponent(ambientLight)->SetStrength(0.25f); + SHComponentManager::GetComponent(ambientLight)->SetType(SH_LIGHT_TYPE::AMBIENT); } void SBTestScene::Update(float dt) { static float rotation = 0.0f; + SHVec3 direction{0.0f, 0.0f, 1.0f}; + direction = SHVec3::RotateY(direction, rotation); + auto* lightComp =SHComponentManager::GetComponent(0); + lightComp->SetDirection (direction); + rotation += 0.005f; //auto& transform = *SHADE::SHComponentManager::GetComponent_s(testObj); //transform.SetWorldPosition({1.0f, 1.0f, -1.0f}); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index fd122334..6800e955 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -41,9 +41,9 @@ namespace SHADE } - void SHLightComponent::SetDiffuseColor(SHVec4 diffuseColor) noexcept + void SHLightComponent::SetColor(SHVec4 color) noexcept { - lightData.diffuseColor = diffuseColor; + lightData.color = color; MakeDirty(); } @@ -100,6 +100,12 @@ namespace SHADE } + void SHLightComponent::SetStrength(float value) noexcept + { + lightData.strength = value; + MakeDirty(); + } + SHLightData const& SHLightComponent::GetLightData(void) const noexcept { return lightData; @@ -115,6 +121,11 @@ namespace SHADE return bound; } + bool SHLightComponent::GetActive(void) const noexcept + { + return active; + } + uint32_t SHLightComponent::GetIndexInBuffer(void) const noexcept { return indexInBuffer; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index 20ae3892..d267d2d4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -40,7 +40,7 @@ namespace SHADE void SetPosition (SHVec3 position) noexcept; void SetType (SH_LIGHT_TYPE type) noexcept; void SetDirection (SHVec3 direction) noexcept; - void SetDiffuseColor (SHVec4 diffuseColor) noexcept; + void SetColor (SHVec4 color) noexcept; void ModifyLayer (uint8_t layerIndex, bool value) noexcept; void SetAllLayers (void) noexcept; void ClearAllLayers (void) noexcept; @@ -49,11 +49,13 @@ namespace SHADE void Unbind (void) noexcept; void SetBound (uint32_t inIndexInBuffer) noexcept; void SetActive (bool flag) noexcept; + void SetStrength (float value) noexcept; SHLightData const& GetLightData (void) const noexcept; bool IsDirty (void) const noexcept; bool GetBound (void) const noexcept; + bool GetActive (void) const noexcept; uint32_t GetIndexInBuffer (void) const noexcept; }; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.cpp index ba910408..8e8f0783 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.cpp @@ -15,7 +15,7 @@ namespace SHADE direction = SHVec3::Forward; // Diffuse color set to 1 - diffuseColor = SHVec4::One; + color = SHVec4::One; } } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h index 607978a4..fccc2856 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h @@ -10,6 +10,7 @@ namespace SHADE DIRECTIONAL = 0, POINT, SPOT, + AMBIENT, NUM_TYPES }; @@ -40,7 +41,10 @@ namespace SHADE uint32_t cullingMask; //! Diffuse color emitted by the light - SHVec4 diffuseColor; + SHVec4 color; + + //! Strength of the light + float strength; void Reset (void) noexcept; //! TODO: diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 6e8dd916..97d8b24f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -42,13 +42,23 @@ namespace SHADE lightPtr->cullingMask = lightData.cullingMask; lightPtr->direction = lightData.direction; - lightPtr->diffuseColor = lightData.diffuseColor; + lightPtr->diffuseColor = lightData.color; + lightPtr->active = lightComp->GetActive(); break; } case SH_LIGHT_TYPE::POINT: break; case SH_LIGHT_TYPE::SPOT: break; + case SH_LIGHT_TYPE::AMBIENT: + { + SHAmbientLightData* lightPtr = reinterpret_cast(address); + lightPtr->ambientColor = lightData.color; + lightPtr->strength = lightData.strength; + lightPtr->cullingMask = lightData.cullingMask; + lightPtr->active = lightComp->GetActive (); + break; + } case SH_LIGHT_TYPE::NUM_TYPES: break; default: @@ -176,6 +186,9 @@ namespace SHADE case SH_LIGHT_TYPE::SPOT: // TOOD: Change after creating spot light struct return 4; + case SH_LIGHT_TYPE::AMBIENT: + return sizeof(SHAmbientLightData); + return 4; case SH_LIGHT_TYPE::NUM_TYPES: default: return 4; @@ -406,8 +419,8 @@ namespace SHADE { perTypeData[enumValue].AddLight(logicalDevice, &light, expanded); - // add to light count - ++lightCountsData[enumValue]; + //// add to light count + //++lightCountsData[enumValue]; } // if there was modification to the light data @@ -427,6 +440,11 @@ namespace SHADE data.WriteToGPU(frameIndex); } + for (uint32_t i = 0; i < NUM_LIGHT_TYPES; ++i) + { + lightCountsData[i] = perTypeData[i].GetNumLights(); + } + lightCountsBuffer->WriteToMemory(lightCountsData.data(), static_cast(lightCountsData.size()) * sizeof (uint32_t), 0, lightCountsAlignedSize * frameIndex); // If any of the buffers got expanded, the descriptor set is invalid because the expanded buffer @@ -444,8 +462,6 @@ namespace SHADE // so we do it anyway. #NoteToSelf: if at any point it affects performance, do a check before computing. ComputeDynamicOffsets(); - //cmdBuffer->ForceSetPipelineLayout() - // Bind descriptor set (We bind at an offset because the buffer holds NUM_FRAME_BUFFERS sets of data). cmdBuffer->BindDescriptorSet(lightingDataDescSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::DYNAMIC_GLOBALS, {dynamicOffsets[frameIndex]}); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index efc6ddf6..dfb956ec 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -35,6 +35,26 @@ namespace SHADE }; + // Represents how the data will be interpreted in GPU. we want to copy to a container of these before passing to GPU. + struct SHAmbientLightData + { + //! Diffuse color emitted by the light + SHVec4 ambientColor; + + //! Strength of the ambient light + float strength; + + //! Represents if the light is active or not + uint32_t active; + + //! Each bit in this 32 bit field will represent a layer. If the bit is set, + //! when a fragment is being evaluated, the shader will use the fragment's + //! layer value to AND with the light's. If result is 1, do lighting calculations. + uint32_t cullingMask; + + + }; + class SH_API SHLightingSubSystem { private: diff --git a/TempShaderFolder/DeferredCompositeCs.glsl b/TempShaderFolder/DeferredCompositeCs.glsl index c707901f..bd482b1a 100644 --- a/TempShaderFolder/DeferredCompositeCs.glsl +++ b/TempShaderFolder/DeferredCompositeCs.glsl @@ -8,6 +8,14 @@ struct DirectionalLightStruct vec4 diffuseColor; }; +struct AmbientLightStruct +{ + vec4 ambientColor; + float strength; + uint isActive; + uint cullingMask; +}; + layout(local_size_x = 16, local_size_y = 16) in; layout(set = 4, binding = 0, rgba32f) uniform image2D positions; layout(set = 4, binding = 1, rgba32f) uniform image2D normals; @@ -19,6 +27,7 @@ layout(set = 1, binding = 0) uniform LightCounts uint directionalLights; uint pointLights; uint spotLights; + uint ambientLights; } lightCounts; @@ -27,6 +36,11 @@ layout(std430, set = 1, binding = 1) buffer DirectionalLightData DirectionalLightStruct dLightData[]; } DirLightData; +layout(std430, set = 1, binding = 4) buffer AmbientLightData +{ + AmbientLightStruct aLightData[]; +} AmbLightData; + void main() { // convenient variables @@ -55,6 +69,13 @@ void main() fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse; } + for (int i = 0; i < lightCounts.ambientLights; ++i) + { + // Just do some add + //fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (0.5f); + fragColor += pixelDiffuse.rgb * AmbLightData.aLightData[i].ambientColor.rgb * vec3 (AmbLightData.aLightData[i].strength); + } + // store result into result image imageStore(targetImage, ivec2(gl_GlobalInvocationID.xy), vec4(fragColor, 1.0f)); diff --git a/TempShaderFolder/DeferredCompositeCs.spv b/TempShaderFolder/DeferredCompositeCs.spv index 455ab5483f63c9c8c37d786c435e1d7ca6138b50..4ec7ac0f659951dcc4c1a5dcbdfd79bf13eaee50 100644 GIT binary patch delta 1472 zcmYk5%W6|m6oz;1Z8V^u)C(=qj6@N{iBQrK6zf1~MRepOO=FriO*A>FR$EW1X}#22 z8yq?C6_hv=pTUt2(2;K-UJ(4hlfC7f@U!;%*V=3Sd#|1D(NDQdESgIh6ESI%F};tO zKanFzlQQGRn3zypnyr@W-sNg#-fNkDGMbI}F*Bz~RY)lFwrnAkb}^ux3?Sn>chGN!SXqdgTUV0 z5&4_4^ih8AU1~VLMZk0>PbvogM&K@;zpZsdI3=xnWOoE|z;BP!n3$guHM)umj;s z1Ku|ulvI#Y7uZPPw+i9k5)eQ`)-*gQ+Ym;qkASv-fP(%?H)NLuZka<7!?Ksj-4%#W zn<3Tmjk#w@0(@K_nJqTWNx!LOmL- z;Lo=qbgj>WdLm?mX{H9Z^KpB;gOuzufw()&bFC44RbsfA7e>zwlFyMZwT7dR h<6c=VDm$an%<;9L0)~9zTS7^V5lmy^e^uq2@DG4#r_cZZ delta 407 zcmX|-OG*P#5Jhi)l4whV10{+?(CA2U90(#AITCdZCjNhkQ$+{vpr=CCAni=tf%|Zx zD-gkR+in{U^={Rzs`vV({kV`uVY?v(N|fs6IsFdum2feLYU*dL_%-{C-&eO4t1oF8 zVyN^I=cv@9{I34ywrrcfOXY1 zMI3=WW|)0Vj`OFa6W?#rK1XT*UTJOn5u~uIMzQ|5%sKDRqi^x@2Xq3iyLXm&3LCJm vT5;9$GDrB&UHs*Cib0j}vNZagdyH-oufPM`;JV*^z#?DRi(UU=N(X)c55_6? From 0cab0107b2a2f549833942508c1d38177c5b95c6 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Thu, 27 Oct 2022 19:37:05 +0800 Subject: [PATCH 06/22] Fixed minimizing by resetting command pools and fences --- Assets/Editor/Layouts/UserLayout.ini | 22 +++++++++--------- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 21 +++++++++++++---- TempShaderFolder/DeferredCompositeCs.glsl | 3 ++- TempShaderFolder/DeferredCompositeCs.spv | Bin 4532 -> 4656 bytes 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Assets/Editor/Layouts/UserLayout.ini b/Assets/Editor/Layouts/UserLayout.ini index e27f5cca..664330ba 100644 --- a/Assets/Editor/Layouts/UserLayout.ini +++ b/Assets/Editor/Layouts/UserLayout.ini @@ -10,7 +10,7 @@ Collapsed=0 [Window][Hierarchy Panel] Pos=0,142 -Size=494,690 +Size=382,690 Collapsed=0 DockId=0x00000007,0 @@ -20,14 +20,14 @@ Size=400,400 Collapsed=0 [Window][Inspector] -Pos=1649,48 -Size=271,1012 +Pos=1588,48 +Size=332,1012 Collapsed=0 DockId=0x00000006,0 [Window][Profiler] Pos=0,48 -Size=494,92 +Size=382,92 Collapsed=0 DockId=0x00000003,0 @@ -38,25 +38,25 @@ Collapsed=0 DockId=0x00000002,0 [Window][ Viewport] -Pos=496,48 -Size=1151,1012 +Pos=384,48 +Size=1202,1012 Collapsed=0 DockId=0x00000002,0 [Window][ Asset Browser] Pos=0,834 -Size=494,226 +Size=382,226 Collapsed=0 DockId=0x00000008,0 [Docking][Data] DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Split=X - DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1992,1036 Split=X - DockNode ID=0x00000001 Parent=0x00000005 SizeRef=494,1036 Split=Y Selected=0x1E6EB881 + DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1586,1036 Split=X + DockNode ID=0x00000001 Parent=0x00000005 SizeRef=382,1036 Split=Y Selected=0x1E6EB881 DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881 DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,940 Split=Y Selected=0xE096E5AE DockNode ID=0x00000007 Parent=0x00000004 SizeRef=494,690 Selected=0xE096E5AE DockNode ID=0x00000008 Parent=0x00000004 SizeRef=494,226 Selected=0xB128252A - DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1151,1036 CentralNode=1 Selected=0xB41284E7 - DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=271,1036 Selected=0xE7039252 + DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1202,1036 CentralNode=1 Selected=0xB41284E7 + DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=332,1036 Selected=0xE7039252 diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index df884f57..ad040cd9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -183,10 +183,10 @@ namespace SHADE worldRenderGraph->Init(device, swapchain); worldRenderGraph->AddResource("Position", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); worldRenderGraph->AddResource("Normals", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32G32B32A32Sfloat); - worldRenderGraph->AddResource("Albedo", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); + worldRenderGraph->AddResource("Albedo", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); worldRenderGraph->AddResource("Depth Buffer", { SH_ATT_DESC_TYPE_FLAGS::DEPTH_STENCIL }, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); - worldRenderGraph->AddResource("Entity ID", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); - worldRenderGraph->AddResource("Light Layer Indices", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + worldRenderGraph->AddResource("Entity ID", { SH_ATT_DESC_TYPE_FLAGS::COLOR }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); + worldRenderGraph->AddResource("Light Layer Indices", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); worldRenderGraph->AddResource("Scene", { SH_ATT_DESC_TYPE_FLAGS::COLOR, SH_ATT_DESC_TYPE_FLAGS::INPUT, SH_ATT_DESC_TYPE_FLAGS::STORAGE }, windowDims.first, windowDims.second); auto gBufferNode = worldRenderGraph->AddNode("G-Buffer", @@ -219,7 +219,7 @@ namespace SHADE // deferred composite auto deferredCompositeShader = shaderModuleLibrary.GetShaderModule("DeferredCompositeCs.glsl"); - gBufferNode->AddNodeCompute(deferredCompositeShader, { "Position", "Normals", "Albedo", "Scene" }); + gBufferNode->AddNodeCompute(deferredCompositeShader, { "Position", "Normals", "Albedo", "Light Layer Indices", "Scene" }); auto dummyNode = worldRenderGraph->AddNode("Dummy Pass", { "Scene" }, {"G-Buffer"}); // no predecessors @@ -486,7 +486,20 @@ namespace SHADE void SHGraphicsSystem::BeginRender() { if (window->IsMinimized() || renderContext.GetWindowIsDead()) + { + // #BackEndTest: For for the fence initialized by queue submit + renderContext.WaitForFence(); + + // #BackEndTest: Get the current frame from frame manager + auto& currFrameData = renderContext.GetCurrentFrameData(); + + // #BackEndTest: Reset command pool + if (currFrameData.cmdPoolHdls.empty()) + throw std::runtime_error("No command pools available!"); + currFrameData.cmdPoolHdls[0]->Reset(); + return; + } // Finalise all batches for (auto vp : viewports) diff --git a/TempShaderFolder/DeferredCompositeCs.glsl b/TempShaderFolder/DeferredCompositeCs.glsl index bd482b1a..c1caf0aa 100644 --- a/TempShaderFolder/DeferredCompositeCs.glsl +++ b/TempShaderFolder/DeferredCompositeCs.glsl @@ -20,7 +20,8 @@ layout(local_size_x = 16, local_size_y = 16) in; layout(set = 4, binding = 0, rgba32f) uniform image2D positions; layout(set = 4, binding = 1, rgba32f) uniform image2D normals; layout(set = 4, binding = 2, rgba8) uniform image2D albedo; -layout(set = 4, binding = 3, rgba8) uniform image2D targetImage; +layout(set = 4, binding = 3, r32ui) uniform uimage2D lightLayerData; +layout(set = 4, binding = 4, rgba8) uniform image2D targetImage; layout(set = 1, binding = 0) uniform LightCounts { diff --git a/TempShaderFolder/DeferredCompositeCs.spv b/TempShaderFolder/DeferredCompositeCs.spv index 4ec7ac0f659951dcc4c1a5dcbdfd79bf13eaee50..03ef7ac5b615ad4dd42a57f4cad2daf5876ceb6a 100644 GIT binary patch delta 159 zcmdm@yg`MRnMs+Qfq{{Mi-DJ6+D2Y^7I9VvHioGT3=BD$=@}(HiIu5EE{P?H44buC zJedqxfD-NuEDV!?G&c}SLir#KN=W%ubnvxd` delta 55 zcmdm>vPGGfnMs+Qfq{{Mi-DJ6@ Date: Fri, 28 Oct 2022 13:54:46 +0800 Subject: [PATCH 07/22] Getters for light --- .../MiddleEnd/Lights/SHLightComponent.cpp | 32 ++++++++++++++++-- .../MiddleEnd/Lights/SHLightComponent.h | 33 ++++++++++--------- .../Graphics/MiddleEnd/Lights/SHLightData.h | 3 ++ 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 6800e955..39bfccd9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -10,7 +10,7 @@ namespace SHADE lightData.Reset(); SetType(SH_LIGHT_TYPE::DIRECTIONAL); indexInBuffer = std::numeric_limits::max(); - active = true; + lightData.active = true; Unbind(); } @@ -96,7 +96,7 @@ namespace SHADE void SHLightComponent::SetActive(bool flag) noexcept { MakeDirty(); - active = flag; + lightData.active = flag; } @@ -111,6 +111,32 @@ namespace SHADE return lightData; } + SHVec3 const& SHLightComponent::GetPosition(void) const noexcept + { + return lightData.position; + } + + SH_LIGHT_TYPE SHLightComponent::GetType(void) const noexcept + { + return lightData.type; + } + + SHVec3 const& SHLightComponent::GetDirection(void) const noexcept + { + return lightData.direction; + } + + SHVec4 const& SHLightComponent::GetColor(void) const noexcept + { + return lightData.color; + } + + uint32_t const& SHLightComponent::GetCullingMask(void) const noexcept + { + return lightData.cullingMask; + } + + bool SHLightComponent::IsDirty(void) const noexcept { return dirty; @@ -123,7 +149,7 @@ namespace SHADE bool SHLightComponent::GetActive(void) const noexcept { - return active; + return lightData.active; } uint32_t SHLightComponent::GetIndexInBuffer(void) const noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index d267d2d4..45c205c2 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -24,8 +24,6 @@ namespace SHADE //! If the light's data is already in the buffers, this will be set to true. bool bound; - //! If the light is active, this is true. - bool active; public: /*-----------------------------------------------------------------------*/ @@ -37,25 +35,30 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - void SetPosition (SHVec3 position) noexcept; - void SetType (SH_LIGHT_TYPE type) noexcept; - void SetDirection (SHVec3 direction) noexcept; - void SetColor (SHVec4 color) noexcept; - void ModifyLayer (uint8_t layerIndex, bool value) noexcept; - void SetAllLayers (void) noexcept; - void ClearAllLayers (void) noexcept; - void MakeDirty (void) noexcept; + void SetPosition (SHVec3 position) noexcept; // serialized + void SetType (SH_LIGHT_TYPE type) noexcept; // serialized + void SetDirection (SHVec3 direction) noexcept; // serialized + void SetColor (SHVec4 color) noexcept; // serialized + void ModifyLayer (uint8_t layerIndex, bool value) noexcept; // serialized + void SetAllLayers (void) noexcept; // serialized + void ClearAllLayers (void) noexcept; // serialized + void MakeDirty (void) noexcept; void ClearDirtyFlag (void) noexcept; - void Unbind (void) noexcept; + void Unbind (void) noexcept; void SetBound (uint32_t inIndexInBuffer) noexcept; - void SetActive (bool flag) noexcept; - void SetStrength (float value) noexcept; + void SetActive (bool flag) noexcept; // serialized + void SetStrength (float value) noexcept; // serialized - SHLightData const& GetLightData (void) const noexcept; + SHLightData const& GetLightData (void) const noexcept; + SHVec3 const& GetPosition (void) const noexcept; // serialized + SH_LIGHT_TYPE GetType (void) const noexcept; // serialized + SHVec3 const& GetDirection (void) const noexcept; // serialized + SHVec4 const& GetColor (void) const noexcept; // serialized + uint32_t const& GetCullingMask (void) const noexcept; // serialized bool IsDirty (void) const noexcept; bool GetBound (void) const noexcept; - bool GetActive (void) const noexcept; + bool GetActive (void) const noexcept; // serialized uint32_t GetIndexInBuffer (void) const noexcept; }; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h index fccc2856..05938647 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h @@ -46,6 +46,9 @@ namespace SHADE //! Strength of the light float strength; + //! If the light is active, this is true. + bool active; + void Reset (void) noexcept; //! TODO: //! - Add cut off. (inner and outer). From 7d6af884a46beded910ca49aa8d01fe25376e489 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 28 Oct 2022 13:53:05 +0800 Subject: [PATCH 08/22] Added Color struct --- SHADE_Managed/src/Graphics/Color.cxx | 154 ++++++++++++++ SHADE_Managed/src/Graphics/Color.hxx | 287 +++++++++++++++++++++++++++ SHADE_Managed/src/Math/Math.cxx | 11 + SHADE_Managed/src/Math/Math.hxx | 20 +- 4 files changed, 471 insertions(+), 1 deletion(-) create mode 100644 SHADE_Managed/src/Graphics/Color.cxx create mode 100644 SHADE_Managed/src/Graphics/Color.hxx diff --git a/SHADE_Managed/src/Graphics/Color.cxx b/SHADE_Managed/src/Graphics/Color.cxx new file mode 100644 index 00000000..cf1fff47 --- /dev/null +++ b/SHADE_Managed/src/Graphics/Color.cxx @@ -0,0 +1,154 @@ +/************************************************************************************//*! +\file Color.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 3, 2021 +\brief Contains the definition of the functions of the managed Color struct. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Graphics/Color.hxx" +// Standard Libraries +#include +// Project Includes +#include "Math/Math.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + Color::Color(float _red) + : Color { _red, 0.0f, 0.0f, 1.0f } + {} + Color::Color(float _red, float _green) + : Color { _red, _green, 0.0f, 1.0f } + {} + Color::Color(float _red, float _green, float _blue) + : Color { _red, _green, _blue, 1.0f } + {} + Color::Color(float _red, float _green, float _blue, float _alpha) + : r { _red } + , g { _green } + , b { _blue } + , a { _alpha } + {} + + /*---------------------------------------------------------------------------------*/ + /* IEquatable */ + /*---------------------------------------------------------------------------------*/ + bool Color::Equals(Object^ o) + { + try + { + Color col = safe_cast(o); + return Equals(col); + } + catch (System::InvalidCastException^) + { + return false; + } + } + + /*---------------------------------------------------------------------------------*/ + /* Object Overrides */ + /*---------------------------------------------------------------------------------*/ + bool Color::Equals(Color other) + { + return Math::CompareFloat(this->r, other.r) + && + Math::CompareFloat(this->g, other.g) + && + Math::CompareFloat(this->b, other.b) + && + Math::CompareFloat(this->a, other.a); + } + int Color::GetHashCode() + { + const int HASH = 19; + const int HASH2 = 23; + const int HASH3 = 29; + return r.GetHashCode() * HASH + + g.GetHashCode() * HASH2 + + b.GetHashCode() * HASH3 + + a.GetHashCode(); + } + + /*---------------------------------------------------------------------------------*/ + /* Static Functions */ + /*---------------------------------------------------------------------------------*/ + Color Color::Lerp(Color colA, Color colB, float t) + { + return LerpUnclamped(colA, colB, std::clamp(t, 0.0f, 1.0f)); + } + + Color Color::LerpUnclamped(Color colA, Color colB, float t) + { + return colA + ((colB - colA) * t); + } + Color Color::operator+(Color lhs, Color rhs) + { + return Color + ( + lhs.r + rhs.r, + lhs.g + rhs.g, + lhs.b + rhs.b, + lhs.a + rhs.a + ); + } + Color Color::operator-(Color lhs, Color rhs) + { + return Color + ( + lhs.r - rhs.r, + lhs.g - rhs.g, + lhs.b - rhs.b, + lhs.a - rhs.a + ); + } + Color Color::operator*(Color lhs, Color rhs) + { + return Color + ( + lhs.r * rhs.r, + lhs.g * rhs.g, + lhs.b * rhs.b, + lhs.a * rhs.a + ); + } + Color Color::operator*(Color lhs, float rhs) + { + return Color + ( + lhs.r * rhs, + lhs.g * rhs, + lhs.b * rhs, + lhs.a * rhs + ); + } + Color Color::operator/(Color lhs, float rhs) + { + return Color + ( + lhs.r / rhs, + lhs.g / rhs, + lhs.b / rhs, + lhs.a / rhs + ); + } + bool Color::operator==(Color lhs, Color rhs) + { + return lhs.Equals(rhs); + } + bool Color::operator!=(Color lhs, Color rhs) + { + return !(lhs == rhs); + } +} diff --git a/SHADE_Managed/src/Graphics/Color.hxx b/SHADE_Managed/src/Graphics/Color.hxx new file mode 100644 index 00000000..d6a46216 --- /dev/null +++ b/SHADE_Managed/src/Graphics/Color.hxx @@ -0,0 +1,287 @@ +/************************************************************************************//*! +\file Color.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the managed Color struct with the + declaration of functions for working with it. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +namespace SHADE +{ + /// + /// CLR version of the the SHADE Engine's Color struct which describes a Color + /// encoded using floating point numbers that range from 0.0f to 1.0f. + /// + [System::Runtime::InteropServices::StructLayout(System::Runtime::InteropServices::LayoutKind::Sequential)] + public value struct Color : public System::IEquatable + { + public: + /*-----------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------*/ + /// + /// A static class that contains a set of default Colors. + /// + ref class Defaults abstract sealed + { + public: + /*-------------------------------------------------------------------------*/ + /* Properties */ + /*-------------------------------------------------------------------------*/ + /// + /// Pure black. + /// + static property Color Black + { + Color get() { return Color(0.0f, 0.0f, 0.0f); } + } + /// + /// Light Gray, lighter than gray. + /// + static property Color LightGray + { + Color get() { return Color(0.827451f, 0.827451f, 0.827451f); } + } + /// + /// Gray, halfway between black and white. + /// + static property Color Gray + { + Color get() { return Color(0.5f, 0.5f, 0.5f); } + } + /// + /// Dark Gray, darker than gray. + /// + static property Color DarkGray + { + Color get() { return Color(0.622f, 0.622f, 0.622f); } + } + /// + /// Pure white. + /// + static property Color White + { + Color get() { return Color(1.0f, 1.0f, 1.0f); } + } + /// + /// Pure red. + /// + static property Color Red + { + Color get() { return Color(1.0f, 0.0f, 0.0f); } + } + /// + /// Pure green. + /// + static property Color Green + { + Color get() { return Color(0.0f, 1.0f, 0.0f); } + } + /// + /// Pure blue. + /// + static property Color Blue + { + Color get() { return Color(0.0f, 0.0f, 1.0f); } + } + /// + /// Pure cyan, mix of pure green and blue. + /// + static property Color Cyan + { + Color get() { return Color(0.0f, 1.0f, 1.0f); } + } + /// + /// Pure magenta, mix of pure red and blue. + /// + static property Color Magenta + { + Color get() { return Color(1.0f, 0.0f, 1.0f); } + } + /// + /// Pure yellow, mix of pure red and green. + /// + static property Color Yellow + { + Color get() { return Color(1.0f, 1.0f, 0.0f); } + } + }; + + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor to construct a Color with the specified components with the + /// green, blue and alpha component set to 1.0f. + /// + /// Red component to set. + Color(float _red); + /// + /// Constructor to construct a Color with the specified components with the + /// blue and alpha component set to 1.0f. + /// + /// Red component to set. + /// Green component to set. + Color(float _red, float _green); + /// + /// Constructor to construct a Color with the specified components with the + /// alpha component set to 1.0f. + /// + /// Red component to set. + /// Green component to set. + /// Blue component to set. + Color(float _red, float _green, float _blue); + /// + /// Constructor to construct a Color with the specified components. + /// + /// Red component to set. + /// Green component to set. + /// Blue component to set. + /// Alpha component to set. + Color(float _red, float _green, float _blue, float _alpha); + + /*-----------------------------------------------------------------------------*/ + /* Public Members */ + /*-----------------------------------------------------------------------------*/ + /// + /// Red component of the colour. Ranges from 0.0f to 1.0f. + /// + float r; + /// + /// Green component of the colour. Ranges from 0.0f to 1.0f. + /// + float g; + /// + /// Blue component of the colour. Ranges from 0.0f to 1.0f. + /// + float b; + /// + /// Alpha component of the colour. Ranges from 0.0f to 1.0f. + /// + float a; + + /*-----------------------------------------------------------------------------*/ + /* IEquatable */ + /*-----------------------------------------------------------------------------*/ + /// + /// Compares equality with an object of the same type. + /// + /// The object to compare with. + /// True if both objects are the same. + virtual bool Equals(Color other); + + /*-----------------------------------------------------------------------------*/ + /* Object */ + /*-----------------------------------------------------------------------------*/ + /// + /// Compares equality with another unboxed object. + /// + /// The unboxed object to compare with. + /// True if both objects are the same. + bool Equals(Object^ o) override; + /// + /// Gets a unique hash for this object. + /// + /// Unique hash for this object. + int GetHashCode() override; + + + /*-----------------------------------------------------------------------------*/ + /* Static Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Linearly interpolates between two specified points. + /// This is most commonly used to find a point some fraction of the way along a + /// line between two endpoints. + /// + /// The start Color, returned when t = 0.0. + /// The end Color, returned when t = 1.0. + /// + /// Value used to interpolate between a and b which is clamped to + /// the range[0, 1]. + /// + /// The interpolated Vector3. + static Color Lerp(Color colA, Color colB, float t); + /// + /// Linearly interpolates between two specified points. + /// This is most commonly used to find a point some fraction of the way along a + /// line between two endpoints. + /// Unlike Lerp(), t is not clamped to a range at all. + /// + /// The start Color, returned when t = 0.0. + /// The end Color, returned when t = 1.0. + /// Value used to interpolate between a and b. + /// The interpolated Color. + static Color LerpUnclamped(Color colA, Color colB, float t); + + /*-----------------------------------------------------------------------------*/ + /* Overloaded Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Adds two Colors together and returns the result. + /// + /// Color to add. + /// Another Color to add. + /// The result of lhs added to rhs + static Color operator+(Color lhs, Color rhs); + /// + /// Subtracts a Color from another Color and returns the result. + /// + /// Color to subtract from. + /// Another Color to subtract. + /// The result of rhs subtracted from lhs. + static Color operator-(Color lhs, Color rhs); + /// + /// Calculates the component-wise multiplication of two Colors and returns the + /// result. + /// + /// Color to multiply with. + /// Another Color to multiply with. + /// The result of rhs subtracted from lhs. + static Color operator*(Color lhs, Color rhs); + /// + /// Calculates the multiplication of a Color with a scalar value and returns + /// the result. + /// + /// Color to multiply with. + /// Scalar to multiply with. + /// The result of the scalar multiplication. + static Color operator*(Color lhs, float rhs); + /// + /// Calculates the division of a Color with a scalar value and returns + /// the result. + /// + /// Scalar to divide with. + /// Color to divide with. + /// The result of the scalar division. + static Color operator/(Color lhs, float rhs); + /// + /// Checks if two Colors are approximately equal. + /// + /// Color to compare. + /// Another Color to compare. + /// + /// True if all components are approximately equal within the default + /// tolerance value. + /// + static bool operator==(Color lhs, Color rhs); + /// + /// Checks if two Colors are not approximately equal. + /// + /// Color to compare. + /// Another Color to compare. + /// + /// True if all components are not approximately equal within the default + /// tolerance value. + /// + static bool operator!=(Color lhs, Color rhs); + }; +} diff --git a/SHADE_Managed/src/Math/Math.cxx b/SHADE_Managed/src/Math/Math.cxx index fa72e2b6..bc625f5b 100644 --- a/SHADE_Managed/src/Math/Math.cxx +++ b/SHADE_Managed/src/Math/Math.cxx @@ -54,4 +54,15 @@ namespace SHADE { return (value - a) / (b - a); } + + bool Math::CompareFloat(float a, float b) + { + return CompareFloat(a, b, Epsilon); + } + + bool Math::CompareFloat(float a, float b, float tolerance) + { + return System::MathF::Abs(a - b) < tolerance; + } + } diff --git a/SHADE_Managed/src/Math/Math.hxx b/SHADE_Managed/src/Math/Math.hxx index 1578d97c..c6b8394e 100644 --- a/SHADE_Managed/src/Math/Math.hxx +++ b/SHADE_Managed/src/Math/Math.hxx @@ -81,12 +81,30 @@ namespace SHADE /// The interpolated float result between the two float values. static float LerpUnclamped(float a, float b, float t); /// - /// Calculates the linear parameter t that produces the interpolant value within the range [a, b]. + /// Calculates the linear parameter t that produces the interpolant value within + /// the range [a, b]. /// /// Start value. /// End value. /// Value between start and end. /// Percentage of value between start and end. static float InverseLerp(float a, float b, float value); + /// + /// Compares if two float values are close enough to be the same with a tolerance + /// of Epsilon. + /// + /// One of the values to compare. + /// The other value to compare. + /// True if a and b are practically the same. + static bool CompareFloat(float a, float b); + /// + /// Compares if two float values are close enough to be the same with the + /// specified tolerance value. + /// + /// One of the values to compare. + /// The other value to compare. + /// Tolerance for floating point comparison. + /// True if a and b are practically the same. + static bool CompareFloat(float a, float b, float tolerance); }; } From baa77e5d37e4af2a95607067ce0259f4f0f1293b Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 28 Oct 2022 14:10:08 +0800 Subject: [PATCH 09/22] setter for culling mask --- .../MiddleEnd/Lights/SHLightComponent.cpp | 7 ++++- .../MiddleEnd/Lights/SHLightComponent.h | 27 ++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 39bfccd9..e8d7b6f7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -47,7 +47,7 @@ namespace SHADE MakeDirty(); } - void SHLightComponent::ModifyLayer(uint8_t layerIndex, bool value) noexcept + void SHLightComponent::ModifyCullingMask(uint8_t layerIndex, bool value) noexcept { if (value) lightData.cullingMask |= (1u << layerIndex); @@ -58,6 +58,11 @@ namespace SHADE } + void SHLightComponent::SetCullingMask(uint32_t value) noexcept + { + lightData.cullingMask = value; + } + void SHLightComponent::SetAllLayers(void) noexcept { lightData.cullingMask = std::numeric_limits::max(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index 45c205c2..951e6071 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -35,19 +35,20 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - void SetPosition (SHVec3 position) noexcept; // serialized - void SetType (SH_LIGHT_TYPE type) noexcept; // serialized - void SetDirection (SHVec3 direction) noexcept; // serialized - void SetColor (SHVec4 color) noexcept; // serialized - void ModifyLayer (uint8_t layerIndex, bool value) noexcept; // serialized - void SetAllLayers (void) noexcept; // serialized - void ClearAllLayers (void) noexcept; // serialized - void MakeDirty (void) noexcept; - void ClearDirtyFlag (void) noexcept; - void Unbind (void) noexcept; - void SetBound (uint32_t inIndexInBuffer) noexcept; - void SetActive (bool flag) noexcept; // serialized - void SetStrength (float value) noexcept; // serialized + void SetPosition (SHVec3 position) noexcept; // serialized + void SetType (SH_LIGHT_TYPE type) noexcept; // serialized + void SetDirection (SHVec3 direction) noexcept; // serialized + void SetColor (SHVec4 color) noexcept; // serialized + void ModifyCullingMask (uint8_t layerIndex, bool value) noexcept; // serialized + void SetCullingMask (uint32_t value) noexcept; + void SetAllLayers (void) noexcept; // serialized + void ClearAllLayers (void) noexcept; // serialized + void MakeDirty (void) noexcept; + void ClearDirtyFlag (void) noexcept; + void Unbind (void) noexcept; + void SetBound (uint32_t inIndexInBuffer) noexcept; + void SetActive (bool flag) noexcept; // serialized + void SetStrength (float value) noexcept; // serialized SHLightData const& GetLightData (void) const noexcept; From f110f9b16ba64aa9d90fe68886b3b76c13f6cb0e Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 28 Oct 2022 15:56:22 +0800 Subject: [PATCH 10/22] Removed isActive from component --- .../Graphics/MiddleEnd/Lights/SHLightComponent.cpp | 13 +------------ .../Graphics/MiddleEnd/Lights/SHLightComponent.h | 2 -- .../src/Graphics/MiddleEnd/Lights/SHLightData.h | 2 -- .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 4 ++-- 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index e8d7b6f7..35278a81 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -10,7 +10,7 @@ namespace SHADE lightData.Reset(); SetType(SH_LIGHT_TYPE::DIRECTIONAL); indexInBuffer = std::numeric_limits::max(); - lightData.active = true; + isActive = true; Unbind(); } @@ -98,12 +98,6 @@ namespace SHADE indexInBuffer = inIndexInBuffer; } - void SHLightComponent::SetActive(bool flag) noexcept - { - MakeDirty(); - lightData.active = flag; - - } void SHLightComponent::SetStrength(float value) noexcept { @@ -152,11 +146,6 @@ namespace SHADE return bound; } - bool SHLightComponent::GetActive(void) const noexcept - { - return lightData.active; - } - uint32_t SHLightComponent::GetIndexInBuffer(void) const noexcept { return indexInBuffer; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index 951e6071..2cea9f1a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -47,7 +47,6 @@ namespace SHADE void ClearDirtyFlag (void) noexcept; void Unbind (void) noexcept; void SetBound (uint32_t inIndexInBuffer) noexcept; - void SetActive (bool flag) noexcept; // serialized void SetStrength (float value) noexcept; // serialized @@ -59,7 +58,6 @@ namespace SHADE uint32_t const& GetCullingMask (void) const noexcept; // serialized bool IsDirty (void) const noexcept; bool GetBound (void) const noexcept; - bool GetActive (void) const noexcept; // serialized uint32_t GetIndexInBuffer (void) const noexcept; }; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h index 05938647..e9a02c1a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightData.h @@ -46,8 +46,6 @@ namespace SHADE //! Strength of the light float strength; - //! If the light is active, this is true. - bool active; void Reset (void) noexcept; //! TODO: diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index 97d8b24f..e8d85dd1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -43,7 +43,7 @@ namespace SHADE lightPtr->cullingMask = lightData.cullingMask; lightPtr->direction = lightData.direction; lightPtr->diffuseColor = lightData.color; - lightPtr->active = lightComp->GetActive(); + lightPtr->active = lightComp->isActive; break; } case SH_LIGHT_TYPE::POINT: @@ -56,7 +56,7 @@ namespace SHADE lightPtr->ambientColor = lightData.color; lightPtr->strength = lightData.strength; lightPtr->cullingMask = lightData.cullingMask; - lightPtr->active = lightComp->GetActive (); + lightPtr->active = lightComp->isActive; break; } case SH_LIGHT_TYPE::NUM_TYPES: From fa6e3cf1df1e7a8e2ed851c4f90d24ea93c53049 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Fri, 28 Oct 2022 17:58:16 +0800 Subject: [PATCH 11/22] Light Component Serialization & Inspector --- Assets/Editor/Layouts/UserLayout.ini | 62 ------------------- .../Inspector/SHEditorComponentView.hpp | 44 +++++++++++++ .../Inspector/SHEditorInspector.cpp | 5 ++ SHADE_Engine/src/Editor/SHEditorWidgets.hpp | 40 +++++++++++- .../MiddleEnd/Lights/SHLightComponent.cpp | 37 +++++++++-- .../MiddleEnd/Lights/SHLightComponent.h | 12 ++-- .../src/Serialization/SHSerialization.cpp | 10 +++ .../Serialization/SHSerializationHelper.hpp | 4 +- 8 files changed, 139 insertions(+), 75 deletions(-) delete mode 100644 Assets/Editor/Layouts/UserLayout.ini diff --git a/Assets/Editor/Layouts/UserLayout.ini b/Assets/Editor/Layouts/UserLayout.ini deleted file mode 100644 index 664330ba..00000000 --- a/Assets/Editor/Layouts/UserLayout.ini +++ /dev/null @@ -1,62 +0,0 @@ -[Window][MainStatusBar] -Pos=0,1060 -Size=1920,20 -Collapsed=0 - -[Window][SHEditorMenuBar] -Pos=0,48 -Size=1920,1012 -Collapsed=0 - -[Window][Hierarchy Panel] -Pos=0,142 -Size=382,690 -Collapsed=0 -DockId=0x00000007,0 - -[Window][Debug##Default] -Pos=60,60 -Size=400,400 -Collapsed=0 - -[Window][Inspector] -Pos=1588,48 -Size=332,1012 -Collapsed=0 -DockId=0x00000006,0 - -[Window][Profiler] -Pos=0,48 -Size=382,92 -Collapsed=0 -DockId=0x00000003,0 - -[Window][Viewport] -Pos=648,48 -Size=2519,1319 -Collapsed=0 -DockId=0x00000002,0 - -[Window][ Viewport] -Pos=384,48 -Size=1202,1012 -Collapsed=0 -DockId=0x00000002,0 - -[Window][ Asset Browser] -Pos=0,834 -Size=382,226 -Collapsed=0 -DockId=0x00000008,0 - -[Docking][Data] -DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Split=X - DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1586,1036 Split=X - DockNode ID=0x00000001 Parent=0x00000005 SizeRef=382,1036 Split=Y Selected=0x1E6EB881 - DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881 - DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,940 Split=Y Selected=0xE096E5AE - DockNode ID=0x00000007 Parent=0x00000004 SizeRef=494,690 Selected=0xE096E5AE - DockNode ID=0x00000008 Parent=0x00000004 SizeRef=494,226 Selected=0xB128252A - DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1202,1036 CentralNode=1 Selected=0xB41284E7 - DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=332,1036 Selected=0xE7039252 - diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 7fa39d74..043eba0a 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -13,10 +13,24 @@ #include "Editor/IconsFontAwesome6.h" #include "ECS_Base/Components/SHComponent.h" #include "Editor/SHEditorWidgets.hpp" +#include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Physics/Components/SHColliderComponent.h" #include "Reflection/SHReflectionMetadata.h" namespace SHADE { + template + std::vector GetRTTREnumNames() + { + auto const rttrType = rttr::type::get(); + if(!rttrType.is_enumeration()) + return {}; + auto const enumAlign = rttrType.get_enumeration(); + auto const names = enumAlign.get_names(); + std::vector result; + std::transform(names.begin(), names.end(), std::back_inserter(result), [](rttr::string_view const& name){return name.data();}); + return result; + } + template::value, bool> = true> static void DrawContextMenu(T* component) { @@ -273,4 +287,34 @@ namespace SHADE } else DrawContextMenu(component); } + + template<> + static void DrawComponent(SHLightComponent* component) + { + if (!component) + return; + const auto componentType = rttr::type::get(*component); + SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }); + ImGui::SameLine(); + if (ImGui::CollapsingHeader(componentType.get_name().data())) + { + DrawContextMenu(component); + + static auto const enumAlign = rttr::type::get().get_enumeration(); + static std::vector list(GetRTTREnumNames()); + + SHEditorWidgets::ComboBox("Type", list, [component] {return static_cast(component->GetType()); }, [component](int const& idx) + { + component->SetType(static_cast(idx)); + }); + SHEditorWidgets::DragVec3("Position", {"X", "Y", "Z"}, [component](){return component->GetPosition();}, [component](SHVec3 const& vec){component->SetPosition(vec);}); + SHEditorWidgets::DragVec3("Direction", {"X", "Y", "Z"}, [component](){return component->GetDirection();}, [component](SHVec3 const& vec){component->SetDirection(vec);}); + SHEditorWidgets::ColorPicker("Color", [component](){return component->GetColor();}, [component](SHVec4 const& rgba){component->SetColor(rgba);}); + SHEditorWidgets::DragFloat("Strength", [component](){return component->GetStrength();}, [component](float const& value){component->SetStrength(value);}); + } + else + { + DrawContextMenu(component); + } + } } \ No newline at end of file diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index ada5a35a..92ccbbc9 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -82,6 +82,10 @@ namespace SHADE { DrawComponent(rigidbodyComponent); } + if(auto lightComponent = SHComponentManager::GetComponent_s(eid)) + { + DrawComponent(lightComponent); + } ImGui::Separator(); // Render Scripts SHScriptEngine* scriptEngine = static_cast(SHSystemManager::GetSystem()); @@ -92,6 +96,7 @@ namespace SHADE DrawAddComponentButton(eid); DrawAddComponentButton(eid); DrawAddComponentButton(eid); + DrawAddComponentButton(eid); if(DrawAddComponentButton(eid)) { if(SHComponentManager::GetComponent_s(eid) == nullptr) diff --git a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp index b54a6799..46538827 100644 --- a/SHADE_Engine/src/Editor/SHEditorWidgets.hpp +++ b/SHADE_Engine/src/Editor/SHEditorWidgets.hpp @@ -192,8 +192,8 @@ namespace SHADE ImGuiColors::colors[i], 4); ImGui::SameLine(0, g.Style.ItemInnerSpacing.x); - ImGui::PopID(); ImGui::PopItemWidth(); + ImGui::PopID(); } ImGui::EndColumns(); ImGui::PopID(); @@ -615,5 +615,43 @@ namespace SHADE } return edited; } + + static bool ColorPicker(const std::string_view& label, std::function get, std::function set, std::string_view const& tooltip = {}, float speed = 0.1f, const char* displayFormat = "%.3f", float valueMin = 0.0f, float valueMax = 0.0f, + ImGuiSliderFlags flags = 0) + { + bool changed = false; + ImGui::BeginGroup(); + ImGui::PushID(label.data()); + + SHVec4 values = get(); + //changed |= DragN(label.data(), {"R", "G", "B", "A"}, { &values.x, &values.y, &values.z, &values.w }, speed, displayFormat, valueMin, valueMax, flags); + //ImGui::SameLine(); + TextLabel(label); + changed = ImGui::ColorEdit4("##Col4", &values.x, ImGuiColorEditFlags_AlphaPreviewHalf | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_DisplayRGB ); + static bool startRecording = false; + if(changed) + { + SHCommandManager::PerformCommand(std::reinterpret_pointer_cast(std::make_shared>(get(), values, set)), startRecording); + if(!startRecording) + startRecording = true; + } + if (startRecording && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) + { + startRecording = false; + } + ImGui::PopID(); + ImGui::EndGroup(); + if (!tooltip.empty()) + { + if (ImGui::IsItemHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text(tooltip.data()); + ImGui::EndTooltip(); + } + } + return changed; + } }; + }//namespace SHADE diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp index 35278a81..fb8795fa 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.cpp @@ -20,7 +20,7 @@ namespace SHADE } - void SHLightComponent::SetPosition(SHVec3 position) noexcept + void SHLightComponent::SetPosition(SHVec3 const& position) noexcept { lightData.position = position; MakeDirty(); @@ -34,14 +34,14 @@ namespace SHADE } - void SHLightComponent::SetDirection(SHVec3 direction) noexcept + void SHLightComponent::SetDirection(SHVec3 const& direction) noexcept { lightData.direction = direction; MakeDirty(); } - void SHLightComponent::SetColor(SHVec4 color) noexcept + void SHLightComponent::SetColor(SHVec4 const& color) noexcept { lightData.color = color; MakeDirty(); @@ -57,8 +57,7 @@ namespace SHADE MakeDirty(); } - - void SHLightComponent::SetCullingMask(uint32_t value) noexcept + void SHLightComponent::SetCullingMask(uint32_t const& value) noexcept { lightData.cullingMask = value; } @@ -151,4 +150,32 @@ namespace SHADE return indexInBuffer; } + float SHLightComponent::GetStrength(void) const noexcept + { + return lightData.strength; + } + +} + +RTTR_REGISTRATION +{ + using namespace SHADE; + using namespace rttr; + + registration::enumeration("Light Type") + ( + value("Directional", SH_LIGHT_TYPE::DIRECTIONAL), + value("Point", SH_LIGHT_TYPE::POINT), + value("Spot", SH_LIGHT_TYPE::SPOT), + value("Ambient", SH_LIGHT_TYPE::AMBIENT) + ); + + registration::class_("Light Component") + .property("Position", &SHLightComponent::GetPosition, &SHLightComponent::SetPosition) + .property("Type", &SHLightComponent::GetType, &SHLightComponent::SetType) + .property("Direction", &SHLightComponent::GetDirection, &SHLightComponent::SetDirection) + .property("Color", &SHLightComponent::GetColor, &SHLightComponent::SetColor) + .property("Layer", &SHLightComponent::GetCullingMask, &SHLightComponent::SetCullingMask) + .property("Strength", &SHLightComponent::GetStrength, &SHLightComponent::SetStrength) + ; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h index 2cea9f1a..81eb80f5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightComponent.h @@ -1,5 +1,6 @@ #pragma once +#include #include "ECS_Base/Components/SHComponent.h" #include "SHLightData.h" @@ -35,12 +36,12 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - void SetPosition (SHVec3 position) noexcept; // serialized + void SetPosition (SHVec3 const& position) noexcept; // serialized void SetType (SH_LIGHT_TYPE type) noexcept; // serialized - void SetDirection (SHVec3 direction) noexcept; // serialized - void SetColor (SHVec4 color) noexcept; // serialized + void SetDirection (SHVec3 const& direction) noexcept; // serialized + void SetColor (SHVec4 const& color) noexcept; // serialized void ModifyCullingMask (uint8_t layerIndex, bool value) noexcept; // serialized - void SetCullingMask (uint32_t value) noexcept; + void SetCullingMask (uint32_t const& value) noexcept; void SetAllLayers (void) noexcept; // serialized void ClearAllLayers (void) noexcept; // serialized void MakeDirty (void) noexcept; @@ -59,6 +60,7 @@ namespace SHADE bool IsDirty (void) const noexcept; bool GetBound (void) const noexcept; uint32_t GetIndexInBuffer (void) const noexcept; - + float GetStrength (void) const noexcept; + RTTR_ENABLE() }; } diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 3804db95..73442092 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -14,6 +14,7 @@ #include "Math/Transform/SHTransformComponent.h" #include "Physics/Components/SHRigidBodyComponent.h" #include "ECS_Base/Managers/SHSystemManager.h" +#include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Scripting/SHScriptEngine.h" namespace SHADE @@ -192,6 +193,10 @@ namespace SHADE { components[rttr::type::get().get_name().data()] = SHSerializationHelper::SerializeComponentToNode(rigidbody); } + if(const auto light = SHComponentManager::GetComponent_s(eid)) + { + components[rttr::type::get().get_name().data()] = SHSerializationHelper::SerializeComponentToNode(light); + } node[ComponentsNode] = components; YAML::Node scripts; @@ -250,6 +255,10 @@ namespace SHADE if (id.has_value()) componentIDList.push_back(id.value()); + id = GetComponentID(componentsNode); + if(id.has_value()) + componentIDList.push_back(id.value()); + return componentIDList; } @@ -259,5 +268,6 @@ namespace SHADE if (!componentsNode) return; SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); } } diff --git a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp index da98c885..fddd330c 100644 --- a/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp +++ b/SHADE_Engine/src/Serialization/SHSerializationHelper.hpp @@ -188,12 +188,12 @@ namespace SHADE return; auto rttrType = rttr::type::get(); auto componentNode = componentsNode[rttrType.get_name().data()]; - if (componentsNode.IsNull()) + if(!componentNode.IsDefined()) return; auto properties = rttrType.get_properties(); for (auto const& prop : properties) { - if (componentNode[prop.get_name().data()]) + if (componentNode[prop.get_name().data()].IsDefined()) { InitializeProperty(component, prop, componentNode[prop.get_name().data()]); } From 199897adb4cd084551ae1f2d554955e096867eb7 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 28 Oct 2022 19:00:17 +0800 Subject: [PATCH 12/22] Added GenericHandles to SHADE_Managed --- SHADE_Engine/src/Resource/SHHandle.h | 6 ++ SHADE_Engine/src/Resource/SHHandle.hpp | 5 ++ SHADE_Engine/src/Resource/SparseSet.hpp | 8 +-- SHADE_Managed/src/Engine/GenericHandle.cxx | 47 +++++++++++++++ SHADE_Managed/src/Engine/GenericHandle.hxx | 68 ++++++++++++++++++++++ SHADE_Managed/src/Utility/Convert.cxx | 16 +++++ SHADE_Managed/src/Utility/Convert.hxx | 19 ++++++ 7 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 SHADE_Managed/src/Engine/GenericHandle.cxx create mode 100644 SHADE_Managed/src/Engine/GenericHandle.hxx diff --git a/SHADE_Engine/src/Resource/SHHandle.h b/SHADE_Engine/src/Resource/SHHandle.h index 6acc85ed..49dd56b9 100644 --- a/SHADE_Engine/src/Resource/SHHandle.h +++ b/SHADE_Engine/src/Resource/SHHandle.h @@ -195,6 +195,11 @@ namespace SHADE template inline bool operator==(const Handle& rhs) const noexcept; + /*-----------------------------------------------------------------------------*/ + /* Query Functions */ + /*-----------------------------------------------------------------------------*/ + inline SHResourceLibraryBase* GetLibrary() const; + protected: /*-----------------------------------------------------------------------------*/ /* Data Members */ @@ -206,6 +211,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ template friend class Handle; + friend class Convert; }; /// diff --git a/SHADE_Engine/src/Resource/SHHandle.hpp b/SHADE_Engine/src/Resource/SHHandle.hpp index 53061ac7..91eed058 100644 --- a/SHADE_Engine/src/Resource/SHHandle.hpp +++ b/SHADE_Engine/src/Resource/SHHandle.hpp @@ -96,6 +96,11 @@ namespace SHADE return id.Raw == rhs.id.Raw && library == static_cast(rhs.library); } + SHResourceLibraryBase* SHADE::Handle::GetLibrary() const + { + return library; + } + /*---------------------------------------------------------------------------------*/ /* ISelfHandle - Constructors */ /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Resource/SparseSet.hpp b/SHADE_Engine/src/Resource/SparseSet.hpp index 5afcdee7..816ca432 100644 --- a/SHADE_Engine/src/Resource/SparseSet.hpp +++ b/SHADE_Engine/src/Resource/SparseSet.hpp @@ -70,13 +70,13 @@ namespace SHADE } template - SparseSet::reference SparseSet::at(index_type idx) + typename SparseSet::reference SparseSet::at(index_type idx) { return const_cast(static_cast&>(*this).at(idx)); } template - SparseSet::const_reference SparseSet::at(index_type idx) const + typename SparseSet::const_reference SparseSet::at(index_type idx) const { // Range Check if (idx >= sparseArray.size() || !contains(idx)) @@ -84,7 +84,7 @@ namespace SHADE return denseArray[sparseArray[idx]]; } template - SparseSet::size_type SparseSet::size() const + typename SparseSet::size_type SparseSet::size() const { return denseArray.size(); } @@ -105,7 +105,7 @@ namespace SHADE } template template - SparseSet::reference SparseSet::insert(index_type idx, Args && ...args) + typename SparseSet::reference SparseSet::insert(index_type idx, Args && ...args) { // We need to resize the array if (idx >= sparseArray.size()) diff --git a/SHADE_Managed/src/Engine/GenericHandle.cxx b/SHADE_Managed/src/Engine/GenericHandle.cxx new file mode 100644 index 00000000..41a69c18 --- /dev/null +++ b/SHADE_Managed/src/Engine/GenericHandle.cxx @@ -0,0 +1,47 @@ +/************************************************************************************//*! +\file Renderable.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the functions of the managed Renderable class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#include "SHpch.h" +#include "GenericHandle.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + GenericHandle::GenericHandle(Handle handle) + : id { handle.GetId().Raw } + , library { reinterpret_cast(handle.GetLibrary()) } + {} + + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + System::UInt64 GenericHandle::Id::get() + { + return id; + } + System::IntPtr GenericHandle::Library::get() + { + return library; + } + + /*---------------------------------------------------------------------------------*/ + /* Overloaded Operators */ + /*---------------------------------------------------------------------------------*/ + GenericHandle::operator bool() + { + return library.ToPointer() != nullptr && id != System::UInt64::MaxValue; + } + +} diff --git a/SHADE_Managed/src/Engine/GenericHandle.hxx b/SHADE_Managed/src/Engine/GenericHandle.hxx new file mode 100644 index 00000000..3f8e395f --- /dev/null +++ b/SHADE_Managed/src/Engine/GenericHandle.hxx @@ -0,0 +1,68 @@ +/************************************************************************************//*! +\file Handle.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the managed GenericHandle struct. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// External Dependencies +#include "Resource/SHHandle.h" + +namespace SHADE +{ + /// + /// Managed version of the generic Handle. + /// + public value struct GenericHandle + { + public: + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructs a GenericHandle for a native generic Handle. + /// + /// Handle to create a GenericHandle from. + explicit GenericHandle(Handle handle); + + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// The internal ID of the handle. + /// + property System::UInt64 Id + { + System::UInt64 get(); + } + /// + /// The library that the handle was issued by. + /// + property System::IntPtr Library + { + System::IntPtr get(); + } + + /*-----------------------------------------------------------------------------*/ + /* Overloaded Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Converts to true if this is a valid Handle. + /// + inline operator bool(); + + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + System::UInt64 id; + System::IntPtr library; + }; +} \ No newline at end of file diff --git a/SHADE_Managed/src/Utility/Convert.cxx b/SHADE_Managed/src/Utility/Convert.cxx index cb4815aa..1d89569f 100644 --- a/SHADE_Managed/src/Utility/Convert.cxx +++ b/SHADE_Managed/src/Utility/Convert.cxx @@ -84,4 +84,20 @@ namespace SHADE { return msclr::interop::marshal_as(str); } + + /*---------------------------------------------------------------------------------*/ + /* Handle Conversions */ + /*---------------------------------------------------------------------------------*/ + Handle Convert::ToNative(GenericHandle handle) + { + Handle nativeHandle; + nativeHandle.id.Raw = handle.Id; + nativeHandle.library = reinterpret_cast(handle.Library.ToPointer()); + return nativeHandle; + } + + GenericHandle Convert::ToCLI(Handle handle) + { + return GenericHandle(handle); + } } diff --git a/SHADE_Managed/src/Utility/Convert.hxx b/SHADE_Managed/src/Utility/Convert.hxx index 19faffde..d3dca740 100644 --- a/SHADE_Managed/src/Utility/Convert.hxx +++ b/SHADE_Managed/src/Utility/Convert.hxx @@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited. #include "Math/Vector/SHVec3.h" #include "Math/SHQuaternion.h" #include "Math/SHRay.h" +#include "Resource/SHHandle.h" // Project Includes #include "Engine/Entity.hxx" @@ -27,6 +28,7 @@ of DigiPen Institute of Technology is prohibited. #include "Math/Vector3.hxx" #include "Math/Quaternion.hxx" #include "Math/Ray.hxx" +#include "Engine/GenericHandle.hxx" namespace SHADE { @@ -118,6 +120,23 @@ namespace SHADE /// The native std::string to convert from. /// Managed copy of a native std::string. static System::String^ ToCLI(const std::string& str); + + /*-----------------------------------------------------------------------------*/ + /* Handle Conversions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Converts from a managed GenericHandle to a Handle. + /// + /// GenericHandle to convert from. + /// Native generic Handle. + static Handle ToNative(GenericHandle handle); + /// + /// Converts from a native generic Handle to a managed GenericHandle. + /// + /// The native handle to convert. + /// Managed copy of the native Handle. + static GenericHandle ToCLI(Handle handle); + }; /// From 541f44c039c4b5234d94ffd3f7d2e213c6566bb2 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 28 Oct 2022 19:02:54 +0800 Subject: [PATCH 13/22] Fixed bugs in SHMaterial, SHMeshLibrary and removed unused functions in SHTextureLibrary --- .../MiddleEnd/Interface/SHMaterial.hpp | 4 +- .../Interface/SHMaterialInstance.hpp | 10 +-- .../MiddleEnd/Interface/SHMeshLibrary.h | 3 +- .../MiddleEnd/Textures/SHTextureLibrary.cpp | 62 ------------------- .../MiddleEnd/Textures/SHTextureLibrary.h | 3 - 5 files changed, 9 insertions(+), 73 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.hpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.hpp index 49587921..dceee512 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.hpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.hpp @@ -33,7 +33,7 @@ namespace SHADE } // Get offset and modify the memory directly - T* dataPtr = propMemory.get() + PROP_INFO->offset; + T* dataPtr = reinterpret_cast(propMemory.get() + PROP_INFO->offset); *dataPtr = value; } template @@ -47,7 +47,7 @@ namespace SHADE } // Get offset and return the memory directly - T* dataPtr = propMemory.get() + PROP_INFO->offset; + T* dataPtr = reinterpret_cast(propMemory.get() + PROP_INFO->offset); return *dataPtr; } template diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.hpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.hpp index 4621c273..e70631ea 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.hpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterialInstance.hpp @@ -69,15 +69,15 @@ namespace SHADE // Search Override Data for the property uint32_t PROP_IDX = SHADER_INFO->GetVariableIndex(key); - auto prop = std::find(overrideData.begin(), overrideData.end(), [&](const OverrideData& data) - { - return PROP_IDX == data.Index; - }); + auto prop = std::find_if(overrideData.begin(), overrideData.end(), [&](const OverrideData& data) + { + return PROP_IDX == data.Index; + }); if (prop == overrideData.end()) throw std::invalid_argument("Attempted to get an property that was not set previously!"); // Get offset and return the memory directly - T* dataPtr = dataStore.get() + prop->StoredDataOffset; + T* dataPtr = reinterpret_cast(dataStore.get() + prop->StoredDataOffset); return *dataPtr; } template diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h index 72ac1878..b0cbdce1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h @@ -17,7 +17,8 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "Resource/SHHandle.h" #include "Resource/SHResourceLibrary.h" -#include "Math/SHMath.h" +#include "Math/Vector/SHVec2.h" +#include "Math/Vector/SHVec3.h" namespace SHADE { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp index 5c315ff6..8719458b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp @@ -214,66 +214,4 @@ namespace SHADE SHLOG_ERROR("Image layouts are invalid. "); } } - - vk::Format SHTextureLibrary::ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear) - { - switch (format) - { - case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm: - return vk::Format::eBc1RgbaUnormBlock; - case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm_SRGB: - return vk::Format::eBc1RgbaSrgbBlock; - case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm: - case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm_SRGB: - return isLinear ? vk::Format::eBc2UnormBlock : vk::Format::eBc2SrgbBlock; - case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm: - case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm_SRGB: - return isLinear ? vk::Format::eBc3UnormBlock : vk::Format::eBc3SrgbBlock; - case tinyddsloader::DDSFile::DXGIFormat::BC5_UNorm: - case tinyddsloader::DDSFile::DXGIFormat::BC5_SNorm: - return isLinear ? vk::Format::eBc5UnormBlock : vk::Format::eBc5SnormBlock; - case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm: - case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm_SRGB: - return isLinear ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb; - case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_SNorm: - return vk::Format::eR8G8B8A8Snorm; - case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm: - case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm_SRGB: - return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb; - case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm: - case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm_SRGB: - return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8Srgb; - default: - throw std::runtime_error("Unsupported DDS format."); - } - - //switch (format) - //{ - //case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm: - //case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm_SRGB: - // return (isLinear) ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb; - // - - //case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm: - //case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm_SRGB: - // return (isLinear) ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb; - // - - //case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm: - //case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm_SRGB: - // return (isLinear) ? vk::Format::eBc1RgbaUnormBlock : vk::Format::eBc1RgbaSrgbBlock; - - //case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm: - //case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm_SRGB: - // return (isLinear) ? vk::Format::eBc2UnormBlock : vk::Format::eBc2SrgbBlock; - - //case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm: - //case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm_SRGB: - // return (isLinear) ? vk::Format::eBc3UnormBlock : vk::Format::eBc3SrgbBlock; - - //case tinyddsloader::DDSFile::DXGIFormat::BC5_UNorm: - // return (isLinear) ? vk::Format::eBc5UnormBlock : vk::Format::eBc5SnormBlock; - // - //} - } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h index 935a7a4d..9357b0e0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h @@ -14,8 +14,6 @@ of DigiPen Institute of Technology is prohibited. // STL Includes #include -// External Dependencies -#include "tinyddsloader.h" // Project Includes #include "Resource/SHHandle.h" #include "Resource/SHResourceLibrary.h" @@ -169,6 +167,5 @@ namespace SHADE /* Helper Functions */ /*-----------------------------------------------------------------------------*/ void preparePipelineBarriers(vk::ImageLayout oldLayout, vk::ImageLayout newLayout, vk::PipelineStageFlagBits& srcStage, vk::PipelineStageFlagBits& dstStage, std::vector& barriers); - vk::Format ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear); }; } From 7e5c8198133ad264304fb3caddbf97d1f8f30a29 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 28 Oct 2022 19:03:07 +0800 Subject: [PATCH 14/22] Fixed warning with Collider not being made abstract --- SHADE_Managed/src/Components/Collider.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SHADE_Managed/src/Components/Collider.hxx b/SHADE_Managed/src/Components/Collider.hxx index f827ab71..9f88b983 100644 --- a/SHADE_Managed/src/Components/Collider.hxx +++ b/SHADE_Managed/src/Components/Collider.hxx @@ -27,7 +27,7 @@ namespace SHADE /// /// Base interface for all Collider Shapes. /// - public ref class ColliderBound + public ref class ColliderBound abstract { public: /*-----------------------------------------------------------------------------*/ From 9617ed3838d210585413ec5a076343bc231eaaa1 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Fri, 28 Oct 2022 19:23:40 +0800 Subject: [PATCH 15/22] Added NativeAsset, Material and Mesh representations along with a stub for Renderable --- SHADE_Managed/src/Assets/Material.cxx | 119 ++++++++++++++++++++ SHADE_Managed/src/Assets/Material.hxx | 81 +++++++++++++ SHADE_Managed/src/Assets/Mesh.cxx | 34 ++++++ SHADE_Managed/src/Assets/Mesh.hxx | 41 +++++++ SHADE_Managed/src/Assets/NativeAsset.cxx | 26 +++++ SHADE_Managed/src/Assets/NativeAsset.h++ | 49 ++++++++ SHADE_Managed/src/Assets/NativeAsset.hxx | 66 +++++++++++ SHADE_Managed/src/Components/Renderable.cxx | 37 ++++++ SHADE_Managed/src/Components/Renderable.hxx | 53 +++++++++ 9 files changed, 506 insertions(+) create mode 100644 SHADE_Managed/src/Assets/Material.cxx create mode 100644 SHADE_Managed/src/Assets/Material.hxx create mode 100644 SHADE_Managed/src/Assets/Mesh.cxx create mode 100644 SHADE_Managed/src/Assets/Mesh.hxx create mode 100644 SHADE_Managed/src/Assets/NativeAsset.cxx create mode 100644 SHADE_Managed/src/Assets/NativeAsset.h++ create mode 100644 SHADE_Managed/src/Assets/NativeAsset.hxx create mode 100644 SHADE_Managed/src/Components/Renderable.cxx create mode 100644 SHADE_Managed/src/Components/Renderable.hxx diff --git a/SHADE_Managed/src/Assets/Material.cxx b/SHADE_Managed/src/Assets/Material.cxx new file mode 100644 index 00000000..f4262c2a --- /dev/null +++ b/SHADE_Managed/src/Assets/Material.cxx @@ -0,0 +1,119 @@ +/************************************************************************************//*! +\file Material.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the implementation of the functions of the managed Material + class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Material.hxx" +// Standard Library +#include +// Project Includes +#include "Utility/Convert.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Macro Definitions */ + /*---------------------------------------------------------------------------------*/ + #define SET_PROP(NATIVE_TYPE, MANAGED_TYPE) \ + (T::typeid == MANAGED_TYPE::typeid) \ + { \ + const NATIVE_TYPE VAL = safe_cast(System::Convert::ChangeType(value, MANAGED_TYPE::typeid)); \ + NativeObject->SetProperty(PROP_NAME, VAL); \ + } \ + + #define SET_PROP_CONVERT(NATIVE_TYPE, MANAGED_TYPE) \ + (T::typeid == MANAGED_TYPE::typeid) \ + { \ + const NATIVE_TYPE VAL = Convert::ToNative(safe_cast(System::Convert::ChangeType(value, MANAGED_TYPE::typeid))); \ + NativeObject->SetProperty(PROP_NAME, VAL); \ + } \ + + #define GET_PROP(NATIVE_TYPE, MANAGED_TYPE) \ + (T::typeid == MANAGED_TYPE::typeid) \ + { \ + return safe_cast(NativeObject->GetProperty(PROP_NAME)); \ + } \ + + #define GET_PROP_CONVERT(NATIVE_TYPE, MANAGED_TYPE) \ + (T::typeid == MANAGED_TYPE::typeid) \ + { \ + return safe_cast(Convert::ToCLI(NativeObject->GetProperty(PROP_NAME))); \ + } + + /*---------------------------------------------------------------------------------*/ + /* Explicit Template Instantiation */ + /*---------------------------------------------------------------------------------*/ + template ref class NativeAsset; + + /*---------------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*---------------------------------------------------------------------------------*/ + Material::Material(Handle material) + : NativeAsset{ material } + {} + + /*---------------------------------------------------------------------------------*/ + /* Material Properties Functions */ + /*---------------------------------------------------------------------------------*/ + generic + void Material::SetProperty(System::String^ name, T value) + { + if (!NativeObject) + throw gcnew System::InvalidOperationException("Attempted to set property on an invalid material!"); + + // Call the correct one based on type + const std::string PROP_NAME = Convert::ToNative(name); + try + { + if SET_PROP (int, System::Int32) + else if SET_PROP (int, System::Int64) + else if SET_PROP (float, float) + else if SET_PROP (double, double) + else if SET_PROP_CONVERT(SHVec2, Vector2) + else if SET_PROP_CONVERT(SHVec3, Vector3) + // TODO: Vector4 + } + catch (const std::invalid_argument&) + { + throw gcnew System::ArgumentException("Attempted to modify an invalid property on a material."); + } + } + + generic + T Material::GetProperty(System::String^ name) + { + if (!NativeObject) + throw gcnew System::InvalidOperationException("[Material] Attempted to get property of an invalid material!"); + + // Call the correct one based on type + const std::string PROP_NAME = Convert::ToNative(name); + try + { + if GET_PROP (int, System::Int32) + else if GET_PROP (int, System::Int64) + else if GET_PROP (float, float) + else if GET_PROP (double, double) + else if GET_PROP_CONVERT(SHVec2, Vector2) + else if GET_PROP_CONVERT(SHVec3, Vector3) + // TODO: Vector4 + } + catch (const std::invalid_argument&) + { + throw gcnew System::ArgumentException("Attempted to retrieve a property on a material with an invalid type."); + } + + throw gcnew System::ArgumentException("Attempted to retrieve an invalid property on a material."); + } +} diff --git a/SHADE_Managed/src/Assets/Material.hxx b/SHADE_Managed/src/Assets/Material.hxx new file mode 100644 index 00000000..25cc96a6 --- /dev/null +++ b/SHADE_Managed/src/Assets/Material.hxx @@ -0,0 +1,81 @@ +/************************************************************************************//*! +\file Material.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the managed Mesh class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// External Dependencies +#include "Resource/SHHandle.h" +#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h" +// Project Includes +#include "NativeAsset.hxx" +#include "Engine/GenericHandle.hxx" + +namespace SHADE +{ + /// + /// Managed counterpart of the native MaterialInstance object containing material + /// data that can be fed to Renderables for rendering. + /// + public ref class Material : public NativeAsset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the Material + /// + /// Handle to the native material object. + Material(Handle material); + + public: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + // TODO: Change Shader + + /*-----------------------------------------------------------------------------*/ + /* Material Properties Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Set the value of a specific property. + /// + /// Type of property to set. + /// Name of the property to set. + /// Value to set te property to. + /// + /// If this Material object is invalid. + /// + /// + /// If the name or type was specified that does not match the material's shader's + /// defined properties. + /// + generic + void SetProperty(System::String^ name, T value); + /// + /// Retrieves the value of a specified property on the material. + /// + /// Type of property to get. + /// Name of the property to get. + /// Value of that property on the material. + /// + /// If this Material object is invalid. + /// + /// + /// If the name or type was specified that does not match the material's shader's + /// defined properties. + /// + generic + T GetProperty(System::String^ name); + }; +} diff --git a/SHADE_Managed/src/Assets/Mesh.cxx b/SHADE_Managed/src/Assets/Mesh.cxx new file mode 100644 index 00000000..95a61ff6 --- /dev/null +++ b/SHADE_Managed/src/Assets/Mesh.cxx @@ -0,0 +1,34 @@ +/************************************************************************************//*! +\file Mesh.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the implementation of the functions of the managed Mesh class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Mesh.hxx" +// Project Headers +#include "Utility/Convert.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Explicit Template Instantiation */ + /*---------------------------------------------------------------------------------*/ + template ref class NativeAsset; + + /*---------------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*---------------------------------------------------------------------------------*/ + Mesh::Mesh(Handle mesh) + : NativeAsset { mesh } + {} +} diff --git a/SHADE_Managed/src/Assets/Mesh.hxx b/SHADE_Managed/src/Assets/Mesh.hxx new file mode 100644 index 00000000..8cd356ba --- /dev/null +++ b/SHADE_Managed/src/Assets/Mesh.hxx @@ -0,0 +1,41 @@ +/************************************************************************************//*! +\file Mesh.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the managed Mesh class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// External Dependencies +#include "Resource/SHHandle.h" +#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" +// Project Includes +#include "NativeAsset.hxx" +#include "Engine/GenericHandle.hxx" + +namespace SHADE +{ + /// + /// Managed counterpart of the native Mesh object containing vertex data that can + /// be fed to Renderables for rendering. + /// + public ref class Mesh : public NativeAsset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the Mesh + /// + /// Handle to the mesh object. + Mesh(Handle mesh); + }; +} diff --git a/SHADE_Managed/src/Assets/NativeAsset.cxx b/SHADE_Managed/src/Assets/NativeAsset.cxx new file mode 100644 index 00000000..674207a1 --- /dev/null +++ b/SHADE_Managed/src/Assets/NativeAsset.cxx @@ -0,0 +1,26 @@ +/************************************************************************************//*! +\file NativeAsset.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the explicit template instantiation for some types of the + templated managed NativeAsset class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#include "SHpch.h" +// Primary Include +#include "NativeAsset.hxx" +// Project Includes +#include "Engine/GenericHandle.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Explicit Tempalte Instantiations */ + /*---------------------------------------------------------------------------------*/ +} \ No newline at end of file diff --git a/SHADE_Managed/src/Assets/NativeAsset.h++ b/SHADE_Managed/src/Assets/NativeAsset.h++ new file mode 100644 index 00000000..a4cd94b4 --- /dev/null +++ b/SHADE_Managed/src/Assets/NativeAsset.h++ @@ -0,0 +1,49 @@ +/************************************************************************************//*! +\file NativeAsset.h++ +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of templated functions for the managed + NativeAsset classes. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// Primary Include +#include "NativeAsset.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + template + GenericHandle NativeAsset::NativeObjectHandle::get() + { + return nativeObjHandle; + } + template + Handle NativeAsset::NativeObject::get() + try + { + return Handle(Convert::ToNative(nativeObjHandle)); + } + catch (const BadHandleCastException&) + { + return Handle(); // Null handle + } + + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + template + NativeAsset::NativeAsset(Handle nativeObj) + : nativeObjHandle{ Convert::ToCLI(Handle(nativeObj)) } + {} + +} diff --git a/SHADE_Managed/src/Assets/NativeAsset.hxx b/SHADE_Managed/src/Assets/NativeAsset.hxx new file mode 100644 index 00000000..68addb75 --- /dev/null +++ b/SHADE_Managed/src/Assets/NativeAsset.hxx @@ -0,0 +1,66 @@ +/************************************************************************************//*! +\file NativeAsset.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the template definition of the managed class that represents + native assets with a pointer to the corresponding native object. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +#include "Engine/GenericHandle.hxx" + +namespace SHADE +{ + /// + /// Generalised template class for a managed representation of a native asset + /// + /// + /// The type of the asset's native representation. + /// + template + public ref class NativeAsset + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + /// + /// Generic handle for the native object + /// + property GenericHandle NativeObjectHandle + { + GenericHandle get(); + } + /// + /// Copy of the Handle to the native object. + /// + property Handle NativeObject + { + Handle get(); + } + + /*-----------------------------------------------------------------------------*/ + /* Constructors/Destructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor for the native asset + /// + /// Native asset object. + NativeAsset(Handle ptr); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + GenericHandle nativeObjHandle; + }; +} + +#include "NativeAsset.h++" diff --git a/SHADE_Managed/src/Components/Renderable.cxx b/SHADE_Managed/src/Components/Renderable.cxx new file mode 100644 index 00000000..08a43506 --- /dev/null +++ b/SHADE_Managed/src/Components/Renderable.cxx @@ -0,0 +1,37 @@ +/************************************************************************************//*! +\file Renderable.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the functions of the managed Renderable class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Renderable.hxx" +#include "Assets/NativeAsset.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + Renderable::Renderable(Entity entity) + : Component(entity) + {} + + /*---------------------------------------------------------------------------------*/ + /* Usage Functions */ + /*---------------------------------------------------------------------------------*/ + +} diff --git a/SHADE_Managed/src/Components/Renderable.hxx b/SHADE_Managed/src/Components/Renderable.hxx new file mode 100644 index 00000000..c21ebdd6 --- /dev/null +++ b/SHADE_Managed/src/Components/Renderable.hxx @@ -0,0 +1,53 @@ +/************************************************************************************//*! +\file Renderable.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 28, 2022 +\brief Contains the definition of the managed Renderable class with the + declaration of functions for working with it. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// Project Includes +#include "Components/Component.hxx" +#include "Math/Vector3.hxx" +#include "Math/Quaternion.hxx" +// External Dependencies +#include "Graphics/MiddleEnd/Interface/SHRenderable.h" + +namespace SHADE +{ + /// + /// CLR version of the SHADE Engine's SHRenderableComponent. + /// + public ref class Renderable : public Component + { + internal: + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructs a Renderable Component that represents a native Renderable + /// component tied to the specified Entity. + /// + /// Entity that this Component will be tied to. + Renderable(Entity entity); + + public: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + + /*-----------------------------------------------------------------------------*/ + /* Usage Functions */ + /*-----------------------------------------------------------------------------*/ + + }; +} + From 19dc999e4f2b233945f4c61e0fcbd87b68e4d71f Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sat, 29 Oct 2022 02:19:36 +0800 Subject: [PATCH 16/22] Added full implementation of Renderable script interface --- SHADE_Managed/src/Components/Renderable.cxx | 42 ++++++++++++++++++--- SHADE_Managed/src/Components/Renderable.hxx | 30 ++++++++++++--- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/SHADE_Managed/src/Components/Renderable.cxx b/SHADE_Managed/src/Components/Renderable.cxx index 08a43506..d1bbb4c8 100644 --- a/SHADE_Managed/src/Components/Renderable.cxx +++ b/SHADE_Managed/src/Components/Renderable.cxx @@ -16,13 +16,10 @@ of DigiPen Institute of Technology is prohibited. // Primary Header #include "Renderable.hxx" #include "Assets/NativeAsset.hxx" +#include "Utility/Convert.hxx" namespace SHADE { - /*---------------------------------------------------------------------------------*/ - /* Properties */ - /*---------------------------------------------------------------------------------*/ - /*---------------------------------------------------------------------------------*/ /* Constructors */ /*---------------------------------------------------------------------------------*/ @@ -31,7 +28,40 @@ namespace SHADE {} /*---------------------------------------------------------------------------------*/ - /* Usage Functions */ + /* Properties */ /*---------------------------------------------------------------------------------*/ - + SHADE::Mesh^ Renderable::Mesh::get() + { + return gcnew SHADE::Mesh(GetNativeComponent()->Mesh); + } + void Renderable::Mesh::set(SHADE::Mesh^ value) + { + if (value == nullptr) + { + GetNativeComponent()->Mesh = Handle(); + } + else + { + GetNativeComponent()->Mesh = Handle(Convert::ToNative(value->NativeObjectHandle)); + } + } + SHADE::Material^ Renderable::Material::get() + { + return gcnew SHADE::Material(GetNativeComponent()->GetMaterial()); + } + void Renderable::Material::set(SHADE::Material^ value) + { + if (value == nullptr) + { + GetNativeComponent()->SetMaterial(Handle()); + } + else + { + GetNativeComponent()->SetMaterial(Handle(Convert::ToNative(value->NativeObjectHandle))); + } + } + System::Byte Renderable::LightLayer::get() + { + return GetNativeComponent()->GetLightLayer(); + } } diff --git a/SHADE_Managed/src/Components/Renderable.hxx b/SHADE_Managed/src/Components/Renderable.hxx index c21ebdd6..e8f11ef6 100644 --- a/SHADE_Managed/src/Components/Renderable.hxx +++ b/SHADE_Managed/src/Components/Renderable.hxx @@ -20,6 +20,8 @@ of DigiPen Institute of Technology is prohibited. #include "Math/Quaternion.hxx" // External Dependencies #include "Graphics/MiddleEnd/Interface/SHRenderable.h" +#include "Assets/Mesh.hxx" +#include "Assets/Material.hxx" namespace SHADE { @@ -43,11 +45,29 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Properties */ /*-----------------------------------------------------------------------------*/ - - /*-----------------------------------------------------------------------------*/ - /* Usage Functions */ - /*-----------------------------------------------------------------------------*/ - + /// + /// Mesh used to render this Renderable. + /// + property SHADE::Mesh^ Mesh + { + SHADE::Mesh^ get(); + void set(SHADE::Mesh^ value); + } + /// + /// Material used to render this Renderable. + /// + property SHADE::Material^ Material + { + SHADE::Material^ get(); + void set(SHADE::Material^ value); + } + /// + /// Material used to render this Renderable. + /// + property System::Byte LightLayer + { + System::Byte get(); + } }; } From 25db4db99a22b3c71817a598fbf59eb5760fa73e Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 29 Oct 2022 17:00:35 +0800 Subject: [PATCH 17/22] Catered to light comp deletion and solved minimize bugs Editor can also now shift the viewport around without Vulkan vomiting validation layers --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 41 +++++++++-------- .../MiddleEnd/Interface/SHGraphicsSystem.h | 2 + .../MiddleEnd/Lights/SHLightingSubSystem.cpp | 44 +++++++++++++++---- .../MiddleEnd/Lights/SHLightingSubSystem.h | 13 +++++- .../MiddleEnd/PerFrame/SHRenderContext.cpp | 1 + 5 files changed, 71 insertions(+), 30 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index ad040cd9..66c41e3e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -73,15 +73,7 @@ namespace SHADE if (width == 0 || height == 0) return; -#ifdef SHEDITOR - - //PrepareResize(1, 1, SHVec2(0, 0)); - -#else - - PrepareResize(resizeWidth, resizeHeight, SHVec2(0, 0)); - -#endif + PrepareResize(resizeWidth, resizeHeight); }); window->RegisterWindowCloseCallback([&](void) @@ -352,6 +344,12 @@ namespace SHADE void SHGraphicsSystem::Run(double) noexcept { if (window->IsMinimized() || renderContext.GetWindowIsDead()) + { + restoredFromMinimize = true; + return; + } + + if (restoredFromMinimize) return; // Frame data for the current frame @@ -487,17 +485,12 @@ namespace SHADE { if (window->IsMinimized() || renderContext.GetWindowIsDead()) { - // #BackEndTest: For for the fence initialized by queue submit - renderContext.WaitForFence(); - - // #BackEndTest: Get the current frame from frame manager - auto& currFrameData = renderContext.GetCurrentFrameData(); - - // #BackEndTest: Reset command pool - if (currFrameData.cmdPoolHdls.empty()) - throw std::runtime_error("No command pools available!"); - currFrameData.cmdPoolHdls[0]->Reset(); + restoredFromMinimize = true; + return; + } + if (restoredFromMinimize) + { return; } @@ -548,7 +541,17 @@ namespace SHADE void SHGraphicsSystem::EndRender() { if (window->IsMinimized() || renderContext.GetWindowIsDead()) + { + restoredFromMinimize = true; return; + } + + if (restoredFromMinimize) + { + restoredFromMinimize = false; + return; + } + const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame(); auto& currFrameData = renderContext.GetCurrentFrameData(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index ae93bd78..8830bfa5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -356,5 +356,7 @@ namespace SHADE uint32_t resizeWidth; uint32_t resizeHeight; + bool restoredFromMinimize = false; + }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp index e8d85dd1..5ca879c4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.cpp @@ -67,6 +67,7 @@ namespace SHADE } } + /***************************************************************************/ /*! @@ -88,6 +89,7 @@ namespace SHADE // Get data required for struct lightDataSize = GetLightTypeSize(type); + lightDataAlignedSize = logicalDevice->PadSSBOSize(lightDataSize); // So create some data! Expand(logicalDevice); @@ -123,10 +125,10 @@ namespace SHADE // Initialize the data for lights intermediateData = std::make_unique(lightDataSize * maxLights); - lightDataAlignedSize = logicalDevice->PadSSBOSize(lightDataSize * maxLights); + lightDataTotalAlignedSize = logicalDevice->PadSSBOSize(lightDataAlignedSize * maxLights); // We want to initialize 3 times the amount of data required. - dataBuffer = logicalDevice->CreateBuffer(lightDataAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, lightDataAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); + dataBuffer = logicalDevice->CreateBuffer(lightDataTotalAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, lightDataTotalAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); } else { @@ -145,7 +147,7 @@ namespace SHADE maxLights *= 2; // calculate total + padding - lightDataAlignedSize = logicalDevice->PadSSBOSize(lightDataSize * maxLights); + lightDataTotalAlignedSize = logicalDevice->PadSSBOSize(lightDataAlignedSize * maxLights); // destroy old data and initialize container for double the amount of data. intermediateData = std::make_unique(lightDataSize * maxLights); @@ -154,7 +156,7 @@ namespace SHADE std::memcpy(intermediateData.get(), oldData.get(), lightDataSize * OLD_MAX_LIGHTS); // Resize the GPU buffer. TODO: Replace with Resize no copy here - dataBuffer->ResizeReplace(maxLights * lightDataAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, oldData.get(), lightDataAlignedSize * OLD_MAX_LIGHTS); + dataBuffer->ResizeReplace(maxLights * lightDataTotalAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, oldData.get(), lightDataTotalAlignedSize * OLD_MAX_LIGHTS); } @@ -205,7 +207,7 @@ namespace SHADE uint32_t SHLightingSubSystem::PerTypeData::GetAlignmentSize(void) const noexcept { - return lightDataAlignedSize; + return lightDataTotalAlignedSize; } uint32_t SHLightingSubSystem::PerTypeData::GetDataSize(void) const noexcept @@ -254,7 +256,7 @@ namespace SHADE // Now that the container is big enough, bind the new light // Get address of write location - void* writeLocation = reinterpret_cast(intermediateData.get()) + (lightDataSize * numLights); + void* writeLocation = reinterpret_cast(intermediateData.get()) + (lightDataAlignedSize * numLights); // Write the light data to address WriteLightToAddress(writeLocation, unboundLight); @@ -280,7 +282,7 @@ namespace SHADE /***************************************************************************/ void SHLightingSubSystem::PerTypeData::ModifyLight(SHLightComponent* lightComp) noexcept { - void* writeLocation = reinterpret_cast(intermediateData.get()) + (lightDataSize * lightComp->GetIndexInBuffer()); + void* writeLocation = reinterpret_cast(intermediateData.get()) + (lightDataAlignedSize * lightComp->GetIndexInBuffer()); WriteLightToAddress(writeLocation, lightComp); } @@ -289,10 +291,15 @@ namespace SHADE if (intermediateData) { // we want to write to the offset of the current frame - dataBuffer->WriteToMemory(intermediateData.get(), lightDataSize * numLights, 0, lightDataSize * maxLights * frameIndex); + dataBuffer->WriteToMemory(intermediateData.get(), lightDataAlignedSize * numLights, 0, lightDataAlignedSize * maxLights * frameIndex); } } + void SHLightingSubSystem::PerTypeData::ResetNumLights(void) noexcept + { + numLights = 0; + } + /***************************************************************************/ /*! @@ -343,6 +350,14 @@ namespace SHADE } } + void SHLightingSubSystem::ResetNumLights(void) noexcept + { + for (auto& data : perTypeData) + { + data.ResetNumLights(); + } + } + /***************************************************************************/ /*! @@ -391,6 +406,7 @@ namespace SHADE dynamicOffsets[i].resize(NUM_LIGHT_TYPES + 1); // +1 for the count } + numLightComponents = 0; } /***************************************************************************/ @@ -409,13 +425,23 @@ namespace SHADE auto& lightComps = SHComponentManager::GetDense(); bool expanded = false; + bool rewrite = false; + + if (numLightComponents > lightComps.size()) + { + rewrite = true; + ResetNumLights(); + } + + numLightComponents = lightComps.size(); + for (auto& light : lightComps) { auto enumValue = SHUtilities::ToUnderlying(light.GetLightData().type); // First we want to make sure the light is already bound to the system. if it // isn't, we write it to the correct buffer. - if (!light.GetBound()) + if (!light.GetBound() || rewrite) { perTypeData[enumValue].AddLight(logicalDevice, &light, expanded); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h index dfb956ec..fb7aa2de 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Lights/SHLightingSubSystem.h @@ -65,7 +65,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* STATIC MEMBER VARIABLES */ /*-----------------------------------------------------------------------*/ - static constexpr uint32_t STARTING_NUM_LIGHTS = 20; + static constexpr uint32_t STARTING_NUM_LIGHTS = 50; /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER VARIABLES */ @@ -74,11 +74,13 @@ namespace SHADE uint32_t maxLights; //! SSBOs need to be aligned. This is to pad descriptor offset - uint32_t lightDataAlignedSize; + uint32_t lightDataTotalAlignedSize; //! size needed to store 1 struct object uint32_t lightDataSize; + uint32_t lightDataAlignedSize; + //! type of the light. Will be used later when we want to expand SH_LIGHT_TYPE lightType; @@ -103,6 +105,7 @@ namespace SHADE void AddLight (Handle logicalDevice, SHLightComponent* unboundLight, bool expanded) noexcept; void ModifyLight (SHLightComponent* lightComp) noexcept; void WriteToGPU (uint32_t frameIndex) noexcept; + void ResetNumLights (void) noexcept; /*-----------------------------------------------------------------------*/ /* GETTERS */ @@ -138,11 +141,17 @@ namespace SHADE //! For padding in the buffer uint32_t lightCountsAlignedSize; + //! Number of SHLightComponents recorded. If at the beginning of the run function the size returned by the dense + //! set is less than the size recorded, rewrite all light components into the its respective buffers. If its more, + //! don't do anything. + uint32_t numLightComponents; + /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ void UpdateDescSet (uint32_t binding) noexcept; void ComputeDynamicOffsets (void) noexcept; + void ResetNumLights (void) noexcept; public: diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp index 8041adfd..45103819 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp @@ -133,6 +133,7 @@ namespace SHADE { SHLOG_ERROR("Frame index retrieved from vkAcquireNextImageKHR is not the same as currentFrame."); } + currentFrame = frameIndex; } From 6f2ca54f7e7cac33473c7c35904d9e5f0a44aa97 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 29 Oct 2022 21:36:11 +0800 Subject: [PATCH 18/22] WIP compute barriers --- .../RenderGraph/SHRenderGraphNodeCompute.cpp | 32 ++++++++++++++++++- .../RenderGraph/SHRenderGraphNodeCompute.h | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index 678fc41b..e4d2360e 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -68,7 +68,7 @@ namespace SHADE cmdBuffer->ComputeDispatch(groupSizeX, groupSizeY, 1); // TODO: barrier - + } void SHRenderGraphNodeCompute::HandleResize(void) noexcept @@ -103,6 +103,36 @@ namespace SHADE groupSizeX = maxWidth / workGroupSizeX; groupSizeY = maxHeight / workGroupSizeY; + + for (uint32_t i = 0; auto& barriers : memoryBarriers) + { + barriers.clear(); + + for (auto& resource : resources) + { + vk::AccessFlags srcAccessMask = (barriers.empty()) ? vk::AccessFlagBits::eInputAttachmentRead : (vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite); + barriers.push_back(vk::ImageMemoryBarrier + { + .srcAccessMask = srcAccessMask, + .dstAccessMask = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite, + .oldLayout = vk::ImageLayout::eGeneral, + .newLayout = vk::ImageLayout::eGeneral, + .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, + .image = resource->GetImage((resource->resourceTypeFlags & static_cast(SH_ATT_DESC_TYPE_FLAGS::COLOR_PRESENT)) ? i : 0)->GetVkImage(), + .subresourceRange = vk::ImageSubresourceRange + { + .aspectMask = resource->imageAspectFlags, + .baseMipLevel = 0, + .levelCount = resource->mipLevels, + .baseArrayLayer = 0, + .layerCount = 1, + } + }); + } + + ++i; + } } } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index ba4cf387..711fb317 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -44,6 +44,8 @@ namespace SHADE float numWorkGroupScale; + std::array, SHGraphicsConstants::NUM_FRAME_BUFFERS> memoryBarriers; + public: SHRenderGraphNodeCompute(Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, float inNumWorkGroupScale = 1.0f) noexcept; From 5da7638c0a5828940753334d809b6408184a1d89 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 29 Oct 2022 22:52:15 +0800 Subject: [PATCH 19/22] Compute barriers --- .../src/Graphics/RenderGraph/SHRenderGraphNode.cpp | 2 +- .../Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp | 10 ++++++---- .../Graphics/RenderGraph/SHRenderGraphNodeCompute.h | 5 ++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index c315bffd..b4590da4 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -268,7 +268,7 @@ namespace SHADE } // Create the subpass compute with the resources - auto nodeCompute = graphStorage->resourceManager->Create(graphStorage, computeShaderModule, std::move(nodeComputeResources)); + auto nodeCompute = graphStorage->resourceManager->Create(graphStorage, computeShaderModule, std::move(nodeComputeResources), nodeComputes.empty()); nodeComputes.push_back(nodeCompute); return nodeCompute; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index e4d2360e..5323d706 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -13,12 +13,13 @@ namespace SHADE { - SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, float inNumWorkGroupScale/* = 1.0f*/) noexcept + SHRenderGraphNodeCompute::SHRenderGraphNodeCompute(Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, bool followingEndRP, float inNumWorkGroupScale/* = 1.0f*/) noexcept : computePipeline{} , pipelineLayout{} , resources{} , groupSizeX{0} , groupSizeY{0} + , followingEndRenderpass {followingEndRP} , numWorkGroupScale {std::clamp(inNumWorkGroupScale, 0.0f, 1.0f)} { SHPipelineLayoutParams pipelineLayoutParams @@ -67,8 +68,9 @@ namespace SHADE // dispatch compute cmdBuffer->ComputeDispatch(groupSizeX, groupSizeY, 1); - // TODO: barrier - + cmdBuffer->PipelineBarrier((followingEndRenderpass) ? vk::PipelineStageFlagBits::eFragmentShader : vk::PipelineStageFlagBits::eComputeShader, + vk::PipelineStageFlagBits::eFragmentShader, + {}, {}, {}, memoryBarriers[frameIndex]); } void SHRenderGraphNodeCompute::HandleResize(void) noexcept @@ -110,7 +112,7 @@ namespace SHADE for (auto& resource : resources) { - vk::AccessFlags srcAccessMask = (barriers.empty()) ? vk::AccessFlagBits::eInputAttachmentRead : (vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite); + vk::AccessFlags srcAccessMask = (followingEndRenderpass) ? vk::AccessFlagBits::eInputAttachmentRead : (vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite); barriers.push_back(vk::ImageMemoryBarrier { .srcAccessMask = srcAccessMask, diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h index 711fb317..2cd3c948 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.h @@ -2,6 +2,7 @@ #include "Resource/SHHandle.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" +#include "Graphics/SHVulkanIncludes.h" #include #include #include @@ -44,10 +45,12 @@ namespace SHADE float numWorkGroupScale; + bool followingEndRenderpass; + std::array, SHGraphicsConstants::NUM_FRAME_BUFFERS> memoryBarriers; public: - SHRenderGraphNodeCompute(Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, float inNumWorkGroupScale = 1.0f) noexcept; + SHRenderGraphNodeCompute(Handle graphStorage, Handle computeShaderModule, std::vector>&& subpassComputeResources, bool followingEndRP, float inNumWorkGroupScale = 1.0f) noexcept; void Execute (Handle cmdBuffer, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; From 5db92996993420b1bb0c96ab50a41e46884303e7 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 30 Oct 2022 00:07:02 +0800 Subject: [PATCH 20/22] Reverted back to old asset IDs --- Assets/Cube.003.shmesh.shmeta | 2 +- Assets/Cube.012.shmesh.shmeta | 2 +- Assets/RaccoonBag_Color_Ver4.shtex.shmeta | 2 +- .../RaccoonPreTexturedVer1_Base9.shtex.shmeta | 2 +- Assets/Shaders/Kirsch_CS.shshaderb | Bin 5909 -> 5909 bytes Assets/Shaders/Kirsch_CS.shshaderb.shmeta | 2 +- Assets/Shaders/PureCopy_CS.shshaderb | Bin 1273 -> 1273 bytes Assets/Shaders/PureCopy_CS.shshaderb.shmeta | 2 +- Assets/Shaders/TestCube_FS.glsl | 21 +++++++++--------- Assets/Shaders/TestCube_FS.shshaderb | Bin 2545 -> 2309 bytes Assets/Shaders/TestCube_FS.shshaderb.shmeta | 2 +- Assets/Shaders/TestCube_VS.glsl | 13 ++++------- Assets/Shaders/TestCube_VS.shshaderb | Bin 3305 -> 2501 bytes Assets/Shaders/TestCube_VS.shshaderb.shmeta | 2 +- Assets/TD_Checker_Base_Color.shtex.shmeta | 2 +- 15 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Assets/Cube.003.shmesh.shmeta b/Assets/Cube.003.shmesh.shmeta index 99185bf3..628ecd00 100644 --- a/Assets/Cube.003.shmesh.shmeta +++ b/Assets/Cube.003.shmesh.shmeta @@ -1,3 +1,3 @@ Name: Cube.003 -ID: 77135977 +ID: 71245919 Type: 4 diff --git a/Assets/Cube.012.shmesh.shmeta b/Assets/Cube.012.shmesh.shmeta index b3bf270f..56d2d0f5 100644 --- a/Assets/Cube.012.shmesh.shmeta +++ b/Assets/Cube.012.shmesh.shmeta @@ -1,3 +1,3 @@ Name: Cube.012 -ID: 81876417 +ID: 80365422 Type: 4 diff --git a/Assets/RaccoonBag_Color_Ver4.shtex.shmeta b/Assets/RaccoonBag_Color_Ver4.shtex.shmeta index 70631c1e..d386e9a4 100644 --- a/Assets/RaccoonBag_Color_Ver4.shtex.shmeta +++ b/Assets/RaccoonBag_Color_Ver4.shtex.shmeta @@ -1,3 +1,3 @@ Name: RaccoonBag_Color_Ver4 -ID: 66703095 +ID: 58303057 Type: 3 diff --git a/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta b/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta index 61be80e0..e1a72340 100644 --- a/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta +++ b/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta @@ -1,3 +1,3 @@ Name: RaccoonPreTexturedVer1_Base9 -ID: 60820650 +ID: 64651793 Type: 3 diff --git a/Assets/Shaders/Kirsch_CS.shshaderb b/Assets/Shaders/Kirsch_CS.shshaderb index 6219d9a9c9a9e8ae16a498e700cba315f72f58b8..4c54946c91f269b181aa2869965af1861c3cd8c5 100644 GIT binary patch delta 10 RcmbQLH&u^OVI!l6H~a4?u=O&SG&9a-P6xm&HOuMic{M+zu%ZI%(OXVmP^PSHT#5^g8%VV z$^Z2HFY#$JWj5AdL@TeJM*}hkXPqRz8N(b$gSEY58- z-iik{i-xb?+I~L%)JGkQ#h=FcdNv#_$9b&jHnf}a^!??gCIrT8{ry$;fmiTn zc5yP=iYpi!d2JO`r=b|L;>u++7bhgNS?;KW7}z)iiqN5_qz8PF>5V$D zaqo8(gM7XsU)YoD#Vo7yV4mpoN6e1bi8-st@Hxe!9^?~}=%+0@DSy6ebiR$Y{`0eh zFZdm=vjebiw2f(T{K;26K|dwWgEHWEM)H^9=)^uG&H*DfI1*kZ;774xqn%lT;SwK z=l43~|IW+7pLa_vVuX5bdW?9tyi88?yW-57euvX=dc&EpfQ> zkC29VNB^14X%X{c?)T)$9L|WqJF1fTv_APTi(3w;uE(c443 zAEkdDZ%G(9@z~8zq7V-oyQ44mbz6jeUB1Ns*<;{=KKOoq5k`J|-h1qhWctK*U)$n4 r2ctgr{6Iu~VNUG)p$Hs*-UWK_eF(3Bt>>?qn%YN}jvCW4bLNEkZVH(*=7^0nyt+rDGIn`tpSpa<95XZZ`QBh_usp8P<<%S4 zNqy3^>l?^@${aTxNq8@DISxuXAwDa&dzthBZ&H0GHSb#$sXh}V92 z5RdIBDU-^^t`a`&Vt z_u}6sN#>q7TgpF&zxU`-Z?F*$N27RL9b`7nTyEpkmAc98Tkfj!_&Apjvq{f6(`BS#1_$VVxRdj+6ZtG0Y@a*-2(}s$I{ruZ-Nu zOsBqaZ8P5_+qP+eziZx>UD>DAq_mpY6q}d)KB+d#Vzi!ANnHyVG%T{Bl$_CvfKiJ- z-)9eG9>!Bwl8ttg2F50ATO}2Bl_QeWUAA;d#)WFtQ3?IygHnnR(a)l!uT6H_yo*Cb zJwe~|`9eX=4PQ%aU3wTxeVN?~EvM1sWdHj4it=~sJuD{GMqat7YkmIx393_sZE21b8i z`g9NDxECxElm8vb88II!xgtr37^tU8BT3E?Pi=71UXTqD%j{0pdZ*T3^x8Jd!v9n; z#BpEHKRwht^}IRL5_2E_0oe3%R=>yvo#%e^^U|n45?@d}{}b5EGt%#@B(dPPz0Dhe z5kDtMJh|r8Ki?d&;7D>Dm!uwi&jq$hCv zJ+=cN9q-uZzL&>ID0V9pcYPC!QS%@#m$36VEPT z6VI&P7c;+*pSgVC@ipDXygm{yiiyF;JjqS$$71|j-d^??`I#->E;|Iy8RpD43{DL5 z{!C2GAuqFE_4rSUq30W7&Vh&8Z%Ti)_RocZQ#)_>g*eoXFZ4;yFTFqHyDj_Gd|wFz zCm(NrR~+);3v*^4?s@;FV#$BsW8i`R@cpa_!v68{f*b=Xk= diff --git a/Assets/Shaders/TestCube_FS.shshaderb.shmeta b/Assets/Shaders/TestCube_FS.shshaderb.shmeta index 0e7e4bda..42f270af 100644 --- a/Assets/Shaders/TestCube_FS.shshaderb.shmeta +++ b/Assets/Shaders/TestCube_FS.shshaderb.shmeta @@ -1,3 +1,3 @@ Name: TestCube_FS -ID: 47024851 +ID: 37450402 Type: 2 diff --git a/Assets/Shaders/TestCube_VS.glsl b/Assets/Shaders/TestCube_VS.glsl index 49f107dd..7b58d1cf 100644 --- a/Assets/Shaders/TestCube_VS.glsl +++ b/Assets/Shaders/TestCube_VS.glsl @@ -14,14 +14,13 @@ layout(location = 8) in uvec2 integerData; layout(location = 0) out struct { - vec4 vertPos; // location 0 + vec4 vertColor; // location 0 vec2 uv; // location = 1 - vec4 normal; // location = 2 } Out; // material stuff -layout(location = 3) out struct +layout(location = 2) out struct { int materialIndex; uint eid; @@ -37,14 +36,10 @@ layout(set = 2, binding = 0) uniform CameraData void main() { - + Out.uv = aUV; Out2.materialIndex = gl_InstanceIndex; Out2.eid = integerData[0]; Out2.lightLayerIndex = integerData[1]; - - Out.vertPos = worldTransform * vec4(aVertexPos, 1.0f); - Out.uv = aUV; - Out.normal.rgb = mat3(transpose(inverse(worldTransform))) * aNormal.rgb; - Out.normal.rgb = normalize (Out.normal.rgb); gl_Position = cameraData.vpMat * worldTransform * vec4 (aVertexPos, 1.0f); + Out.vertColor = vec4 (aVertexPos, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/TestCube_VS.shshaderb b/Assets/Shaders/TestCube_VS.shshaderb index 03e23af37451b6c4c0791110541c7b6e31d07bbe..e070a9a6e4478efc121bc03a322dd966e0b786cd 100644 GIT binary patch literal 2501 zcmZ9M+foxj5QYZ`LB$iIf{GYGMFsJEL_q}&XaFsc+tgID;#Mu2)MmlMm9L=B`rQnNp(&C-GBG=O!ube_hI8!U+>g_F+JvpIcC-~lNmC-vKTXH%5JaLHfwX8 zv^jVG!EGqVO`l`JIiVk`B-yoLj6NvAdRB5ya!E2Lc_euzsY%u(efsrk|D!}DRZy+f zs~a2D+Ut6w-L7}iZ&6T>!Z@fm!z5^=;eG(`P=Oc5jcBh~B=n0>tfgOPg%3Xaw zNYbTN)Jk-ISrKr!&)&W<#Bhg=z0~R4#eUp&`f2H`vKcU5-?eFwgf?1@o55G-D>)ze zg0R`;a@Q!_`JC45w;;*b)XO{Rth?HD#(;aXov6MVcTyWS0-sjCe)pDPoCZ5VvTRc; zOWDjSPW<;lvaMUW5@gNnf9N^AL?fJa=SvzO<64 zxs}+s^Qo2WW?bgUX4lpov6b9>*>zED)LCg`RDh~Y}2WWxmF_>Dw^aRXX zfSF@rW^&9-<3A)>(J8ze3l7WM$cK&H+sKKHxAZo2Y|L&|9^VK2{_UpZW37mVjhy`s zXB;q`lLu`2z@3e}#Q8h%&XWi5gfNRc^XA+!tEuF^T`&uOO?&Z;cxNzo8P+MBGa&>< zKP#=Qy&@S=JavJ|59TewaL0xDCgEVO2p`c-F6{F;_V0K`_^9J$?=q9)W3urs#2?Rf z@(~ZF@7_Noo&5O8H>|xPVU6ph`QAALd*&;Nm&M>CCz#nGkFQ}wI*S@cwR0YM;Debh zU&96I#Ny{oE^6m2-h_DG7cO?jarBzrGKXO7#NW|Q4cLhXGoSw6_j29y z9|}_=7(SSJ#m2im)lS`sgkM2w8 z8)uM%{ydOi_xQ1Ndi6^&_@7ANV24AGo=fP@2XW}lVs6vcwY|t~^uY68<~I8AUfrXA zuO!63kl?4!Kb05Xl7#c&a0mMSTEgu5w+6%WwY`yEtgR}HjpgfDk&dlc+iGqr*7jC5 Y;^E_`Hebg(>CA|)0}TJ4vObpl2LeRA7XSbN literal 3305 zcmZ9O`*svX5XL*%OOODH$VJ7to1mi6cmqU{OUz{xS+a`>@y^=p4$J85Y|iW?f`9o6 z`ba*BkKsR@4h2Rrrc3?+>LX{opjSeoSSv^ zY;U!<+e?#luypD2M^H|`ccVo$t#k#Bo`&`OFomVOYTb`R`fTm z{U0T&Dyr4)wK|^n)NtyW@$lYKBqE{=qX2wZ!9O z)dI%avqGfPM{sI6*t_FX?ZkWS{Zc#_v*&kwJPcxJu2sC} zoOEi!<~?U6i-pZB<7Y70jc=e;hS{1$&+Ix%O&Y-mTQrCI2_GxmI86HC7qw8H_pc@zF6X~Z@q*jKc} zrDo!>`Ch>Af36)qe(JrUowLB~ymjfu-zGbHl;(yfM$aH#^|F$&?3}5cA zx}T+U2Hz&qGs}0%+%xMp6oCx~KQnh$!dxk$};B(h^CCm>t@AiR&`M9eZ8rnaUfUykYKN?{4#;}hI zj6QXBo2GXD0VWkl>@ zyW2JC-0hfNh`W9%p=NU7+bMc*T{=GQLTxuCV62XQ$>_^12{^(c4|lbgW$DC#Tg+F| z!4Vd|a?FZsV!$kBRXRArvY4*!z_+y~xg{YtTzj{c^mPgSrQQt*T<~SZ^4)zcpW0a;_gT%jv9%B2WD{{=@z#o-Qv2^iR0eH!2`27xGUY_ zxL;HDHxh8`({_P@v#d|NHTT~sur=*)t)_d@EqA#GyTXZKQ4>5ci~Cl(#g%*Top3vg zICx+d_kAg@+=CyAIO_pCFnaJndtc%u%(l(*puo)zWM7p0tr+I}p#%=N&Bai9`FnmO z8;oV|5lRQ6hlc%HVAN;d^Ka6LhmXJfJx8)RACA4_NIJjCvl4oP4ezN=x+?h}iWKt; diff --git a/Assets/Shaders/TestCube_VS.shshaderb.shmeta b/Assets/Shaders/TestCube_VS.shshaderb.shmeta index ad3a1725..b133437b 100644 --- a/Assets/Shaders/TestCube_VS.shshaderb.shmeta +++ b/Assets/Shaders/TestCube_VS.shshaderb.shmeta @@ -1,3 +1,3 @@ Name: TestCube_VS -ID: 40523220 +ID: 41688429 Type: 2 diff --git a/Assets/TD_Checker_Base_Color.shtex.shmeta b/Assets/TD_Checker_Base_Color.shtex.shmeta index c25ba444..8c0d5b77 100644 --- a/Assets/TD_Checker_Base_Color.shtex.shmeta +++ b/Assets/TD_Checker_Base_Color.shtex.shmeta @@ -1,3 +1,3 @@ Name: TD_Checker_Base_Color -ID: 55706287 +ID: 51995224 Type: 3 From b46b6b0b85fd959e8cd3797c6f6a0415a0b7e0ec Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 30 Oct 2022 00:25:49 +0800 Subject: [PATCH 21/22] CompileAll uncommented and asset manager metadata writes commented SHmeta files should now be identical to what's on main Shaders themselves have some changes (binaries also updated) --- Assets/Shaders/Kirsch_CS.shshaderb | Bin 5909 -> 5909 bytes Assets/Shaders/PureCopy_CS.shshaderb | Bin 1273 -> 1273 bytes Assets/Shaders/TestCube_FS.glsl | 21 +++++++++++---------- Assets/Shaders/TestCube_FS.shshaderb | Bin 2309 -> 2545 bytes Assets/Shaders/TestCube_VS.glsl | 13 +++++++++---- Assets/Shaders/TestCube_VS.shshaderb | Bin 2501 -> 3305 bytes SHADE_Engine/src/Assets/SHAssetManager.cpp | 6 +++--- 7 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Assets/Shaders/Kirsch_CS.shshaderb b/Assets/Shaders/Kirsch_CS.shshaderb index 4c54946c91f269b181aa2869965af1861c3cd8c5..6219d9a9c9a9e8ae16a498e700cba315f72f58b8 100644 GIT binary patch delta 10 RcmbQLH&u_3X(OYEH~F(3Bt>>?qn%YN}jvCW4bLNEkZVH(*=7^0nyt+rDGIn`tpSpa<95XZZ`QBh_usp8P<<%S4 zNqy3^>l?^@${aTxNq8@DISxuXAwDa&dzthBZ&H0GHSb#$sXh}V92 z5RdIBDU-^^t`a`&Vt z_u}6sN#>q7TgpF&zxU`-Z?F*$N27RL9b`7nTyEpkmAc98Tkfj!_&Apjvq{f6(`BS#1_$VVxRdj+6ZtG0Y@a*-2(}s$I{ruZ-Nu zOsBqaZ8P5_+qP+eziZx>UD>DAq_mpY6q}d)KB+d#Vzi!ANnHyVG%T{Bl$_CvfKiJ- z-)9eG9>!Bwl8ttg2F50ATO}2Bl_QeWUAA;d#)WFtQ3?IygHnnR(a)l!uT6H_yo*Cb zJwe~|`9eX=4PQ%aU3wTxeVN?~EvM1sWdHj4it=~sJuD{GMqat7YkmIx393_sZE21b8i z`g9NDxECxElm8vb88II!xgtr37^tU8BT3E?Pi=71UXTqD%j{0pdZ*T3^x8Jd!v9n; z#BpEHKRwht^}IRL5_2E_0oe3%R=>yvo#%e^^U|n45?@d}{}b5EGt%#@B(dPPz0Dhe z5kDtMJh|r8Ki?d&;7D>Dm!uwi&jq$hCv zJ+=cN9q-uZzL&>ID0V9pcYPC!QS%@#m$36VEPT z6VI&P7c;+*pSgVC@ipDXygm{yiiyF;JjqS$$71|j-d^??`I#->E;|Iy8RpD43{DL5 z{!C2GAuqFE_4rSUq30W7&Vh&8Z%Ti)_RocZQ#)_>g*eoXFZ4;yFTFqHyDj_Gd|wFz zCm(NrR~+);3v*^4?s@;FV#$BsW8i`R@cpa_!v68{f*b=Xk= literal 2309 zcmZ9MOLG%P5XUFzfiVFL4v+*8GUge;A&wy=JOy?MSBbIa4?u=O&SG&9a-P6xm&HOuMic{M+zu%ZI%(OXVmP^PSHT#5^g8%VV z$^Z2HFY#$JWj5AdL@TeJM*}hkXPqRz8N(b$gSEY58- z-iik{i-xb?+I~L%)JGkQ#h=FcdNv#_$9b&jHnf}a^!??gCIrT8{ry$;fmiTn zc5yP=iYpi!d2JO`r=b|L;>u++7bhgNS?;KW7}z)iiqN5_qz8PF>5V$D zaqo8(gM7XsU)YoD#Vo7yV4mpoN6e1bi8-st@Hxe!9^?~}=%+0@DSy6ebiR$Y{`0eh zFZdm=vjebiw2f(T{K;26K|dwWgEHWEM)H^9=)^uG&H*DfI1*kZ;774xqn%lT;SwK z=l43~|IW+7pLa_vVuX5bdW?9tyi88?yW-57euvX=dc&EpfQ> zkC29VNB^14X%X{c?)T)$9L|WqJF1fTv_APTi(3w;uE(c443 zAEkdDZ%G(9@z~8zq7V-oyQ44mbz6jeUB1Ns*<;{=KKOoq5k`J|-h1qhWctK*U)$n4 r2ctgr{6Iu~VNUG)p$Hs*-UWK_e@y^=p4$J85Y|iW?f`9o6 z`ba*BkKsR@4h2Rrrc3?+>LX{opjSeoSSv^ zY;U!<+e?#luypD2M^H|`ccVo$t#k#Bo`&`OFomVOYTb`R`fTm z{U0T&Dyr4)wK|^n)NtyW@$lYKBqE{=qX2wZ!9O z)dI%avqGfPM{sI6*t_FX?ZkWS{Zc#_v*&kwJPcxJu2sC} zoOEi!<~?U6i-pZB<7Y70jc=e;hS{1$&+Ix%O&Y-mTQrCI2_GxmI86HC7qw8H_pc@zF6X~Z@q*jKc} zrDo!>`Ch>Af36)qe(JrUowLB~ymjfu-zGbHl;(yfM$aH#^|F$&?3}5cA zx}T+U2Hz&qGs}0%+%xMp6oCx~KQnh$!dxk$};B(h^CCm>t@AiR&`M9eZ8rnaUfUykYKN?{4#;}hI zj6QXBo2GXD0VWkl>@ zyW2JC-0hfNh`W9%p=NU7+bMc*T{=GQLTxuCV62XQ$>_^12{^(c4|lbgW$DC#Tg+F| z!4Vd|a?FZsV!$kBRXRArvY4*!z_+y~xg{YtTzj{c^mPgSrQQt*T<~SZ^4)zcpW0a;_gT%jv9%B2WD{{=@z#o-Qv2^iR0eH!2`27xGUY_ zxL;HDHxh8`({_P@v#d|NHTT~sur=*)t)_d@EqA#GyTXZKQ4>5ci~Cl(#g%*Top3vg zICx+d_kAg@+=CyAIO_pCFnaJndtc%u%(l(*puo)zWM7p0tr+I}p#%=N&Bai9`FnmO z8;oV|5lRQ6hlc%HVAN;d^Ka6LhmXJfJx8)RACA4_NIJjCvl4oP4ezN=x+?h}iWKt; literal 2501 zcmZ9M+foxj5QYZ`LB$iIf{GYGMFsJEL_q}&XaFsc+tgID;#Mu2)MmlMm9L=B`rQnNp(&C-GBG=O!ube_hI8!U+>g_F+JvpIcC-~lNmC-vKTXH%5JaLHfwX8 zv^jVG!EGqVO`l`JIiVk`B-yoLj6NvAdRB5ya!E2Lc_euzsY%u(efsrk|D!}DRZy+f zs~a2D+Ut6w-L7}iZ&6T>!Z@fm!z5^=;eG(`P=Oc5jcBh~B=n0>tfgOPg%3Xaw zNYbTN)Jk-ISrKr!&)&W<#Bhg=z0~R4#eUp&`f2H`vKcU5-?eFwgf?1@o55G-D>)ze zg0R`;a@Q!_`JC45w;;*b)XO{Rth?HD#(;aXov6MVcTyWS0-sjCe)pDPoCZ5VvTRc; zOWDjSPW<;lvaMUW5@gNnf9N^AL?fJa=SvzO<64 zxs}+s^Qo2WW?bgUX4lpov6b9>*>zED)LCg`RDh~Y}2WWxmF_>Dw^aRXX zfSF@rW^&9-<3A)>(J8ze3l7WM$cK&H+sKKHxAZo2Y|L&|9^VK2{_UpZW37mVjhy`s zXB;q`lLu`2z@3e}#Q8h%&XWi5gfNRc^XA+!tEuF^T`&uOO?&Z;cxNzo8P+MBGa&>< zKP#=Qy&@S=JavJ|59TewaL0xDCgEVO2p`c-F6{F;_V0K`_^9J$?=q9)W3urs#2?Rf z@(~ZF@7_Noo&5O8H>|xPVU6ph`QAALd*&;Nm&M>CCz#nGkFQ}wI*S@cwR0YM;Debh zU&96I#Ny{oE^6m2-h_DG7cO?jarBzrGKXO7#NW|Q4cLhXGoSw6_j29y z9|}_=7(SSJ#m2im)lS`sgkM2w8 z8)uM%{ydOi_xQ1Ndi6^&_@7ANV24AGo=fP@2XW}lVs6vcwY|t~^uY68<~I8AUfrXA zuO!63kl?4!Kb05Xl7#c&a0mMSTEgu5w+6%WwY`yEtgR}HjpgfDk&dlc+iGqr*7jC5 Y;^E_`Hebg(>CA|)0}TJ4vObpl2LeRA7XSbN diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 228f3fdc..76b68e50 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -349,13 +349,13 @@ namespace SHADE meshAsset.id = GenerateAssetID(AssetType::MESH); meshAsset.type = AssetType::MESH; assetCollection.push_back(meshAsset); - SHAssetMetaHandler::WriteMetaData(meshAsset); + //SHAssetMetaHandler::WriteMetaData(meshAsset); } continue; } assetCollection.push_back(newAsset); - SHAssetMetaHandler::WriteMetaData(newAsset); + //SHAssetMetaHandler::WriteMetaData(newAsset); } } @@ -372,7 +372,7 @@ namespace SHADE ****************************************************************************/ void SHAssetManager::Load() noexcept { - //CompileAll(); + CompileAll(); InitLoaders(); BuildAssetCollection(); //LoadAllData(); From da05cb3edc82390865a783a978488178024ac86b Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 30 Oct 2022 02:37:58 +0800 Subject: [PATCH 22/22] Fixed script error and added support for static functions in CallbackAction --- SHADE_CSharp/src/Events/CallbackAction.cs | 268 ++++++++++++++++++---- SHADE_CSharp/src/Events/CallbackAction.tt | 27 ++- SHADE_Managed/src/Components/Collider.hxx | 2 +- TempScriptsFolder/PhysicsTest.cs | 2 +- 4 files changed, 243 insertions(+), 56 deletions(-) diff --git a/SHADE_CSharp/src/Events/CallbackAction.cs b/SHADE_CSharp/src/Events/CallbackAction.cs index 968302ed..623e4f59 100644 --- a/SHADE_CSharp/src/Events/CallbackAction.cs +++ b/SHADE_CSharp/src/Events/CallbackAction.cs @@ -61,8 +61,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[1]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -86,7 +103,7 @@ namespace SHADE /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -103,7 +120,7 @@ namespace SHADE { targetAction.Invoke(t1); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; _ = targetMethod.Invoke(TargetObject, parameters); @@ -138,8 +155,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[2]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -158,12 +192,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[2]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -180,7 +214,7 @@ namespace SHADE { targetAction.Invoke(t1, t2); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; parameters[1] = t2; @@ -216,8 +250,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[3]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -236,12 +287,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[3]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -258,7 +309,7 @@ namespace SHADE { targetAction.Invoke(t1, t2, t3); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; parameters[1] = t2; @@ -295,8 +346,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[4]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -315,12 +383,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[4]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -337,7 +405,7 @@ namespace SHADE { targetAction.Invoke(t1, t2, t3, t4); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; parameters[1] = t2; @@ -375,8 +443,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[5]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -395,12 +480,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[5]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -417,7 +502,7 @@ namespace SHADE { targetAction.Invoke(t1, t2, t3, t4, t5); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; parameters[1] = t2; @@ -456,8 +541,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[6]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -476,12 +578,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[6]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -498,7 +600,7 @@ namespace SHADE { targetAction.Invoke(t1, t2, t3, t4, t5, t6); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; parameters[1] = t2; @@ -538,8 +640,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[7]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -558,12 +677,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[7]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -580,7 +699,7 @@ namespace SHADE { targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; parameters[1] = t2; @@ -621,8 +740,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[8]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -641,12 +777,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[8]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -663,7 +799,7 @@ namespace SHADE { targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; parameters[1] = t2; @@ -705,8 +841,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[9]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -725,12 +878,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[9]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -747,7 +900,7 @@ namespace SHADE { targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8, t9); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; parameters[1] = t2; @@ -790,8 +943,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[10]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -810,12 +980,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[10]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action action) { targetAction = action; @@ -832,7 +1002,7 @@ namespace SHADE { targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { parameters[0] = t1; parameters[1] = t2; diff --git a/SHADE_CSharp/src/Events/CallbackAction.tt b/SHADE_CSharp/src/Events/CallbackAction.tt index fffd4251..34789b67 100644 --- a/SHADE_CSharp/src/Events/CallbackAction.tt +++ b/SHADE_CSharp/src/Events/CallbackAction.tt @@ -78,8 +78,25 @@ namespace SHADE /// public CallbackAction() {} /// - /// Constructs a CallbackAction that represents a call to the specified method on the - /// specified target. + /// Constructs a CallbackAction that represents a call to the specified static + /// method. + /// + /// Method to call. + /// + /// Thrown if a method that is not compatible with the target is specified. The method's + /// source type must match the target's type. + /// + public CallbackAction(MethodInfo method) + { + // No errors, assign + targetMethod = method; + + // Create storage for parameters for calling + parameters = new Object[<#=i#>]; + } + /// + /// Constructs a CallbackAction that represents a call to a specified member + /// method on the specified target. /// /// Object to call the method on. /// Method to call. @@ -98,12 +115,12 @@ namespace SHADE targetMethod = method; // Create storage for parameters for calling - parameters = new Object[1]; + parameters = new Object[<#=i#>]; } /// /// Constructs a Callback action based on an action. /// - /// + /// Action that wraps a function to be called. public CallbackAction(Action<<# for (int t = 1; t < i + 1; ++t) { #>T<#=t#><# if (t != i) { #>, <# } #><# } #>> action) { targetAction = action; @@ -120,7 +137,7 @@ namespace SHADE { targetAction.Invoke(<# for (int t = 1; t < i + 1; ++t) { #>t<#=t#><# if (t != i) { #>, <# } #><# } #>); } - else if (TargetObject != null && targetMethod != null) + else if (targetMethod != null) { <# for (int t = 0; t < i; ++t) {#>parameters[<#=t#>] = t<#=t+1#>; <# } #>_ = targetMethod.Invoke(TargetObject, parameters); diff --git a/SHADE_Managed/src/Components/Collider.hxx b/SHADE_Managed/src/Components/Collider.hxx index 1d1196f5..dc17ae7f 100644 --- a/SHADE_Managed/src/Components/Collider.hxx +++ b/SHADE_Managed/src/Components/Collider.hxx @@ -194,7 +194,7 @@ namespace SHADE /* Properties */ /*-----------------------------------------------------------------------------*/ /// - /// Total number of ColliderBounds in the Collider component. + /// Total number of ColliderShapes in the Collider component. /// property int CollisionShapeCount { diff --git a/TempScriptsFolder/PhysicsTest.cs b/TempScriptsFolder/PhysicsTest.cs index 6f9774c9..add5971d 100644 --- a/TempScriptsFolder/PhysicsTest.cs +++ b/TempScriptsFolder/PhysicsTest.cs @@ -28,7 +28,7 @@ public class PhysicsTest : Script Debug.LogError("Collider is NULL!"); } - var subColider = Collider.ColliderBoundsCount; + var subColider = Collider.CollisionShapeCount; Debug.Log($"There are {subColider} colliders."); } protected override void update()